ID Number: Q12273
2.00 2.03 2.10 3.00
WINDOWS
Summary:
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. 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.