Develop WM application series Article indexes using C ++
Introduction:
In the previous blog, we touched a little bit about screen rotation processing. In the previous blog, we touched mobile device applications of MFC.ProgramProgramming, learning how to send text messages, make calls, and use the cedit control and button control. Today, let's take a look at the use of The ListBox control in MFC.
The ListBox control is intended for most common applications. Today, we need to learn how to add items to a ListBox and how to clear items in ListBox. Of course, also, let's take a look at the use of the cedit control.
Body:
First, we should first create a C ++ MFC smart device application, and select wm5 as the platform, based on the dialog box. Then you can set other settings by default!
Then, we make the following settings in the dialog box:
We can see that we need to drag and drop a cedit control, a button control (whose caption attribute is input), and a ListBox control. Their names can be kept by default. Then, we add their names to the cedit control and ListBox control respectively.Control variables(Cedit corresponds to txtedit and ListBox corresponds to lb). If you forget how to add it, please refer to this article for a review. Then we will add an "event handler" for the input button ", this is the function of the program. We enter a string of characters in the cedit control, and then click the input button to add the string to ListBox.
Therefore, the input button event is as follows:
Input button code
VoidCmfclistdlg: onbnclickedbutton1 ()
{
Cstring textboxinfo;//Declare a cstring variable to store the input in the cedit control.
Txtedit. getwindowtext (textboxinfo );//Store the input in the cedit control in the variable.
LB. addstring (textboxinfo );//Add this variable to ListBox
}
In this way, we can use the addstring () function of ListBox to easily add items to ListBox. Then, let's take a look at the events in ListBox, I noticed a dblclk event, which seems to be a left-click event. Let's try to add an event handler for ListBox and select lbn_dblclk, for example:
Then, add the following to the method body of this event:Code:
VoidCmfclistdlg: onlbndblclklist1 ()
{
LB. resetcontent ();
}
It is also very easy. We double-click to clear all items in ListBox ~
The following is a demonstration:
1. input the following characters to the cedit control:
2. Click input and insert the ListBox:
After you double-click ListBox, The ListBox is cleared ~
Postscript:
now, we have learned how to add the basic ListBox item addstring (), clear all items resetcontent (), and believe in the next step, you will continue to study how to clear selected items ...... And other interesting operations. If you have studied it, please do not mean your achievements, share your achievements after the article ~ Jack thanked me here ~ Hey. My girlfriend came back from her hometown today and will be at the airport later ~~~~~ This Article is written here first.