API之FindWindowEx和SendMessage

最近在VC6.0开发中碰到了两个函数,经过一番搜索查阅,特记录于此。

FindWindowEx

// The FindWindowEx function retrieves a handle to a window
// whose class name and window name match the specified strings.
// The function searches child windows, beginning with the one following
// the specified child window. This function does not perform a case-sensitive search.
// 翻译:该函数获取一个指定类名和窗口标题字符串(大小写不敏感)都匹配的子窗口的句柄。
//
// HWND FindWindowEx(
//                     HWND hwndParent,             // handle to parent window父窗口句柄,如果为NULL,则指 桌面
//            HWND hwndChildAfter,  // handle to child window直系子窗口该窗口和此函数要查
//找的窗口
即返回的结果窗口是兄弟关系
//  
                  LPCTSTR lpszClass,            // class name类名,编辑框为EDIT,组合框为COMBOBOX等
//                     LPCTSTR lpszWindow       // window name标题名字字符串
//    )

CBN_SELCHANGE 

利用SendMessage向指定的组合框发送消息, 直接引用MSDN中关于CBN_SELCHANGE的描述:
The CBN_SELCHANGE notification message is sent when the user changes the current selection in the list box of a combo box. The user can change the selection by clicking in the list box or by using the arrow keys. The parent window of the combo box receives this notification in the form of a WM_COMMAND message with CBN_SELCHANGE in the high-order word of the wParam parameter.

CBN_SELCHANGE
idComboBox = (int) LOWORD(wParam); // identifier of combo box 
hwndComboBox = (HWND) lParam; // handle to combo box 

To get the index of the current selection, send the CB_GETCURSEL message to the control.
The CBN_SELCHANGE notification message is not sent when the current selection is set using the CB_SETCURSEL  message. 

也就是说,需要先发送CB_SETCURSEL消息后,再发送CBN_SELCHANGE消息才能响应事件,举例如下:
::SendMessage(hwndCombo, CB_SETCURSEL, 1, 0);
int id = ::GetDlgCtrlID(hwndCombo);
::SendMessage(hwndDialog, WM_COMMAND, MAKEWPARAM(id, CBN_SELCHANGE), (LPARAM)hwndCombo);
注意第二次发送消息时,第一个参数hwndDialog是父窗口的句柄,与组合框的句柄要区别开来,第三个参数用到了MAKEWPARM函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值