如何在 C++ 中打印粗体字符串?
我有一个用 C++ 编写的旧应用程序。我对此没有任何经验,但我应该在应用程序中进行一些更改。其中之一是更改一些文本。问题是更新文本的一部分需要加粗,但我不知道该怎么做。我用谷歌搜索但没有取得太大成功。我现在只是想用 \n
转到新行,并用 \t
转到新选项卡。
有什么聪明的建议吗?
编辑:
代码示例:
BEGIN
STRING1 "First Example"
STRING2 "Second Example"
使用 STRING1 的地方:
// WelcomeTip ---------------------------------------------//
LPSTR idsWelcomeTip = (LPSTR)GlobalAlloc(GPTR, sizeof(CHAR) * 4098 );
LoadString( waveInDlg->hInstance, STRING1, idsWelcomeTip, 4098 );
waveInDlg->hwndWelcomeTip = CreateWindow(
"STATIC",
idsWelcomeTip,
WS_CHILD | WS_VISIBLE | SS_LEFT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
waveInDlg->hwnd,
NULL,
waveInDlg->hInstance,
NULL
);
SetWindowLongPtr(waveInDlg->hwndWelcomeTip, GWLP_USERDATA ,(LONG)waveInDlg );
SendMessage(waveInDlg->hwndWelcomeTip, WM_SETFONT , (WPARAM)waveInDlg->hFontDefault , TRUE );
ShowWindow(waveInDlg->hwndWelcomeTip, SW_HIDE);
GlobalFree( (HGLOBAL)idsWelcomeTip );
谢谢,
岛
I got an old application which was written in a C++. I have 0 experience with it but I am suppose to make some changes in app. One of them is to change some text. Problem is that part of updated text needs to be bold, but i have no idea how to do that. I googled but with no much success. Only think I now is to go to new line with \n
and new tab with \t
.
Any clever advise?
EDIT:
Example of code:
BEGIN
STRING1 "First Example"
STRING2 "Second Example"
And place where STRING1 is used:
// WelcomeTip ---------------------------------------------//
LPSTR idsWelcomeTip = (LPSTR)GlobalAlloc(GPTR, sizeof(CHAR) * 4098 );
LoadString( waveInDlg->hInstance, STRING1, idsWelcomeTip, 4098 );
waveInDlg->hwndWelcomeTip = CreateWindow(
"STATIC",
idsWelcomeTip,
WS_CHILD | WS_VISIBLE | SS_LEFT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
waveInDlg->hwnd,
NULL,
waveInDlg->hInstance,
NULL
);
SetWindowLongPtr(waveInDlg->hwndWelcomeTip, GWLP_USERDATA ,(LONG)waveInDlg );
SendMessage(waveInDlg->hwndWelcomeTip, WM_SETFONT , (WPARAM)waveInDlg->hFontDefault , TRUE );
ShowWindow(waveInDlg->hwndWelcomeTip, SW_HIDE);
GlobalFree( (HGLOBAL)idsWelcomeTip );
Thanks,
Ile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
C++ 中没有粗体文本的概念,可能在显示字符文本的特定设备中存在,例如富文本格式或 HTML 标记或终端屏幕。后者通常涉及发送一些与该特定终端相关的“转义序列”。
There is no concept of bold text in C++, there may be in a particular device that displays character text, for example rich-text-format or HTML tagging or a terminal screen. The latter usually involves sending some "escape sequence" relevant to that particular terminal.
好的,我已经敲出了一些代码,应该可以概述您所追求的内容,我还没有成功编译它,因为我需要编写更多内容来测试,但它应该指出您的正确方向方向:
我希望这会有所帮助。
OK, I've knocked up some code that should give an overview of what you're after, I've not managed to compile it as I'd need to write a lot more to test, but it should point you in the right direction:
I hope this helps.
请通过以下链接寻求帮助
http://msdn.microsoft.com/en-us/ library/dd162499(VS.85).aspx
是的,您必须在对话框类中重写 WM_PAINT 并调用 drawtext 函数。
Please go through the below link for help
http://msdn.microsoft.com/en-us/library/dd162499(VS.85).aspx
Yes, you have to override WM_PAINT in your dialog class and call drawtext function.
在 WM_PAINT 消息处理程序中使用 DrwaText API。
dc.DrawText (_T ("Hello, MFC"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
使用 DrawTextEx 方法。
有关更多信息,请访问以下链接
ms-help://MS.MSDNQTR.v90.en/gdi/fontext_4pbs.htm
Use DrwaText API in WM_PAINT message handler.
dc.DrawText (_T ("Hello, MFC"), -1, &rect,
DT_SINGLELINE ¦ DT_CENTER ¦ DT_VCENTER);
use DrawTextEx method.
For more inforamtion go through the follwoing link
ms-help://MS.MSDNQTR.v90.en/gdi/fontext_4pbs.htm