目前我正在开发一些自定义控件,我目前面临的问题是我不知道如何检测我的自定义控件何时需要重绘。
我WM_PAINT
用来画一切,所以我依靠RedrawWindow()
功能。但是,当我的自定义控件移出绘图区域然后返回时,它不会重绘。我尝试捕捉WM_NCPAINT
效果很好,但是WM_PAINT
每次我在父窗口内移动鼠标时它都会发送消息。
所以我的问题是 - 如何检测子窗口回到绘图区域后何时重绘?
以下是我的代码CALLBACK
:
LRESULT CALLBACK WinMsgHandler(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
settings.TrackingEvent.hwndTrack = hWnd;
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
switch (settings.CurrentState)
{
case cctrl_UNSELECTED_HOVER:
On_UnselectedHover(&hdc, &ps.rcPaint);
break;
case cctrl_UNSELECTED:
On_Unselected(&hdc, &ps.rcPaint);
break;
case cctrl_SELECTED_HOVER:
On_SelectedHover(&hdc, &ps.rcPaint);
break;
case cctrl_SELECTED:
On_Selected(&hdc, &ps.rcPaint);
break;
case cctrl_3STATE_HOVER:
On_IntermediateHover(&hdc, &ps.rcPaint);
break;
case cctrl_3STATE:
On_Intermediate(&hdc, &ps.rcPaint);
break;
default:
break;
}
EndPaint(hWnd, &ps);
}
break;
case WM_NCPAINT:
RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_FRAME
| RDW_INVALIDATE | RDW_ALLCHILDREN);
break;
case WM_MOUSEMOVE:
On_MouseMove();
break;
case WM_MOUSEHOVER:
On_MouseHover();
break;
case WM_MOUSELEAVE:
On_MouseLeave();
break;
case WM_LBUTTONDOWN:
On_LButtonDown();
break;
case WM_LBUTTONUP:
On_LButtonUp();
break;
case WM_DESTROY:
OnDestroy();
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}