开发者

Detecting to which process a MessageBox belongs

Is it possible to开发者_如何转开发 find out to which process a MessageBox belongs? If yes, how?


You want to use GetWindowThreadProcessId. Here is an example.

#include <windows.h>

static const TCHAR g_cszClass = TEXT("#32770"); // dialog box class

// returned handle must be closed with CloseHandle() when no longer used
HANDLE GetMessageBoxProcess(__in_z LPCTSTR lpcszTitle, __in DWORD dwAccess)
{
  HWND    hWnd;
  DWORD   dwProcessId = 0;
  HANDLE  hRET;

  hWnd = FindWindow(g_cszClass, lpcszTitle);
  if (hWnd != NULL)
  {
    GetWindowThreadProcessId(hWnd, &dwProcessId);
    if (dwProcessId != 0)
      hRET = OpenProcess(dwAccess, FALSE, dwProcessId);
  }
  return hRET;
}

Not sure why you'd want the process though. Reasons I can think of:

  • terminating the message box completely
  • detecting a process
  • detecting a certain message box

all of which have superior & more optimal alternative solutions.


Another answer gives the programmatic solution. If this is a one-off thing for debugging, you can choose the window with Spy++, get the process ID from the properties window, and then look up the process in Task Manager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