丢人呀!API高手看过来~~~~~~~~~(200分)

  • 主题发起人 主题发起人 doxpix
  • 开始时间 开始时间
D

doxpix

Unregistered / Unconfirmed
GUEST, unregistred user!
老脸不要了,决定不耻"上"问!!!<br><br>GetTextExtentExPoint具体用来干什么的?<br>怎么用?越具体越生动越好(好像你就像在给小学生上课:-p),有实例最棒。<br><br>--英文说明-----------------------------------------------------------------------<br>The GetTextExtentExPoint function retrieves the number of characters in <br>a specified string that will fit within a specified space and fills <br>an array with the text extent for each of those characters. <br>(A text extent is the distance between the beginning of the space <br>and a character that will fit in the space.) This information is useful <br>for word-wrapping calculations. <br><br>BOOL GetTextExtentExPoint(<br><br>&nbsp; &nbsp; HDC hdc, // handle of device context <br>&nbsp; &nbsp; LPCTSTR lpszStr, // address of character string <br>&nbsp; &nbsp; int cchString, // number of characters in string <br>&nbsp; &nbsp; int nMaxExtent, // maximum width for formatted string <br>&nbsp; &nbsp; LPINT lpnFit, // address of value specifying max. number of chars. &nbsp;<br>&nbsp; &nbsp; LPINT alpDx, // address of array for partial string widths <br>&nbsp; &nbsp; LPSIZE lpSize // address of structure with string dimensions <br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>hdc<br><br>Identifies the device context. <br><br>lpszStr<br><br>Points to the null-terminated string for which extents are to be retrieved. <br><br>cchString<br><br>Specifies the number of bytes in the string pointed to by the lpszStr parameter. <br><br>nMaxExtent<br><br>Specifies the maximum allowable width, in logical units, of the formatted string.<br>&nbsp;<br><br>lpnFit<br><br>Points to an integer to receive a count of the maximum number of characters <br>that will fit in the space specified by the nMaxExtent parameter. When the <br>lpnFit parameter is NULL, the nMaxExtent parameter is ignored. <br><br>alpDx<br><br>Points to an array of integers to receive partial string extents. <br>Each element in the array gives the distance, in logical units, <br>between the beginning of the string and one of the characters <br>that fits in the space specified by the nMaxExtent parameter. <br>Although this array should have at least as many elements as <br>characters specified by the cchString parameter, the function fills <br>the array with extents only for as many characters as are given <br>by the lpnFit parameter. If alpDx is NULL, the function does not <br>compute partial string widths. <br><br>lpSize<br><br>Points to a SIZE structure that contains the dimensions of the string, <br>in logical units when the function returns. This value cannot be NULL. <br><br>&nbsp;<br><br>Return Values<br><br>If the function succeeds, the return value is nonzero.<br>If the function fails, the return value is zero. To get extended error <br>information, call GetLastError. <br><br>Remarks<br><br>If both the lpnFit and alpDx parameters are NULL, calling the <br>GetTextExtentExPoint function is equivalent to calling the <br>GetTextExtentPoint function. <br><br>See Also<br><br>GetTextExtentPoint, SIZE <br>---------------------------------------------------------------------------------<br><br>--中文说明(翻译地不太好)---------------------------------------------------------<br>&nbsp; &nbsp; 函数功能:该函数取得一个指定字符串里的字符数,该字符串将符合一个指定的空间,<br>并且将其中每一个字符的范围放入一个数组。(一个正文的范围是指空间开始处到一个<br>字符的间距)。此函数对自动换行的计算非常有用。<br><br>&nbsp; &nbsp; 函数原型:BOOL GetTextExtentPoint(HDC hdc, LPCTSTR lpszStr, int cchString, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int nMaxExten, LPINT lpnFit, LPINT alpDx, LPSIZE lpSize);<br><br>&nbsp; &nbsp; 参数:<br><br>&nbsp; &nbsp; hdc:设备环境句柄。<br><br>&nbsp; &nbsp; lpszStr:指向以/0(Null)结束的字符串的指针,函数取得该字符中的范围。<br><br>&nbsp; &nbsp; cchString:指定由lpszStr指向的字符串的字节数。<br><br>&nbsp; &nbsp; nMaxExtent:为格式经的字符串指定最大可允许的逻辑单位宽度。<br><br>&nbsp; &nbsp; lpnFit:指向整数的指针,该整数用于接收符合指定范围的字符的最大个数,<br>该范围由nMaxExtent指定。如果lpnFit为NULL,则nMaxExtent无效。<br><br>&nbsp; &nbsp; alpDx:指向整数数组的指针,该数组用于接收部分字符串范围。此数组的<br>每一个元素给出一个间隔值,(按逻辑单位),表示字符串的开始处和在由nMaxExtent<br>指定的空间里的一个字符之间的距离。尽管此数组应当至少有cchString指定那么多个<br>元素,但函数向数组中填入其范围的字符数却由lpnFit确定。如果alpDx为NULL,<br>则函数不计算局部字符串宽度。<br><br>&nbsp; &nbsp; lpSize:指向结构SIZE的指针,该结构在函数返回时含有字符串的尺寸(按逻辑单位)。<br><br>&nbsp; &nbsp; 返回值:如果函数调用成功,返回值非零,如果函数调用失败,返回值是0。<br><br>&nbsp; &nbsp; Windows NT:若想获得更多错误信息,请调用GetLastError函数。<br><br>&nbsp; &nbsp; 备注:如果lpnFit和alpDx的值均为NULL,则调用GetTextExtentPoint等同于<br>调用GetTextExtentExPoint。<br><br>&nbsp; &nbsp; Windows CE:cchString指定由lpszStr指向的字符串的字符个数而不是字节数。<br>在Windows桌面平台下也是如此。<br><br>&nbsp; &nbsp; 速查:Windows NT:3.1及以上版本;Windows:95及以上版本;<br>Windows CE:1.0及以上版本;头文件:wingdi.h;库文件:gdi32.lib;<br>Unicode:在Windows NT环境下实现为Unicode和ANSI两种版本。<br>---------------------------------------------------------------------------------
 
就是计算文本显示宽度的,在hdc这个设备上
 
跟字体没关系?
 
头晕中。。。
 
小声的说:学习~
 
这是从Delphi帮助里复制的吧?
 
&nbsp; &nbsp;函数功能:该函数取得一个指定字符串里的字符数,该字符串将符合一个指定的空间,<br>并且将其中每一个字符的范围放入一个数组。(一个正文的范围是指空间开始处到一个<br>字符的间距)。此函数对自动换行的计算非常有用。<br>&nbsp; &nbsp; &nbsp;这个都翻译出来了,还不会用吗?那我等菜鸟更加不行了◎!!!!!<br>
 
当然跟字体有关系啦,HDC是包含了字体的嘛,你如果用api的话,SelectObject就可以<br>用来给HDC指定一个font,否则就是系统缺省的font
 
其实很简单, 你看一下下面的例子就清楚了(那翻译得太差了,越看越糊涂[:(!])<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HDC &nbsp; &nbsp; &nbsp;hDC;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SIZE &nbsp; &nbsp; size;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int &nbsp; &nbsp; &nbsp;nFit;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hDC = GetDC( hWnd );<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Draw a rectangle.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//..................<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Rectangle( hDC, 10, 10, 120, 50 );<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Find out how many characters will<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// fit within the rectangle.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//..................................<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetTextExtentExPoint( hDC, lpText, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strlen( lpText ),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;100, &amp;nFit, NULL, &amp;size );<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Output the number of characters<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// returned from GetTextExtentExPoint().<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//......................................<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextOut( hDC, 15, 20, lpText, nFit ); <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReleaseDC( hWnd, hDC );<br>
 
忘了一句: LPCTSTR lpText = "This is a long string.";[:)]
 
请看。。http://www.delphibbs.com/delphibbs/dispq.asp?lid=774787
 
nMaxExtent是以像素为单位吗?<br><br>整个函数的意思是——<br>&nbsp; &nbsp; 计算字符串lpszStr在nMaxExtent像素宽度的画布上能放置lpnFit^个字符?<br>&nbsp; &nbsp; 是这个意思吗?
 
注意不是像素,而是逻辑点,一个逻辑点对几个像素是SetMapMode决定的
 
谢谢。非常感谢各位的回复。<br>
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
775
import
I
I
回复
0
查看
746
import
I
I
回复
0
查看
806
import
I
后退
顶部