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

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

        <tfoot id='ru43u'></tfoot>

        如何获取窗口的可执行文件名称

        时间:2023-08-01

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

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

                • 本文介绍了如何获取窗口的可执行文件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试获取所有已启动窗口的可执行文件名称,但我的问题是:

                  I try to get the name of executable name of all of my launched windows and my problem is that:

                  我用的方法

                  UINT GetWindowModuleFileName(      
                  HWND hwnd,
                  LPTSTR lpszFileName,
                  UINT cchFileNameMax);
                  

                  我不明白为什么它不起作用.

                  And I don't understand why it doesn't work.

                  关于窗口的数据是:
                  -HWND AND PROCESSID

                  Data which I have about a window are:
                  -HWND AND PROCESSID

                  错误是:例如:

                  HWND: 00170628 
                  ProcessId: 2336        
                  WindowTitle: C:	est.cpp - Notepad++
                  GetWindowModuleFileName():  C:	est.exe
                  
                  HWND: 00172138 
                  ProcessId: 2543        
                  WindowTitle: Firefox
                  GetWindowModuleFileName():  C:	est.exe
                  
                  HWND: 00120358 
                  ProcessId: 2436        
                  WindowTitle: Mozilla Thunderbird
                  GetWindowModuleFileName():  C:	est.exe
                  

                  注意:test.exe 是我的可执行文件的名称,但它不是 Notepad++ 的完整路径...它也适用于 Mozilla Thunderbird...我不明白为什么

                  Note: test.exe is the name of my executable file, but it is not the fullpath of Notepad++... and it make this for Mozilla Thunderbird too... I don't understand why

                  我使用这样的函数:

                  char filenameBuffer[4000];
                  if (GetWindowModuleFileName(hWnd, filenameBuffer, 4000) > 0)
                  {
                      std::cout << "GetWindowModuleFileName(): " << filenameBuffer << std::endl;
                  }
                  

                  感谢您的回复.

                  推荐答案

                  GetWindowModuleFileName 函数仅适用于当前进程中的窗口.

                  The GetWindowModuleFileName function works for windows in the current process only.

                  您必须执行以下操作:

                  1. 使用检索窗口进程GetWindowThreadProcessId.
                  2. 使用PROCESS_QUERY_INFORMATION和PROCESS_VM_READ访问权限打开进程api/processthreadsapi/nf-processthreadsapi-openprocess" rel="noreferrer">OpenProcess.
                  3. 使用 GetModuleFileNameEx 在进程句柄上.
                  1. Retrieve the window's process with GetWindowThreadProcessId.
                  2. Open the process with PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights using OpenProcess.
                  3. Use GetModuleFileNameEx on the process handle.

                  如果您确实想获取注册窗口的模块的名称(而不是进程可执行文件),则可以使用 GetWindowLongPtrGWLP_HINSTANCE.然后可以将模块句柄传递给前面提到的 GetModuleFileNameEx.

                  If you really want to obtain the name of the module with which the window is registered (as opposed to the process executable), you can obtain the module handle with GetWindowLongPtr with GWLP_HINSTANCE. The module handle can then be passed to the aforementioned GetModuleFileNameEx.

                  TCHAR buffer[MAX_PATH] = {0};
                  DWORD dwProcId = 0; 
                  
                  GetWindowThreadProcessId(hWnd, &dwProcId);   
                  
                  HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ , FALSE, dwProcId);    
                  GetModuleFileName((HMODULE)hProc, buffer, MAX_PATH);
                  CloseHandle(hProc);
                  

                  这篇关于如何获取窗口的可执行文件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Windows 上获取实际文件名(带有正确的大小写 下一篇:为什么 MAKEINTRESOURCE() 有效?

                  相关文章

                  最新文章

                • <small id='YPk0L'></small><noframes id='YPk0L'>

                  <legend id='YPk0L'><style id='YPk0L'><dir id='YPk0L'><q id='YPk0L'></q></dir></style></legend>
                • <tfoot id='YPk0L'></tfoot>

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