如题,部分代码如下void CMyButton::OnMouseMove(UINT nFlags, CPoint point) 
{
CRect rc;
GetClientRect(&rc);
IsMouseOn=rc.PtInRect(point); //IsMouseOn是BOOL成员变量
//DrawItem();//想触发DrawItem哪知道带有一个参数,就不知道怎么触发了
CButton::OnMouseMove(nFlags, point);
}void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{

CDC dc;
dc.Attach(lpDrawItemStruct->hDC);//得到绘制的设备环境CDC
VERIFY(lpDrawItemStruct->CtlType==ODT_BUTTON);

this->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON1));//设置图标也不成功,但也不报错
const int bufSize = 512;
TCHAR buffer[bufSize];
GetWindowText(buffer, bufSize);

int size=strlen(buffer); //得到长度

if   (IsMouseOn)
{
RECT rc=lpDrawItemStruct->rcItem;
rc.top=rc.top+1;rc.bottom=rc.bottom-1; 
rc.left=rc.left+1;rc.right=rc.right-1;
dc.Draw3dRect(&rc,RGB(255,0,0),RGB(0,0,0));
}还有个小问题,this->SetIcon(AfxGetApp()->LoadIcon(IDI_ICON1));//设置图标也不成功,但也不报错
我想按钮上既有图标又有文字,

解决方案 »

  1.   

    Called by the framework when a visual aspect of an owner-drawn button has changed. An owner-drawn button has the BS_OWNERDRAW style set. Override this member function to implement drawing for an owner-drawn Cbutton object. The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before the method terminates.
      

  2.   

    既然是自绘,那么图标也要自绘,
    pDC->DrawIcon()响应DrawItem,直接Invalidate()
      

  3.   

    没反应dc.DrawIcon(0,0,AfxGetApp()->LoadIcon(IDI_ICON1));
      

  4.   

    响应DrawItem,不用调用这个函数,设置上相应的属性BS_OWNERDRAW,Invalidate一下调用。