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

📄 index053.htm

📁 一本不错的VC编程的参考书
💻 HTM
字号:
<html>
<style type="text/css"><!--
.p9 {  font-family: "宋体"; font-size: 9pt}a        {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../di2001.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">如何计算一个串的大小</font></td></tr>
<tr><td><p>
</Br>
函数CDC:: Det text Extent 根据当前选择的字体计算一个串的高度和宽度。如果使用的不是系统字体而是其他字体,则在调用GetTextExtent之前将字体选进设备上下文中是很重要的,否则计算高度和宽度时将依据系统字体,由此得出的结果当然是不正确的。下述样板程序当改变下压按钮的标题时动态调整按钮的大小,按钮的大小由按钮的字体和标题的大小而定。响应消息WM_SETTEXT时调用OnSetText,该消息使用ON_MESSAE宏指令定义的用户自定义消息。<Br>
</Br>
LRESULT CMyButton:: OnSettext (WPARAM wParam, LPARAM lParam)<Br>
{<Br>
&nbsp;//Pass message to window procedure.<Br>
&nbsp;LRESULT bResult=CallWindowProc (*GetSuperWndProcAddr(), m_hWnd, GetCurrentMessage() ->message,wParam,lParam)<Br>
&nbsp;//Get title of push button.<Br>
&nbsp;CString strTitle<Br>
&nbsp;GetWindowText (strTitle)<Br>
</Br>
&nbsp;//Select current font into device context.<Br>
&nbsp;CDC* pDC=GetDc ()<Br>
&nbsp;CFont*pFont=GetFont ()<Br>
&nbsp;CFont*pOldFont=pDC->SelectObject (pFont)<Br>
</Br>
&nbsp;//Calculate size of title.<Br>
&nbsp;CSize size=pDC->GetTextExent (strTitle,strTitle.GetLength())<Br>
</Br>
&nbsp;//Adjust the button's size based on its title.<Br>
&nbsp;//Add a 5-pixel border around the button.<Br>
&nbsp;SetWindowPos (NULL, 0, 0, size.cx+10, size.cy+10, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE)<Br>
&nbsp;//Clean up.<Br>
&nbsp;pDC->SelectFont (pOldFont)<Br>
&nbsp;ReleaseDC (pDC)<Br>
</Br>
&nbsp;return bResult<Br>
}<Br>
</Br>
</p></td></tr>
</table>
</body></html>

⌨️ 快捷键说明

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