自定义按钮

首先创建一个基于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);

}

 

 

旋转文字的制作

实例:
void CAssDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 CDC* pDC=GetDC();
 CFont m_Font;
 pDC->SetBkMode(TRANSPARENT);
 CRect m_rect;
 GetClientRect(m_rect);
 pDC->FillRect(m_rect,NULL);
 pDC->SetViewportOrg(m_rect.Width()/2,m_rect.Height()/2);
 for(int i=1;i<360;i+=5)
 {
  m_Font.CreateFont(-14,-10,i*10,0,600,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_ROMAN,"微软雅黑");
  pDC->SelectObject(&m_Font);
  pDC->SetTextColor(RGB(255-i,i*50,i));
  pDC->TextOut(0,0,"明日科技有限公司");
  m_Font.DeleteObject();
 }
}

 

 

晃动窗体 方法:获取窗体和鼠标的位置,然后调用MoveWindow方法实现。

实例:

void CTEMPDlg::OnRoct()

{  // TODO: Add your control notification handler code here  CRect rect;

   this->GetWindowRect(&rect);

   int off=10;

   for(int i=0;i<20;i++)

   {  

     rect.OffsetRect(off,0);

      this->MoveWindow(&rect,true);

      if(off==-10)    off=10;  

     else    off=-10;   

    ::Sleep(30);  

  }

}

 

 

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3