<i id='OwPP2'><tr id='OwPP2'><dt id='OwPP2'><q id='OwPP2'><span id='OwPP2'><b id='OwPP2'><form id='OwPP2'><ins id='OwPP2'></ins><ul id='OwPP2'></ul><sub id='OwPP2'></sub></form><legend id='OwPP2'></legend><bdo id='OwPP2'><pre id='OwPP2'><center id='OwPP2'></center></pre></bdo></b><th id='OwPP2'></th></span></q></dt></tr></i><div id='OwPP2'><tfoot id='OwPP2'></tfoot><dl id='OwPP2'><fieldset id='OwPP2'></fieldset></dl></div>

      <small id='OwPP2'></small><noframes id='OwPP2'>

        <bdo id='OwPP2'></bdo><ul id='OwPP2'></ul>
      <tfoot id='OwPP2'></tfoot>
    1. <legend id='OwPP2'><style id='OwPP2'><dir id='OwPP2'><q id='OwPP2'></q></dir></style></legend>

        CreateWindow/CreateDialog 中的 HWND 可以从另一个线程获

        时间:2023-08-01
        <tfoot id='XQAdB'></tfoot>
        1. <legend id='XQAdB'><style id='XQAdB'><dir id='XQAdB'><q id='XQAdB'></q></dir></style></legend>
          • <i id='XQAdB'><tr id='XQAdB'><dt id='XQAdB'><q id='XQAdB'><span id='XQAdB'><b id='XQAdB'><form id='XQAdB'><ins id='XQAdB'></ins><ul id='XQAdB'></ul><sub id='XQAdB'></sub></form><legend id='XQAdB'></legend><bdo id='XQAdB'><pre id='XQAdB'><center id='XQAdB'></center></pre></bdo></b><th id='XQAdB'></th></span></q></dt></tr></i><div id='XQAdB'><tfoot id='XQAdB'></tfoot><dl id='XQAdB'><fieldset id='XQAdB'></fieldset></dl></div>

                <bdo id='XQAdB'></bdo><ul id='XQAdB'></ul>

                <small id='XQAdB'></small><noframes id='XQAdB'>

                    <tbody id='XQAdB'></tbody>
                  本文介绍了CreateWindow/CreateDialog 中的 HWND 可以从另一个线程获取 GetMessage 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  使用 Win32 API,是否可以在一个线程中创建一个窗口或对话框,然后从另一个线程为它收集事件?

                  HWND 是否与线程相关联?

                  尝试下面的人为示例,我从未看到 GetMessage() 触发.

                  <前>HWND g_hWnd;DWORD WINAPI myThreadProc(LPVOID lpParam){while(GetMessage(&msg, hWnd, 0, 0) > 0){...}}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MYDIALOG), 0, myDlgProc);CreateThread(NULL, 0 myThreadProc, NULL, 0, NULL);...}

                  但在这里,我愿意.

                  <前>HWND g_hWnd;HINSTANCE g_hInstance;DWORD WINAPI myThreadProc(LPVOID lpParam){hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MYDIALOG), 0, myDlgProc);while(GetMessage(&msg, hWnd, 0, 0) > 0){...}}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){g_hInstance = hInstance;CreateThread(NULL, 0 myThreadProc, NULL, 0, NULL);...}

                  有人能解释一下我看到了什么吗?

                  解决方案

                  没有

                  GetMessage 在当前线程的输入队列上返回消息.HWND 参数是一个过滤器,因此 GetMessage 只返回当前线程的输入队列中用于该窗口的消息.

                  Windows 具有线程关联性 - 用于窗口的消息在创建并因此拥有该窗口的线程上得到处理.

                  Using the Win32 APIs, is it possible to create a Window or Dialog in one thread then collect events for it from another thread?

                  Are HWNDs tied to threads?

                  Trying the contrived example below I never see GetMessage() fire.

                  HWND g_hWnd;
                  
                  DWORD WINAPI myThreadProc(LPVOID lpParam)
                  {
                      while(GetMessage(&msg, hWnd, 0, 0) > 0)
                      {
                         ...
                      }
                  
                  }
                  
                  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) 
                  {
                      hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MYDIALOG), 0, myDlgProc);
                      CreateThread(NULL, 0 myThreadProc, NULL, 0, NULL);
                      ...
                  }
                  

                  But here, I do.

                  HWND g_hWnd;
                  HINSTANCE g_hInstance;
                  
                  DWORD WINAPI myThreadProc(LPVOID lpParam)
                  {
                      hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MYDIALOG), 0, myDlgProc);
                  
                      while(GetMessage(&msg, hWnd, 0, 0) > 0)
                      {
                         ...
                      }
                  
                  }
                  
                  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) 
                  {
                      g_hInstance = hInstance;
                      CreateThread(NULL, 0 myThreadProc, NULL, 0, NULL);
                      ...
                  }
                  

                  Can somebody explain what I'm seeing?

                  解决方案

                  No.

                  GetMessage returns messages on the current thread's input queue. The HWND parameter is a filter, so that GetMessage only returns messages in the current thread's input queue intended for that window.

                  Windows have thread affinity - messages intended for a window get handled on the thread that created and therefore owns the window.

                  这篇关于CreateWindow/CreateDialog 中的 HWND 可以从另一个线程获取 GetMessage 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 DWORD 显式初始化为 1,但调试器显示超出范围 下一篇:InvalidateRect 和 RedrawWindow 的区别

                  相关文章

                  最新文章

                  <tfoot id='MVLd2'></tfoot>
                1. <i id='MVLd2'><tr id='MVLd2'><dt id='MVLd2'><q id='MVLd2'><span id='MVLd2'><b id='MVLd2'><form id='MVLd2'><ins id='MVLd2'></ins><ul id='MVLd2'></ul><sub id='MVLd2'></sub></form><legend id='MVLd2'></legend><bdo id='MVLd2'><pre id='MVLd2'><center id='MVLd2'></center></pre></bdo></b><th id='MVLd2'></th></span></q></dt></tr></i><div id='MVLd2'><tfoot id='MVLd2'></tfoot><dl id='MVLd2'><fieldset id='MVLd2'></fieldset></dl></div>
                  • <bdo id='MVLd2'></bdo><ul id='MVLd2'></ul>
                2. <small id='MVLd2'></small><noframes id='MVLd2'>

                  <legend id='MVLd2'><style id='MVLd2'><dir id='MVLd2'><q id='MVLd2'></q></dir></style></legend>