• 0

Get HWND of running process (AppName.exe)


Question

4 answers to this question

Recommended Posts

  • 0
  marcoo said:
I have application running in system tray. I know only its name like (AppName.exe)

How do I get HWND of that application?

BTW FindWindow(NULL, "Window_Title_AppName") doesn't return right handle.

I need it to kill that process with PostMessage(hwnd, WM_CLOSE).

If it doesn't have a form, it wouldn't have an Handle, would it?

  • 0

Depending on how the target application handles thread messages using PostThreadMessage could work.

Other than that, your best (and the easiest too) bet is still FindWindow(Ex). The problem is that "the HWND associated with process X" doesn't exist - a process may have (almost) any number of windows - including zero. A process which registers a tray icon typically has at least one window, but it's not required to IIRC.

You don't really explain what you mean when you say that FindWindow doesn't return the "right" handle. My interpretation is that posting WM_CLOSE doesn't have the desired effect on that particular window. If that is the case, get Spy++ and try to use this method on other windows the process has created.

And before I forget - do you really "need to" use WM_CLOSE? If not, using WM_QUIT is often a lot easier.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.