, windows.h:
LoadIcon (Icon) ;
LoadCursor (Cursor) ;
GetStockObject (Stock);
RegisterClassEx ;
CreateWindow ;
ShowWindow ;
UpdateWindow ;
GetMessage ;
TranslateMessage , ;
DispatchMessage ;
BeginPaint ;
GetClientRect ;
DrawText ;
EndPaint ;
PostQuitMessage ;
DefWindowProc .
Windows , .
, : c ; by BYTE ( ); n ; i ; cx, cy ( x y; count); b f BOOL ( , f flag); w WORD ( ); l LONG ( ); dw DWORD ( ); fn ; s ; sz , (string terminated by zero); h (handle); p (pointer).
, , Windows. - , , , : CS (Class Style); IDI (ID Icon); IDC ; WS (windows style); WM c .
, , UINT 32- (unsigned int), PSTR (pointer string), .. char*; LONG .
WndProc LRESULT Long RESULT. WinMain WINAPI ( Windows), WndProc CALLBACK , Windows .
: MSG (message); WNDCLASSEX ; PAINTSTRUCT ; RECT .
, , msg MSG; wndclass WNDCLASSEX.
|
|
, (handles): HINSTANCE (instance) ; HWND (handle to a window); HDC .
windows.h, , . WndProc Hello.
( ), main Windows WinMain:
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow);
WINAPI Windows . :
hInstance , ;
hPrevInstance (previous) ; , hPrevInstance = 0 NULL;
szCmdLine , , ;
iCmdShow , , ; : SW_SHOWNORMAL (1) , SW_SHOWMINNOACTIVE (7) ; SW (show window).
. , .
, RegisterClassEx, Register-Class (Ex extended ). WNDCLASSEX, :
typedef struct tagWNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCSTR lpszMenuName;
LPCSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX;
LP lp (long pointer), lpfn (long pointer to a function); cb (counter of bytes); hbr (handle to a brush).
WinMain :
WNDCLASSEX wndclass;
. ( ), , , . , .
cbSize . :
wndclass.style = CS_HREDRAW | CS_VREDRAW;
Ȼ (|). Windows, , CS, 32- , 1. , CS_VREDRAW () 0x0001, CS_HREDRAW () 0x0002 , . (bit flags).
|
|
wndclass.lpfnWndProc = WndProc; .
:
wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0;
, , 0, .
, WinMain:
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
(), . NULL; . , IDI _ APPLICATION . LoadIcon wndclass.hIcon wndclass.hIconSm, HICON ( handle to an icon).
LoadCursor IDC _ ARROW hCursor:
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
hbrBackground ( hbr handle to a brush). , . Windows .
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
GetStockObject .
, .. NULL:
wndclass.lpszMenuName = NULL;
, , szAppName:
wndclass.lpszClassName = szAppName;
, , : RegisterClassEx (& wndclass);
, .
CreateWindow , , :
hwnd = CreateWindow (szAppName, ;
"First Example", ;
WS_OVERLAPPEDWINDOW, ;
CW_USEDEFAULT, x
CW_USEDEFAULT, y;
CW_USEDEFAULT, x
CW_USEDEFAULT, y;
NULL, ;
NULL, ;
hInstance, ;
NULL); .
szAppName Hello, , .
, , , , , .
WS _ OVERLAPPEDWINDOW ; , .
x y ; CW_USEDEFAULT ; x y.
, NULL; NULL ( ).
, WinMain.
|
|
NULL, , .
CreateWindow , hwnd . Windows , . , , Windows.
Windows hwnd, Windows , .
, CreateWindow , Windows, .
ShowWindow (hwnd, iCmdShow);
hwnd ; iCmdShow : SW _ SHOWNORMAL (1) , ; SW _ SHOWMINNOACTIVE (7) , .
UpdateWindow (hwnd); , WM _ PAINT (WndProc).
. , , Windows (message queue). , , .
, , (message loop):
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
msg MSG, :
typedef struct tagMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
POINT
typedef struct tagPOINT {
LONG x;
LONG y;
} POINT;
GetMessage (&msg, NULL, 0, 0);
Windows msg; , (NULL 0) , . Windows . :
hwnd , ;
message , WM ( window message);
wParam 32- , ;
lParam 32- , ;
time , ;
pt .
message , , , WM _ QUIT (0x0012), GetMessage ; WM _ QUIT , wParam msg.
TranslateMessage (&msg); msg Windows .
DispatchMessage (& msg); msg (WndProc). WndProc , Windows, DispatchMessage. Windows DispatchMessage , , GetMessage.
|
|
, .
(WndProc) . . , RegisterClassEx. CreateWindow . .
:
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam);
MSG.
, iMsg .
, , switch. , 0. , , DefWindowProc, .
WndProc WM_PAINT WM_DESTROY, DefWindowProc ( ) , .
WM_PAINT
WM _ PAINT , (invalid) .
WM _ PAINT , .
WM _ PAINT :
hdc = BeginPaint (hwnd, &ps);
EndPaint (hwnd, &ps);
, PAINTSTRUCT, , .
BeginPaint , ; , () .
EndPaint , .
GetClientRect (hwnd, &rect);
rect RECT (rectangle ), LONG (left , top , right , bottom ), ; left, top 0, right, bottom .
rect :
DrawText (hdc, "Hello, Windows!", 1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
; (1) , ; , , , , rect. Hello, Windows! .
WM_DESTROY
, ( Close , < Alt > + < F 4>).
PostQuitMessage (0);
WM _ QUIT . GetMessage , , WM _ QUIT, 0, WinMain , .