`
xitong
  • 浏览: 6188510 次
文章分类
社区版块
存档分类
最新评论

Combo Box的简单使用(Win32)

 
阅读更多

ComboBox函数简单介绍

1SendMessage函数向窗口发送消息

LRESULTSendMessage(

HWNDhWnd,//handletodestinationwindow

UINTMsg,//message

WPARAMwParam,//firstmessageparameter

LPARAMlParam//secondmessageparameter

);

2ComboBox添加数据

HWNDhWndComboBox=GetDlgItem(hWnd,IDC_COMBO1);

TCHARszMessage[20]="Hello";

SendMessage(hWndComboBox,CB_ADDRSTRING,0,(LPARAM)szMessage);

3ComboBox插入数据

HWNDhWndComboBox=GetDlgItem(hWnd,IDC_COMBO1);

TCHARszMessage[20]="World";

SendMessage(hWndComboBox,CB_INSERTRSTRING,0,(LPARAM)szMessage);

4ComboBox删除数据

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;
}


分享到:
评论

相关推荐

    combo_box 的用法,word文档

    其中较详细介绍了MFC中combox box的用法。 google的编程规范

    window32 API大全 win32编程

    Win32 API提供的一系列易用特性使得有残疾的人也能很容易的使用计算机,Win32 API提供了一些函数和结构来控制这些特性。 按钮函数(Button) Microsoft提供了对话框和控制来支持应用程序与用户之间的交互通讯。...

    VS2013 MFC连接Access数据库(ADO)详细版实例操作(含Combo Box读取数据库内容)

    VS2013 MFC连接Access数据库(ADO)详细版实例操作(含Combo Box读取数据库内容)

    WIN32 API 控件例子

    这个例子简单得显示了,怎么用API 创建一般控件,包括button,edit,combo box等等!

    (推荐)Win32 API大全

    1.1 为什么使用Win32 API …………………………………………………………………1 1.2 Win32 API简介 …………………………………………………………………………1 1.3 综述…………………………………………...

    vs2008 制作对话框向导 程序向导

    用VS2008_制作对话框向导 在写Win32应用程序的时候,通常我们都会使用向导。 但你想拥有自己的向导吗? 开来看看吧!

    EasySkin

    2、支持所有的Combo Box。 3、支持滚动条。 4、支持进度条。 5、支持通用对话窗与MessageBox。 6、全部支持Hover状态。 7、支持单文档、多文档、对话窗程序。 8、支持VC6/7、VB6/7、CB5/6/7。 9、支持Win95...

    ESB Professional Computation Suite for VCL v6.2.0

    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...

    最全的WinAPI手册

    为什么使用 Wiu32 API 14 Win32 API 简介 15 第二章 窗口管理函数 16 第一节 易用特性函数(Accessibility Features) 20 SoundSentryProc 20 SystemParametersinfo 21 第二节 按钮函数(Button) 34 CheckDlgButton...

    vc++ 应用源码包_1

    Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...

    vc++ 应用源码包_2

    Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...

    PICO2000品科监控卡软件

    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" ...

    vc++ 应用源码包_3

    Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...

    rx第三方控件

    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, ...

    vc++ 应用源码包_6

    Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...

    vc++ 应用源码包_5

    Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...

    vc++ 开发实例源码包

    Skin_Combo_Box_demo 自绘Combox控件的实例。 SkinList_Demo 自绘List控件的实例。 Smile 自绘List控件的实例。 SOCK登录SSL加密网站 调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的...

    VB编程资源大全(英文源码 控件)

    <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 ...

Global site tag (gtag.js) - Google Analytics