c++ - 编写另一个以 LPCTSTR 开头的文本行的最佳方法是什么?
问题描述
我正在尝试再写第二行,但我不知道要使用哪个代码。
我尝试过使用 \r\n、\n、\r 等,但它们都不起作用。
感谢所有提供帮助的人!:)
这是我的代码的一部分。(我也包括了标题。)
HINSTANCE g_hInst;
LPCTSTR lpszClass = L"HelloAPI";
LPCTSTR ChildClassName = L"ChildWin";
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdParam,
int nCmdShow)
hWnd=CreateWindow(lpszClass,
L"Visual C++",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
200, 200,
600, 600,
(HWND)NULL,
(HMENU)NULL,
NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage,
WPARAM wParam, LPARAM lParam)
{
LPCTSTR text = L"Visual C++201934-243369";
switch(iMessage) {
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
TextOut(hdc,100, 100, text, lstrlen(text));
EndPaint(hWnd,&ps);
return 0;
}
解决方案
TextOut
不处理输入字符串中的换行符。改为使用DrawText
,指定DT_WORDBREAK
标志。
元评论:现在你明白我们为什么需要你发布你的代码了。
推荐阅读
- r - 基于所有先前保留的数据组 R for 循环过滤行
- python - 频率 DataFrame Pandas
- postgresql - 自动化 RDS 的手动快照(postgres)
- json - 我在使用 PyKafka 在 Kafka 上发布 JSON 消息时遇到问题
- amazon-web-services - 多个 DynamoDB GSI 添加/删除和 CI/CD 管道
- reactjs - 一旦我提交表单并从输入字段中获取值并将其分配给 api url 并获得响应,我想使用 useEffect
- typescript - Expo TypeScript 选项卡快照测试 App.tsx
- python - Discord.py 超时命令
- python - 使用弹性搜索中的另一个索引检查一个索引中的python值并创建一个新数据库
- postgresql - Postgres 如何计算 current_timestamp?