I. Usage of cmnue
1. how to load a menu in dolog
First add a cmenu * mu variable
In the initial function with dolog, oninitdialog ()
Add mu = new (cmenu); // create a new menu
Mu. loadmenu (idr_menu); // load menu
Setmenu (MU); // display menu
2. How to operate menus
Change menu ID
Cmenu: modifymenu
Bool modifymenu (uint nposition, uint nflags, uint nidnewitem = 0, lpctstr lpsznewitem = NULL );
Nposition is the ID of the menu to be changed;
Nflags 1: mf_bycommand menu ID; 2: mf_byposition indicates the sequential menu position, starting from 0
Nidnewitem 1: id_change its menu
2: mf_popup: Specify the drop-down menu/sub-menu handle
Lpsznewitem: content to be changed
For example:Cmenu * mu; <br/> .......... <br/> Mu-> modifymenu (idr_1, mf_bycommand, idr_1, "open"); <br/> setmenu (MU );
3. How is the menu control invalid?
Uint Enablemenuitem ( Uint Nidenableitem, Uint Nenable );
WhereNenableYes
Mf_bycommand: Specify the parameter to indicate the existing menu command ID.
Mf_byposition: specify a parameter to indicate an existing menu position.
Mf_disabled: the menu item is invalid so that it cannot be selected but remains unchanged in the future.
Mf_grayed: makes the menu item invalid and grayed out.
Mf_enabled: Make the menu effective so that they can be selected and restored from the gray state.
Note: any changes must be displayed by cmenu re-painting and setmenu..
Ii. Dialog Box Problems
1) create and use modal
Cdlg DLG; <br/> DLG. domodal ();
2) The non-modal mode is different from the modal mode. After the non-modal dialog box is displayed, you can still use the parent dialog box, but the modal mode does not work. The modal mode must end the subdialog box to continue to use the parent dialog box.
Cdlg DLG; // use the heap variable in. h file definition <br/> ..... <br/> DLG. create (ID, this); // create a directory where you want to <br/> DLG. showwondow (sw_show) // display dialog box <br/>
The non-modal dialog box is created using a pointer instead of the above method.
Cdlg * DLG = new cdlg; <br/> DLG-> Create (ID, this); <br/> DLG-> showwindow (sw_show );
3) Destruction of the non-Modal Dialog Box
How to reload oncancel for a non-modal dialog box? The dialog box is hidden and not destroyed, and resources are not released.
How to destroy the non-Modal Dialog Box
1. Reload oncancel and call destroywindow (); FunctionNote that this function must be placed at the end. After the function is called, it directly enters the postncdestroy () function. If there are other resources not released, an error will occur.
: Oncancel () <br/>{< br/> destroywindow (); <br/>}
2. Reload postncdestroy (). The dialog box will be destroyed.
: Postncdestroy () <br/>{< br/> Delete this; <br/> cdialog: postncdestroy (); <br/>}
4) how to obtain the server dialog box handle from the subdialog box for communication
Cwnd: getparent (); // note that forced type conversion is required;
Complete typeHwnd getparent (hwndHwnd// Handle to Child Window); // If the parent class dialog box does not exist, null is returned.
3. Window. the dialog box size is changed accordingly.
Cwnd: onsize
Afx_msg Void Onsize ( Uint Ntype, Int CX, Int Cy );
The corresponding window changes. The dialog box size changes, and the control size needs to be changed within the function.
4. How to directly convert various types of data into strings
Use sprintf (char * buf_a, "% F", );
A is the data to be converted, and buf_a is the storage address to be converted to a string.
Note:: % F only keeps 6 valid data bits.
Use %. NF if you want to retain multiple decimal places
N indicates the reserved decimal point.
Note:: The difference from printf. Printf only prints data to the specified display.
5. Convert the data in the string to the corresponding type.
The first type of ATO? : Must contain# Include <stdlib. h>
Double Atof ( Const Char *String ); // Convert to float
Int Atoi ( Const Char *String ); // Convert to int
_ Int64 _ atoi64 ( Const char *String );
Long Atol ( Const Char *String ); // Convert to long int
The function will scan the string, skip non-numeric characters, know that the conversion of the first number or plus or minus signs ends with a non-numeric character or string terminator ('/0'), and return the result
Stirto?# Include <stdlib. h>
Double Strtodd ( Const Char *Nptr, Char **Endptr ); // Convert to double
Double Wcstod ( Const Wchar_t *Nptr, Wchar_t **Endptr ); // Convert the width byte to double
Long strtol (const char *Nptr, Char **Endptr, IntBase); // Long int
Long wcstol (const wchar_t *Nptr, Wchar_t **Endptr, IntBase);
Only char * needs to be defined for use *Nptr// Entity required
Char * en // only the pointer is required and does not need to be materialized
This type of function converts the first numeric character or positive and negative character in the nptr to the corresponding data, ends with a non-numeric character, and retains the remaining character strings in the ne, ne is the subsequent string after the conversion is stopped, and for long, base is the base of the number of digits. In this way, the data can be directly converted into 16-bit, 8-bit, and 32-bit data:
For example, msdn
# Include <stdlib. h> <br/> # include <stdio. h> </P> <p> void main (void) <br/> {<br/> char * string, * stopstring; <br/> double X; <br/> long l; <br/> int base; <br/> unsigned long ul; <br/> string = "3.1415926 this stopped it "; <br/> X = strtodd (string, & stopstring); <br/> printf ("string = % s/n", string ); <br/> printf ("strtodd = % F/N", x); <br/> printf ("stopped scan at: % s/n", stopstring ); <br/> string = "-10110134932 this stopped it"; <br/> L = strtol (string, & stopstring, 10 ); <br/> printf ("string = % s", string); <br/> printf ("strtol = % lD", L ); <br/> printf ("stopped scan at: % s", stopstring); <br/> string = "10110134932 "; <br/> printf ("string = % s/n", string); <br/>/* convert string using base 2, 4, and 8: */<br/> for (base = 2; base <= 8; base * = 2) <br/> {<br/>/* convert the string: */<br/> ul = strtoul (string, & stopstring, base); <br/> printf ("strtol = % LD (base % d)/n", UL, base); <br/> printf ("stopped scan at: % s/n", stopstring ); <br/>}</P> <p> output </P> <p> string = 3.1415926 this stopped it <br/> strtodd = 3.141593 <br /> stopped scan: this stopped it </P> <p> string =-10110134932 this stopped it strtol =-2147483647 stopped scan: this stopped itstring = 10110134932 <br/> strtol = 45 (base 2) <br/> stopped scan at: 34932 <br/> strtol = 4423 (Base 4) <br/> stopped scan at: 4932 <br/> strtol = 2134108 (base 8) <br/> stopped scan at: 932 </P> <p>
This type of function also includes:
IntStrtoint (LpctstrLpsrc );
2) convert char and int to cstring
Use
Char * A = "just do it"; <br/> cstring B; <br/> B. Format ("% s", );