Use the combo box control in Win32 programs

Source: Internet
Author: User

 

The first time I used Win32 to write code, I summarized the use of the combo box control in the Code:


1. Use sendmessage to send messages to the window. Perform basic operations on the combo box, such as adding data, deleting data, and obtaining the value of the selected item. For details, see:

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


2. To make the combo box control visible or invisible, use the enablkewindow function:

Enablewindow (hcombo, true );

Enablewindow (hcombo, false );


3. Respond to the notification message of the combo box. For example, if a different item in the combo box is selected, the cbn_selchange message is returned.

Msdn explanation:

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 contains es 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, uint message, wparam, 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 );
// Select the analysis menu:
Switch (wmevent)
{
Case cbn_selchange:
If (wmid = idc_combo_mode) // determines which combo box is selected
{

......

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

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.