Notes of Visual C ++ 6.0

xiaoxiao2021-03-06  115

Notes of Visual C 6.0

Resource symbol

Table 1 resource symbol definition common prefix

Category resource symbol prefix represented resources or object resource IDR_IDD_IDC_ idi_ idb_ accelerator key or menu and related resource dialog resource cursor resource icon resource bitmap resource menu item command control IDM_ ID_IDC_ menu item command item control string IDS_ idp_ string String used in the table in the table

2. API (Application Programming Interface) is an abbreviation for the application programming interface. Windows API is a standard program interface between Windows systems and Windows applications.

According to the function completed by the Windows API, it can be divided into three categories:

l Window management function: implement the creation, movement, and modification of the window;

l Graphic Equipment (GDI) function: Implementation of graphical operational functions independently of equipment;

l System service function: implement a variety of functions related to the operating system.

So far, Microsoft has released several Windows API versions, where Win32 is used for Windows NT, and Windows 98 API is close to Win32.

3. Handle and Windows Message

The handle (Handle) is the basis for the entire Windows programming. A handle refers to a unique integer value used by Windows. It is a 4-byte long value that identifies different objects and different instances in the application, such as a window, buttons, icon, scroll bar, Output devices, controls or files, etc. The application can access the corresponding object information through the handle.

l Windows Applications Windows Messages (Message) exchange with other Windows applications and Windows systems.

The message in Windows consists of three parts: message number, word parameter and long word parameters. The message number is used by the predetermined message name ID; the word parameter (WPARAM), and long word parameters (lParam) are used to provide additional information for messages, and the meaning of additional information is related to the value of the specific message number. In Windows, the message is often represented by a structural MSG, and the definition of the structural MSG is as follows:

Typedef struct tagmsg

{

Hwnd hwnd;

Uint Message;

WPARAM WPARAM;

LParam Lparam;

DWORD TIME;

Point pt;

} Msg;

among them:

l hwnd is a window handle to retrieve a message. If this parameter is NULL, you can retrieve all messages in the message queue.

l Message is a message value representing a message, and each Windows message has a message value, which is identified by the macro definition in the Windows.h header file.

l WPARAM and LPARAM are additional information about messages, which is different from different messages.

l Time Specifies the time to send to the queue.

l Pt Specify the location of the screen cursor when the message is sent. PT's data POINT is also a structure, and the definition of Point is as follows:

TypedEf struct tagpoint

{

LONG X, Y; // X and Y indicate the abscissa and ordinate of the screen, respectively

Point;

4. The system defined message prefix is ​​as follows:

l BM represents button control message

l CB represents a combination frame control message

l DM represents the default lower press button control message

l EM represents editing control message

ll represents a list box control message

l WM represents window message

5. Forms of Windows Applications 2 Five Files of Windows Applications Extensions and Types

Extended file type Remarks .c or .cpp C language source program file

.H header file contains external constants, variables, data structures, and functions required for source file files and their descriptions. DEF module define file module definition file definition program module's properties, in Windows 95/98, this file can be omitted .rc Resource Description File Resource Description File Defines the resources used by the source. Mak project files After compiling the source program files, generate engineering files, which is further compiled into executable

6. Source program composition structure

Windows application has a relatively fixed basic structure, which makes a basic framework by the entrance function WinMain and window functions, and contains various data types, data structures and functions. The entrance function WinMain and window functions are the main body of the Windows application.

1) WinMain function

The WinMain function is the entry of all Windows applications. It is similar to the main function in the C language. It features a set of definitions and initialization work and generates a message loop. The message loop is the core of the entire program.

The WinMain function implements the following features:

l Register the window class, create a window and perform other necessary initialization work.

l Enter the message loop, call the corresponding processing process based on the message received from the application message queue.

l Terminate the program to run when the message loop retrieves the WM_QUIT message.

Winmain functions have three basic components: function description, initialization, and message loop.

(1). Function Description

The description of the WinMain function is as follows:

Int WinApi Winmain

(

Hinstance hthisinst, // application current instance handle

Hinstance hprevinst, // application Other instance handles

LPSTR LPSZCMDLINE, / / ​​Pointer to point to program command line parameters

INT ncmdshow // application starts the integer value identity of the window display mode

)

The Windows system performs an instance of the application every time the application is called the application, and uses an instance handle to uniquely identify it.

(2) Initialization

