Win32程序中使用Combo box控件

 

第一次使用win32写代码,将代码中对Combo box 控件的使用做个总结:


1.   使用SendMessage向窗口发送消息,对Combo Box进行基本操作如添加数据,删除数据,得到所选Item的值等,请参考:

       http://blog.csdn.net/qiurisuixiang/article/details/6746234


2. 使Combo box控件可见或不可见,需使用EnablkeWindow函数:

    EnableWindow(hCombo,TRUE);

    EnableWindow(hCombo,FALSE);


3. 响应Combo box的Notification message,比如选择Combo box中一个不同于当前的Item时,会响应CBN_SELCHANGE消息。

MSDN的解释:

CBN_SELCHANGE Notification


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 aWM_COMMAND message with CBN_SELCHANGE in the high-order word of the wParam parameter.

Syntax

CBN_SELCHANGE

    WPARAM wParam
    LPARAM lParam;
    

Parameters

wParam
The low-order word specifies the control identifier of the combo box.

The high-order word specifies the notification message.

lParam
Handle to the combo box. 



Process Message Code:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
          int wmId, wmEvent;

          switch (message)
          {
          case WM_COMMAND:

// low-order word specifies the control identifier of the combo box.

               wmId    = LOWORD(wParam);  

//high-order word specifies the notification message.

               wmEvent = HIWORD(wParam);
              // 分析菜单选择:
              switch (wmEvent)
               {
               case CBN_SELCHANGE:
                       if (wmId==IDC_COMBO_MODE)   //判断选中的是哪个Combo box
                         {

                               . . . . . .

                        }
                       break;
               }
              break;
       case WM_DESTROY:
              PostQuitMessage(0);
              break;

          //Although the dialog box procedure is similar to a window procedure, 

          //it must not call the DefWindowProc function to process unwanted messages
        //  default:
        //  return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值