Ch 02 ¼Ð·Çµøµ¡

¦b¤W¤@³¹ùØ¡A¤p¤ì°¸«Ø¥ß¤F¤@­Ó¥u¥Î¨ÓÅã¥Ü¤å¦r²³æªºµøµ¡¡A¥¦¥u¦³¤@­Ó«ö¶s¥i¥HÃö³¬µøµ¡¡C¦b³o¤@³¹ùØ¡A¤p¤ì°¸±N­n«Ø¥ß¤@­Ó¼Ð·Çªº 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


­ì²z

«Ø¥ß¼Ð·Çµøµ¡

­n«Ø¥ß¤@­Ó¼Ð·Çªºµøµ¡¡A¨Ïµøµ¡¯à°÷±µ¦¬¨t²Îªº°T®§¡A¤]¯à¶Ç»¼°T®§µ¹¨t²Î¡A©Ò»Ý¨BÆJ¦p¤U¡G

  1. ±o¥ý¨ú±oµ{¦¡ªº¼Ò²Õ¥N½X ( module handle¡Aµy«á»¡©ú )
  2. «Ø¥ß¤@­Óµøµ¡Ãþ§O ( window class¡Aµù¤@ )¡Aµøµ¡Ãþ§O¬O¥Î¨Ó©w¸qµøµ¡¥~Æ[¡B¾Þ§@¤èªkµ¥¡Aµøµ¡Ãþ§Oªº¸ê®Æ¬O¥Ñ¤@­Óµ²ºcÅé©w¸q¡A¦¹µ²ºcÅéºÙ¬° WNDCLASSEX¡C
  3. ¥H¦¹µ²ºcÅé¦V§@·~¨t²Î¡yµù¥U¡z
  4. ¥H³o¨â­Ó³Ì­«­nªº¸ê®Æ¡A¼Ò²Õ¥N½X¤Îµøµ¡Ãþ§O¡A¦V¨t²Î­n¨D«Ø¥ßµøµ¡¡A°²¦p¦¨¥\ªº¸Ü¡A¨t²Î³£·|µo¤@­Ó¡y¸¹½XµP¡z·í§@³o­Óµøµ¡ªº¡y¨­¤ÀÃÒ¡z¡A³o­Ó¸¹½XµPºÙ¬°µøµ¡¥N½X ( window handle )¡A¥H«á¨t²Î´N¥H¦¹µøµ¡¥N½X»P§Ú­Ì©Ò«Ø¥ßªºµøµ¡¤¬³q°T®§¡C
  5. ¨ì¦¹¶È¶È§i¶D¨t²Î¤@­Ó§Ú­Ìªºµ{¦¡­n«Ø¥ß¤@­Óµøµ¡¤w¸g·Ç³Æ§¹¦¨¡A¦ý¬O¨Ã¨S¦³¦b¿Ã¹õ¤WÅã¥Ü¥Xµøµ¡¨Ó¡A©Ò¥HÁÙ±o¦A©I¥s Win32 API Åã¥Üµøµ¡¡C(µù¤G)
  6. ±µ¤U¨Ó¡A¶i¤J°T®§°j°é¥HÀò±o¨Ï¥ÎªÌªº°T®§¡C
  7. ¦A¨Ó¬O¶i¤Jµøµ¡¨ç¦¡³B²z°T®§¡C

³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¤W­z«Ø¥ß¼Ð·Çµøµ¡ªº²Ä 6 ¨Bªº­ì²z¡C

°T®§¡I°T®§¡I

¨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


­ì©lµ{¦¡

©³¤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


¸ê®Æ¬q

²Ä 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´N­n«ü©w¨º¤@­Óµøµ¡­n³Q§ó·s¡A¦]¦¹°£¤F©w¸q¼Ò²Õ¥N½X¥~¡A¤]­n©w¸qµøµ¡¥N½X¡C

WNDCLASSEX µ²º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

  1. cbSize¡G³o¬Oµ²ºcÅéªø«×¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C¦@¦³ 12 ­ÓÄæ¦ì ( field )¡A¥B¨C­ÓÄæ¦ì¬O 4 ­Ó¦ì¤¸²Õ¡A¬G¶ñ¤W 30H¡C¤§©Ò¥H¦³³o­ÓÄæ¦ì¬O¬°¤F API ª©¥»ªº¬Û®e©Ê¡C

  2. style¡G¥Î¨Óªí¥ÜÄݩ󦹵øµ¡Ãþ§Oªºµøµ¡ªº­·®æ¡A¦b²Ä 26 ¦æ¦³
            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

  3. lpfnWndProc¡G³o­ÓÄæ¦ì¬O«ü¦V¤@­Óµøµ¡¨ç¦¡ ( window procedure ) ªº¦ì§}¡Aµøµ¡¨ç¦¡¬O¨Ì¾Ú¨Ï¥ÎªÌµ¹ªº°T®§°õ¦æ¤£¦Pªº³B²z°Ê§@¡A¤]¥i¥H»¡µøµ¡¨ç¦¡ªí²{¥X¸Óµøµ¡ªº¾Þ§@¤è¦¡©Îµøµ¡ªº¦æ¬°¡A·í¨Ï¥ÎªÌ¦bµøµ¡ÂI«ö·Æ¹«©Î«ö¤UÁä½L®É¡Aµøµ¡¦p¦ó¦^À³³£¥Ñ³o­Óµøµ¡¨ç¦¡³B²z¡C¦Ü©ó¨Ï¥ÎªÌ¿é¤Jªº°T®§¦p¦ó¶Ç¤J»P DispatchMessage ¦³Ãö¡A³o³¡¤Àªº»¡©úµy«á¦A»¡¡C

  4. cbClsExtra¡G¦¹Äæ¦ì§i¶D¨t²Îµù¥U¦¹µøµ¡Ãþ§O¡AÁÙ­nÃB¥~«O¯d¦h¤Ö¦ì¤¸²Õ¡A³o¨ÇÃB¥~ªº¦ì¤¸²Õ¬Oµ¹±z¦Û¤v©w¸qÄÝ©ó¦Û¤vªºÄÝ©Ê¡A¨t²Î¤£¥Î¨ì³o¨ÇÄÝ©Ê¡A¥²¶·±z¦Û¤v³]­pµ{¦¡¨Ó¥Î¥¦¡C

  5. cbWndExtra¡G¦¹Äæ¦ì¬O¥Î¨Ó§i¶D¨t²Î¡A¥H¦¹µøµ¡Ãþ§O²£¥Í¤@­Óµøµ¡¡AÁÙ­nÃB¥~«O¯d¦h¤Ö¦ì¤¸²Õ¡C

  6. hInstance¡G¼Ò²Õ¥N½X¡Aªí¥Ü¦¹µøµ¡Ãþ§OÄݩ󨺤@­Óµ{¦¡¼Ò²Õ¡C

  7. hIcon¡Gµøµ¡¹Ï¥Ü¥N½X¡C

  8. hCursor¡G´å¼Ð¥N½X¡C·í´å¼Ð²¾¨ì¸Óµøµ¡¤u§@°Ï ( client area ) ®Éªº§Îª¬¡C

  9. hbrBackground¡G¤u§@°Ï­I´ºÃC¦â¡Chbr ªí¥Ü¦¹Äæ¦ì¬O¤@­Ó¨ê¤l¥N½X¡A¨ê¤l¬O¥Î¨Ó§âÃC®Æ¶î¦b¯È¤Wªº¡A³oùتí¥Ü¦b¤u§@°ÏµÛ¦âªº·N«ä¡C¨t²Î¤w¸g©w¸q¤F¤@¨ÇÃC¦â­È¡A¨Ò¦p COLOR_WINDOW¡A¦ý¬O¨t²Î¤¤³W©w¥²¶·¦A¥[¤W¤@¡C

  10. lpszMenuName¡Gªí¥Ü¦¹µøµ¡Ãþ§Oªº¿ï³æ¦WºÙ¡A³o¬O¤@­Ó«ü¼Ð¡A«ü¦V¤@­Ó¥H¹s¬°µ²§Àªº¦r¦ê¡C°²¦p¦¹Äæ¦ì¬°¹s¡A¥i¥H¦b©I¥s CreateWindowEx ùتº°Ñ¼Æ©w¸q¡A¦pªG¨âªÌ³£¬°¹sªº¸Ü¡Aªí¥Ü¨S¦³¿ï³æ¡C

  11. lpszClassName¡G¦¹µøµ¡Ãþ§O¦WºÙ¡A¤]¬O¤@­Ó«ü¼Ð¡A«ü¦Vµøµ¡Ãþ§O¦WºÙ¡A¤]¬O¥H¹s¬°µ²§À¡C

  12. hIconSm¡G¤p¹Ï¥Ü¥N½X¡A³o¬O¥Î¨ÓÅã¥Ü¦b¤u§@¦C¤Wªº¹Ï¥Ü¡A°²¦p¦¹Äæ¦ì¬°¹s¡Aªí¥Ü©M¹Ï¥Ü¬Û¦P¡A¥u¬OÁY¤p¦Ó¤w¡C

MSG µ²ºcÅé

²Ä 19 ¦æ¬O©w¸q¤@­Óµ²ºcÅéÅܼơAmsg¡A³o­Óµ²ºcÅé¬O¥Î¨Ó©M¨t²Î¶Ç»¼°T®§¥Îªº¡A¦Ü©ó¥¦ªº¤º®eµy«á»¡©ú¡C


µ{¦¡½X¬q

±q²Ä 21 ¦æ¶}©l¨ìµ²§ô¬Oµ{¦¡½X¬q¡A¤j­P¥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 ¦æ )

«Ø¥ß¨Ã¦b¿Ã¹õ¤WÅã¥Üµøµ¡

GetModuleHandle API

µ{¦¡¤@¶}©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

GetCommandLine API

±µ¤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 API

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
   );