Initialization includes the definition of the window class, registration. Create a window instance and a display window.

a) Window definition

In a Windows application, the window class defines the form and functionality of the window. The window class definition is completed by assigning the window data structure WNDCLASS, which contains various attributes of the window class. Window definitions are commonly used:

l loadicon function

The role of the LoadICon function is to load a window icon in the application. Its prototype is:

Hicon Loadicon

(

The module handle of Hinstance Hinstance, // icon resource; if NULL, use the system predefined icon

LPCTSTR LPICONNAME // icon resource name or system predefined icon identifier name

)

l loadingcursor function

The role of the LoadCursor function is to load a window cursor in the application. Its prototype is:

HCURSOR LOADCURSOR

(

The module handle where Hinstance Hinstance, / / ​​cursor resource is located; if null, use the system predefined cursor

LPCTSTR LPCURSORNAME / / Cursor resource name or system predefined categot identification name

)

l getStockObject function

The application also calls the background brush provided by the function GetStockObject Getting System, which is:

Hbrush getStockObject (int nbrush); // nbrush is the logo name of the background brush provided by the system

b) The registration window WINDOWS system itself provides some predefined window classes, and programmers can customize the window, and window classes must be used first. The registration of the window class is implemented by the function regiSterclass (). The form is:

Registerclass (& Wndclass); // WNDClass is a window structure

The return value of the RegisterClass function is a Boolean. If the registration is successful, the return value is true.

c) Creating a window

An instance of creating a window class is implemented by a function createWindows (), which is:

HWND CREATEWINDOW

(

LPCTSTR LPSZCLASSNAME, // Window Category Name

LPCTSTR LPSZTILE, // Window Title Name

DWORD DWSTYLE, / / ​​Create a window style, common window style as shown in Table 3

INT X, // Window Left upper horizontal coordinates

INT Y, // Wave place in the upper left corner

INT nwidth, // window width

INT nheight, // window height

HWND HWNDPARENT, / / ​​The parent window handle of the window

HMENU HMENU, // Window main menu handle

Hinstance Hinstance, // Create a window for the application current handle

LPVOID LPPARAM / / Pointer to a parameter value passed to the window

)

Table 3 Common window styles

Identifies the description WS_BORDER created along the border of the window WS_CAPITION create a window title bar along the window area WS_HSCROLL create a horizontal scroll bar WS_MAXMIZEBOX created along the maximize button along the window WS_MAXMIZE create a maximized window WS_MINMIZEBOX created along the minimize button in the window area to create a minimum WS_MINMIZE Window WS_OVERLAPPED Create a Border and Title Bar WS_OVERLAPPEDWINDOW Create a Border, Title Bar, System Menu and Maximum, Minimize Window WS_POPUP Create a pop-up window WS_POPUPWINDOW Create a Border and System Menu pop-up WS_SYSMENU Create Window of the System Menu WS_VSCROLL Creates a window with a vertical scroll bar

d) display window

The display of the window class is implemented by the showWindow and UpdateWindow functions. The application calls the showwindow function to display the window on the screen, which is:

ShowWindow (HWND, NCMDSHOW);

Where hwnd is the window handle, ncmdshow is identified by the window display form, and Table 4 lists the common display form identity and its description.

Table 4 common display form identification and its identification

Identification Description SW_HIDE Hide Window SW_SHOWNORMAL Display and Activate Window SW_SHOWMIMIZE Display and Minimize Window SW_SHOWMAXIMIZE Display and Maximize Window SW_SHOWNOACTIVE Show but does not activate the original location and size of the window SW_RESTORE recovery window

After the window is displayed, the application often invokes the UpdateWindow function to update and draw the user area and issue a WM_PAINT message. The form is: UpdateWindow (HWND);

(3) Message cycle

The run of the Windows application is based on the message. Windows will be generated in the application's message queue, and the application's WinMain function extracts the message in the queue from the message loop, and passes it to the corresponding process of the window function.

The common format of the message loop is as follows:

MSG msg;

...

While (GetMessage (& MSG, NULL, 0, 0))

{

TranslateMessage (& MSG);

DispatchMessage (& MSG);

}

Where the function getMessage is to read a message from the message queue and place the message in an MSG structure. The form is: GetMessage

(

LPMSG; / / Pointer to the MSG structure

HWnd,

NMSGFiltermin, // Minimum message number for message filtering

NMSGFilterMax // Maximum message number for message filtering

)

