VC ++ technical insider (Fourth Edition) Note (chapter 2)

Source: Internet
Author: User
Tags textout

/****************************/

Chapter 1 reusable Framework Window

1. Reusable base class design: the class designed for a project should be extracted so that it can be further generalized and applied to other applications.Program.

2. Some important functions:
1) cframewnd: activateframe
Virtual void activateframe (INT ncmdshow =-1 );
// Call the cwnd: showwindow function with ncmdshow as the parameter to display the frame window (the control bar window of the menu view will also be displayed ). Ncmdshow determines whether the window is maximized or minimized.
// Load activateframe In the derived class and modify the value of ncmdshow before ncmdshow is passed to cframewnd: activateframe. You can also call cwnd: setwindowplacement to set the position and size of the frame window and set the visual status of the control bar.
2) cwnd: precreatewindow
Virtual bool precreatewindow (createstruct & CS );
// Precreatewindow is called by the framework before the activateframe function is called to change the features of the window before the window is displayed. (For details, refer to createstruct structure.
// Reload it in the derived class, and change the value of the CS structure before the CS is passed to the base class to customize (Display) the window.
3) In MDI, The showwindow function of the main framework window is called by the initinstance function of the application class, not by the cframewnd: activateframe function. Therefore, to control some features of the MDI main framework window, add the correspondingCode.

3. Window registry
1) The Window registry is a group of system files managed by windows. windows and other applications can save some permanent information in the registry.
the Windows registry is organized into a hierarchical database. Character and integer data can be accessed through multiple key values.
2) operation:
setregistrykey causes application settings to be stored in the registry instead of. ini files.

getprofileint retrieves an integer from an entry in the application's. INI file.
writeprofileint writes an integer to an entry in the application's. INI file.
getprofilestring retrieves a string from an entry in the application's. INI file.
writeprofilestring writes a string to an entry in the application's. INI file.
Note:
1) starting from vc5, appwziard has a pair of cwinapp: setre in the initinstance function of the application class. Call the gistrykey function as follows:
setregistrykey (_ T ("Local Appwizard-generated Applications");
call the function to enable the application to use the registry, if you remove the file, the application does not use the registry. Only one INI file is created in the Windows directory and the file is used.
the string parameter of setregistrykey establishes the top-level key. The subsequent registry function defines the following two layers (called the header name and entry name ).
2) to be able to access the function using the registry, you need a pointer to the object of the application instance, which can be obtained through the afxgetapp function.
afxgetapp ()-> writeprofilestring ("Text Formatting", "font", "Times Roman");
afxgetapp () -> writeprofileint ("Text Formatting", "points", 10);
3) The Registry access function can treat the registry as a cstring object or an unsigned integer.

4. In the cstring class, lpctstr is not a pointer to a cstring object, but a unicode version used to replace const char.
1) cstring STR;
Char ch [] = "abcdefg ";
Strcpy (Str. getbuffer (strlen (CH), ch );
Str. releasebuffer ();
PDC-> textout (0, 0, STR );
Output: abcdefg
2) cstring STR ("abcdefg ");
Char ch [20];
Strcpy (CH, lpctstr (STR ));
PDC-> textout (0, 0, CH );
Output: abcdefg
Note:
Char * strcpy (char * strdestination, const char * strsource );
3) Compile function principles with string parameters:
A. If the string content is not changed: You can use the const char * parameter, and you can use the cstring & type parameter.
B. If you change the string content, you can use the cstring & type parameter (pointer can be used, but it is not recommended here ).

5. Obtain the window coordinates
Getwindowplacement
// Retrieves the show state and the normal (restored), minimized, and maximized positions of a window.
Setwindowplacement (screen coordinates before maximization can be returned)
// Sets the show state and the normal (restored), minimized, and maximized positions for a window.
Getwindowrect
// Gets the screen coordinates of cwnd.

//
///////// /// //

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.