¥Ñ¤W­z¸ê®Æª¾¡ALoadIcon ¦³¨â­Ó°Ñ¼Æ¡A²Ä¤@­Ó°Ñ¼Æ¬O¼Ò²Õ¥N½X¡A²Ä¤G­Ó¬O«ü¦V¹Ï¥Ü¸ê·½¦WºÙªº¦ì§}¡A¦¹¦ì§}¥²¶·¥H 0 ¬°µ²§À¡C¨t²Î¤w¸g¹w¥ý©w¸q¤F´X­Ó¹Ï¥Ü¥i¨Ñ¨Ï¥Î¡A°²¦p­n¥Î¨t²Î¹w©wªº¹Ï¥Ü¡A¨º»ò hInstance ­n³]¬° NULL¡A¦Ó lpIconName ¥i¥H¬O¤U­±´XºØ±¡§Î¡G

²Å¸¹ ¼Æ­È´y­z
IDI_APPLICATION32512¤º©w­È
IDI_ASTERISK32516 ­^¤å¦r¥À¡yi¡z¡A³q±`¥Î©ó³qª¾
IDI_EXCLAMATION32515 Åå¼Û¸¹¡A³q±`¥Î©óĵ§i
IDI_HAND32513 ¥æ¤e¡A³q±`¥Î©óÄY­«Äµ§i
IDI_QUESTION32514 °Ý¸¹¡A³q±`¥Î©ó´£¥Ü°T®§

