How do I get an application's .exe name using visual C++
-
I have an application, prog B, that starts minimized. Another program, let's say winamp, currently has the focus. My program - prog B should be able to retrieve the .exe name based on whichever application that currently has the focus, in this case, winamp. I'm not sure how to go about and tackle this problem. Can somebody please help me out? Environment - Windows 2000 Thanks in advance,
-
I have an application, prog B, that starts minimized. Another program, let's say winamp, currently has the focus. My program - prog B should be able to retrieve the .exe name based on whichever application that currently has the focus, in this case, winamp. I'm not sure how to go about and tackle this problem. Can somebody please help me out? Environment - Windows 2000 Thanks in advance,
Search for GetWindowModuleFileName on MSDN, it should work only on Win2000 though. You may use it with GetForegroundWindow to retrieve the exe filename associated with the current foreground window. Cheers, Paolo.
-
I have an application, prog B, that starts minimized. Another program, let's say winamp, currently has the focus. My program - prog B should be able to retrieve the .exe name based on whichever application that currently has the focus, in this case, winamp. I'm not sure how to go about and tackle this problem. Can somebody please help me out? Environment - Windows 2000 Thanks in advance,
If you want to track application's exe name based on current focus, I recommend you write small DLL to hook some events. You may need to hook couple of them like WH_CBT and WH_SHELL using SetWindowsHookEx(). From my experience, you need serious testing to make sure your DLL is really tracing focus movement. There are many ways to move focus to another application and covering all of them may need long time work. Once you have that DLL that will attach itself to exe by hooking function, then the filename of that exe can be obtained by GetModuleFileName(). Even if GetModuleFileName() won't work right for some application, you can use very powerfull ToolHelp32 functions to; 1 enumelate all processes 2 find process ID that matches what GetCurrentProcessId() returns Just for your info, if you unfamilier with DLL which attaches itself to exe by SetWindowsHookEx(), then take a look at Matt Pietrek's article MSJ No 12 Vol 6 (MouseWheel.DLL). Have fun! reiko