SetParent and Control Notifications

Last reviewed: November 2, 1995
Article ID: Q104069
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

An edit, list box, or combo box control sends notifications to the original parent window even after SetParent has been used to change the control's parent. A button control sends notifications to the new parent after SetParent has been used to change its parent.

Edit, list box, and combo box controls keep a private copy of the window handle of the parent at the time of creation. This handle is not changed when SetParent is used to change the control's parent. Consequently, the notifications (EN_*, LBN_*, and CBN_* notifications) go to the original parent.

Note that WM_PARENTNOTIFY messages go to the new parent and GetParent() returns the new parent. If it is required that notifications go to the new parent window, code must be added to the old parent's window procedure to pass on the notifications to the new parent.

For example:

case WM_COMMAND:

  hwndCtl = LOWORD(lParam);

  // If notification is from a control and the control is no longer this
  //   window's child, pass it on to the new parent.
  if (hwndCtl && !IsChild(hWnd, hwndCtl))
      SendMessage(GetParent(hwndCtl), WM_COMMAND, wParam,  lParam);
  else Do normal processing;

Button controls send notifications to the new parent after SetParent has been used to change the parent.


Additional reference words: 3.10 3.50 3.51 4.00 95 listbox combobox
KBCategory: kbui
KBSubcategory: UsrCtl


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.