WM_NCHITTEST: Sizing Commands Not Working

407 views Asked by At

I have a custom borderless window, and I want to be able to resize it. I have a code that tests for a virtual border, to grab and resize. It worked with Windows 7. But, for some reason, it does not work with Windows 10. Here is the code in WM_NCHITTEST:

case WM_NCHITTEST:
 {
     bool  bLeft = 0, bRight = 0, bTop = 0, bBottom = 0;
     bool bHorz =0, bVert =0;
     RECT rMenu;

     GetWindowRect(hWnd, &rWnd);

     if (LOWORD(lParam) > rWnd.left && LOWORD(lParam) < rWnd.left+4)      bLeft = 1;
     if (LOWORD(lParam) > rWnd.right-4 && LOWORD(lParam) < rWnd.right)    bRight = 1;
     if (HIWORD(lParam) > rWnd.top && HIWORD(lParam) < rWnd.top+4)        bTop = 1;
     if (HIWORD(lParam) > rWnd.bottom-4 && HIWORD(lParam) < rWnd.bottom)  bBottom = 1;

     if (bLeft && bTop)      return HTTOPLEFT;
     if (bRight && bTop)     return HTTOPRIGHT;
     if (bLeft && bBottom)   return HTBOTTOMLEFT;
     if (bRight && bBottom)  return HTBOTTOMRIGHT;

     if (bLeft)    return HTLEFT;
     if (bRight)   return HTRIGHT;
     if (bTop)     return HTTOP;
     if (bBottom)  return HTBOTTOM;

     GetMenuItemRect(hWnd, hMenu, NUMMI, &rMenu);
     if (LOWORD(lParam)>rMenu.right && LOWORD(lParam)<rWnd.right-100)              bHorz = 1;
     if (HIWORD(lParam)>rWnd.top+WFRAME && HIWORD(lParam)<rWnd.top+WFRAME+cyMenu)  bVert = 1;
     if (bHorz && bVert)  return HTCAPTION;

     auto nchResult = DefWindowProc(hWnd, WM_NCHITTEST, wParam, lParam);
     return nchResult;
 }

As I mentioned, this worked great with Win7. But, it somehow doesn't work with Win10. I should also note that the final section, the one returning HTCAPTION, does work. In fact, I can replace any of the sizing commands, HTLEFT, HTTOP, etc, with HTCAPTION, and drag the window around by that border. So, I know that the border testing is accurate. However, none of the sizing commands work. I do not get the double-arrow cursor. Nor, can I drag that border to resize the window.

0

There are 0 answers