Simple use of combo box (win32)

Source: Internet
Author: User

 

A Brief Introduction to combo box Functions

 

1. The sendmessage function sends messages to the window.

Lresult sendmessage (

Hwnd, // handle to destination window

Uint MSG, // message

Wparam, // first Message Parameter

Lparam // second Message Parameter

);

 

2. Add data to combo box

Hwnd hwndcombobox = getdlgitem (hwnd, idc_combo1 );

Tchar szmessage [20] = "hello ";

Sendmessage (hwndcombobox, cb_addrstring, 0, (lparam) szmessage );

 

3. insert data to the combo box

Hwnd hwndcombobox = getdlgitem (hwnd, idc_combo1 );

Tchar szmessage [20] = "world ";

Sendmessage (hwndcombobox, cb_insertrstring, 0, (lparam) szmessage );

 

4. delete data from combo box

Sendmessage (hwndcombobox, cb_deletestring, 1, 0); // Delete the second data item

 

5. Clear all combo box data

Sendmessage (hwndcombobox, cb_resetcontent, 0, 0 );

 

6. Get the number of combo box data items

Uint ucount;

Ucount = sendmessage (hwndcombobox, cb_getcount, 0, 0 ):

 

7. Obtain the value of a combo box item.

Tchar szmessage [200];

Zeromessage (szmessage, sizeof (szmessage )):

Sendmessage (hwndcombobox, cb_getlbtext, 1, (lparam) szmessage); // obtain the data of the second item

MessageBox (null, szmessage, "", mb_ OK );

 

Two Combo box for simple use

1. The interface design is shown in figure

 

2. function implementation code (a simple Win32 project is created)

// ComboBox. CPP # include "stdafx. H "# include" resource. H "lresult callback Dialog (hwnd, uint, wparam, lparam); int apientry winmain (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, uint umessage, wparam, lparam) {Switch (umessage) {case when: 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 is the last added data case when: getdlgitemtext (hwnd, idc_edit1, szbuff, sizeof (szbuff); sendmessage (hwndcombobox, cb_addstring, 0, (lparam) szbuff); break; // cb_addstring is used to add data case when: getdlgitemtext (hwnd, idc_edit1, szbuff, sizeof (szbuff); sendmessage (hwndcombobox, expires, 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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.