marcoo Posted October 9, 2004 Share Posted October 9, 2004 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). Link to comment Share on other sites More sharing options...
0 Mordkanin Posted October 9, 2004 Share Posted October 9, 2004 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? Link to comment Share on other sites More sharing options...
0 Mouton Posted October 9, 2004 Share Posted October 9, 2004 I use AfxGetMainWnd()->m_hWnd myself... but it depends if u use MFC or not. Link to comment Share on other sites More sharing options...
0 ilmcuts Posted October 9, 2004 Share Posted October 9, 2004 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. Link to comment Share on other sites More sharing options...
0 marcoo Posted October 9, 2004 Author Share Posted October 9, 2004 (edited) It was wrong window_title_name. It works now. Thank you guys for your comments. Edited October 9, 2004 by marcoo Link to comment Share on other sites More sharing options...
Question
marcoo
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).
Link to comment
Share on other sites
4 answers to this question
Recommended Posts