VC ++ learning notes (2)

xiaoxiao2021-03-06  40

When you need to change the title (CAPTION), you can use the bitmap change in C escles / NVC .

General consisting of applications: Applications objects and window objects. There is no MFC program that must have an application object, responsible for launching and terminating the application. Document class: Data for managing applications

View class: Data for displaying applications

Components: Dedicated, self-included window objects, which are usually elements that make up the user interface. Also known as the control. Components must be included in other windows and make the window as ax window. So the control is also called a sub-window control. MFC's six embedded window families: cstatic - used to display text or icon control CButton - button, check box, radio button, group box clistbox - Display project scroll list control ccomboBox - display can be retracted Project list control cscrollbar - horizontal or vertical scroll bar CEDIT - single or multi-line text editing control

Resources: Special forms of read-only data, by a program called the resource compiler to the executable. Two basic forms of resources: binary-graphic resources, including icons, cursors, and bitmap text - structured resources, including dialogs, menus, string tables, and acceleration keys. Binary resources store in a separate file, text resources are stored in a normal ASCII text file that describes the structure of each element. The ASSCII file is called a resource description file - usually with your project is the same name, its extension is .rc

DECLARE_MESSAGE_MAP () This macro tells Visualc This class will respond to the Windows message, the entry, and the corresponding mapping portal in the implementation file is part of the advanced macro system for establishing a message mapping. Message mapping guarantees that Windows messages are handed over to the correct member function.

#include "stdafx.h" is the standard application frame header file that all MFC programs are used. It introduces the language standard MFC components, most universal extensions, and definitions of Internet Explorer4 common controls.

Conversion of official and debugging: Using Build | Set Active Configuration.

Constructor and InitInstance () function: The constructor is called in the object creation. InitInstance () is overloaded when WinMain () is called. So enough to find a function is called before WinMain () is called. At this time, many MFC systems have not completed their initialization, only WinMain () will be called only if the primary application object is constructed.

In an API application, the WinMain () function has three tasks, it must be completed: 1. Register a new main window class 2, create an instance of a window and display it 3, run the message loop initInstance () function is MFC The WinMain () function performs the second content of the above content.

The key virtual function or overload function 1 for the CWINAPP class definition in CWINAPMFC is 1, initInstance () is definitely the 2, Run () scan message to be overloaded and processes the message. 3, OnIDLC (), when run () does not have a message to be a director, you will call the function. Onder () can take advantage of this opportunity to perform background tasks, otherwise the background task reduces system response speed. 4, EXITINSTANCE (), is called by run () when an application ends.

CDIALOG-based windows are created in the stack in the form of local variables, while CWND-based windows are created in the free memory (free memory) in the form of dynamic variables. Therefore, there is a CDIALOG class: cfourupdlg DLG; m_pmainwnd = & dlg; for CWND-based classes: m_pmainwnd = new cmainwindow;

Cfourupdlg :: cfourupdlg (cwnd * pparent / * = null * /): cdialog (cfourupdlg :: IDD, pParent) constructor in cfourupdlg :: IDD is an enumeration (defined in header file), including dialog template Resource ID (included in the resource description). Indicates that the CDIALOG constructor reads the information from the dialog template, and then constructs a window, which is used in the constructor is a specification given by the template. In order to create a dialog window (and all controls are included in the dialog template), the CDIALOG constructor uses the CWnd :: Create () or CWnd :: createEx () function, call the function to the main dialog and touch it. Each of the controls is called once. CWnd: Create () Function Prototype: virtual BOOL Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT & rect, UINT nID, CCreateContext * pContext = NULL); In Windows, each window is divided into two parts: a non- Customer district (including title bar, window boundary) and customer area. Where Windows is responsible for the drawing of non-client districts

Whenever Windows wants to draw a window's client area, Windows sends a WM_PAINT message to the window, usually by an onpaint () member function. OnPaint () is roughly divided into: 1. Get the canvas or draw a plane, in Windows, the drawing plane used is referred to as the device environment (DC) .2. Create an environment, including all the needed brush and painting brush, and The size of the working plane is measured to be able to correctly correct it on the plane. 3. Draw the window with the Windows graphics library GDI

You can only create a CPAINTDC object in OnPaint (). You need to call CclientDC to call the entire window with CclientDC when drawing elsewhere.

Brush: Color Brush for Picture Line or Graphics Border: Color inventory objects for filling graphics or drawing window background: Several embedded brushes and brushes provided by Windows. You can choose from SelectStockObject ().

Timer creation: setTimer (), it has three functions: 1. Timer ID - distinguish between different timer instances. 2. Timer interval - maximum resolution 55 milliseconds 3. Timer callback function - special callback The address of the function is used to handle timer messages. If the value is null, Windows will notify you the WM_TIMER message. In the dialog-based application, the OnInitDialog () function is the best place to create a timer. If Creating a successful creation, the timer ID returned by the setTimer () function is the same as the function used. Delete Timer: KillTimer () to deliver the ID used by the timer. Timer is a limited global resource. After the device, the tune KillTimer () is a must-have. It is usually possible to process the KillTimer () function timer when the corresponding WM_DESTORY message: When the counter overflows, a WM_TIMER message is generated, typically handled the WM_TIMER message in ONTIMER ()

Create a brush: The first: use constructor, such as: CPEN Greepen (PS_SOLID, 10, RGB (0,255,0)); second: two-step method cpen greenpen; Greepen.createpen (ps_solid, 10, RGB (0,255, 0)); third: Create an instance of the logpen structure to construct Logpen LP; lp.lopnStyle = ps_sdlid; lp.lopnwidth = 10; lp.lopncolor = RGB (0,255,0); cpen greenpen; greenpen.createpenIndirect (& lp) ;

转载请注明原文地址:https://www.9cbs.com/read-55592.html

New Post(0)