⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 visual c++编程技巧之三.htm

📁 载之“阿蒙编程乐园”
💻 HTM
📖 第 1 页 / 共 2 页
字号:
face="Times New Roman">&gt; PostMessage (</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>WM_NCLBUTTONDOWN , HTCAPTION , 
MAKELPARAM (poitn .x , point .y) );</FONT> </P>
<P><FONT face="Times New Roman" size=+0>}</FONT> </P>
<P><FONT size=+0>该技术也适用于对话框和基于对的应用程序,只是不必调用<FONT face="Times New Roman">CWnd : : 
GetParentFrame </FONT>。</FONT> </P>
<P><FONT face="Times New Roman" size=+0>void CSampleDialog : : OnLbuttonDown 
(UINT nFlags, Cpoint point )</FONT> </P>
<P><FONT face="Times New Roman" size=+0>{</FONT> </P>
<P><FONT face="Times New Roman" size=+0>Cdialog : : OnLButtonDow (nFlags, goint 
);</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Fool dialog into thinking simeone 
clicked on its caption bar .</FONT> </P>
<P><FONT face="Times New Roman" size=+0>PostMessage (WM_NCLBUTTONDOWN , 
HTCAPTION , MAKELPARM (point.x , point. y ) )</FONT> </P>
<P><FONT face="Times New Roman" size=+0>}</FONT> </P>
<P><A name=tip22></A><B><FONT size=+2><FONT 
face="Times New Roman">22</FONT><FONT face=黑体>、如何改变视窗的背景颜色</FONT></FONT></B> 
</P>
<P><FONT size=+0><FONT face="Times New Roman">Windows</FONT>向窗口发送一个<FONT 
face="Times New Roman">WM_ERASEBKGND</FONT>消息通知该窗口擦除背景,可以使用</FONT> </P>
<P><FONT size=+0><FONT 
face="Times New Roman">ClassWizard</FONT>重载该消息的缺省处理程序来擦除背景(实际是画),并返回<FONT 
face="Times New Roman">TRUE</FONT>以</FONT> </P>
<P><FONT size=+0>防止<FONT face="Times New Roman">Windows</FONT>擦除窗口。</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Paint area that needs to be 
erased.</FONT> </P>
<P><FONT face="Times New Roman" size=+0>BOOL CSampleView : : OnEraseBkgnd (CDC* 
pDC)</FONT> </P>
<P><FONT face="Times New Roman" size=+0>{</FONT> </P>
<P><FONT face="Times New Roman" size=+0>// Create a pruple brush.</FONT> </P>
<P><FONT face="Times New Roman" size=+0>CBrush Brush (RGB (128 , 0 , 128) 
);</FONT> </P>
<P><FONT face="Times New Roman" size=+0>// Select the brush into the device 
context .</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">CBrush* pOldBrush = 
pDC</FONT>—<FONT face="Times New Roman">&gt;SelcetObject 
(&amp;brush);</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>// Get the area that needs to be erased 
.</FONT> </P>
<P><FONT face="Times New Roman" size=+0>CRect reClip ;</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">pDC</FONT>—<FONT 
face="Times New Roman">&gt;GetCilpBox (&amp;rcClip);</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Paint the area.</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">pDC</FONT>—<FONT 
face="Times New Roman">&gt; PatBlt (rcClip.left , rcClip.top ,</FONT></FONT> 
</P>
<P><FONT face="Times New Roman" size=+0>rcClip.Width ( ) , rcClip.Height ( ) , 
PATCOPY );</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Unselect brush out of device context 
.</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">pDC</FONT>—<FONT 
face="Times New Roman">&gt;SelectObject (pOldBrush );</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>// Return nonzero to half fruther 
processing .</FONT> </P>
<P><FONT face="Times New Roman" size=+0>return TRUE;</FONT> </P>
<P><FONT face="Times New Roman" size=+0>}</FONT> </P>
<P><A name=tip23></A><B><FONT size=+2><FONT 
face="Times New Roman">23</FONT><FONT face=黑体>、如何改变窗口标题</FONT></FONT></B> </P>
<P><FONT size=+0>调用<FONT face="Times New Roman">CWnd : : 
SetWindowText</FONT>可以改变任何窗口(包括控件)的标题。</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Set title for application's main frame 
window .</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">AfxGetMainWnd ( ) </FONT>—<FONT 
face="Times New Roman">&gt; SetWindowText (_T("Application title") 
);</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Set title for View's MDI child frame 
window .</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">GetParentFrame ( ) </FONT>—<FONT 
face="Times New Roman">&gt; SetWindowText ("_T ("MDI Child Frame new title") 
);</FONT></FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Set title for dialog's push button 
control.</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">GetDigitem (IDC_BUTTON) 
</FONT>—<FONT face="Times New Roman">&gt; SetWindowText (_T ("Button new title 
") );</FONT></FONT> </P>
<P><FONT size=+0>如果需要经常修改窗口的标题(注:控件也是窗口),应该考虑使用半文档化</FONT> </P>
<P><FONT size=+0>的函数<FONT 
face="Times New Roman">AfxSetWindowText</FONT>。该函数在<FONT 
face="Times New Roman">AFXPRIV.H</FONT>中说明,在<FONT 
face="Times New Roman">WINUTIL.CPP</FONT>中实现,在</FONT> </P>
<P><FONT size=+0>联机帮助中找不到它,它在<FONT face="Times New Roman">AFXPRIV.H</FONT>中半文档化, 
在以后发行的<FONT face="Times New Roman">MFC</FONT>中将文档化。</FONT> </P>
<P><FONT size=+0><FONT 
face="Times New Roman">AfxSetWindowText</FONT>的实现如下:</FONT> </P>
<P><FONT face="Times New Roman" size=+0>voik AFXAPI AfxSetWindowText (HWND 
hWndCtrl , LPCTSTR IpszNew )</FONT> </P>
<P><FONT face="Times New Roman" size=+0>{</FONT> </P>
<P><FONT face="Times New Roman" size=+0>itn nNewLen= Istrlen (Ipaznew);</FONT> 
</P>
<P><FONT face="Times New Roman" size=+0>TCHAR szOld [256];</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//fast check to see if text really 
changes (reduces flash in the controls )</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">if (nNewLen &gt;_contof (szOld) 
</FONT>||</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">: : GetWindowText (hWndCrtl , 
szOld , _countof (szOld) !=nNewLen </FONT>||</FONT> </P>
<P><FONT face="Times New Roman" size=+0>Istrcmp (szOld , IpszNew )! = 0</FONT> 
</P>
<P><FONT face="Times New Roman" size=+0>{</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//change it</FONT> </P>
<P><FONT face="Times New Roman" size=+0>: : SetWindowText (hWndCtrl , IpszNew 
);</FONT> </P>
<P><FONT face="Times New Roman" size=+0>}</FONT> </P>
<P><FONT face="Times New Roman" size=+0>}</FONT> </P>
<P><A name=tip24></A><B><FONT size=+2><FONT 
face="Times New Roman">24</FONT><FONT 
face=黑体>、如何防止主框窗口在其说明中显示活动的文档名</FONT></FONT></B> </P>
<P><FONT size=+0>创建主框窗口和<FONT face="Times New Roman">MDI</FONT>子窗口进通常具有<FONT 
face="Times New Roman">FWS_ADDTOTITLE</FONT>风格位, 如果不希望在</FONT> </P>
<P><FONT size=+0>说明中自动添加文档名, 必须禁止该风格位, 可以使用<FONT 
face="Times New Roman">ClassWizard</FONT>重置</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">CWnd: : 
PreCreateWindow</FONT>并关闭<FONT 
face="Times New Roman">FWS_ADDTOTITLE</FONT>风格。</FONT> </P>
<P><FONT face="Times New Roman" size=+0>BOOL CMainFrame : : PreCreateWindow 
(CREATESTRUCT&amp;cs)</FONT> </P>
<P><FONT face="Times New Roman" size=+0>{</FONT> </P>
<P><FONT face="Times New Roman" size=+0>//Turn off FWS_ADDTOTITLE in main frame 
.</FONT> </P>
<P><FONT size=+0><FONT face="Times New Roman">cs.styel &amp; = ~FWS_ADDTOTITLE 
;</FONT> </FONT> </P>
<P><FONT face="Times New Roman" size=+0>return CMDIFrameWnd : : PreCreateWindow 
(cs );</FONT> </P>
<P><FONT face="Times New Roman" size=+0>}</FONT> </P>
<P><FONT size=+0>关闭<FONT face="Times New Roman">MDI</FONT>子窗口的<FONT 
face="Times New Roman">FWS _ADDTOTITLE</FONT>风格将创建一个具有空标题的窗口,可以调</FONT> </P>
<P><FONT size=+0>用<FONT face="Times New Roman">CWnd: : 
SetWindowText</FONT>来设置标题。记住自己设置标题时要遵循接口风格指南。</FONT> </P>
<HR>

<P>&nbsp;<A 
href="http://www.vchome.net/tech/skill.htm">返回上页</A>&nbsp;&nbsp;&nbsp;</P></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -