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

VC常见入门问题总结(三)(4)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
11.如何改变窗口标题 调用CWnd : : SetWindowText可以改变任何窗口(包括控件)的标题。 //Set title for applications main frame window . AfxGetMainWnd ( ) ― SetWindowText (_T(

11.如何改变窗口标题

  调用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 );

  }

}

11.如何防止主框窗口在其说明中显示活动的文档名

  创建主框窗口和MDI子窗口进通常具有FWS_ADDTOTITLE风格位, 如果不希望在说明中自动添加文档名, 必  须禁止该风格位, 可以使用ClassWizard重置CWnd: : PreCreateWindow并关闭FWS_ADDTOTITLE风格。

  BOOL CMainFrame : : PreCreateWindow (CREATESTRUCT&cs)

{

  //Turn off FWS_ADDTOTITLE in main frame .

  cs.styel & = ~FWS_ADDTOTITLE ; 

  return CMDIFrameWnd : : PreCreateWindow (cs );

}

  关闭MDI子窗口的FWS _ADDTOTITLE风格将创建一个具有空标题的窗口,可以调用CWnd: : SetWindowText来 设置标题。记住自己设置标题时要遵循接口风格指南。

12.如何获取有关窗口正在处理的当前消息的信息

  调用CWnd: : GetCurrentMessage可以获取一个MSG指针。例如,可以使用ClassWizard将几个菜单项处理程 序映射到一个函数中,然后调用GetCurrentMessage来确定所选中的菜单项。

viod CMainFrame : : OnCommmonMenuHandler ( )

{

  //Display selected menu item in debug window .

  TRACE ("Menu item %u was selected . " ,

                 GetCruuentMessage ( ) ―> wParam );

}

精彩图集

赞助商链接