VC++6.0 自定义按钮,无标题对话框的拖动方法

VC++6.0 自定义按钮,无标题对话框的拖动方法

自定义按钮

  首先创建一个基于CButton的CCustomButton类 添加该类的虚函数DrawItem代码如下:

void CCustomButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
  // TODO: Add your code to draw the specified item  CRect rect;
    GetClientRect(rect);  CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);
    int x,y,r;  
    x=rect.Width()/2;
    y=rect.top;  r=rect.Height()/2;
    dc.Ellipse(0,0,rect.Width(),rect.Height());
    dc.DrawText(TEXT(""),rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}

  然后添加一个按钮,修改其属性为OwnerDraw,并为其关联一个CCustomButton的变量。然后就可以实现自定义按钮的绘制了。

无标题对话框的拖动方法

  实例: 为要添加此方法的对话框添加WM_LBUTTONDOWN消息函数中发送WM_SYSCOMMAND消息,代码如下:

void CLkDlg::OnLButtonDown(UINT nFlags, CPoint point)
{  
    // TODO: Add your message handler code here and/or call default
    // ::SendMessage();
    ::SendMessage(GetSafeHwnd(),WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0);
    CDialog::OnLButtonDown(nFlags, point);
}
原文地址:https://www.cnblogs.com/Dageking/p/2978694.html