question

JaveneCppMcGowan-4589 avatar image
0 Votes"
JaveneCppMcGowan-4589 asked XiaopoYang-MSFT commented

Understanding win32 standard scrollbars on windows xp and windows 7

Greetings, this is my first time asking a question here.

I am implementing a text field from scratch, that will allow auto suggestions on individual words in the text field. Win32 Edit Control has an auto suggestion OLE object, but it does auto suggestion on the entire text. So that is why I must create my own text field.

My only problem now is the behaviour of the scrollbar. I want the scrollbar to be hidden when the text field is 1 character in height. I have tried handling WM_NCCALCSIZE and WM_NCPAINT.

     //Here I attempt to draw a 4 sided red margin around the text
     if(msg == WM_NCPAINT)
     {
      HDC ctx = GetWindowDC(hwnd);
      GetWindowRect(hwnd,&m_nc_rect);
      m_nc_rect.right -= m_nc_rect.left;
      m_nc_rect.bottom -= m_nc_rect.top;
      m_nc_rect.left = m_nc_rect.top = 0;
      fillRect(ctx,&m_nc_rect,RGB(255,0,0));
      //FrameRect(ctx,&m_nc_rect,GetStockBrush(BLACK_BRUSH));
      //DefWindowProc(hwnd,msg,wparam,lparam);
      ReleaseDC(hwnd,ctx);
      return 0;
     }
    
     //Here I attempt to size the non-client area
     if(msg == WM_NCCALCSIZE)
     {
         if(wparam)
         {
          RECT *rect = (RECT*)lparam;
          rect->left += 4;
          rect->top += 4;
          rect->right -= 4;
          rect->bottom -= 4;
         }
         else
         {
          NCCALCSIZE_PARAMS *param = (NCCALCSIZE_PARAMS*)lparam;
          param->rgrc->left += 4;
          param->rgrc->top += 4;
          param->rgrc->right -= 4;
          param->rgrc->bottom -= 4;
         }
    
         return 0;
     }


On Windows 7, this works flawlessly. On Windows Xp, the scrollbar still gets drawn inside the 4 pixel margin. I have tried printing all the messages that is handled, and I see no message where the scrollbar would be drawn. In other words, the scrollbar is drawn without any message being sent.

Please explain to me how I can prevent the standard scrollbar from being drawn. Or is this just a win xp bug that was fixed on Windows 7. Win32 EditControls inside a dialog does not display a scrollbar when they are 1 character height.

Should I avoid setting the scrollbar to avoid the scrollbar being drawn. I use the scrollbar to store the scrolling position, scrolling max size and scrolling page size.

I tried using Scrollbar controls. They work perfectly, except that they don't draw themselves in the non client area.

Finally, trying to do everything in client area seems impossible. I am trying to add a 4 pixel margin, and I dont know how to clip the caret within a certain bounds inside the client area. I tried researching on google, but google doesn't give any links to answers describing this problem.

windows-api
· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Finally, trying to do everything in client area seems impossible. I am trying to add a 4 pixel margin, and I dont know how to clip the caret within a certain bounds inside the client area.

You can add margins with EM_SETRECT
For example, I added a 20, 20 margin and I drew rectangles in the margin in WM_PAINT :

145141-edit-setrect.jpg


0 Votes 0 ·
edit-setrect.jpg (18.0 KiB)

Kindly note that I am not using win32 Edit Control; but rather my own Custom text field.

0 Votes 0 ·

Could you please show a minimal, reproducible sample without private information?

0 Votes 0 ·
Show more comments

Maybe you should show and hide the scrollbar by manipulating the WS_VSCROLL window style.


0 Votes 0 ·

0 Answers