【问题标题】:What is the best way to write another text line starting with LPCTSTR?编写另一个以 LPCTSTR 开头的文本行的最佳方法是什么?
【发布时间】:2019-06-08 09:04:53
【问题描述】:

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

我尝试过使用\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;
            }

【问题讨论】:

  • 请发布您的代码
  • 你可以按照这个添加新行godbolt.org/z/g9lVhL
  • { LPCTSTR text = L"Visual C++ 201934-243369";开关(iMessage){
  • 这是我遇到问题的部分。
  • 我删除了部分代码,因为它说我主要只发布代码。

标签: c++ visual-studio-2012


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-06
    • 2013-12-12
    相关资源
    最近更新 更多