ºÝºÝߣ
Submit Search
03 ???????
?
0 likes
?
6,236 views
jaypi Ko
Follow
WinMain, WndProc
Read less
Read more
1 of 30
Download now
Downloaded 19 times
More Related Content
03 ???????
1.
CHAP. 3 1st ???? 1
2.
2 #include <windows.h> LRESULT CALLBACK
WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArg, int nCmdShow) { HWND hWnd; MSG msg; WNDCLASS WndClass; WndClass.style = NULL; WndClass.lpfnWndProc = WndProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = hInstance; WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.lpszMenuName = NULL; WndClass.lpszClassName = ¡°Hello¡±; if(!RegisterClass(&WndClass)) return NULL;
3.
3 hWnd = CreateWindow( ¡°Hello¡±, ¡°Hello¡±, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
NULL, hInstance, NULL ); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
4.
4 LRESULT CALLBACK WndProc(HWND
hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); }
5.
?? ??? ??? 5 ?????
??? ????? ??? ? ?? ?? ??? ??? ?? ??. ??? ? ??? ??? C ??? ???
6.
?? ??? ???
?? ? 6
7.
??? ?? ???
Windows (????)? ??? ????? ?? ?? ??? ???? ?? ??? ??? ?? ? ??? ??? ?? ?? ?? ?? ?? ????? Event-Driven Programming 7 ? ?? ??? ??? 1?? ?? ???
8.
8 ??? ?? ?? ???
?? ?? ???? ? ? ? ?? ??? ?? ?? ?????? ??? ?? ? ??
9.
9 #include <windows.h> LRESULT CALLBACK
WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArg, int nCmdShow); ??? ?? ?? ??? ?? ?? WinMain WndProc ??? ? ??? ??? ??? ??? ?? ? ? ?
10.
10 ??? ????? ??
??? ??? ??? ??? ? ???? ??? ??? ? ?? ??? ??? ? ???? ???? ? ?? ????? ? ??? ?? ???? ? ??? ??? ? ??? ????
11.
11 ? ???? ???
??? ? ?? ??? ??? ? ???? ???? ? ?? ????? ? ??? ?? ???? ? ??? ??? ? ??? ???? ? ??? ?? ??? ?? ? ??? ?? ??? ?? ? ???? ? ??? ?? ?? ?? ? ??? ?? ?? typedef struct { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG ??? ??? ??? ?? ????, ??? ????
12.
12 typedef struct { HWND hwnd; UINT
message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG unsigned int Handle to a Window HINSTANCE handle to an Instance (Program) ? ?????? ? ? ?? ?? ?? ???? ?? ?? ??
13.
????? ?? ??
??? 13 ?~ ?? ? ?? ?? ??
14.
14 #include <windows.h> ??? ??????
????
15.
15 LRESULT CALLBACK WndProc(HWND,
UINT, WPARAM, LPARAM); ??? ?? ??? ????? LRESULT CALLBACK HWND UINT WPARAM LPARAM ?? ??; ??? ?? ?? ?? ?? ?? ?? ??? ?? ??? ??? ???? 1 ???? 2 PASCAL ?? ?? C ?? ?? ? word parameter = 4 bytes ? long word parameter = 4 bytes ?? word ? 2 bytes ?? long? 2? ??? ??? ? ? 4 bytes
16.
16 LRESULT CALLBACK WndProc(HWND,
UINT, WPARAM, LPARAM); ??? ?? ??? ????? LRESULT CALLBACK HWND UINT WPARAM LPARAM ?? ??; ??? ??? ?? ?? ?? ?? ?? ?? ??? ?? ??? ??? ???? 1 ???? 2 PASCAL ?? ?? C ?? ?? __stdcall ??? ? ??? ?? ?? ??? callback ???? ?? ????? MSG? ??
17.
17 int WINAPI WinMain( HINSTANCE
hInstance, HINSTANCE hPrevInstance, LPSTR lpszArg, int nCmdShow) { } ??? ???? ?? ?? WINAPI HINSTANCE LPSTR ??? ???? ?? ?? ??? ???? ID ??? ??? ???? ID ?? ? ???? ??? ??? ?? ?? ?? ???? ?? ? ??? ??? ??? ??? ?? ?? ?? ??? __stdcall
18.
18 WinMain() { } ??? ??? ?? ???
??? ?? ??? ?? ??? ?? ??? ??? ???? C++ ??? ?? ?? ?? ??; ?? ? ?? ??? ???? ?????? ?? ??? ?? ?? ???? ??? ?? ??? ?? ?? ????? ??? ??? ??? ?? ? ??? ?? ???? ? ??? ??? ?? ??? ??? ? ??? ?? ? ??? ??? ?? ??
19.
19 WinMain(HINSTANCE hInstance,¡) { WNDCLASS WndClass; WndClass.style
= NULL; WndClass.lpfnWndProc = WndProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = hInstance; WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClass.lpszMenuName = NULL; WndClass.lpszClassName = "Hello"; } ??? ??: ???? ? ?? ?? ?????? ??? ??? ? ?? ?? ? ???? ?? ??? ??; ?? ??? ???? ID? ??? ?? ??? ?? ?? ????
20.
20 if(!RegisterClass(&WndClass)) return NULL; ????
?? ???? ?? ???, ??? ??? ?? ? ?? ??? ??: ???? ????? ??
21.
21 WinMain(HINSTANCE hInstance,¡) { HWND hWnd; hWnd
= CreateWindow( "Hello", "Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); } ??? ??: ?? ??? ?? CreateWindow 11?? ??? ?? ? ??? ? ??? ??? ??? ????
22.
22 WinMain(HINSTANCE hInstance,¡) { HWND hWnd; hWnd
= CreateWindow( "Hello", "Hello", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); } WndClass.lpszClassName = "Hello"; ???? ?? ? ?? ?? ??? ??? ???? ??? ?? ??? ??? ?? ???? WndProc ????¡ ?? ???? ?? ?
23.
23 WinMain(¡, int nCmdShow) { hWnd
= CreateWindow(¡); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); } ??? ???? ??? ??? ???? ?? ?? ? ??? ???? ???? ??? ? ???? ? ?? ? ??? ?? ? ? ??? ???? ??? ?? ???? ?? ? ?? ??? hWnd ?? ???? ????? ?? ??? ?? ??, ?? ? ?? ??? ??? ? ?? ??? ???? ??? ?????? ??? ??? SW_SHOW?? ??. ? ?? windows.h ? ???? ??. SW_SHOW, WS_HIDE ??? API
24.
24 WinMain(¡, ) { MSG msg; while(GetMessage(&msg,
NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } ??? ??: ??? ???? ???? ???? ?? ?? ?? ? GetMessage( ) ? false? ? ? ??? ?? ??? ? ???? WM_QUIT ? ? ???? ??? ??? ??? ? Application Queue ?? ??? ??? WndProc?? ??? ??? ????? ???
25.
25 WinMain(¡, ) { MSG msg; while(GetMessage(&msg,
NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } ??? ??? ?? ??? ???? ? ??? ??? ?? ????? ? ??? ????? WndProc ?? ? ? ??? ???? ??? ??? ?? ???? ?? WinMain ?? ?
26.
26 LRESULT CALLBACK WndProc(HWND
hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } ???? ??? ? ?? ????? ???? ?? ??? ??? ?? ??, ???~ ??? ???? ?? ???? ? ?? ??? ?? ?? ? PostQuitMessage(0)? ??? ???? ? WM_DESTROY
27.
27 LRESULT CALLBACK WndProc(HWND
hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } ???? ??? ? ?? ????? ???? ?? ??? ??? ?? ?? ??? ???? ?? ???? ? ?? ??? ?? ?? ? PostQuitMessage(0)? ??? ???? ? WM_QUIT ???? ?????? ?? ??? ?? ??? ?? ??
28.
28 LRESULT CALLBACK WndProc(HWND
hWnd, UINT mesg, WPARAM wParam, LPARAM lParam) { switch(mesg) { case WM_DESTROY : PostQuitMessage(0); return FALSE; } return DefWindowProc(hWnd, mesg, wParam, lParam); } ?? ? ?? ???? ? WM_SIZE WM_MOVE ???? ??? ??? ??
29.
???? ? ?? ?????
?? !!! 29 ??? ??? ??? ???? ????
30.
30 typedef LONG LONG; typedef
LONG LRESULT; #define CALLBACK __stdcall #define WINAPI __stdcall #define VOID void typedef unsigned int UINT; // 4??? typedef UINT WPARAM; // 4??? typedef LONG LPARAM; // 4??? typedef unsigned short WORD; // 2??? typedef unsigned long DWORD; // 4??? typedef CHAR *LPSTR, *PSTR; // 4??? typedef unsigned char BYTE; // 1??? typedef char CHAR; // 1??? typedef float FLOAT; // 4??? typedef int INT; // 4??? typedef int BOOL; // 4??? typedef struct tagPOINT { LONG x, LONG y } POINT; ??? ?? ?? ??? ?? ? ??? ? ?? ?? ¡ù ??? ??? ?? ? ??
Download