You can use the createjavaswex function to create a subwindow. The lpclassname is the class that defines the window. If it is not a subwindow, you can use registerclass to register the class. Otherwise, use (class ):
Class |
Controls used to create |
Button |
Button control, single-choice button control, check box control, and group box Control |
ComboBox |
Combo Control |
Edit |
Edit box Control |
ListBox |
List box Control |
Static |
Static text Control |
When creating a sub-window, the style of the style and each class can be used together.
For example:Ws_child | ws_visible | lbs_standard | ws_hscroll (lbs_standard is the style of The ListBox class)
You can use the createmediawex function to create any windows and subwindows, and use the corresponding classes of MFC to create any windows and subwindows (for example, the create member function of clistbox can create a list box)
The following is a window that uses createmediawex to create a window that uses registerclass to register the window class, and then uses createmediawex to subwindows Based on The ListBox class.
Hwnd = createjavaswex ("customwnd", "win32app", ws_caption | ws_overlappedwindow | ws_sysmenu, 50, 50, 500,500, null, null, wndcls. hinstance, null );
Createmediawex ("ListBox", null, ws_child | ws_visible | lbs_standard | ws_hscroll, 200,200, hwnd, null, wndcls. hinstance, null); // a combination of window styles
You can use msdn to find information about subwindows, such as styles, supported events, and control messages ....
1. Input: createmediawex
2. createmediawex function: Windows Management
In this way, you can see the classes supported when creating the subwindow. after entering a class, you can see the messages and notifications supported by the subwindow.
Messages (the program is used to control messages in subwindows)
(If a program sends messages to a subwindow, the program controls messages in the subwindow)
Win32 compilation is directly sent using the sendmessage function, while MFC uses the class member function to control subwindows.
Major (high 16-bit notification code for wm_command messages)
(Messages sent to the program in the subwindow. Most messages are sent using wm_command. The 16-bit high is the notification code, and the notification code is listed in msdn)
Wm_command messages are directly monitored during windows in Win32 compilation, while message ing macros are defined in MFC (controls created using CREATE) (If the control on the dialog box is right-click the control in the editing area and select: Add event handle), it can be monitored.
I. static text Control)
Static text control is a one-way interaction control used to display data but does not accept input.
1. Create a subwindow Based on the cstatic class:
1) Use the toolbox to create static text (only available in the dialog box ).
2) create with the create function of the cstatic class
Declare in. h file
Cstatic test;
Call the create function in the member function
Test. Create ("jiangkai", ws_child | ws_visible | ss_center, crect (200,100, 123), this );
2. Use the static text control to implement "text display function", "display icon function", "display bitmap function", and "Click Event" through the has a link"
If you use a static text control created in the toolbox, you must add a variable to the control before implementing the has a relationship.
Text display function:
Test. setwindowtext ("happy ");
Show icon function:
Test. modifystyle (0, ss_icon); // modify the button style
Test. seticon (afxgetapp ()-> loadicon (idi_icon1); // load the icon
Display bitmap Function
1) Use the toolbox to create static text (only available in the dialog box ).
M_static2.modifystyle (0, ss_bitmap); // modify the button style
M_static2.setbitmap (loadbitmap (AfxGetInstanceHandle (), makeintresource (idb_bitmap1); // you can specify a bitmap.
Function prototype: hbitmap loadbitmap (hinstance, lpctstr lpbitmapname );
Parameters:
Hlnstance: The handle pointing to the module instance. The executable file of this module contains the bitmap to be loaded.
Lpbitmapname: point to a string (ended with null) Batch pointer. This string contains the name of the bitmap resource to be loaded. Another way is that this parameter can be composed of a resource identifier and a zero-bit header. You can use macro makeintresource to create this parameter value.
2) create with the create function of the cstatic class
Test. Create ("Jk", ss_bitmap | ws_child | ws_visible, crect (20, 40, 200,100), this, 123); // The style cannot be added with ss_center
Test. modifystyle (0, ss_bitmap); // modify the button style
Test. setbitmap (loadbitmap (AfxGetInstanceHandle (), makeintresource (idb_bitmap1); // you can specify a bitmap.
Click Event (for other events, see msdn)
1) Use the toolbox to create static text (only available in the dialog box ).
Right-click the static text control in the editing area and choose add event handle.
2) create with the create function of the cstatic class
Test. Create ("jiangkai", ws_child | ws_visible | ss_center | ss_notify, crect (200,100, 123), this, wm_user +); // The style must contain ss_notify
Add a message ing macro
On_control (stn_clicked, wm_user + 123, JK); // and finally sends the wm_command message to the program
2. edit box)
The edit box control is a window that can be input and edited from the keyboard. in the edit box control, you can enter, copy, cut, paste, delete, and other operations.
1. Create a subwindow Based on the cedit class:
1) create with Toolbox (only available in the dialog box) edit box
2) use the create function of the cedit class to create
Declare in. h file
Cedit test;
Call the create function in the member function
Test. Create (ws_child | ws_visible | ss_center, crect (123,), this );
2. Use the edit box control in the has a relationship to implement "set edit box control content", "Get edit box content", and "undo the last operation in the edit box"
Set the content of the edit box control and obtain the content of the edit box.
Cstring temp;
M_edit4.getwindowtexta (temp );
Test. setwindowtexta (temp );
Undo the last operation in the edit box
M_edit4.undo ();
3. list box Control)
The list box control displays an optional list. You can use the list box to view or select data items, and the number of items in the list is flexible.
1. Create a subwindow Based on the clistbox class:
1) create with Toolbox (only available in the dialog box) list box
2) create with the create function of the clistbox class
Declare in. h file
Clistbox test;
Call the create function in the member function
Test. Create (ws_child | ws_visible | lbs_standard | ws_hscroll, crect (200,200, 123), this, wm_user + );
2. using the has a relationship, use the edit box Control to "insert data to the list box control", "Search for data in the list box", "process the lbn_dbclk event of the list box control", and "implement the file listing function"
Insert data to the list box Control
M_list.addstring ("lingri"); // insert data
M_list.addstring ("Ling Zhongtian ");
M_list.addstring ("Lingyun ");
M_list.addstring ("lingjing ");
Search for data in the list box
M_list.selectstring (0, "Lingyun"); // query data
Process the lbn_dbclk event of the list box Control
Int Pos = m_list.getcursel (); // obtain the index of the selected item
Cstring STR;
M_list.gettext (Pos, STR); // obtain the data of the specified index.
M_static.setwindowtext (STR );
List objects
M_list.resetcontent (); // delete all data
M_list.dir (ddl_directory | ddl_system, "d: // *. *"); // list the directory of the D Drive File
4. Combo box)
The combo box control combines the edit box with the characteristics of the list box, which can be input or selected in the components of the list box.
1. Create a subwindow Based on the ccombobox class:
1) Use the toolbox to create a combo box (only available in the dialog box)
2) use the create function of the ccombobox class to create
Declare in. h file
Ccombobox test;
Call the create function in the member function
Test. Create (ws_child | ws_visible | cbs_dropdown, crect (20, 123,), this, wm_user + );
2. Use the combo box control through the has a relationship to implement "add data and insert data", "delete data in the combo box", "display current data in the combo box", and "list disk directories"
"Add data and insert data"
Test. addstring ("Spring Festival rain ");
Test. addstring ("Spring Festival rain ");
Test. insertstring (0, "to break the soul ");
"Delete the data in the combo box"
Test. resetcontent (); // delete data
"Display current data of the combo box"
Cstring STR;
M_combo3.getwindowtext (STR); // obtain the current display data of the combo3.getwindowtext control.
M_button.setwindowtext (STR );
"List disk directories"
Test. dir (ddl_drives | ddl_exclusive, ""); // list disk Directories
5. Button)
The button control can accept user commands and execute a command by clicking or double-clicking.
1. Create a subwindow Based on the cbutton class:
1) create a button using the Toolbox (only available in the dialog box)
2) use the create function of the cbutton class to create
Declare in. h file
Cbutton test;
Call the create function in the member function (Button & check box & single button & group box)
Test. Create ("Jk", ws_child | ws_visible | bs_policy | bs_pushbutton, crect (123,), this, wm_user + );
Bs_pushbutton is a button, bs_autocheckbox is a check box, bs_autoradiobutton is a single button, bs_groupbox is a group box
2. Use the button control to implement the "button display bitmap function", "button display icon function", "button display mouse image function", and "select button function" through the has a link"
"Button display bitmap function"
M_button1.modifystyle (0, bs_bitmap); // you can specify the bitmap attribute.
M_button1.setbitmap (loadbitmap (AfxGetInstanceHandle (), makeintresource (idb_bitmap1); // you can specify a bitmap.
"Button display icon function"
M_button2.modifystyle (0, bs_icon); // you can specify the icon attribute.
M_button2.seticon (afxgetapp ()-> loadicon (idi_icon1); // set the icon
"Button display mouse image function"
M_button3.modifystyle (0, bs_icon); // you can specify the icon attribute.
M_button3.setcursor (afxgetapp ()-> loadcursor (idc_cursor1); // sets the mouse Image
"Select button function" Highlights
Cbutton * m_button = (cbutton *) This-> getdlgitem (idc_check1 );
M_button-> setcheck (true );
M_button = (cbutton *) getdlgitem (idc_radio1 );
M_button-> setcheck (true );