Thread: Retrieving the window handle of a window a control resides in

  1. #1
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54

    Question Retrieving the window handle of a window a control resides in

    For example, let's say i want to get the HWND of the window that IDC_MYEDITCONTROL is located, how would i go about doing that?

    Thanks.
    Not yet, have to think of one...

  2. #2
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    If you know the ID and the parent window handle of the child, you can get its window handle like so:
    Code:
    hwndChild = GetDlgItem (hwndParent, idChild);
    ...or, do you mean you want to find the parent window handle of the child window?

  3. #3
    Registered User -leech-'s Avatar
    Join Date
    Nov 2001
    Posts
    54
    Originally posted by JasonD
    ...or, do you mean you want to find the parent window handle of the child window?
    Yup, that's what i'm looking for, with just the resource ID. Something like:

    Code:
    HWND parentHwnd = GetParentHWND(IDC_EDITCONTROL);
    Not yet, have to think of one...

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Try GetWindowLong() using GWL_HWNDPARENT, you'll still need the handle of the control though, see Jason's post.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    To get the handle of the control, you need the handle of the parent. Heh. So, I guess you are going to have to store one or the other.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Jason:

    If he knows the title of the parent window, he could use FindWindow(NULL, Title); to get it's handle. I guess like you, I'm a little mystified as to why he hasn't got/had this info. anyway.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    that's strange. GetParent() requires the hwnd. You can't just use a control ID to get a parent.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I would assume that is because there can be more than one control with the same id (each for different windows, of course).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. g_hWndMain = hWnd;error C2065,C2440
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 03:36 PM