Thread: Child window handle not known

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    44

    Child window handle not known

    I defined a child window in my Window procedure as follows:

    Code:
    for(i = 3; i < 13; i++) hwndEdit[i] = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("edit"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL, 2*cxChar, (6+(2+7/4)*i)*cyChar, 10*cxChar, 7*cyChar/4, hwnd, (HMENU) i+3, ((LPCREATESTRUCT) lParam) -> hInstance, NULL);
    For i=5 I obviously have a child window ID of 8. In the procedure I can communicate with this child window through this ID. However, if I try to communicate with this child window in a Dialog procedure it doesn't work. If I try to get the child window handle with:

    Code:
    hChild = GetDlgItem(hwnd, 8);
    if(hChild) MessageBox(NULL, TEXT("A handle is returned"), TEXT("Warning!"), MB_OK | MB_ICONINFORMATION);
    the MessageBox will not show up. hwnd is provided as a parameter to the Dialog Procedure. What am I doing wrong?

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    44
    Actually I think I should use hChild = GetDlgItem(GetParent(hwnd), 8), because hwnd is the handle to the Dialog Window. The child window with ID 8 also has the parent of the Dialog Window as its parent.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    44
    hmmm, still this doesn't work though....

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    44
    ok, this is pretty stupid. I fixed it myself The 'i+3' after (HMENU) in CreateWindow has to be in between brackets, otherwise only the handle to ID equal to 3 is known.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  2. Posting a message to a child window
    By axr0284 in forum Windows Programming
    Replies: 6
    Last Post: 01-27-2005, 09:35 AM
  3. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM