龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC实用小知识总结 (一)(5)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
(18) 如何改变视窗的背景颜色 Windows向窗口发送一个WM_ERASEBKGND消息通知该窗口擦除背景,可以使用ClassWizard重载该消息的缺省处理程序来擦除背景(实际

  (18) 如何改变视窗的背景颜色

  Windows向窗口发送一个WM_ERASEBKGND消息通知该窗口擦除背景,可以使用ClassWizard重载该消息的缺省处理程序来擦除背景(实际是画),并返回TRUE以防止Windows擦除窗口。

   //Paint area that needs to be erased.
  BOOL CSampleView : : OnEraseBkgnd (CDC* pDC)
  {
  // Create a pruple brush.
  CBrush Brush (RGB (128 , 0 , 128) )

  // Select the brush into the device context .
  CBrush* pOldBrush = pDC―>SelcetObject (&brush)

  // Get the area that needs to be erased .
  CRect reClip
  pDC―>GetCilpBox (&rcClip)
  //Paint the area.
  pDC―> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height( ) , PATCOPY )

  //Unselect brush out of device context .
  pDC―>SelectObject (pOldBrush )

  // Return nonzero to half fruther processing .
  return TRUE
  } 

  (19) 如何改变窗口标题

  调用CWnd : : SetWindowText可以改变任何窗口(包括控件)的标题。

   //Set title for application's main frame window .
  AfxGetMainWnd ( ) ―> SetWindowText (_T("Application title") )

  //Set title for View's MDI child frame window .
  GetParentFrame ( ) ―> SetWindowText ("_T ("MDI Child Frame new title")
  )

  //Set title for dialog's push button control.
  GetDigitem (IDC_BUTTON) ―> SetWindowText (_T ("Button new title ") ) 

  如果需要经常修改窗口的标题(注:控件也是窗口),应该考虑使用半文档化的函数AfxSetWindowText。该函数在AFXPRIV.H中说明,在WINUTIL.CPP中实现,在联机帮助中找不到它,它在AFXPRIV.H中半文档化, 在以后发行的MFC中将文档化。

  AfxSetWindowText的实现如下:

   voik AFXAPI AfxSetWindowText (HWND hWndCtrl , LPCTSTR IpszNew )
  {
  itn nNewLen= Istrlen (Ipaznew)
  TCHAR szOld [256]
  //fast check to see if text really changes (reduces
  flash in the
  controls )
  if (nNewLen >_contof (szOld)
  || : : GetWindowText (hWndCrtl, szOld , _countof (szOld) !=nNewLen
  || Istrcmp (szOld , IpszNew)! = 0
  {
  //change it
  : : SetWindowText(hWndCtrl , IpszNew )
  }
  } 

收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!
按钮 内容不能为空!
立刻说两句吧! 查看0条评论
精彩图集

赞助商链接