if you use MFC OnPaint() be called by Frame(框架)if you overload the OnPaint() then OnDraw() must be called in OnPaint() by yourself控件必须设置成自绘制,OnDrawItem()才会起作用
The framework calls OnDrawItem() function for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed. then the DrawItem virtual function of the appropriate class is called.
自绘控件时调用OnDrawItem()就可以了,不用重载OnPaint()吧。 The WM_PAINT message is sent <when the system or another application makes a request to paint a portion of an application's window>. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function. The WM_DRAWITEM message is sent to the owner window of an owner-drawn button, combo box, list box, or menu when <a visual aspect of the button, combo box, list box, or menu has changed>. 我觉得两个消息的区别就在我打了<>的地方。当后者被发送时前者就不用理会了,windows(或mfc)会自己打点好的。
OnPaint调用DrawItem,DrawItem用法如下:void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { UINT uStyle = DFCS_BUTTONPUSH; // This code only works with buttons. ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); // If drawing selected, add the pushed style to DrawFrameControl. if (lpDrawItemStruct->itemState & ODS_SELECTED) uStyle |= DFCS_PUSHED; // Draw the button frame. ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, DFC_BUTTON, uStyle); // Get the button's text. CString strText; GetWindowText(strText); // Draw the button text using the text color red. COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0)); ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER); ::SetTextColor(lpDrawItemStruct->hDC, crOldColor); }
OnPaint() be called by Frame(框架)if you overload the OnPaint() then OnDraw() must be called in OnPaint() by yourself控件必须设置成自绘制,OnDrawItem()才会起作用
我在onpaint()里给控件画背景,但是我发现重载
onpaint()以后,在drawitem里画的东西就不显示了
这是怎么回事?还有顺便问一下ondrawitem()和drawitem()有什么区别?
这个问题再解决了马上分分
then the DrawItem virtual function of the appropriate class is called.
The WM_PAINT message is sent <when the system or another application makes a request to paint a portion of an application's window>. The message is sent when the UpdateWindow or RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.
The WM_DRAWITEM message is sent to the owner window of an owner-drawn button, combo box, list box, or menu when <a visual aspect of the button, combo box, list box, or menu has changed>.
我觉得两个消息的区别就在我打了<>的地方。当后者被发送时前者就不用理会了,windows(或mfc)会自己打点好的。
OnDrawItem是控件中的某某数据项需要刷新时用的
{
UINT uStyle = DFCS_BUTTONPUSH; // This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); // If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED; // Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle); // Get the button's text.
CString strText;
GetWindowText(strText); // Draw the button text using the text color red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
msdn上好象是说cdialog的paint就相当于cview的ondraw,这样理解对不对还有我现在不能给分是怎么回事?
"贴子回复次数大于跟给分次数 "
msdn上好象是说cdialog的paint就相当于cview的ondraw,这样理解对不对还有我现在不能给分是怎么回事?
"贴子回复次数大于跟给分次数 "
Onpaint()中用CPaintDC;
CPaintDC的构造函数调用BeginPaint 解构函数Endpaint()
防止WM_PAINT不断发出
OnPaint()是WM_PAINT的消息处理函数