首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WM_COMMAND中使用TextOut()

在WM_COMMAND中使用TextOut()
EN

Stack Overflow用户
提问于 2011-04-12 15:43:41
回答 2查看 2.8K关注 0票数 1

我正在尝试打印WM_COMMAND案例中的文本,因为我需要在按下按钮后打印文本。

下面是我的代码:

代码语言:javascript
复制
switch(msg)
{
default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case 1:
        PAINTSTRUCT ps;
        HDC         hDC;
        hDC = BeginPaint(hwnd, &ps);
        {
            TextOut(hDC, 10, 50, "hello", 5);
        }
        EndPaint(hwnd, &ps);
        UpdateWindow(hwnd);
        break;
    }
    break;
}

遗憾的是,它没有打印任何内容。

编辑:

我可以通过这种方式在WM_COMMAND中使用TextOut()

代码语言:javascript
复制
HDC         hDC;
hDC = GetDC(hwnd);
TextOut(hDC, 10, ypos, "Warnings: ", 10);
UpdateWindow(hwnd);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-04-12 16:14:52

最好将你的程序组织起来,这样所有的绘制都在WM_PAINT中执行。

因此,您可以将其更改为如下所示:

代码语言:javascript
复制
LRESULT CALLBACK WndProc(/*blah blah blah*/) 
{
    static wchar_t my_text[] = L"hello";
    static BOOL show_btn_text = FALSE;
    HDC dc;
    PAINTSTRUCT ps;
    switch (msg) {
          case WM_COMMAND:
               switch (LOWORD(wParam)) {
                  case 1:
                       show_btn_text = !show_btn_text;
                       InvalidateRect(hwnd, NULL, TRUE); //tells windows that the whole client area needs to be repainted
                       break;
               }
               return 0;
           case WM_PAINT:
                dc = BeginPaint(hwnd, &ps);
                if (show_btn_text) {
                    TextOut(dc, 0, 0, my_text, wcslen(my_text));
                }
                EndPaint(hwnd, &ps);

            return 0;
            /*the rest of the window procedure
    }
}
票数 7
EN

Stack Overflow用户

发布于 2011-04-12 16:10:26

  • For painting of WM_PAINT:
    • of of WM_PAINT:
      • For painting inside of WM_PAINT:
        • of WM_PAINT:WM_PAINT
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5631937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档