·í©I¥s LoadIcon ¦¨¥\®É¡A·|¦b EAX ¶Ç¦^¹Ï¥Ü¥N½X¡A­Y¥¢±Ñ¡A«h EAX ¬°¹s¡C

LoadCursor API

³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°²¦p­n¨Ï¥Î¨t²Î©Ò©w¸qªº´å¼Ð¡A«h hInstance ¥²¶·³]¬° NULL¡A¦Ó lpCursorName ¥i¥H¬O¤U­±´XºØ±¡§Î¡G

²Å¸¹ ¼Æ­È´y­z
IDC_ARROW32512 ¨t²Î¨Ï¥Îªº½bÀY¡A³Ì±`¨Ï¥Îªº·Æ¹«´å¼Ð
IDC_APPSTARTING32650 ½bÀY»P¨Fº|¡A·í¨t²Î¦£¸L¤¤¨Ï¥Îªº´å¼Ð
IDC_SIZENS32645 ¤W¤U¤è¦VªºÂù½bÀY¡A±`¥Î©ó·Æ¹«²¾¨ìµøµ¡¤W¤UÃä½t
IDC_SIZEWE32644 ¥ª¥k¤è¦VªºÂù½bÀY¡A±`¥Î©ó·Æ¹«²¾¨ìµøµ¡¥ª¥kÃä½t
IDC_HAND32649¤â§Î

ÁÙ¦³´XºØ±¡§Î¡A½Ð¦Û¦æ°Ñ¦Ò Win32 API¡C

RegisterClassEx API

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
   );

CreateWindowEx API

³o­Ó API ¬O«Ø¥ßµøµ¡¡A±z¥i¥H·Q¹³¥¦¬O¦b°O¾ÐÅ餤«O¯d¤@¶ô°O¾ÐÅé´y­z³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¨Ç°Ñ¼Æ´y­z¦p¤U¡G

  1. dwExStyle¡Gµøµ¡ªº©µ¦ù­·®æ ( extended styles¡A¤]¥sÂX®i­·®æ )¡C¦b Win 3.1 ®É¡A¦³¥t¥~¤@­Ó CreateWindow API¡A¦Ó Win 9x/2K/NT/XP ¬°¤F¨Ï¥Î§ó¦hªº©µ¦ù­·®æ¡A¨Ò¦p¨Ïµøµ¡Á`¬O¦b³Ì¤W­±¡A¦Ó¦h¤F¤@­Ó·sªº API¡A´N¬O CreateWindowEx¡A­Y¤£¥Î³o¨Ç©µ¦ùªº­·®æ¡ACreateWindow ©M CreateWindowsEx ¨âªÌ¤j­P¬Û¦P¡A³o®É¥i¥H¨Ï¥Î NULL¡C­Y­n¨Ï¥Î©µ¦ù­·®æ¡A«h¦¹Äæ¼Æ­È¥²¶·«ü©w¡A¦Ü©ó­þ¨Ç©µ¦ù­·®æ¥i¨Ñ¨Ï¥Î¡A½Ð¬Ý Win32 API¡A³o¨Ç©µ¦ùªº­·®æ¤j¦h¥H WS_EX_ ¶}ÀY¡A¨Ò¦p WS_EX_TOPMOST ¬O¨Ïµøµ¡Á`¬O¦b³Ì¤W­±¡C( WS ¬O Window Style¡AEX ¬O Extend )

  2. lpClassName¡G«ü¦V¥H¹s¬°µ²§Àªºµøµ¡Ãþ§O¦W¦r¦ê¦ì§}¡C³o­Óµøµ¡Ãþ§O¥²¶·¬O¤wµù¥U§¹¦¨ªºµøµ¡Ãþ§O¦W¡A³o¼Ë¦¹µøµ¡«K·|¾Ö¦³¸Óµøµ¡Ãþ§Oªº©Ò¦³­·®æ¡Cµ{¦¡°õ¦æ¨ì¦¹³B¡A¤w¸g¦V¨t²Îµù¥U¹L¤@­Óµøµ¡Ãþ§O¡A¨ä¦WºÙ¬° ClassName¡A¥¦¬O¦b²Ä 18 ¦æ©w¸qªº¡A©Ò¥H¦¹³B´N«ü¦V ClassName ªº¦ì§}¡C

  3. lpWindowName¡G«ü¦V¥H¹s¬°µ²§Àªºµøµ¡¦WºÙ¦ì§}¡C¦¹¦r¦ê·|Åã¥Ü¦b¼ÐÃDÄæ¤W­±¡A°²¦p¦¹Äæ¦ì¬° NULL¡Aµøµ¡ªº¼ÐÃDÄæ´N¨S¦³¦r¦ê¡C

  4. dwStyle¡G«ü©wµøµ¡­·®æ¡A±`¥H WS_ ¶}ÀY ( WS_ ¬O«ü window styles ªº·N«ä )¡A©³¤U¦C¥X´X­Ó±`¥Îªº¡G
    ²Å¸¹ ¼Æ­È´y­z
    WS_OVERLAPPED0000000h Åã¥Ü¤@­Ó¨S¦³¼ÐÃDÄæ¡BÃä®Ø¡B¨t²Î¿ï³æ¡B³Ì¤j¤Æ¡B³Ì¤p¤Æ¡BÃö³¬«ö¶sªºµøµ¡
    WS_HSCROLL0100000h Åã¥Ü¤ô¥­±²¶b
    WS_VSCROLL0200000h Åã¥Ü««ª½±²¶b
    WS_OVERLAPPEDWINDOW0CF0000h ³o¬O³Ì±`¥Îªº­·®æ¡A¦³¼ÐÃDÄæ¡B³Ì¤j¤Æ«ö¶s¡B³Ì¤p¤Æ«ö¶s

  5. x¡By¡Gµøµ¡¥ª¤W¨¤ªº¦ì¸m¡C­ìÂI¬O¿Ã¹õ³Ì¥ª¤W¨¤ªº¨º¤@ÂI¡A¸ÓÂI®y¼Ð¬° (0¡A0)¡A¨C¦V¥ª¤@ÂI¡Ax ®y¼Ð¥[¤@¡A¨C¦V¤U¤@ÂI¡Ay ®y¼Ð¥[¤@¡A°²¦p±z·Q¦b®y¼Ð (100¡A200) Åã¥Üªº¸Ü¡A´N§â x¡By ¤À§O³]¬° 100¡B200¡C¦pªG³o­Óµøµ¡¬O¤lµøµ¡ªº¸Ü¡A­ìÂIªº¦ì¸m¬O¤÷µøµ¡ªº¥ª¤W¨¤¡C°²¦p x¡By ³]¬° CW_USEDEFAULT «h¥Ñ¨t²Î³]©w¡C

  6. nWidth¡BnHeight¡G³o¨â­ÓÄæ¦ì¤À§O¬O¥Î¨Óªíµøµ¡ªº¼e«×»Pªø«×¡C°²¦p¥Î CW_USEDEFAULT «hªí¥Ü¥Ñ¨t²Î³]©w¡C

  7. hWndParent¡G©ÒÄݪº¤÷µøµ¡¥N½X¡A³o¬O¬°¤FÃö³¬¤÷µøµ¡®É¦P®É¤]¯àÃö³¬¤lµøµ¡¡C§Ú­Ì©Ò«Ø¥ßªºµøµ¡¤£ÄÝ©ó¨ä¥Lµøµ¡¬G³]¬° NULL¡C

  8. hMenu¡G¿ï³æ¥N½X¡C°²¦p¦¹Ä欰¹s¡Aªí¥Ü¨Ï¥Îµù¥Uµøµ¡Ãþ§Oªº¿ï³æ¡A°²¦p¨âªÌ¬Ò¬° NULL¡Aªí¥Ü¨S¦³¿ï³æ¡C

  9. hInstance¡G¦¹µøµ¡©ÒÄݪºµ{¦¡¼Ò²Õ¡C

  10. lpParam¡G«ü¦V¤@­Ó°Ñ¼Æ¦ì§}¡A¦¹°Ñ¼Æ¯à°÷¶Ç°T®§µ¹§Ú­Ì©Ò«Ø¥ßªºµøµ¡¡C­Y¤£»Ý­n¡A«h³]¬° NULL¡C

