Thread: FindWindowEx - By INSTANCE not by name

  1. #1
    Registered User
    Join Date
    Jan 2008

    FindWindowEx - By INSTANCE not by name


    is it possible to find a control within a window by the instance and not by the name. the name may differ in other windows language, but the instance may always be the same number.

    thanks in advance.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    By "instance" you mean the reference (like pointer)?
    If so then I suppose your question is to check if that control exists in a window (if you want the control, you already have it )
    MyForm.Controls.Contains(MyControl); //Returns true if MyForm has MyControl

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jan 2008
    i'm talking about >>WinApi<<. I need to hook another window which contains a listview and find this listview. it has a name, but it differs in each language.

  4. #4
    Registered User
    Join Date
    May 2003
    You're trying to find the main window, or the listview's HWND?

    You can try to find the window (in whatever language) by name, then see what it has for a window class. You can only search by title or by window class, so hopefully you can do a search by class.


    Also, you could always enumerate all windows, go through the list, and using GetWindowThreadProcessId and GetModuleFileNameEx you can get the name of the process that spawned the window.
    Last edited by Cat; 02-26-2010 at 01:45 PM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Registered User
    Join Date
    Sep 2007
    To get the HWND of the listview you can use its Control ID in conjunction with GetDlgItem() (where hDlg is the listviews parent handle, and nIDDlgItem is the Control ID of the listview). Since the Control ID will stay the same in most applications, it's easier to check for that then to check for window names (which could change as you mentioned). And if there are multiple listview controls on a form then it is easier to check for the Control ID rather than the Class Name since the Control ID is unique to each control.

    You can get the Control ID of the listview using something like Spy++.
    Last edited by HLMetroid; 02-26-2010 at 07:46 PM.

  6. #6
    Registered User
    Join Date
    Jan 2008
    wow it really works!
    I enter the control ID (instead of Hinstance) and i found the control!
    thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another question :O need ideas and confirmation
    By Akkernight in forum C++ Programming
    Replies: 7
    Last Post: 02-23-2009, 02:29 PM
  2. Monitor a running instance of MS Word
    By BobS0327 in forum C# Programming
    Replies: 0
    Last Post: 07-18-2008, 12:40 PM
  3. which design is better to wrap another class instance
    By George2 in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2008, 12:27 AM
  4. Which one is "quicker" ?
    By AloneInTheDark in forum C# Programming
    Replies: 2
    Last Post: 02-08-2008, 08:23 PM
  5. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
Website Security Test