WM_DRAWITEM是一般的消息,如果一個按鈕設置了自繪,那麼他會給父窗口發送WM_DRAWITEM,父窗口找到消息處理函數
看源碼:
void CWnd::OnDrawItem(int /*nIDCtl*/, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (lpDrawItemStruct->CtlType == ODT_MENU)
{
CMenu* pMenu = CMenu::FromHandlePermanent(
(HMENU)lpDrawItemStruct->hwndItem);
if (pMenu != NULL)
{
pMenu->DrawItem(lpDrawItemStruct);
return; // eat it
}
}
else
{
// reflect notification to child window control
if (ReflectLastMsg(lpDrawItemStruct->hwndItem))
return; // eat it
}
// not handled - do default
Default();
}
如果發送給父窗口的控件是菜單的話就執行if裏面的代碼,如果不是的話就將消息反射給控件ReflectLastMsg(lpDrawItemStruct->hwndItem)