°²¦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

ShowWindow API

¦b°O¾ÐÅ餤«Ø¥ß¦n¤@­Óµøµ¡«á¡A­n¯à¦b¿Ã¹õ¤WÅã¥Ü¡A¨Ï¥ÎªÌ¤~¬Ý±o¨£ ( ¦³¨Çµ{¦¡¬O¤£Åã¥Üµøµ¡ªº¡A¨Ò¦p¯f¬r )¡C­nÅã¥Üµøµ¡¥i¥H©I¥s ShowWindow API¡A¨ä¨ç¼Æ­ì«¬¦p¤U¡G

BOOL ShowWindow(
    HWND    hWnd,       // handle of window
    int     nCmdShow    // show state of window
   );

²Ä¤@­Ó°Ñ¼Æ¬O·Q­nÅã¥Üµøµ¡ªºµøµ¡¥N½X¡A²Ä¤G­Ó°Ñ¼Æ¬OÅã¥Ü¤è¦¡¡A±`¥ÎªºÅã¥Ü¤è¦¡¦p¤Uªí¡G

²Å¸¹ ¼Æ­È´y­z
SW_HIDE0ÁôÂÃ
SW_MINIMIZE6³Ì¤p¤Æ
SW_MAXIMIZE3³Ì¤j¤Æ
SW_SHOWDEFAULT10 ¥Ñ¨t²Î¤º©w

ShowWindow ¦³¶Ç¦^­È¡A°²¦p­ì¥ýªºµøµ¡¬O¥i¨£ªº¡AEAX ¤£¬°¹s¡A¤Ï¤§¬°¹s¡C¤£¹L¦b³o­Óµ{¦¡ùتº¶Ç¦^­È¤£­«­n¡C

UpdateWindow API

Åã¥Üµøµ¡«áÁÙ±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  
   );

¶i¤JµL½a°T®§°j°é±o¨ì°T®§

GetMessage API

±µ¤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°²¦p­n¨ú±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

TranslateMessage API

³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 API

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

³B²z°T®§ªºµøµ¡¨ç¦¡ ( window procedure )

·í§Ú­Ìªºµ{¦¡¦Û¨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¥D­nªº¤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

ªº´y­z¦Ó¤w¡A¬J¨S¦³©I¥s WndProc¡A¤]¨S¦³¶Ç»¼°T®§ªºÃþ¦ü´y­z¡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¬O­n³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

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¤j­P¬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

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

µ²§ôµ{¦¡

WM_CLOSE¡BWM_DESTROY¡BWM_QUIT °T®§

·í¨Ï¥ÎªÌ«ö¤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®v­nª`·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¤£¤F­n¥Î¨ì³\¦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


¨ì²Ä¤@³¹¡A ¨ì­º­¶¡A ¨ì²Ä¤T³¹