The filtering of the message can be implemented by setting the parameter nmsgfiltermin and NMSGFiltermax, that is, only the message within the determined message number range. If both parameters are 0, the message is not filtered.

The TranslateMessage function is responsible for converting the virtual keys of the message to character information, which is:

TranslateMessage (LPMSG);

The DispatchMessage function transmits the message points to the parameter LPMSG to the specified window function, which is:

DispatchMessage (LPMSG);

When the getMessage function returns a zero value, the program will end the loop and exit when the WM_QUIT message is retrieved.

2) Window function

The window function is a function of the application processing received message, which contains the processing of the application to various messages that may receive.

The general form of window functions is as follows:

LResult Callback WndProc

(

HWND HWND, // window handle

Uint message, / / ​​represent the message value of the message processed

Additional parameters for WPARAM WPARAM, //

Additional parameters for lParam lParam //

)

{

...

Switch (Message)

{

Case ...

...

Break;

...

Case WM_DESTROY:

PostquitMessage (0);

DEFAULT:

Return DefWindowProc (Hwnd, Message, WPARAM, LPARAM);

}

Return (0);

}

Programmers only need to write corresponding processing segments in the CASE statement based on messages that may be received by the window.

Wherein, there is generally been processed on the message WM_DESTROY, which is sent when the window is turned off. Under normal circumstances, the application call function PostquitMessage responds to this message. The prototype of the PostQuitMessage function is as follows:

Void PostquitMessage (int nexitcode); // nexitcode is exit code for the application

The function of the function PostquitMessage is to issue a WM_QUIT message to the application, requesting an exit. In addition, the application is provided for the message of the undefined process by adding the following statement in the message processing program segment.

Default handle:

Default: Return DefwindowProc (HWnd, Message, WPARAM, LPARAM);

Function DefWindowProc is a system default processing process to ensure that all messages sent to this window are handled.

3) Data type

Windows.h is the key to the user call system function, which defines the data type used by the Windows system, including many simple types and structures.

Table 5 commonly used part of Windows data type and its description

Data Type Description Word 16-bit No Symbol Integer Long 32 Bits Symbol Integer DWORD 32 Bit Non-Symbol Integers Handle Handle UINT 32 Bit Non-Symbol Integer Bool Boolean Lpistr Point 32-bit Pointer LPCTSTR Pointing 32-bit Pointers to String Constants

4) Data structure

(1) msg

The data structure MSG contains all the information of a message, which is both a format of the message sent, and is also one of the most basic data structures programming for Windows.

(2) WNDCLASS

Structure WNDCLASS contains all information of a window class and one of the basic data structures used in Windows programming. The application defines the properties of the window to determine the window. It is defined as follows: TypedEf struct tagwndclass

{

UINT style; // Window style, generally set to 0

WINDPROC LPFNWNDPROC; / / Pointer to the window function

INT CBCLSEXTRA; / / The number of bytes after allocating on the window structure

INT CBWndextra; // Number of bytes after allocating on window instance

Hinstance Hinstance; // Defines an instance handle of the application of the window class

Hicon Hicon; // window icon

Hcursor hcursor; // window cursor

Hbrush Hbrbackground; // Window Class Background Brush

LPCTSTR LPSZMENUNAME; // Window Type Menu Resource Name

LPCTSTR LPSZCLASSNAME; // Window Classification

} WNDCLASS;

(3) Point

The Point structure defines the X coordinates and Y coordinates of one point on the screen or window. The POINT structure is also one of the most commonly used structures in the application.

(4) RECT

The RECT structure defines a rectangular area, which contains the X coordinates and Y coordinates of the left upper corner and the lower right corner of the rectangular area. It is defined as follows:

Typedef struct tagRect

{

Long left; // Rectangular frame X coordinate

Long Top; // Rectangular frame Y coordinate

Long Right; // Rectangle X coordinate

Long Bottom; // Rammer Y coordinate

}

7. Windows Graphics Device Interface (GDI, Graphics Device Interface "has no device unrelated

GDI Basic Concept:

Device Context is a collection of attributes used to determine the location and image of the GDI output of any device. The application cannot access device description tables directly, but the application can use the handle of the device descriptor to indirectly access the device description table and its properties. When the program requires a handle for the device description table, a device descriptor will be created.

Table 6 Device Description Table Properties and Related Functions

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

New Post(0)