从父窗口设置子控件的光标?

时间:2010-09-21 15:03:33

标签: winapi cursor

如何在没有子类化的情况下从父窗口设置子窗口的游标?

2 个答案:

答案 0 :(得分:1)

WM_SETCURSOR消息会自动传递给父级,因此您可以在那里处理它。如果子控件实际上处理它,那么你将不得不对它进行子类化。或者破解消息循环(哎呀)。

答案 1 :(得分:0)

TCHAR szButtonCoordinates[50];
RECT  rect;
switch (message)
{
...
case WM_MOUSEMOVE:
     hWndButton = GetDlgItem (hWnd, IDC_BUTTON);
     GetClientRect (hWndButton, &rect);
     MapWindowPoints (hWndButton, hWnd, (LPPOINT) &rect, 2);
     // wsprintf (szButtonCoordinates, _T("Top: %d, Left: %d, Bottom: %d, Right: %d."),rect.top, rect.left,  rect.bottom, rect.right);
     if (((LOWORD (lParam) >= rect.left) && (LOWORD (lParam) <= rect.right)) && ((HIWORD (lParam) >=rect.top) && (HIWORD (lParam) <= rect.bottom)))
     {
         //MessageBox (hWndProg3, szButtonCoordinates, _T("Button Coordinates"), MB_ICONINFORMATION);
         SetCursor (LoadCursor (NULL, IDC_CROSS));
      }
      break; 
...
}