菜鸟求救:如何获得字符的显示宽度?
本人在编程中涉及到 SetCaretPos 函数的调用。
如果使用 TEXTMETRIC 结构中的 tmAveCharWidth 字段,SetCaretPos 常使光标位于某显示字符的中间,显然是不准确的。
如用 GetCharABCWidths 函数,显示汉字的宽度又不对。
该如何是好?
问题点数:0、回复次数:8Top
1 楼nielisheng(1+1)回复于 2005-02-04 11:48:13 得分 0
strlen()Top
2 楼beginner_mouse(初学鼠)回复于 2005-02-04 11:55:04 得分 0
strlen() 是求字符串的长度,单位是字符,不是象素。而 SetCaretPos() 的坐标单位是象素Top
3 楼martmy(白金汉公爵)回复于 2005-02-04 17:32:04 得分 0
TabbedTextOutTop
4 楼martmy(白金汉公爵)回复于 2005-02-04 17:34:23 得分 0
The TabbedTextOut function writes a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions. Text is written in the currently selected font, background color, and text color.
LONG TabbedTextOut(
HDC hDC, // handle to DC
int X, // x-coord of start
int Y, // y-coord of start
LPCTSTR lpString, // character string
int nCount, // number of characters
int nTabPositions, // number of tabs in array
CONST LPINT lpnTabStopPositions, // array of tab positions
int nTabOrigin // start of tab expansion
);
Return Values
If the function succeeds, the return value is the dimensions, in logical units, of the string. The height is in the high-order word and the width is in the low-order word.
If the function fails, the return value is zero.
Top
5 楼beginner_mouse(初学鼠)回复于 2005-02-05 13:45:56 得分 0
太感谢公爵了。我对 TabbedTextOut() 函数很陌生,还得好好地研究和领会。
Thank you very much!Top
6 楼naturemickey(米老鼠)回复于 2005-02-05 17:43:38 得分 0
But only "Thank you" is not enough!
You should...Top
7 楼beginner_mouse(初学鼠)回复于 2005-02-06 08:52:56 得分 0
晕~那要该怎么样才算 enough 呀?
另外,做程序我用 VC++ 6.0。虽也学了MFC,也知道用 MFC 一旦上手了,效率就会有很大的提高,但仍然不喜欢用它。为什么呢?一是觉得它生成的代码比较罗嗦,二是觉得用 MFC 不大容易设计个性化的界面(象 QQ 那样),再就是反编译比较容易,毕竟是按人家设计好的步骤去填代码。不知高人以为如何?
类(class)我也不大喜欢用。比如说,界面上有几个编辑框控件就要在内存中分配几个几乎一样的类,也就有几个几乎一样的函数代码。是不是这样?
设计控件性窗口(如按钮、编辑框等)我也没用预定义的窗口类(wndclass),因为我还不知道如何让它按我要求的 LOGFONT 去显示。
Top
8 楼inutility(埋没)回复于 2005-02-06 09:03:46 得分 0
感觉要用DrawText,DT_CALCRECTTop




