LBN_SELCHANGE Notification--------------------------------------------------------------------------------An application sends the LBN_SELCHANGE notification message when the selection in a list box has changed. The parent window of the list box receives this notification message through the WM_COMMAND message. Syntax LBN_SELCHANGE WPARAM wParam LPARAM lParam;
ParameterswParam The low-order word is the list box identifier. The high-order word is the notification message.lParam Handle to the list box
给控件发消息用SendMessage不方便的,有一个专用的API: LONG SendDlgItemMessage( HWND hDlg, // handle of dialog box int nIDDlgItem, // identifier of control UINT Msg, // message to send WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
用Spy来看,这样会容易了解消息机制。
LBN_SELCHANGE WPARAM wParam
LPARAM lParam;
ParameterswParam
The low-order word is the list box identifier.
The high-order word is the notification message.lParam
Handle to the list box
LONG SendDlgItemMessage(
HWND hDlg, // handle of dialog box
int nIDDlgItem, // identifier of control
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDC_EDIT3, LBN_SELCHANGE), (LPARAM)GetDlgItem(IDC_EDIT3)->GetSafeHwnd());
hWnd为对话框的窗口句柄,故可在对话框的成员函数里调CWnd版的SendMessage()SendMessage(WM_COMMAND, MAKEWPARAM(IDC_EDIT3, LBN_SELCHANGE), (LPARAM)GetDlgItem(IDC_EDIT3)->GetSafeHwnd());