一ComboBox函数简单介绍
1SendMessage函数向窗口发送消息
LRESULTSendMessage(
HWNDhWnd,//handletodestinationwindow
UINTMsg,//message
WPARAMwParam,//firstmessageparameter
LPARAMlParam//secondmessageparameter
);
2向ComboBox添加数据
HWNDhWndComboBox=GetDlgItem(hWnd,IDC_COMBO1);
TCHARszMessage[20]="Hello";
SendMessage(hWndComboBox,CB_ADDRSTRING,0,(LPARAM)szMessage);
3向ComboBox插入数据
HWNDhWndComboBox=GetDlgItem(hWnd,IDC_COMBO1);
TCHARszMessage[20]="World";
SendMessage(hWndComboBox,CB_INSERTRSTRING,0,(LPARAM)szMessage);
4向ComboBox删除数据
SendMessage(hWndComboBox,CB_DELETESTRING,1,0);//删除第二项数据
5清除ComboBox所有数据
SendMessage(hWndComboBox,CB_RESETCONTENT,0,0);
6获取ComboBox数据项目的数量
UINTuCount;
uCount=SendMessage(hWndComboBox,CB_GETCOUNT,0,0):
7获取ComboBox某项的值
TCHARszMessage[200];
ZeroMessage(szMessage,sizeof(szMessage)):
SendMessage(hWndComboBox,CB_GETLBTEXT,1,(LPARAM)szMessage);//获取第二项的数据
MessageBox(NULL,szMessage," ",MB_OK);
二ComboBox简单使用
1界面设计如下图
2功能实现代码(建的是简单的Win32工程)
//ComboBox.cpp
#include "stdafx.h"
#include "resource.h"
LRESULT CALLBACK Dialog(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
DialogBox(hInstance, (LPCTSTR)IDD_DIALOG1, NULL, (DLGPROC)Dialog);
return 0;
}
LRESULT CALLBACK Dialog(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
switch(uMessage)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
UINT uSender;
uSender = LOWORD(wParam);
HWND hWndComboBox;
hWndComboBox = GetDlgItem(hWnd, IDC_COMBO1);
TCHAR szBuff[200];
ZeroMemory(szBuff, sizeof(szBuff));
switch(uSender)
{
//CB_ADDSTRING是在最后添加数据
case IDC_BUTTON1:
GetDlgItemText(hWnd, IDC_EDIT1, szBuff, sizeof(szBuff));
SendMessage(hWndComboBox, CB_ADDSTRING, 0, (LPARAM)szBuff);
break;
//CB_ADDSTRING是在指定位置添加数据
case IDC_BUTTON2:
GetDlgItemText(hWnd, IDC_EDIT1, szBuff, sizeof(szBuff));
SendMessage(hWndComboBox, CB_INSERTSTRING, 0, (LPARAM)szBuff);
break;
case IDC_BUTTON3:
SendMessage(hWndComboBox, CB_RESETCONTENT, 0, 0);
break;
case IDC_BUTTON4:
UINT uCount;
uCount = SendMessage(hWndComboBox, CB_GETCOUNT, 0, 0);
SetDlgItemInt(hWnd, IDC_EDIT2, uCount, TRUE);
break;
case IDC_BUTTON5:
UINT uSelect;
uSelect = GetDlgItemInt(hWnd, IDC_EDIT2, NULL, TRUE);
SendMessage(hWndComboBox, CB_GETLBTEXT, uSelect, (LPARAM)szBuff);
MessageBox(hWnd, szBuff, "SHOW", MB_OK|MB_ICONINFORMATION);
break;
case IDOK:
EndDialog(hWnd, lParam);
break;
}
break;
case WM_CLOSE:
EndDialog(hWnd, lParam);
break;
}
return FALSE;
}
分享到:
相关推荐
其中较详细介绍了MFC中combox box的用法。 google的编程规范
Win32 API提供的一系列易用特性使得有残疾的人也能很容易的使用计算机,Win32 API提供了一些函数和结构来控制这些特性。 按钮函数(Button) Microsoft提供了对话框和控制来支持应用程序与用户之间的交互通讯。...
VS2013 MFC连接Access数据库(ADO)详细版实例操作(含Combo Box读取数据库内容)
这个例子简单得显示了,怎么用API 创建一般控件,包括button,edit,combo box等等!
1.1 为什么使用Win32 API …………………………………………………………………1 1.2 Win32 API简介 …………………………………………………………………………1 1.3 综述…………………………………………...
用VS2008_制作对话框向导 在写Win32应用程序的时候,通常我们都会使用向导。 但你想拥有自己的向导吗? 开来看看吧!
2、支持所有的Combo Box。 3、支持滚动条。 4、支持进度条。 5、支持通用对话窗与MessageBox。 6、全部支持Hover状态。 7、支持单文档、多文档、对话窗程序。 8、支持VC6/7、VB6/7、CB5/6/7。 9、支持Win95...
This package was designed for use with EEmbarcadero (formerly CodeGear / Borland) Delphi 7, 2005/Win32, 2006/Win32, 2007, 2009, and 2010 and C++ Builder 2006, 2007, 2009 and 2010, Borland Turbo Delphi...
为什么使用 Wiu32 API 14 Win32 API 简介 15 第二章 窗口管理函数 16 第一节 易用特性函数(Accessibility Features) 20 SoundSentryProc 20 SystemParametersinfo 21 第二节 按钮函数(Button) 34 CheckDlgButton...
Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...
Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...
4. Make sure the "PPP: Internet, Windows NT Server, Windows98 " item is selected from the "Type of Dial-up Server" combo box; 5. Make sure the "Log on to network" and "Enable software compression" ...
Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...
than the Win32 common control, such as custom thumbs. TRxSpinEdit and TRxSpinButton are spin controls variants. TSpeedBar with horizontal or vertical orientation that can be placed at the top, ...
Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...
Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...
Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...
<END><br>5 , vbo_checkcombo.zip Add a checkbox to a combo box and use it to enabled/disable the combo! or whatever you would like to do with it! <END><br>6 , vbo_controlframe.zip Create your ...