Posting a message to a child window

This is a discussion on Posting a message to a child window within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am having some problem with posting messages. Here's the deal. I have a tabbed window with two tabs. ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    Posting a message to a child window

    Hi,
    I am having some problem with posting messages. Here's the deal. I have a tabbed window with two tabs. Each tab contain another child window. Tab 1's child window calls a an object of a class called serial(which is not a window). I want to use PostMessage() from the serial class to send messages to the child window. The thing is I don't know how to pass the handle of the child window to the serial class. What function would you use in the child window to get it's handle. Thanks a lot,
    Amish

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    31
    Why not enumerate the tab's children?

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    31
    Oops-
    Code:
    BOOL EnumChildWindows(
      HWND hWndParent,         // handle to parent window
      WNDENUMPROC lpEnumFunc,  // pointer to callback function
      LPARAM lParam            // application-defined value
    );

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    77
    As I recall PostMessage() places the message in the queue for the thread associated with the Window. Supposedly it would still get to the windows callback function when the message loop in the thread gets to DispatchMessage(). SendMessage() on the other hand sends it directly to the threads callback function. Another advantae to SendMessage() is that it will wait until the callback function finishes before returning, this has the advantage of allowing you to recieve data using the message for cases like WM_GETTEXT messages. PostMessage() puts the message in the queue and returns, the message will have the same effect you just can't be sure when/if you will get any results back.

    Another option would be SendDlgItemMessage(), doesn't get you the handle however you don't need the child's handle to send the message. You just need the handle to the main window and the integer identifier specified when you created teh child window, you can check out that function on MSDN.

    Back to the question you really asked, you can get teh HWND to the child with GetDlgItem(), you specify the handle to the parent window and the identifier for the child and it returns the HWND to the child object. Read about it here.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Quote Originally Posted by Ichmael™
    Oops-
    Code:
    BOOL EnumChildWindows(
      HWND hWndParent,         // handle to parent window
      WNDENUMPROC lpEnumFunc,  // pointer to callback function
      LPARAM lParam            // application-defined value
    );
    That would be good if I wanted to send the message to all the children but I need to send it to only 1 of them.
    Amish

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    [QUOTE=Exile]
    Another option would be SendDlgItemMessage(), doesn't get you the handle however you don't need the child's handle to send the message. You just need the handle to the main window and the integer identifier specified when you created teh child window, you can check out that function on MSDN.
    QUOTE]

    SendDlgItemMessage() seems like a good way of doing it. I currently found a way of sending the message to the main parent and then have the main dispatch it to the child window using SendMessageToDescendants(WM_TIMER,nIDEvent,0,true, false)
    It's a good workaround for now. I will still need to pinpoint the messages to one particular child though and that's where SendDlgItemMessage() might come in useful. Thanks
    Amish

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    77
    Quote Originally Posted by axr0284
    That would be good if I wanted to send the message to all the children but I need to send it to only 1 of them.
    Amish
    You can use it to get the HWND of the child windows. The call back function is given the HWND value of each of the child windows and its numeric identifier. So you could then find the HWND you needed and send the message.

    That way might be a bit complicated because the callback is told about one of the child windows at a time. If you were doing bulk sending to all the messages it would be easy here, but targetting a specific window might be a bit trickier.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Child window message
    By Gordon in forum Windows Programming
    Replies: 1
    Last Post: 02-24-2008, 02:22 PM
  2. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 01:22 AM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. Button positioning
    By Lionmane in forum Windows Programming
    Replies: 76
    Last Post: 10-21-2005, 05:22 AM
  5. posting a mouse message to a window
    By marc74 in forum Windows Programming
    Replies: 1
    Last Post: 01-09-2005, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21