CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Posts
    24

    Find Windows By Exe Name

    How can I find HWND by executable name, or executable name by window HWND?

    Thanks.


  2. #2
    Join Date
    May 1999
    Posts
    116

    Re: Find Windows By Exe Name

    Get exename from hWnd: GetWindowModuleFileName

    Get hwnd from exename:
    dont think there is a direct way.
    You could do an EnumWindows and for each window call GetWindowModuleFileName and see if it is the same as the one you want, then save the current hWnd somewhere. This is not very accurate though as a module could have more than one main window (which is probably why there is no API to do it ;-).
    Also, when you get the window handle, you will have to make sure that it is the main window, and not a modal dialog currently running in the app.


  3. #3
    Join Date
    May 1999
    Posts
    24

    Re: Find Windows By Exe Name

    This is exactly that I need. Thanks a lot.
    Actually, first variant suits me perfectly.
    I need to find .exe name from window's HWND.

    But, in MSDN I found next:
    [This is preliminary documentation and subject to change]. Maybe it won't work on some PC's?

    Bye.

    Thanks,
    Ilgar Mashayev

  4. #4
    Guest

    Re: Find Windows By Exe Name

    There actually IS an API for that!!

    From VC++4 and upper, you can use:
    ToolHelp functions for Win95 and WinNT5 (2000?)
    PSAPI.DLL for WinNT4 from the WinNT4 DDK

    Uli


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured