WM_CTLCOLORBTN跟wm_erasebkgnd

WM_CTLCOLORBTN和wm_erasebkgnd
1.OnCtlColor只能修改元素的颜色,但不能修改元素的界面框架,WM_DRAWITEM则可以。

什么意思?

什么是元素的界面框架?那些算是元素。

用一个按钮的自绘举例。谢谢



第二:
WM_CTLCOLORBTN 和wm_erasebkgnd的关系

case WM_CTLCOLORBTN:
{

SetTextColor((HDC)wParam,RGB(100,0,0)); //文字前景
SetBkColor((HDC)wParam,RGB(0,0,255)); //文字背景
// HFONT hOldFont=(HFONT)SelectObject((HDC)wParam,(HGDIOBJ)&hFont);

//SelectObject((HDC)wParam,hOldFont);

return (LRESULT)GetStockObject(GRAY_BRUSH);   //据说这一句是在文字前景,文字背景,设置完后,再次发出一个wm_erase消息进行填充剩余区域的背景。所谓剩余区域指的是:

出去文字所在的区域
}


------最佳解决方案--------------------
“只能修改元素的颜色,但不能修改元素的界面框架'

就是只能修改元素客户区的颜色,但不能修改元素的边框frame   
------其他解决方案--------------------
1. 按钮自绘,重新CButton类,添加处理虚函数DrawItem
2. 
The WM_CTLCOLORBTN message is sent to the parent window of a button before drawing the button. The parent window can change the button's text and background colors. However, only owner-drawn buttons respond to the parent window processing this message. 

The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting. 


------其他解决方案--------------------
引用:
“只能修改元素的颜色,但不能修改元素的界面框架'

就是只能修改元素客户区的颜色,但不能修改元素的边框frame


wm_ctlcolorbtn

返回刷子,刷子刷按钮的背景, 边框不就改变。。。发截图给你




贴部分代码:

	case WM_DRAWITEM:
{
TCHAR buf[]=_T("hello");
RECT rect;

  if(((LPDRAWITEMSTRUCT)lParam)->CtlID==IDC_BUTTON1)
  {

   GetClientRect( (LPDRAWITEMSTRUCT(lParam))->hwndItem,&rect);
//TextOut( ((LPDRAWITEMSTRUCT)lParam)->hDC, 10,10, buf,_tcslen(buf));
DrawText(((LPDRAWITEMSTRUCT)lParam)->hDC,buf,_tcslen(buf),&rect,DT_CENTER);

}

  return 0;
}

break;
case WM_CTLCOLORBTN:
{

SetTextColor((HDC)wParam,RGB(100,0,0)); //文字前景
SetBkColor((HDC)wParam,RGB(0,0,255)); //文字背景
// HFONT hOldFont=(HFONT)SelectObject((HDC)wParam,(HGDIOBJ)&hFont);

//SelectObject((HDC)wParam,hOldFont);

return (LRESULT)GetStockObject(GRAY_BRUSH);  
}



由此可见 “能修改元素的界面框架,WM_DRAWITEM则可以。”不对,

wm_ctlcolor也可以啊



------其他解决方案--------------------
引用:
1. 按钮自绘,重新CButton类,添加处理虚函数DrawItem
2. 
The WM_CTLCOLORBTN message is sent to the parent window of a button before drawing the button. The parent window can change the button's text and ……


wm_erasebkgnd-----  wm_paint------- wm_ctlcolor----- wm-drawtiem



------其他解决方案--------------------