¦b¤W¤@³¹ùØ¡A¤p¤ì°¸«Ø¥ß¤F¤@Ó¥u¥Î¨ÓÅã¥Ü¤å¦r²³æªºµøµ¡¡A¥¦¥u¦³¤@Ó«ö¶s¥i¥HÃö³¬µøµ¡¡C¦b³o¤@³¹ùØ¡A¤p¤ì°¸±Nn«Ø¥ß¤@ӼзǪº Windows 9x µøµ¡¡ASTDWND.EXE¡A¥¦¯à°÷¦¬¨ì±q Windows §@·~¨t²Î¶Ç¨Óªº°T®§¡A·í¨Ï¥ÎªÌ§â·Æ¹«²¾¨ìÃä®ØÀ£¤U·Æ¹«¥ªÁä¦A²¾°Ê·Æ¹«®É¡A¯à°÷½Õ¾ãµøµ¡¤j¤p¡F·í¨Ï¥ÎªÌ§â·Æ¹«²¾¨ìµøµ¡¥k¤W¨¤ªº©ñ¤j¡BÁY¦Ü³Ì¤p¡BÃö³¬«ö¶s¡A¦A«ö¤U·Æ¹«¥ªÁä®É¡A¤]¯à¹ïµøµ¡°µ¥X¬ÛÀ³°Ê§@¡CÁöµM¥~Æ[¤W³oÓµ{¦¡©M«e¤@³¹ªº message.exe ¤@¼Ë¡A¦ý¤p¤ì°¸±NÂǵ۳oÓµ{¦¡»¡©ú¡y°T®§¡zªºÆ[©À¡A¥¦¤]¬O Win32 µ{¦¡³]pªº°ò¦¡C
n«Ø¥ß¤@ӼзǪºµøµ¡¡A¨Ïµøµ¡¯à°÷±µ¦¬¨t²Îªº°T®§¡A¤]¯à¶Ç»¼°T®§µ¹¨t²Î¡A©Ò»Ý¨BÆJ¦p¤U¡G
³o¨Ç¨BÆJ¦³¨Çµ{¦¡½X«Üªø¡A¦³¨ÇI«á¦³«Ü½ÆÂøªº¨t²Î¤º³¡¹B§@¡A¦ý¬O¦pªG±z¯à°÷¥J²Ó¬ã¨s´N·|ºCºC¤F¸Ñ¡A³o¼Ë±z´N½ñ¤J¤F Windows µ{¦¡³]pªº¤@¤j¨B¤F¡C²{¦b¥ý¨Ó¤F¸Ñ°T®§¡A¥¦¬O Windows µ{¦¡³]pªº«n¤@Àô¡A¤]¬O¤Wz«Ø¥ß¼Ð·Çµøµ¡ªº²Ä 6 ¨Bªºì²z¡C
¨C·í§ÚÌ°õ¦æµ{¦¡«á¡A¤j³¡¤Àªº±¡ªp¤U³£·|Åã¥Ü¤@Óµøµ¡¡A·íµM¦¹®É Windows ®à±¤W¥i¯à¤£¥u¤@Óµøµ¡¡A·í§ÚÌ«ö¤UÁä¡B²¾°Ê·Æ¹«®É¡A¥u¦³¯S©wªºµøµ¡¯à¦¬¨ì¨Ó¦ÛÁä½L©Î·Æ¹«ªº¸ê®Æ¡A¨t²Î¬O«ç»ò¿ì¨ìªº©O¡Hì¨Ó¨CÓµ{¦¡Åã¥Üµøµ¡«á³£·|¶i¤J¤@ÓµL½a°j°é¥HÀò±o¨Ó¦Û¨t²Îªº°T®§¡A¦Ó³o¨Ç°T®§¬O¨Ï¥ÎªÌ«ö¤UÁä½L©Î·Æ¹«®É¡A¨t²Î·|§â³o¨Ç¨Æ¥óÂà´«¦¨¤@Ó¸ê®Æµ²ºc¡A¨ä¤º¥]§t¤F¨Æ¥óµo¥Íªº®É¶¡¡B®y¼Ð¡B«öÁäµ¥µ¥¸ê®Æ¡AºÙ³oÓ¸ê®Æµ²ºc¬°°T®§¡C¦b¬Y¨Ç¯S®íªº±¡§Î¤U¡AÀ³¥Îµ{¦¡¤]¯à¶Ç»¼°T®§µ¹¥t¤@Óµ{¦¡¡C
§ó¸Ô²Ó¦a»¡¡A·í¨Ï¥ÎªÌ«ö¤UÁä½L©Î²¾°Ê·Æ¹«®É¡A³o¨Ç¿é¤J¸Ë¸m·|¸g¥ÑÅX°Êµ{¦¡§â°T®§¶Çµ¹¨t²Î ( ¤U¹Ï°T®§¶Ç»¼¹Ï¤¤ªº½bÀY a )¡A¨t²Î¦A§â³o¨Ç°T®§¦s¦b¤@ÓºÙ¬°¨t²Î°T®§¦î¦C ( system message queue ) ¤¤ ( ¹Ï¤¤½bÀY b )¡A¨C¤@¶µ°T®§¥]§tµo¥Í®É¶¡¡Bµo¥Í®É´å¼Ð¦ì¸m¡B°T®§ºØÃþµ¥¡AµM«á¨t²Î¨Ì¾Ú°T®§¤ºµo¥Í®Éªº´å¼Ð®y¼Ð§â°T®§¶Ç¨ì¦U¦Ûªºµ{¦¡°T®§¦î¦C ( application message queue ) ùØ¡Aµ¥«Ýµ{¦¡´£¨ú°T®§ ( ¹Ï¤¤½bÀY c )¡C´«¥y¸Ü»¡¡AWindows ¨t²Î¤¤¦³¤@Ó¨t²Î°T®§¦î¦C³z¹LÅX°Êµ{¦¡»P¿é¤J¸Ë¸m³s±µ¡A¥t¥~ Windows ÁÙ¬°¨CÓµ{¦¡«Ø¥ßÓ§Oªºµ{¦¡°T®§¦î¦C¡A¼È®É¦s©ñ¥Ñ¨t²Î¶Ç¨Óªº°T®§¡C¤£ºÞ¨t²Î°T®§¦î¦C©Î¦U¦Ûªºµ{¦¡°T®§¦î¦C³£³Q Windows ¨t²ÎºÞ²z¡C½Ð°Ñ¦Ò¤U¹Ï°T®§¶Ç»¼¹Lµ{¡C
·íµ{¦¡°õ¦æ¨ì©I¥s GetMessage ( ³o¬O¦b USER32.DLL ùرªº¤@Ó API¡A¬O¥Î¨Ó±qµ{¦¡°T®§¦î¦C¨ú±o°T®§ªº¡A½Ð«ö³oùجݸԲӥΪk ) ®É¡Aµ{¦¡³z¹L USER32.DLL ( ½bÀY d ) ¨ì¦U¦Ûµ{¦¡°T®§¦î¦C´£¨ú°T®§ ( ½bÀY e )¡A¦î¦Cùتº°T®§«K¶Ç¨ì§Ú̪ºµ{¦¡ùØ ( ½bÀY f¡Bg )¡Aµ{¦¡¦A©I¥s TranslateMessage API §â°T®§¤¤ªºÁä½L±½´y½XÂà´«¦¨ ASCII ½X¡AµM«á¦A©I¥s DispatchMessage API ¥[¥H¤À¬£³B²z°T®§ ( ½bÀY h )¡C±µ¤U¨Ó¬O«á¥b³¡ªº°T®§¶Ç»¼¹Lµ{¡A¤]¬O°T®§ÅX°Ê§@·~¨t²Îªº«nÆ[©À¤§¤@¡A¦ý¬O¤ñ¸û½ÆÂø¡A©Ò¥H¤p¤ì°¸µy«á¦A»¡©ú¡A²{¦b¦³¤F°T®§¤j·§·§©À¤§«á¡A§ÚÌ¥ý¨Ó¬Ý¬Ý STDWND ªºì©lµ{¦¡¡C
©³¤U¬O STDWND.ASM ªºì©l½X¡A¬Ý°_¨Ó¦ü¥Gªø¥B½ÆÂø¡A¦ý¬O¤£»Ý¤Ó¹L¾á¤ß¡A¦]¬°³o¬qµ{¦¡¤j³¡¤À³£¬O¡y¼ÒªO¡z¡A·N«ä¬O³o¬qµ{¦¡ªºµ´¤j³¡¥÷³£¬O¨ä¥L½ÆÂøµ{¦¡ªº°ò¦¡A©Ò¥H·í±z¾Ç·|¤F³o¬qµ{¦¡¤§«á¡A½ÆÂøªºµ{¦¡¥u»Ý§â¥¦«þ¹L¥h§Y¥i¦Aµy¥[קï¡A´N¯à¨Ï¥Î¤£¥²¥t°_Äl¨_¡C
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
25 26 27 28
29 30 31 32
33 34 35 36
37 38 39 40
41 42 43 44
45 46 47 48
49 50 51 52
53 54 55 56
57 58 59 60
61 62 63 64
65 66 |
.386
.MODEL FLAT,STDCALL
OPTION CASEMAP:NONE
INCLUDE WINDOWS.INC
INCLUDE USER32.INC
INCLUDE KERNEL32.INC
INCLUDELIB USER32.LIB
INCLUDELIB KERNEL32.LIB
WndProc PROTO :HWND,:UINT,:WPARAM,:LPARAM ;«Å§iµøµ¡¨ç¦¡ì«¬
;*******************************************************************************
.DATA
ClassName DB "SimpleWinClass",0 ;µøµ¡Ãþ§O¦WºÙ
AppName DB "Our First Window",0
hInstance HINSTANCE ? ;¼Ò²Õ¥N½X
hwnd HWND ? ;µøµ¡¥N½X
CommandLine LPSTR ? ;©R¥O¦C¦ì§}
wc WNDCLASSEX <30h,?,?,0,0,?,?,?,?,0,OFFSET ClassName,?>
msg MSG <?>
;*******************************************************************************
.CODE
start: INVOKE GetModuleHandle,NULL ;¨ú±o¼Ò²Õ¥N½X
mov hInstance,eax
INVOKE GetCommandLine ;¨ú±o©R¥O¦C¦r¦ê°Ñ¼Æ¦ì§}
mov CommandLine,eax
mov wc.style,CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc,OFFSET WndProc
mov eax,hInstance
mov wc.hInstance,eax
mov wc.hbrBackground,COLOR_WINDOW+1
INVOKE LoadIcon,NULL,IDI_APPLICATION ;¨ú±o¹Ï¥Ü¥N½X
mov wc.hIcon,eax ;¦s¤J¹Ï¥Ü¥N½X
mov wc.hIconSm,eax ;¦s¤J¤p¹Ï¥Ü¥N½X
INVOKE LoadCursor,NULL,IDC_ARROW ;¨ú±o´å¼Ð¥N½X
mov wc.hCursor,eax ;¦s¤J´å¼Ð¥N½X
INVOKE RegisterClassEx,OFFSET wc ;µù¥Uµøµ¡Ãþ§O
INVOKE CreateWindowEx,NULL,OFFSET ClassName,OFFSET AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL
mov hwnd,eax
INVOKE ShowWindow,hwnd,SW_SHOWDEFAULT
INVOKE UpdateWindow,hwnd
gt_msg: INVOKE GetMessage,OFFSET msg,NULL,0,0
or eax,eax
jz wm_qut
INVOKE TranslateMessage,OFFSET msg
INVOKE DispatchMessage,OFFSET msg
jmp gt_msg
wm_qut: mov eax,msg.wParam ;µ{¦¡µ²§ô
INVOKE ExitProcess,eax
;-------------------------------------------------------------------------------
WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
cmp uMsg,WM_DESTROY
jne msg_process
INVOKE PostQuitMessage,NULL
jmp exit
msg_process:
INVOKE DefWindowProc,hWnd,uMsg,wParam,lParam
ret
exit: xor eax,eax
ret
WndProc ENDP
;*******************************************************************************
END start
|
©³¤U¬O¥¦Ìªº¤ÀªR»¡©ú¡C¦b¤ÀªR¤§«e¡A¦³¥y¸Ü·Q¸òªì¾ÇªÌ»¡©ú¡A°²¦p±z¬O²Ä¤@¦¸¾Ç Win32 ²Õ¦X»y¨¥µ{¦¡³]p¡A°T®§¶Ç»¼¹Lµ{¬O«nªº³¡¥÷¡AÀ³¸Ó¥ý¤F¸Ñ¡A¦Ü©óµ{¦¡©Ò¨Ï¥Îªºµ²ºcÅ餤¦³³\¦hÄæ¦ì¡A³o¨Ç³£¬O¥½¸`¡AÀ³¸Óµ¥¨ì°T®§¶Ç»¼¹Lµ{¤F¸Ñ¤§«á¦A¨Ó²Ó¬Ý¡C
²Ä¤@¦æ¨ì²Ä¤Q¦æ¬O¸ü¤J¥]§tÀɤΰO¾ÐÅé¼Ò¦¡µ¥«Å§i¡A¦b²Ä¤@³¹¤w¦³»¡©ú¡C
²Ä 13 ¦æ¨ì²Ä 19 ¦æ¬O¸ê®Æ¬q¡A²Ä 15 ¦æ¨ì²Ä 19 ¦æªº¸ê®Æ«¬ºA¦ü¥G«Ü¯S§O¡A¨ä¹ê HINSTANCE¡BHWND¡BLPSTR ³o¨Ç³£¬OÂù¦r²Õªºªø«×¡A¥¦Ì³£³Q©w¸q¦b WINDOWS.INC ùØ¡A±z¦pªG³£¼g¦¨¡yDD¡z¨ä¹ê¤]¥i¥H¡A¦ý¤@¯ë¼g¦¨ HINSTANCE¡BHWND¡BLPSTR¡A¬O¬°¤F¥iŪ©Ê¡C·í±z¬Ý¨ì
hInstance HINSTANCE ?
´Nª¾¹D hInstance ³oÓÅܼƬO¥Î¨Óªí¥Ü¬Y¤@Ó¼Ò²Õ¥N½X ( instance handle )¡A¦Ü©ó¤°»ò¬O instance ©O¡H¤S¡A¤°»ò¬O handle ©O¡Hì¨Ó·íµ{¦¡«O¦s¦b¦bºÏºÐ¤ù¤W¬O¡y¦º¡zªº¡A¦]¬°¦bºÏ¤ù¤Wªºµ{¦¡¨S¦³¸ü¤J°O¾ÐÅ餧«e¤£¯à³Q°õ¦æ¡A¥u¦³¸ü¤J°O¾ÐÅé«á¤~¥i³Q°õ¦æªºµ{¦¡¡AºÙ¬°°õ¦æ¹ê¨Ò ( instance )¡C³o¬O«O¯d¦Û Win16 ( ¥iµø¬° Win 3.1 ) ªº³N»y¡A¦b Win32 ¨t²Î¤¤¡Ainstance ´N¬O module ( ¼Ò²Õ ) ªº·N«ä¡A©Ò¥H¦bµ{¦¡²Ä 22 ¦æ¡A©I¥s GetModuleHandle ¬O¨ú±o¼Ò²Õªº¥N½X¡A«o©ñ¦b hInstance ÅܼÆùØ¡CWin32 ¨t²Î·|¹ï¦b°O¾ÐÅ餤°õ¦æªºµ{¦¡¡A¤À°t¤@Ó¼ÆÈ¡A§ÚÌ¥i¥H§â³oÓ¼ÆÈ¡A¬Ý¦¨¬Oµ{¦¡ªºÃѧO½X¡C
hwnd HWND ? CommandLine LPSTR ?
³o¨â¦æ¬O©w¸qµøµ¡¥N½X ( window handle ) ¥H¤Î¦r¦êªøµ{«ü¼Ð ( long pointer of string¡A¥i°Ñ¦Ò²Ä¹s³¹ )¡C¦b¥·Æ¼Ò¦¡¤Uªº°O¾ÐÅé«ü¼Ð³£¥HÂù¦r²Õªí¥Ü¡AºÙ¬°ªøµ{«ü¼Ð¡C³o¬O¦³§O©ó 16 ¦ì¤¸¨t²Î¡A¦b 64KB ¥H¤ºªººÙ¬°ªñµ{ ( near )¡A64KB ¥H¥~ªººÙ¬°»·µ{ ( far )¡Aªñµ{»P»·µ{³£¬O 16 ¦ì¤¸ªº¿òª«¤F¡CCommandLine ¬O¥Î¨Óªí¥Ü¨Ï¥ÎªÌ±q©R¥O¦C ( ¨Ò¦p DOS ¼Ò¦¡¤¤ ) ©Ò¿é¤J°Ñ¼Æ¦r¦êªº¦ì§}¡A¨Ò¦p¦pªG±z¦b DOS ¼Ò¦¡¤U¿é¤J
H:\HomePage\SOURCE>stdwnd ABCD [Enter]
¨º»ò¡yABCD¡z·|³Qµø¬°¦r¦ê¡A¨ä¦ì§}±N·|¦s©ñ©ó CommandLine ÅܼƤ¤¡C
ÅÜ¼Æ hwnd ±N·|¦s©ñ§Ú̵{¦¡²£¥Íªºµøµ¡¥N½X ( window handle )¡A¨C¤@Ó°õ¦æ¹ê¨Ò¤£¤@©w¥u²£¥Í¤@Óµøµ¡¡A½Ð¬Ýµù¤G¡A©Ò¥Hµøµ¡¥N½X»P¼Ò²Õ¥N½X¨Ã¤£¬Û¦P¡A·í§ÚÌn§ó·s¬YÓµøµ¡µe±®É¡A´Nn«ü©w¨º¤@Óµøµ¡n³Q§ó·s¡A¦]¦¹°£¤F©w¸q¼Ò²Õ¥N½X¥~¡A¤]n©w¸qµøµ¡¥N½X¡C
²Ä 18 ¦æªº wc ¬O¤@Óµ²ºcÅé ( °Ñ¦Ò²Õ¦X»y¨¥²Ä¤Q¤E³¹µ²ºcÅ骺»¡©ú )¡A¥¦©w¸q¤Fµøµ¡ªº¥~Æ[¤Î¾Þ§@¤è¦¡µ¥µ¥¡A³oÓµ²ºcÅé¦b Windows Àô¹Ò¬O«Ü«nªºÅܼơC±z¥i¥H±q Win32 API HELP Àɬd¨ì¥¦ªº¤º®e¤Î¨ä»¡©ú¡A¥¦ªø±o¹³©³¤U¥ªÃ䪺¼Ë¤l¡G
typedef struct _WNDCLASSEX { // wc WNDCLASSEX STRUC UINT cbSize; cbSize DWORD ? UINT style; style DWORD ? WNDPROC lpfnWndProc; lpfnWndProc DWORD ? int cbClsExtra; cbClsExtra DWORD ? int cbWndExtra; cbWndExtra DWORD ? HANDLE hInstance; hInstance DWORD ? HICON hIcon; hIcon DWORD ? HCURSOR hCursor; hCursor DWORD ? HBRUSH hbrBackground; hbrBackground DWORD ? LPCTSTR lpszMenuName; lpszMenuName DWORD ? LPCTSTR lpszClassName; lpszClassName DWORD ? HICON hIconSm; hIconSm DWORD ? } WNDCLASSEX; WNDCLASSEX ENDS
³o¬O¬°¤F C/C++ ªº²ßºD¤~¼g¦¨³o¼Ë¡C¦b WINDOWS.INC ùؤ]¦³µøµ¡Ãþ§Oªº©w¸q¡A¬O¹³¤W±¥kÃä¥Õ¦âªº¼Ë¤l¡A³o¤~¬O²Õ¦X»y¨¥µ²ºcÅ骺¼Ë¤l¡A¥¦©M¦b Win32 API HELP ªº©w¸q³£¬O¤@¼Ëªº¡A¥u¬O¯Ê¥F»¡©ú¡C¦b Win32 ²Õ¦X»y¨¥ùئ³³\¦h¤å¥ó³£n°Ñ¦Ò¥Î C/C++ ©Ò²ßºDªº¤å¥ó¡A©Ò¥H±z¦pªG¦³ C/C++ ªº°ò¦¤]¬O¤£¿ù¡C¦b³oÓµ²ºcÅéùØ¡A©Ò¦³ªºÅܼƳ£¬OÂù¦r²Õ¡A¦b¦V Windows §@·~¨t²Îµù¥U«eÀ³¸Ón§â©Ò¦³¸ê®Æ¶ñ¦n¡A©³¤U¬O WNDCLASSEX µ²ºcÅ骺»¡©ú¡G
mov wc.style,CS_HREDRAW or CS_VREDRAW¡ACS_HREDRAW ¬Oªí¥Ü·í¨Ï¥ÎªÌ§â·Æ¹«²¾¨ìµøµ¡¨âÃ䪺Ãä®Ø¨ÃÀ£¤U·Æ¹«¥kÁä¡A¤ô¥¦a§ïÅܵøµ¡¤j¤p¡AWindows ·|t³d«·sø»sµøµ¡¡CCS_VREDRAW ¥u¬O§ï¦¨««ª½¤è¦V¡C±z¥i¥H¥´¶} WINDOWS.INC ¹î¬Ý CS_HREDRAW ©M CS_VREDRAW ¤À§O¬O¨âӼơA2 ©M 1¡C°£¤F³o¨âÓ¥~¡AÁÙ¦³¨ä¥L³\¦hºØ¥i¥Î¿ï¶µ¡A½Ð°Ñ¦Ò Win32 API HELP¡C
²Ä 19 ¦æ¬O©w¸q¤@Óµ²ºcÅéÅܼơAmsg¡A³oÓµ²ºcÅé¬O¥Î¨Ó©M¨t²Î¶Ç»¼°T®§¥Îªº¡A¦Ü©ó¥¦ªº¤º®eµy«á»¡©ú¡C
±q²Ä 21 ¦æ¶}©l¨ìµ²§ô¬Oµ{¦¡½X¬q¡A¤jP¥i¤À¬°¥|³¡¥÷¡A«Ø¥ß¨Ã¦b¿Ã¹õ¤WÅã¥Üµøµ¡ ( ²Ä 22 ¦æ¨ì²Ä 43 ¦æ )¡B¶i¤JµL½a°T®§°j°é±o¨ì°T®§ ( ²Ä 45 ¦æ¨ì²Ä 50 ¦æ )¡B³B²z°T®§ªºµøµ¡¨ç¦¡ ( ²Ä 54 ¦æ¨ì²Ä 64 ¦æ ) ¤Îµ²§ôµ{¦¡ ( ²Ä 51¡B52 ¦æ )
µ{¦¡¤@¶}©l«K¬O±o¨ìµ{¦¡¥»¨ªº¼Ò²Õ¥N½X¡AGetModuleHandle ³oÓ API ´N¬O¥Î¨Ó¨ú±o¼Ò²Õ¥N½Xªº¡A¥¦ªº¼Ë¤l¦p¤U¡G
HMODULE GetModuleHandle( LPCTSTR lpModuleName // address of module name to return handle for );
¥¦¥u¦³¤@ӰѼơA³oӰѼƬO«ü¦Vµ{¦¡¦WºÙ¦r¦ê¦ì§}¡A³oÓ¦r¦ê¥²»Ý¥H¹s¬°µ²§À¡C¨Ò¦p±z·Q¨ú±o USER32.DLL ªº¼Ò²Õ¥N½X¡A¥i¥H¥Î
szUSER32 db 'USER32.DLL',0 invoke GetModuleHandle,addr szUSER32
°²¦p°Ñ¼Æ¬° NULL ªº¸Ü¡Aªí¥Ü¨ú±o¥»¨ªº¼Ò²Õ¥N½X¡CGetModuleHandle °²¦p¦¨¥\ªº¸Ü¡A¶Ç¦^ªº¼Ò²Õ¥N½X±N¦s©ó¼È¦s¾¹ EAX¡A³oÓ¼Æȵy«á·|¥Î¨ì¡A©Ò¥HÀx¦s¦b hInstance ÅܼÆùØ¡C
±µ¤U¨Óªº¬O GetCommandLine API¡A³oÓ API ¬O¥Î¨Ó¨ú±o©R¥O¦Cªº°Ñ¼Æ¦r¦ê¦ì§}¡A¥¦¥»¨¤£¥Î°Ñ¼Æ¡Aªð¦^®É·|±N©R¥O¦C°Ñ¼Æ¦r¦ê¤§¦ì§}¦s©ó EAX ¼È¦s¾¹ùØ¡C°²¦p¤£¶·³B²z©R¥O¦C°Ñ¼Æ¡A³o¤@¨B¥i¥H¬Ù²¤¡CGetCommandLine ªº¥Îªk¦p¤U¡F
LPTSTR GetCommandLine(VOID)
²Ä 26 ¦æ¨ì²Ä 36 ¦æ¬O§â wc µ²ºcÅéÅܼƶñ¦n¨Ã¦V¨t²Îµù¥Uµøµ¡Ãþ§O¡C¦b wc µ²ºcÅéùتº¦³¨ÇÄæ¦ì¥i¥Hª½±µ¦b¸ê®Æ¬q´N½á¤©¼ÆÈ¡A¹³ cbSize¡Bstyle¡BlpfnWndProc µ¥µ¥¡A¦ý¬O³o¼Ë°µ·|¨Ï±o²Ä 18 ¦æÅܱo¤Óªø¡A©Ò¥H¤p¤ì°¸ÁÙ¬O¦bµ{¦¡ùس]©w¨ä¼ÆÈ¡C¨ä¤¤ LoadIcon¡BLoadCursor ¤À§O¬O¹Ï¥Ü¡B´å¼Ðªº¥N½X¡A¥Ñ LoadIcon ¤Î LoadCursor ³o¨âÓ API t³d¨ú±o¨ä¥N½X¡C
LoadIcon ¬O¥Î¨Ó¸ü¤Jµ{¦¡ªº¹Ï¥Ü¡A¬d Win32 API ¥i±o¡G
HICON LoadIcon( HINSTANCE hInstance, // handle of application instance LPCTSTR lpIconName // icon-name string or icon resource identifier );
¥Ñ¤Wz¸ê®Æª¾¡ALoadIcon ¦³¨âӰѼơA²Ä¤@ӰѼƬO¼Ò²Õ¥N½X¡A²Ä¤GÓ¬O«ü¦V¹Ï¥Ü¸ê·½¦WºÙªº¦ì§}¡A¦¹¦ì§}¥²¶·¥H 0 ¬°µ²§À¡C¨t²Î¤w¸g¹w¥ý©w¸q¤F´Xӹϥܥi¨Ñ¨Ï¥Î¡A°²¦pn¥Î¨t²Î¹w©wªº¹Ï¥Ü¡A¨º»ò hInstance n³]¬° NULL¡A¦Ó lpIconName ¥i¥H¬O¤U±´XºØ±¡§Î¡G
²Å¸¹ | ¼ÆÈ | ´yz |
IDI_APPLICATION | 32512 | ¤º©wÈ |
IDI_ASTERISK | 32516 | ^¤å¦r¥À¡yi¡z¡A³q±`¥Î©ó³qª¾ |
IDI_EXCLAMATION | 32515 | Åå¼Û¸¹¡A³q±`¥Î©óĵ§i |
IDI_HAND | 32513 | ¥æ¤e¡A³q±`¥Î©óÄY«Äµ§i |
IDI_QUESTION | 32514 | °Ý¸¹¡A³q±`¥Î©ó´£¥Ü°T®§ |
·í©I¥s LoadIcon ¦¨¥\®É¡A·|¦b EAX ¶Ç¦^¹Ï¥Ü¥N½X¡AY¥¢±Ñ¡A«h EAX ¬°¹s¡C
³oÓ API ¬O¥Î¨Ó¶Ç¦^´å¼Ð¥N½X¡C¬d Win32 API ¥i±o
HCURSOR LoadCursor( HINSTANCE hInstance, // handle of application instance LPCTSTR lpCursorName // name string or cursor resource identifier );
±oª¾¦¹ API ªð¦^®É·|¶Ç¦^´å¼Ð¥N½X©ó EAX¡A¥¦»Ýn¨âӰѼơA¼Ò²Õ¥N½X»P«ü¦V·Æ¹«´å¼Ð¸ê·½¦WºÙªº¦ì§}¡A¦¹·Æ¹«´å¼Ð¸ê·½¦WºÙ¥²¶·¥H 0 ¬°µ²§À¡C¦P¼Ëªº¨t²Î¤]¹w¥ý©w¸q¤F´XÓ¥i¥Îªº´å¼Ð¡A°²¦pn¨Ï¥Î¨t²Î©Ò©w¸qªº´å¼Ð¡A«h hInstance ¥²¶·³]¬° NULL¡A¦Ó lpCursorName ¥i¥H¬O¤U±´XºØ±¡§Î¡G
²Å¸¹ | ¼ÆÈ | ´yz |
IDC_ARROW | 32512 | ¨t²Î¨Ï¥Îªº½bÀY¡A³Ì±`¨Ï¥Îªº·Æ¹«´å¼Ð |
IDC_APPSTARTING | 32650 | ½bÀY»P¨Fº|¡A·í¨t²Î¦£¸L¤¤¨Ï¥Îªº´å¼Ð |
IDC_SIZENS | 32645 | ¤W¤U¤è¦VªºÂù½bÀY¡A±`¥Î©ó·Æ¹«²¾¨ìµøµ¡¤W¤UÃä½t |
IDC_SIZEWE | 32644 | ¥ª¥k¤è¦VªºÂù½bÀY¡A±`¥Î©ó·Æ¹«²¾¨ìµøµ¡¥ª¥kÃä½t |
IDC_HAND | 32649 | ¤â§Î |
ÁÙ¦³´XºØ±¡§Î¡A½Ð¦Û¦æ°Ñ¦Ò Win32 API¡C
RegisterClassEx ¬O¦V¨t²Îµù¥U¤@ºØµøµ¡Ãþ§O¡A¥¦¥u¦³¤@ӰѼơA´N¬Oµ²ºcÅ骺¦ì§}¡A¦pªGµù¥U¥¢±Ñ¡AEAX ¬°¹s¡A¦pªGµù¥U¦¨¥\¡AEAX ¬°«D¹s¡C¦Ü©óµ²ºcÅé©Ò»Ýªº¸ê®Æ½Ð¬Ý¤W±¤w¸g±Ôz¹L¤F¡ARegisterClassEx ªº¥Îªk¦p¤U¡F¡C
ATOM RegisterClassEx( CONST WNDCLASSEX *lpwcx // address of structure with class data );
³oÓ API ¬O«Ø¥ßµøµ¡¡A±z¥i¥H·Q¹³¥¦¬O¦b°O¾ÐÅ餤«O¯d¤@¶ô°O¾ÐÅé´yz³oÓµøµ¡¡C¥¦ªº C/C++ »yªk¬O¡G
HWND CreateWindowEx( DWORD dwExStyle, // extended window style LPCTSTR lpClassName, // pointer to registered class name LPCTSTR lpWindowName, // pointer to window name DWORD dwStyle, // window style int x, // horizontal position of window int y, // vertical position of window int nWidth, // window width int nHeight, // window height HWND hWndParent, // handle to parent or owner window HMENU hMenu, // handle to menu, or child-window identifier HINSTANCE hInstance, // handle to application instance LPVOID lpParam // pointer to window-creation data );
¥¦¦³ 12 ӰѼơA³o¨Ç°Ñ¼Æ´yz¦p¤U¡G
²Å¸¹ | ¼ÆÈ | ´yz |
WS_OVERLAPPED | 0000000h | Åã¥Ü¤@Ó¨S¦³¼ÐÃDÄæ¡BÃä®Ø¡B¨t²Î¿ï³æ¡B³Ì¤j¤Æ¡B³Ì¤p¤Æ¡BÃö³¬«ö¶sªºµøµ¡ |
WS_HSCROLL | 0100000h | Åã¥Ü¤ô¥±²¶b |
WS_VSCROLL | 0200000h | Åã¥Ü««ª½±²¶b |
WS_OVERLAPPEDWINDOW | 0CF0000h | ³o¬O³Ì±`¥Îªº·®æ¡A¦³¼ÐÃDÄæ¡B³Ì¤j¤Æ«ö¶s¡B³Ì¤p¤Æ«ö¶s |
°²¦p¦¨¥\¦a«Ø¥ß·sµøµ¡¡A«h EAX ·|¶Ç¦^µøµ¡¥N½X¡Aµ{¦¡²Ä 41 ¦æ§â¥¦¦s¤J hwnd ÅܼÆùØ¡C¦pªG«Ø¥ß·sµøµ¡¥¢±Ñ¡AEAX ·|³Q³]¬° NULL (¹s)¡CCreateWindowEx ·|¶Ç°e WM_NCCREATE¡BWM_NCCALCSIZE ©M WM_CREATE µ¹©ÒÄݪºµøµ¡¨ç¦¡¡C
¦b°O¾ÐÅ餤«Ø¥ß¦n¤@Óµøµ¡«á¡An¯à¦b¿Ã¹õ¤WÅã¥Ü¡A¨Ï¥ÎªÌ¤~¬Ý±o¨£ ( ¦³¨Çµ{¦¡¬O¤£Åã¥Üµøµ¡ªº¡A¨Ò¦p¯f¬r )¡CnÅã¥Üµøµ¡¥i¥H©I¥s ShowWindow API¡A¨ä¨ç¼Æ쫬¦p¤U¡G
BOOL ShowWindow( HWND hWnd, // handle of window int nCmdShow // show state of window );
²Ä¤@ӰѼƬO·QnÅã¥Üµøµ¡ªºµøµ¡¥N½X¡A²Ä¤GӰѼƬOÅã¥Ü¤è¦¡¡A±`¥ÎªºÅã¥Ü¤è¦¡¦p¤Uªí¡G
²Å¸¹ | ¼ÆÈ | ´yz |
SW_HIDE | 0 | ÁôÂÃ |
SW_MINIMIZE | 6 | ³Ì¤p¤Æ |
SW_MAXIMIZE | 3 | ³Ì¤j¤Æ |
SW_SHOWDEFAULT | 10 | ¥Ñ¨t²Î¤º©w |
ShowWindow ¦³¶Ç¦^È¡A°²¦pì¥ýªºµøµ¡¬O¥i¨£ªº¡AEAX ¤£¬°¹s¡A¤Ï¤§¬°¹s¡C¤£¹L¦b³oÓµ{¦¡ùتº¶Ç¦^Ȥ£«n¡C
Åã¥Üµøµ¡«áÁÙ±o¥Î UpdateWindow ¨Ó§ó·s¤u§@°Ï¡C°²¦p¤u§@°Ï¤£¬OªÅµL¤@ª«¡AUpdateWindow ·|°e¥X¤@Ó WM_PAINT °T®§µ¹«ü©wµøµ¡ªºµøµ¡¨ç¦¡¡AµM«á¶i¦æ§ó·s¡C°²¦p¦¨¥\«h¶Ç¦^Ȭ°«D¹s¡A¤Ï¤§¬°¹s¡C¥¦¥u¦³¤@ӰѼơA´N¬O±ý§ó·sªºµøµ¡¥N½X¡CUpdateWindow ªº¥Îªk¬O¡F
BOOL UpdateWindow( HWND hWnd // handle of window );
±µ¤U¨Óªº²Ä 45 ¨ì²Ä 50 ¦æ¬O¶i¤J¤@Ó°j°é¥H±o¨ì¨Ï¥ÎªÌªº°T®§¡Cº¥ý¬O©I¥s GetMessage API¡A³oÓ API ¬O¥Î¨Ó±qµ{¦¡°T®§¦î¦C¨ú¥X¤@¶µ°T®§¡A¨ä쫬¦p¤U¡G
BOOL GetMessage( LPMSG lpMsg, // address of structure with message HWND hWnd, // handle of window UINT wMsgFilterMin, // first message UINT wMsgFilterMax // last message );
GetMessage ªº²Ä¤@Ó°Ñ¼Æ lpMsg ¬O«ü¦V¤@Ó¦ì§}¡A³oÓ¦ì§}¬O¤@ÓºÙ¬° MSG ªºµ²ºcÅéÅܼƩҦbªº¦ì§}¡A¸Óµ²ºcÅé¬O¥Î¨Ó±µ¦¬±q°T®§¦î¦C©Ò¶Ç¨Óªº°T®§ªºµ²ºcÅé¡C·í©I¥s GetMessage ®É¡A¨t²Î·|±qµ{¦¡°T®§¦î¦C¤¤¨ú¥X¤@¶µ¸ê®Æ¨Ó¡A¨Ã§â lpMsg ©Ò«ü¦ì§}ªºµ²ºcÅ餺ªºÄæ¦ì¶ñ¦n¡CMSG ªº©w¸q¦b WINDOWS.INC ùØ¡A¥¦ªø±o¹³¤U±ªº¼Ë¤l¡G
MSG STRUC hwnd DWORD ? message DWORD ? wParam DWORD ? lParam DWORD ? time DWORD ? pt POINT <> MSG ENDS
hwnd ¬O«ü¨t²Î±N§â°T®§¶Ç¨ì¨º¤@Óµøµ¡¥N½Xªºµøµ¡¨ç¦¡¡Cmessage ¬O¦¬¨ìªº°T®§ºØÃþ¡AWindows ©w¸q¤F«Ü¦hªº°T®§¡A³£¥H WM_ ¶}ÀY¡A·N«ä¬O windows message ªº·N«ä¡A¦ý¬O¦b§Ú̳oÓµ{¦¡ùØ¡A¥u³B²z°h¥Xµ{¦¡ªº°T®§¡A´N¬O WM_QUIT ( ¼ÆÈ 12h )¡CwParam ©M lParam ¬O¨â¶µÃB¥~ªº°T®§¸ê®Æ¡A©M message ªººØÃþ¦³Ãö¡Ctime ¬Oµo¥Í°T®§ªº®É¶¡¡Apt ¬O¤@Óµ²ºcÅé¡A¥¦ªí¥Üµo¥Í¦¹°T®§®Éªº·Æ¹«¦ì¸m¡C
GetMessage ªº²Ä¤GӰѼƬO hWnd¡Aªí¥Ün¨ú±o¨º¤@Óµøµ¡ªº°T®§¡A°²¦p hWnd ¬°¹sªº¸Ü¡Aªí¥Ü¨ú±oµ{¦¡¦Û¤vµøµ¡ªº°T®§¡CGetMessage ªº²Ä¤TÓ©M²Ä¥|ӰѼƤÀ§Oªí¥Ü¨ú±o°T®§ªº½s¸¹½d³ò¡A°²¦pn¨ú±o©Ò¦³°T®§ªº¸Ü¡A¨âªÌ§¡³]¬°¹s¡C
GetMessage ªº¶Ç¦^Ȧ³¤TºØ±¡§Î¡A°²¦p¶Ç¦^ WM_QUIT °T®§ªº¸Ü¡AEAX ¬°¹s¡A°²¦p¨ú±o°T®§¥¢±Ñªº¸Ü¡AEAX ¬° 0FFFFFFFFH¡A°²¦p¬O¨ä¥L°T®§ªº¸Ü¡AEAX ¬°«D¹sȤ]«D 0FFFFFFFFh¡C
±µ¤U¨Óªº²Ä 46¡B47 ¦æ¬O±q GetMessage ©Ò±o¨ìªº°T®§§PÂ_¡A°²¦p¬O¶Ç¦^ WM_QUIT «h¨ì²Ä 51 ¦æµ²§ôµ{¦¡¡A§_«h©I¥s TranslateMessage ©M DispatchMessage ³o¨âÓ API ³B²z³o¨Ç°T®§¡Cµ²§ôµ{¦¡ÁÙ±o°µ¤@¨Ç¸ÑÄÀ¡A«Ý·|¨à¦A»¡¡A¥ý¨Ó¬Ý¬Ý¤£¬Oµ²§ôµ{¦¡®Éªº±¡§Î¡C
³oÓ API ¬O§â«ü©w¦ì§}ªº MSG µ²ºcÅ骺«öÁä½Ķ¦¨¦r¤¸¡A¦A¶ñ¦^µ{¦¡°T®§¦î¦Cµ¥«Ý¤U¦¸ªº GetMessage ¨ú¦^¡A¸Ô²Ó±¡§Î½Ð°Ñ¦Ò²Ä¤T³¹¦³Ãö WM_CHAR °T®§ªº»¡©ú¡C¥¦¥u¦³¤@Ó¿é¤J°Ñ¼Æ¡A´N¬O MSG µ²ºcÅ骺¦ì§}¡C°²¦pÂà´«¦¨¥\¡A¶Ç¦^«D¹sÈ¡A§_«h¶Ç¦^¹s¡C¨ä¹ê¦b³oÓµ{¦¡ùØ¡A¤p¤ì°¸¨Ã¨S¦³³B²z«öÁä¡A©Ò¥H¤]¥i¥H¬Ù²¤³oÓ API¡CTranslateMessage ªºì«¬¬O¡G
BOOL TranslateMessage( CONST MSG *lpMsg // address of structure with message );
DispatchMessage ¬O§â MSG µ²ºcÅ骺°T®§¶Çµ¹µøµ¡¨ç¦¡¥[¥H³B²z¡C¥¦¥u¦³¤@ӰѼơAMSG ¤§¦ì§}¡A¥¦ªº¼Ë¤l¹³¤U±³o¼Ë¡G
LONG DispatchMessage( CONST MSG *lpmsg // pointer to structure with message );
¥¦¦³¶Ç¦^È¡A³oӶǦ^ÈÀHµÛµ{¦¡³]p®v©Ò¼¶¼gªºµøµ¡¨ç¦¡ªº³]p¦Ó¤£¦P¡A¦ý¬O±`³Q©¿²¤¡C¦³Ãö DispatchMessage ¦¡¦p¦ó¶Ç»¼°T®§µ¹µøµ¡¨ç¦¡¡A½Ð¬Ý¤U¤@¸`¡A³B²z°T®§ªºµøµ¡¨ç¦¡¡C
·í§Ú̪ºµ{¦¡¦Û¨t²Î±o¨ì°T®§¤§«á¡A¥²¶·¨Ì·Óµ{¦¡¦³¿³½ìªº°T®§¥[¥H³B²z¡A³B²z³o¨Ç°T®§ªº¤@¬qµ{¦¡´NºÙ¬°¡yµøµ¡¨ç¦¡¡z¡C¦b Win32 ¨t²ÎùØ¡A§Ú̳q±`§âµøµ¡¨ç¦¡³]p¦¨¤@ӰƵ{¦¡ªº§Î¦¡¡A¦Óµ{¦¡³]p®v¥Dnªº¤u§@´N¬Oקï³o¤@¬qµ{¦¡¡A¨Ï¨º¨Ç°T®§»Ýn¥[¥H³B²z¥H¤Î¦p¦ó³B²z¡A¨º¨Ç«h¤£¥Î¡C
©Ò¥H¤p¤ì°¸¤@¶}©l´N»¡¡ASTDWND.ASM ³oÓì©lµ{¦¡ªº¤j³¡¤À³£¥i«½Æ¨Ï¥Î¡A±z¦pªG¼¶¼g¨ä¥Lµ{¦¡¡A¤]¥u¦³µøµ¡¨ç¦¡³o¬q»Ýnקï¡A¨ä¾l³¡¥÷´X¥G¤£¶·×§ï¡Cµøµ¡¨ç¦¡©M¨t²Î¤§¶¡ªº°T®§¶Ç»¼´N¬O¤p¤ì°¸»¡ªº°T®§¶Ç»¼ªº«á¥b³¡¡A©Ò¥Hµøµ¡¨ç¦¡ªº«n©Ê¥i·Q¦Óª¾¡C©³¤U´N¶}©l»¡©úµøµ¡¨ç¦¡¤F¡C
¦pªG±z¸Ô²ÓÀˬd¾ã¬q STDWND.ASM µ{¦¡¡A¶È¶È¥u¦³¦b³]©w wc ªº²Ä 27 ¦æ¦³
mov wc.lpfnWndProc,offset WndProc
ªº´yz¦Ó¤w¡A¬J¨S¦³©I¥s WndProc¡A¤]¨S¦³¶Ç»¼°T®§ªºÃþ¦ü´yz¡C¨º»ò§Ú̪ºµ{¦¡¦p¦ó©I¥sµøµ¡¨ç¦¡¡A°T®§¤S¦p¦ó¶Ç¹F¨ìµøµ¡¨ç¦¡¡Hì¨Ó¦b Windows ¨t²Î¤¤³£¬O±Ä¥Î¤@ºØºÙ¬°¡ucall back¡v¨ç¦¡ ( ¤¤¤å¤@¯ë½Ķ¦¨¡u¦^©I¨ç¦¡¡v)¡Acall back ¨ç¦¡ªº·N«ä¬O¦¹¨ç¦¡¬O³Q¨t²Î©Ò©I¥sªº¨ç¦¡¡A¦ý¬O¥¦¥»¨«o¬O¦bµ{¦¡³]p®vªºµ{¦¡ùØ¡C´«¥y¸Ü»¡¡A·íµ{¦¡°õ¦æ¨ì GetMessage¡A¦¬¨ì¨Ó¦Û¨t²Îªº°T®§«á¡A¦A¥Ñ DispatchMessage API §â°T®§·í¦¨°Ñ¼Æ©I¥s¨t²Î¡AµM«á¨t²Î¦A©I¥sµøµ¡¨ç¦¡¡Aµøµ¡¨ç¦¡³B²z¦¹°T®§¡C±z¤@©w·|°Ý¬°¤°»òn³o»ò³Â·Ð¡A¤£ª½±µ¥Ñ¦Û¤vªºµ{¦¡©I¥sµøµ¡¨ç¦¡¡A³o¼Ë¤£¬O§óª½±µÂ²³æ¶Ü¡Hì¦]¦³´XÓ¡A¤@Ó«nªºì¦]¬O¤@Óµ{¦¡¥i¯à·|²£¥Í¦n´XÓµøµ¡¡A¦pªGµ{¦¡n¦Û¤v©I¥sµøµ¡¨ç¦¡¡A¨º´N±o¦Û¤vºûÅ@¦³Ãöµøµ¡¥N½Xµ¥©Ê½è¡A³o¼Ë¬O¶V«[¥N©´¥h³B²z§@·~¨t²Î¸Ó°µªº¨Æ¡A¦Ón³B²zªº¤u§@¤Ï¦ÓÅܱo§ó¦h§ó³Â·Ð¤F¡C
½Ð°Ñ¦Ò¤W±°T®§¶Ç»¼¹Ï¡A·íµ{¦¡°õ¦æ¨ì²Ä 49 ¦æ
invoke DispatchMessage,offset msg
µ{¦¡©I¥s DispatchMessage API¡A©Ò¿×¡yDispatch¡z¤¤¤å¬O¡y¤À¬£¡zªº·N«ä¡A¨ä·N¬O«ü§â°T®§¤À°eµ¹µøµ¡¨ç¦¡³B²z¡CDispatchMessage ¬O¦b USER32.DLL ùØ¡AUSER32.DLL ¬O¨t²Îªº¤@³¡¥÷¡C·í©I¥s³oÓ API ®É ( ½bÀY h )¡A·|§â msg µ²ºcÅé¶Çµ¹¨t²Î¡A¥Ñ¸Óµ²ºcÅéÄæ¦ì msg.hwnd¡A¨t²Î¥i¥Hª¾¹D³o¬O¨º¤@Óµøµ¡ªº°T®§¡AµM«á¨t²Î¦A¨Ì¾Ú«Ø¥ß³oÓµøµ¡ªºµøµ¡Ãþ§Oùتº wc.lpfnWndProc ´N¥i¥Hª¾¹D¨º¤@Óµøµ¡¨ç¦¡À³¸Ó³B²z³oÓ°T®§¡A¦A§â°T®§¶Çµ¹³oÓµøµ¡¨ç¦¡ ( ½bÀY i )¡Aµ¥µøµ¡¨ç¦¡³B²z§¹«á¡A¦Aªð¦^¨t²Îªº DispatchMessage ( ½bÀY j )¡ADispatchMessage ¦A³qª¾ì¨Óªºµ{¦¡ ( ½bÀY k )¡A³o¼Ë¤@Ó°T®§´`Àô´N³B²z§¹¦¨¡A°²¦p¨Ï¥ÎªÌ¨S¦³«ö¤Uµøµ¡¥ª¤W¨¤ªºÃö³¬¶s¡Aµ{¦¡·|¦A¶i¤J¤U¤@Ó°T®§´`Àô¡Aª½¨ì¨Ï¥ÎªÌµ²§ô¡C
µøµ¡¨ç¦¡ªºì«¬¦bµ{¦¡²Ä 10 ¦æ¤w¸g«Å§i¡G
WndProc proto :HWND,:UINT,:WPARAM,:LPARAM
¦b Win32 ¨t²ÎùØ¡Aµøµ¡¨ç¦¡ªº°Ñ¼Æ©T©w´N¬O³o¥|Ó¡A¨S¦³¤°»ò¼u©Ê¡C²Ä¤@ӰѼƬOµøµ¡¥N½X¡A¦]¬°¤@Óµ{¦¡¥i¯à¦³¦n´XÓµøµ¡¡A©Ò¥H¥²¶·«ü©wµøµ¡¥N½X¡A§_«h¨t²Î¤£ª¾¹D¬On³B²z¨º¤@Óµøµ¡¡C²Ä¤GӰѼƬO°T®§½s¸¹¡A²Ä¤T©M²Ä¥|ӰѼƬOÃB¥~ªº°T®§¸ê®Æ¡A±z¥i¥Hµo²{¡A¨Æ¹ê¤Wµøµ¡¨ç¦¡©Ò»Ýªº°Ñ¼Æ¡A¨ä¹ê´N¬O MSG µ²ºcÅ骺«e¥|Äæ¡Cµøµ¡¨ç¦¡¦WºÙ¥i¥ô·N¨ú¡A¦¹³B¤p¤ì°¸©R¦W WndProc¡C
¦b¼¶¼gµøµ¡¨ç¦¡®É¡AÁÙ¦³¤@¥ó¨Æ±¡nª`·N¡A¨º´N¬O¦bµøµ¡¨ç¦¡µ²§ô«áªð¦^¨t²Î«e¡A¥²»Ý«O¦s EBX¡BESI¡BEDI¡BEBP¡A§_«h¥²©w³y¦¨·í¾÷¡C³o¬O¦]¬° Windows ¨t²Î¤º¥²¨Ï¥Î³o¨Ç¼È¦s¾¹·í§@«ü¼Ð¡A©Ò¥H±oª`·N«O¦s³o¥|ӼȦs¾¹¡C¨ä¹ê¤£¥u¬Oµøµ¡¨ç¦¡¦p¦¹¡A©Ò¦³³Q¨t²Î©I¥sªº°Æµ{¦¡¡A¹³ Windows API¡A³£¥²¶·¦bªð¦^¨t²Î«e«ì´_³o¥|ӼȦs¾¹ªº¼ÆÈ¡C
²Ä 54 ¦æ¬O proc °²«ü¥O¡A¥¦©M¥H«e¦b DOS ®É¥Nªº¥Îªk®t¤£¦h¡A½Ð¬Ý²Ä¤@³¹µù¤Tªº»¡©ú¡C
²Ä 55 ¦æ¬O§âÂǥѨt²Î¶Ç¹L¨Óªº°T®§©M WM_DESTROY ¤ñ¸û¡A°²¦p¤£¬O WM_DESTROY °T®§ªº¸Ü«h¨ì²Ä 60 ¦æ©I¥s DefWindowProc API¡C¦Ü©ó¬°¤°»ò¬O WM_DESTROY °T®§¦Ó¤£¬O WM_QUIT ©O¡HWM_DESTROY ¤S¦p¦ó²£¥Íªº¡Hµy«áªºµ²§ôµ{¦¡¦A»¡©ú¡C
DefWindowProc API ¬O¨t²Î¤º©wªº³B²z°T®§¨ç¦¡¡A¥¦¯à³B²z³\¦h¨t²Î¤º©wªº°T®§¡A¨Ò¦p¨Ï¥ÎªÌ§â·Æ¹«²¾¨ìµøµ¡Ãä®Ø§ïÅܵøµ¡¤j¤p¡B«ö¤Uµøµ¡¥k¤W¨¤ªº³Ì¤j¤Æ©Î³Ì¤p¤Æ«ö¶sµ¥¡A³o¨Ç°T®§§¡¥i¥Ñ DefWindowProc ³B²z¡CDefWindowProc ªº»yªk¬O¡F
LRESULT DefWindowProc( HWND hWnd, // handle to window UINT Msg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
³q±`¦bµøµ¡¨ç¦¡ùØ¡A§â§Ú̦³¿³½ìªº°T®§Àu¥ý¼g¦b«e±¡A¦Ó³Ì«á³£À³¸Ó©I¥s DefWindowProc ¨Ó³B²z¨t²Î¤º©wªº°T®§³B²z¤è¦¡¡C·í DefWindowProc ³B²z§¹°T®§«á¡A·|§â¶Ç¦^Ȧs¤J EAX¡AEAX ªº¼ÆÈ·|©M³B²zªºµ²ªG¦³Ãö¡A¥¦¤]·|¥i¯à¼vÅT¤U¤@¦¸ªº°T®§¡A©Ò¥H¤£¥i¦A§ïÅÜ EAX ¤§È¡AÀ³¸Óª½±µªð¦^¨t²Î¡C¦Ü©ó§Ú̦ۤv³B²zªº°T®§¡A°²¦p¥¿½TµL»~ªº¸Ü¡A¤]À³¸Ó¿í¦u Window ¨t²Îªº³W©w¡A§â EAX ³]¬°¹s¶Ç¦^µ¹¨t²Î¡C
©Ò¥H°²¦p§Ú̹ï¨âÓ°T®§¡AWM_AAA¡BWM_BBB¡A»Ýn³B²z¡A¨º»òµøµ¡¨ç¦¡À³¸Ón³o¼Ë¼g¡J
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM cmp uMsg,WM_AAA jne nxt1 ³B²z WM_AAA °T®§ªºµ{¦¡ jmp exit nxt1: cmp uMsg,WM_BBB jne nxt2 ³B²z WM_BBB °T®§ªºµ{¦¡ jmp exit nxt2: cmp WM_DESTROY jne nxt3 invoke PostQuitMessage,NULL jmp exit nxt3: invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret exit: xor eax,eax ret WndProc endp
³Ì«áÁÙ±o¦A¥[¤W³B²zµøµ¡¤w³QºR·´ªº WM_DESTROY °T®§¡A¤]´N¬O³B²zµ²§ôªºµ{¦¡¡C¥H¤W¤jP¬Oµøµ¡¨ç¦¡ªºÂú§Î¡A¥i¿×¼Æ¾Ç¡y¤½¦¡¡z¡A©Ò¥H¤p¤ì°¸¯S§O¥H¬õ¦âªí¥Ü¡C
¦¹µ{¦¡ªº²Ä 55 ¦æ¬O¤@±ø¤ñ¸û«ü¥O¡A¤ñ¸û WndProc °Ñ¼Æ©M WM_DESTROY ³oÓ°T®§¬O§_¬Û¦P¡A°²¦p¬Û¦Pªº¸Ü·|¸õ¨ì²Ä 57 ¦æ°õ¦æ PostQuitMessage API¡CPostQuitMessage ¶È¶È¨Ï¨t²Î§â WM_QUIT °T®§©ñ¨ìµ{¦¡°T®§¦î¦CùØ¡Aµ¥«Ýµ{¦¡¥H GetMessage ´£¨ú WM_QUIT °T®§¡C
PostQuitMessage API ªº»yªk¦p¤U¡F
VOID PostQuitMessage( int nExitCode // exit code );
nExitCode ¬Oµ{¦¡µ²§ô®Éªº¶Ç¦^È¡C¦Ü©óµ²§ôµ{¦¡ªº¹Lµ{¥H¤Î°T®§µo¥Í¶Ç»¼ªº¸g¹L¡AÁÙ¦³À³¸Óª`·Nªº¨Æ¶µ¡A¦bµ²§ôµ{¦¡ùØ»¡©ú¡C
·í¨Ï¥ÎªÌ«ö¤Uµøµ¡¥k¤W¨¤ªºÃö³¬¶s©ÎªÌ¥Ñ¿ï³æªº¡yÀɮסz¿ï¾Ü¡yÂ÷¶}¡z®É¡A¨t²Î·|§â WM_CLOSE °T®§¦s¤J¸Óµ{¦¡ªºµ{¦¡°T®§¦î¦CùØ¡A·íµ{¦¡©I¥s GetMessage API ®É·|¶Ç¦^ WM_CLOSE °T®§¡A¦¹°T®§ÂÇ¥Ñ backcall ¤è¦¡§â¦¹°T®§¶Çµ¹µøµ¡¨ç¦¡¡C³q±`§Ṳ́£³B²z³oÓ°T®§¡A¦Ó¥æ¥Ñ DefWindowProc ¥h³B²z¡CDefWindowProc ¦¬¨ì WM_CLOSE «á¦Û¤v¤£³B²z¦Ó¬O©I¥s DestroyWindow API ³B²z¡ADestoryWindow ·|ºR·´µøµ¡¡A¨Ãµo¥X WM_DESTROY °T®§¶ñ¤J¸Óµøµ¡ªºµ{¦¡°T®§¦î¦CùØ¡A·íµøµ¡¨ç¦¡¦¬¨ì¦¹°T®§©M WM_DESTROY ¤ñ¹ï«á«K¸õ¨ì²Ä 57 ¦æ©I¥s PostQuitMessage API¡APostQuitMessage ³oÓ API ¶È¶È§â WM_QUIT ¶Çµ¹¨t²Î¡A³o¼Ë·í GetMessage ¦A¦¸¨ú±oªº°T®§´N¬O WM_QUIT¡A©ó¬Oµ{¦¡²Ä 45 ¦æ¨ì²Ä 50 ¦æªº°T®§°j°é±o¥Hµ²§ô¡C
±z¤@©wı¬°¦óÁÙn©I¥s PostQuitMessage ¡Hµøµ¡¬J¤wºR·´¤£´N§¹¦¨¤F¶Ü¡H¨Æ¹ê¤W¤£¬O³o»ò²³æ¡C°²¦p¤£³o¼Ë°µªº¸Ü¡Aªí±¤Wµøµ¡¤w¸g®ø¥¢¤£¨£¡A¦ý¬O¹ê»Ú¤Wµ{¦¡ªº°T®§°j°é¤´´Ý¯d¦b°O¾ÐÅéùØ¡AÁÙÄ~Äò®ø¯Ó¨t²Î¸ê·½¡C¤£«Hªº¸Ü¡A±z¥i¥H§â¦¹ì©l½Xªº PostQuitMessage ¨º¤@¦æ¥[¤W¡y;¡z¦A²ÕĶ¬Ý¬Ý¡AµM«á°õ¦æ¥¦¦Aµ²§ô³oÓµ{¦¡¡A±z·|µo²{¯à°÷¶¶§Qµøµ¡·|¦b¿Ã¹õ¤W®ø¥¢¡A¦ý¬O¦pªG±z«ö¤U Ctrl¡ÐAlt¡ÐDel¡A·|¥X²{¤@Óµøµ¡¡A¨ä¤º®e¬O¥¿¦b°õ¦æªºµ{¦¡¦Cªí¡C±z¥i¥H§ä¨ì Stdwnd ³oÓµ{¦¡¡C©Ò¥Hµ{¦¡³]p®vnª`·NÀH®É«O«ùµøµ¡¨ç¦¡»P°T®§°j°é¤§¶¡ªºÁpô¡C
³Ì«áÁÙ¦³¤@Ó°ÝÃD¡A¬°¦ó DefWindowProc ¤£¦b¦¬¨ì WM_DESTORY ´N¦Û°Ê©I¥s PostQuitMessage ¦Ón§â³oÓ¤u§@¯dµ¹µ{¦¡³]p®v©O¡Hì¨Ó¬O¤@Óµ{¦¡¥i¯à«Ø¥ß¦n´XÓµøµ¡¡A°²¦p DefWindowProc ¦Û°Ê¥æ¥Ñ PostQuitMessage ¨Ó°h¥Xµ{¦¡¡A¨º»ò«K·|§â©Ò¦³µ{¦¡©Ò«Ø¥ßªºµøµ¡Ãö³¬¡A³o¼Ë¦³®É·|¦³¤£¦X²zªº²{¶H¡C¨Ò¦p¡A°²¦p±z¦b Word ¶}±ÒÂÂÀɮɥX²{¤@Ó¹ï¸Ü²°µøµ¡¡A·í¿ï©wÀɮ׫á³oÓµøµ¡´N·|Ãö³¬¡A«o³Q DefWindowProc ¦]©I¥s PostQuitMessage ¦Ó°h¥X Word¡A³o¼Ë¤£¬O«Ü©_©Ç¶Ü¡H
³o¤@³¹´N¨ì¦¹³Bµ²§ô¡A¤U¤@³¹±N¤¶²Ð¦p¦óÁä½L¿é¤J¨Ã§â¨Ï¥ÎªÌ©Ò«ö¤UªºÁäÅã¥Ü¦bµøµ¡¤W¡C
µù¤@¡GÃþ§O¬Oª«¥ó¾É¦V±`¥Îªº³N»y¡A¦bª«¥ó¾É¦Vªºµ{¦¡³]pÆ[©ÀùØ¡A§â¿Ã¹õ¤W¬Ý¨ìªºªF¦è¡A¦pµøµ¡¡B«ö¶sµ¥³£¬Ý¦¨¯u¹ê¥Í¬¡¤Wªºª«Åé¡A¨Cª«Åé³£¦³¦Û¤vªº¯S©Ê¤Î¨Ï¥Î¤èªk¡A¨Ò¦p®Ñ¥»´N¬O¥Î¨Ó°O¸ü¤å¦r¹Ï¤ùªºªF¦è¡A¥¦Ì³£¦³¬Û¦üªº¥~Æ[¡A³£¬O¤@¶¡B¤@¶¦Lº¡¤å¦r¹Ï¤ùªº¯È±i¸Ëq¦¨¥U¡A®Ñªº¨Ï¥Î¤èªk¤]³£Ãþ¦ü¡C¦b Win32 ¨t²Î¤W±¦³³\¦hªºµøµ¡¡A¦³¨Ç¥~Æ[¬Û¦ü¡A¾Þ§@¤èªk¤]¬Û¦ü¡A©ó¬Oµ{¦¡³]p®É¤]±Ä¥Î¬Û¦PªºÆ[©À¡A§â³o¨Çµøµ¡Âk¯Ç¦¨¦P¤@Ãþ§O¡C·í§Ú̳]pµ{¦¡®É¡A§K¤£¤Fn¥Î¨ì³\¦hµøµ¡¡A©ó¬O¥ýºc·Q³o¨Çµøµ¡ªº¥~Æ[¡B¾Þ§@¤èªk¡AµM«á¦A¨Ï³o¨Çµøµ¡¨ã¦³¬Û¦PªºÃþ§O¡A©ó¬O¥¦Ìªº¥~Æ[¡B¾Þ§@¤èªk³£¤@¼Ë¡C
µù¤G¡G¤@©w¦³³\¦h¤H°Ý¨âÓ°ÝÃD¡G¡yµøµ¡»Pµ{¦¡ªºÃö«Y¡z»P¡y°õ¦æ¹ê¨Ò¡Bµ{¦¡¡B¼Ò²ÕªºÃö«Y¡z¡C
¤@Óµ{¦¡¤£¤@©w´N¬O¤@Óµøµ¡¡A¨Ò¦p±z¦b«þ¨©Àɮ׮ɡA¦pªG¥Øªº¸ê®Æ§¨¦³¬Û¦PÀɦW®É¡A´N·|¼u¥X¤@Ó¤pµøµ¡°Ý±z¬O§_Âл\¡A³o¼Ë³oÓ«þ¨©ªºµ{¦¡´N¾Ö¦³¨âÓµøµ¡¤F¡A¥H³N»y¨Ó»¡´N¬O¡y¦¹°õ¦æ¹ê¨Ò¦³¨âÓµøµ¡¡z¡C¤]¦³µ{¦¡¬O¤£²£¥Íµøµ¡ªº¡A¨Ò¦pÁÙ¥¼µo§@ªº¯f¬r©M¤ì°¨µ{¦¡³£¤£²£¥Íµøµ¡¡C§Ú·Q¤j·§¥i¥H³o»ò»¡¡A¤@Óµ{¦¡¥i¥H¤£²£¥Íµøµ¡¡B¤]¥i¥H²£¥Í¤@Óµøµ¡¡A¤]¥i¥H²£¥Í¤@Ó¥H¤Wªºµøµ¡¡A¬Ý»Ýn¦Ó©w§a¡C