目前我正在开发一些自定义控件,我目前面临的问题是我不知道如何检测我的自定义控件何时需要重绘。
我使用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;
}