Win32程序中使用Combo box控件
第一次使用win32寫代碼,將代碼中對Combo box 控件的使用做個(gè)總結(jié):
1. ? 使用SendMessage向窗口發(fā)送消息,對Combo Box進(jìn)行基本操作如添加數(shù)據(jù),刪除數(shù)據(jù),得到所選Item的值等,請參考:
? ? ???http://blog.csdn.net/qiurisuixiang/article/details/6746234
2. 使Combo box控件可見或不可見,需使用EnablkeWindow函數(shù):
? ? EnableWindow(hCombo,TRUE);
? ? EnableWindow(hCombo,FALSE);
3. 響應(yīng)Combo box的Notification message,比如選擇Combo box中一個(gè)不同于當(dāng)前的Item時(shí),會(huì)響應(yīng)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_SELCHANGEWPARAM wParamLPARAM lParam;Parameters
wParamThe high-order word specifies the notification message.
Process Message Code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
????????? int wmId, wmEvent;
????????? switch (message)
????????? {
????????? case WM_COMMAND:
?????????????? wmId ? ?= LOWORD(wParam);??
//high-order word specifies the notification message.
?????????????? wmEvent = HIWORD(wParam);
????????????? // 分析菜單選擇:
????????????? switch (wmEvent)
???????????????{
?????????????? case CBN_SELCHANGE:
?????????????????????? if (wmId==IDC_COMBO_MODE) ? //判斷選中的是哪個(gè)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;
}
總結(jié)
以上是生活随笔為你收集整理的Win32程序中使用Combo box控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: #pragma pack(n)和size
- 下一篇: C 程序更有效率的 10 种方法