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

wko9yo5t  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(55)

我试着再写一行,但我不知道该用哪一行代码。
我试过使用\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;
            }

字符串

9lowa7mx

9lowa7mx1#

TextOut不处理输入字符串中的换行符。请使用DrawText,并指定DT_WORDBREAK标志。

相关问题