c++ - 编写另一个以 LPCTSTR 开头的文本行的最佳方法是什么?

标签 c++ visual-studio-2012

我正在尝试再写第二行,但我不知道该使用哪个代码。

我尝试过使用\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 标志。

元评论:现在你明白我们为什么需要你发布你的代码了。

关于c++ - 编写另一个以 LPCTSTR 开头的文本行的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56504963/

相关文章:

c++ - 在 std::set 上按名称查找对象

c++ - boost 随机输出从 1.58 到 1.67 的已知差异?

c++ - C++ 中的错误函数

c++ - 我的 "if"语句中只有一个给出了准确的值,即使它们都是相同的结构

c++ - 10 秒后运行代码或按下某个键

c++ - 为什么发布版本 memset 比 visual studio 2012 中的调试版本慢?

visual-studio-2010 - Web 服务器找不到请求的资源 Visual Studio 调试

visual-studio-2012 - 当指定 "Find in Files"时,Visual Studio 2012 "Entire Solution"搜索远远超出解决方案

mysql - ASP.net 代码返回打开 session 错误

c# - 测试资源管理器 > 全部运行 : System. 异常:找不到主应用程序程序集