Windows programming common Win32 types and common structures

Source: Internet
Author: User
Tags textout

CALLBACK replaces far pascal in the CALLBACK routine of the application
HANDLE is a 32-bit unsigned integer used as a HANDLE.
HDC device description handle
HWND a 32-bit unsigned integer used as a window handle
LONG a 32-bit signed integer
LPARAM is used to declare the type of lParam
Similar to LPSTR, but used for read-only string pointers
LPSTR a 32-bit pointer
A normal LPVIOD pointer type is equivalent to (viod *)
Return Value of the LRESULT subwindow Process
NULL is the zero value of an integer. It is often used to activate the default actions and parameters of a function.
UINT is an unsigned integer type. Its size depends on the host environment. It is 32-bit in NT.
WCHAR is a 16-bit UNICODE character used to represent symbols of all languages in the world.
WINAPI replaces far pascal in API Definition
WPARAM Statement on wParam

Common Win32 application Structures

Structure Description
-----------------------------------------------
MSG defines the input message domain
PAINTSTRUCT defines the drawing structure used for drawing in a window
RECT defines a rectangle
WNDCLASS defines a window class

Example:

# Include
Lresult callback WndProc (HWND, UINT, WPARAM, LPARAM );
Char szProgName [] = "ProgName ";
Int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdline, int nCmdShow)
File: // Winmain() Is the start and end of the application. It is mainly responsible for registering the window type of the application; executing the necessary initialization process; Creating and initializing the message loop of the application (used to receive the message queue of the program); ending the program, generally, when the WM_QUIT message is accepted.
File: //WINDOWS passes four parameters to WINMAIN:
File: // Parameter1 hInst: indicates the instance handle. When an application runs in WINDOWS, this number identifies the application.
File: // ParameterNumber 2 hPrevInst: it will always be a NULL value, indicating that other instances without this application are running.
File: // ParameterNumber 3 (lpCmdline:
File: // ParameterNumber 4 nCmdShow:
{
HWND hWnd;
MSG lpMsg;
WNDCLASS wcApp;
WcApp. lpszClassName = szProgName;
WcApp. hInstance = hInst;
WcApp. lpfnWndProc = WndProc;
WcApp. hCursor = LoadCursor (NULL, IDC_ARROW );
WcApp. hIcon = 0;
WcApp. lpszMenuName = 0;
WcApp. hbrBackground = GetStockObject (WHITE_BRUSH );
WcApp. style = CS_HREDRAW | CS_VREDRAW;
WcApp. cbClsExtra = 0;
WcApp. cbWndExtra = 0;
If (! RegisterClass (& wcApp ))
Return 0;
HWnd = CreateWindow (szProgName, "This is an example ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
(HWND) NULL,
(HMENU) NULL,
(HANDLE) hInst,
(LPSTR) NULL );
ShowWindow (hWnd, nCmdShow );
UpdateWindow (hWnd );
While (GetMessage (& lpMsg, 0, 0 )){
TranslateMessage (& lpMsg );
DispatchMessage (& lpMsg );
}
Return (lpMsg. wParam );
}
Lresult callback WndProc (HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
Switch (messg)
{
Case WM_PAINT:
Hdc = BeginPaint (hWnd, & ps );
MoveToEx (hdc, 0, 0, NULL );
LineTo (hdc, 639,429 );
MoveToEx (hdc, 639,0, NULL );
LineTo (hdc, 0,429 );
TextOut (hdc, 120,30, "some lines", 6 );
Chord (hdc, clerk, 20, clerk, 80, 455, 25, clerk, 70 );
TextOut (hdc, "arc", 4 );
Pie (hdc, 400,150,300, 50,300,100 );
TextOut (hdc, 350,50, "Pie Chart", 4 );
Ellipse (hdc 100,100,400,400 );
Ellipse (hdc 249,249,251,251 );
TextOut (hdc, 250,250, "center", 4 );
Rectangle (hdc, 50,300,150,400 );
ValidateRect (hWnd, NULL );
EndPaint (hWnd, & ps );
Break;
Case WM_DESTROY:
PostQuitMessage (0 );
Break;
Default:
Return (DefWindowProc (hWnd, messg, wParam, lParam ));
Break;
}
Return 0;
}

Related Article

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.