Using SendMessage() As Opposed to SendDlgItemMessage()

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

        - Microsoft Windows NT versions 3.1 and 3.5
    

The following information describes under what circumstances it is appropriate to use either the SendMessage() or SendDlgItemMessage() function.

Both SendMessage() and SendDlgItemMessage() can be used to add strings to a list box. SendMessage() is used to send a message to a specific window using the handle to the list box. SendDlgItemMessage() is used to send a message to the child window of a given window using the list box resource ID. SendDlgItemMessage() is most often used in dialog box functions that have a handle to the dialog box and not to the child window control.

The SendDlgItemMessage() call

   SendDlgItemMessage (hwnd, id, msg, wParam, lParam)

is equivalent to the following SendMessage() call:

   hwnd2 = GetDlgItem (hwnd, id);
   SendMessage (hwnd2, msg, wParam, lParam);

Please note that PostMessage() should never be used to talk to the child windows of dialog boxes for the following reasons:

  1. PostMessage() will only return an error if the message was not posted to the control's message queue. Since many messages are sent to control return information, PostMessage() will not work, since it does not return the information to the caller.

  2. 16-bit only: Messages such as the WM_SETTEXT message that include a far pointer to a string can potentially cause problems if posted using the PostMessage() function. The far pointer may point into a buffer that is inside the DS (data segment). Because PostMessage() does not process the message immediately, the DS might get moved. If the DS is moved before the message is processed, the far pointer to the buffer will be invalid.


Additional reference words: 3.00 3.10 3.50
KBCategory: kbui
KBSubcategory: UsrMsg


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.