Sendmessage)
Sendmessage (hwndcombobox, cb_resetcontent, 0, 0 );
Sendmessage (hwndcombobox, cb_addstring, 0, (lparam) text ("Sichuan "));
Sendmessage (hwndcombobox, cb_addstring, 0, (lparam) text ("Guangdong "));
Sendmessage (hwndcombobox, cb_addstring, 0, (lparam) text ("Henan "));
// Set the default items in the combo box and list box
Sendmessage (hwndcombobox, cb_setcursel, 0, 0 );
Sendmessage (hwndlist, lb_setcursel, 0, 0 );
Setfocus (hwndlist );
// Change the display content of the static text Control
Sendmessage (hwndstatic, wm_settext, 0, (lparam) Introduce [0]);
Return 0;
Case wm_command: // Process Control notification messages
Switch (loword (wparam ))
{
Case idc_mycombox: // notification message of the combo box Control
Switch (hiword (wparam ))
{
Case cbn_selchange: // The selected item has changed
// Obtain the index of the items selected in the combo box and reset the items in the list box
Cbindex = sendmessage (hwndcombobox, cb_getcursel, 0, 0 );
Sendmessage (hwndlist, lb_resetcontent, 0, 0 );
If (cbindex <3) // for the first three items in the combo box
{
For (I = 0; I <num [cbindex]; I ++)
{
Sendmessage (hwndlist, lb_addstring, 0,
(Lparam) place [cbindex] [I]);
}
}
Else // for the items that are subsequently added by the user
{
Sendmessage (hwndlist, lb_resetcontent, 0, 0 );
Sendmessage (hwndlist, lb_addstring, 0,
(Lparam) text ("not completed yet "));
// Reset the static text box
Sendmessage (hwndstatic, wm_settext, 0, (lparam) text (""));
}
// Change the display content of the static text Control
Sendmessage (hwndlist, lb_setcursel, 0, 0 );
Sendmessage (hwndstatic, wm_settext, 0,
(Lparam) Introduce [cbindex]);
Break;
Case cbn_editchange: // The user changes the content of the Edit Control in the combo box.
Bchanged = true; // set the identifier
Break;
}
Break;
Case idc_mylist: // notification message for the list box Control
Switch (hiword (wparam ))
{
Case lbn_dblclk: // double-click an item in the list box.
// Obtain the text of the double-click list item
Lbindex = sendmessage (hwndlist, lb_getcursel, 0, 0 );
Sendmessage (hwndlist, lb_gettext, lbindex, (lparam) temp );
Wsprintf (buffer, "% s is a good place", temp );
MessageBox (hwnd, buffer, "welcome", mb_ OK );
Break;
}
Break;
Case idc_mybutton: // button control notification message
Sendmessage (hwnd, wm_close, wparam, lparam );
Break;
Case idc_addbutton: // Add a new item to the combo box
If (bchanged)
{
// Obtain the text in the edit box of the combo box.
Sendmessage (hwndcombobox, wm_gettext, 20, (lparam) temp );
// Add the new item to the combo box
Sendmessage (hwndcombobox, cb_addstring, 0, (lparam) temp );
Sendmessage (hwndcombobox, cb_setcursel, 0, 0 );
Bchanged = false;
}
Break;
}
Return 0;
As shown in the preceding figure,ProgramStdcontrol3 does not use any resources. The values of related identifiers and character arrays are defined in the header file stdcontrol3.h. The type of the combo box is drop-down, and its creation style is a combination of the following values:
Ws_child | ws_visible | ws_vscroll | ws_tabstop | cbs_dropdown
During wm_size message processing, the window sets the position and size of the combo box and list box, And initializes the options in the combo box and list box by sending messages to the control, as shown below:
Sendmessage (hwndcombobox, cb_resetcontent, 0, 0 );
Sendmessage (hwndcombobox, cb_addstring, 0, (lparam) text ("Sichuan "));
...
Sendmessage (hwndcombobox, cb_setcursel, 0, 0 );
...
Note: It is important to send the CB _ resetcontent message to the options in the combo box or list box. Otherwise, the option list will be added to the combo box or list box repeatedly. The cb_setcursel Message sets the option with zero index as the default option.