Efficiency of Using SendMessage Versus SendDlgItemMessage

Last reviewed: November 2, 1995
Article ID: Q66944
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0 and 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
    

SUMMARY

The SendDlgItemMessage function is equivalent to obtaining the handle of a dialog control using the GetDlgItem function and then calling the SendMessage function with that handle. The SendDlgItemMessage function therefore takes slightly longer to execute than the SendMessage function for the same message, because an extra call to the GetDlgItem function is required each time the SendDlgItemMessage function is called.

The GetDlgItem function searches through all controls in a given dialog box to find one that matches the given ID value. If there are many controls in a dialog box, the GetDlgItem function can be quite slow.

If an application needs to send more than one message to a dialog control at one time, it is more efficient to call the GetDlgItem function once, using the returned handle in subsequent SendMessage calls. This saves Windows from searching through all the controls each time a message is sent. The SendMessage function should also be used when your application retains handles to controls that receive messages.

However, if your application needs to send one message to many controls, such as sending WM_SETFONT messages to all the controls in a dialog, then the SendDlgItemMessage function will save code in the application because a call to the GetDlgItem function is not made for each control.

Note that if the message sent to a control may result in a lengthy operation (such as sending the LB_DIR message to a list box), then the overhead in the GetDlgItem call is negligible. Either the SendDlgItemMessage or SendMessage can be used, whichever is more convenient.


Additional reference words: 3.00 3.10 3.50 3.51 4.00 95 dlgitem
KBCategory: kbui
KBSubcategory: UsrDlgs


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.