²Ä¤Q¤C³¹¡@¥\¯àªí¡]¤G¡^

¥»³¹¤¶²Ð§Ö±¶¥\¯àªí»P¨t²Î¥\¯àªí¡C


»P¥\¯àªí¬ÛÃö Win64 API

«e¤@³¹¤w¸g¤¶²Ð¹L´X­Ó±`¥Î¡B»P¥\¯àªí¦³Ãöªº Win64 API¡A¨Ò¦p LoadMenu¡BSetMenu¡BCheckMenuItem¡BGetSubMenu¡C©³¤U¥ý¤¶²Ð¥»³¹·|¥Îªº Win64 API¡AµM«á¦A¤¶²Ð§Ö±¶¥\¯àªí»P¨t²Î¥\¯àªí¡C

TrackPopupMenu API

TrackPopupMenu ¨ç¦¡·|¦b«ü©w¦ì¸mÅã¥Ü§Ö±¶¥\¯àªí¨Ã°lÂܨϥΪ̦b¥\¯àªí¤Wªº¿ï¾Ü¡A¦¹§Ö±¶¥\¯àªí¥i¥H¥X²{¦b¿Ã¹õªº¥ô¦ó¦ì¸m¡CTrackPopupMenu ­ì«¬¦p¤U¡G

invoke  TrackPopupMenu,\
        hMenu,\         ; handle of shortcut menu
        uFlags,\        ; screen-position and mouse-button flags
        x,\             ; horizontal position, in screen coordinates
        y,\             ; vertical position, in screen coordinates
        nReserved,\     ; reserved, must be zero
        hWnd,\          ; handle of owner window
        prcRect         ; points to RECT that specifies no-dismissal area

©³¤U¬O TrackPopupMenu °Ñ¼Æªº»¡©ú¡G

¦pªG¦b uFlags °Ñ¼Æ¤¤«ü©w TPM_RETURNCMD¡A«h¦^¶Ç­È¬O¨Ï¥ÎªÌ©Ò¿ï¶µ¥Øªº¿ï³æÃѧO½X¡F¦pªG¨Ï¥ÎªÌ¦b¨S¦³°µ¥X¿ï¾Üªº±¡ªp¤U¨ú®ø¥\¯àªí¡]¨Ò¦p¤wÅã¥Ü¥\¯àªí«á¡A«o¥H·Æ¹«¥ªÁäÂIÀ»¥\¯àªí¥~ªº°Ï°ì¡^¡A©Îµo¥Í¿ù»~¡A«h¦^¶Ç­È¬°¹s¡C¦pªG¥¼¦b uFlags °Ñ¼Æ¤¤«ü©w TPM_RETURNCMD¡A¨º»ò¦pªG TrackPopupMenu ¦¨¥\°õ¦æ¡A«h¦^¶Ç­È¬°«D¹s¡F¦pªG¥¢±Ñ¡A«h¶Ç¦^­È¬°¹s¡C­Y­n¨ú±oÂX¥R¿ù»~°T®§¡A½Ð©I¥s GetLastError¡C

ClientToScreen API

ClientToScreen ±N¬Y¤@¹³¯À¡]¤]¥iºÙ¬°ÂI¡^ªº¤u§@°Ï®y¼Ð¡AÂàÅܦ¨¿Ã¹õ®y¼Ð¡]¥H¤u§@°Ï¥ª¤W¨¤¬°­ìÂIªº®y¼ÐºÙ¤u§@°Ï®y¼Ð¡A¥H¿Ã¹õ¥ª¤W¨¤¬°­ìÂIªº®y¼ÐºÙ¬°¿Ã¹õ®y¼Ð¡^¡C¨ä­ì«¬¦p¤U¡G

invoke  ClientToScreen,\
        hWnd,\          ; window handle for source coordinates
        lpPoint         ; pointer to structure containing screen coordinates

¤W¦¡¤¤ªº hWnd «ü©w­n¥H­þ¤@­Óµøµ¡ªº¤u§@°Ï¬°­ìÂI¡ClpPoint ¬O POINT µ²ºcÅ骺¦ì§}¡A¸Óµ²ºcÅ餺¦³­nÂàÅܪº¤u§@°Ï®y¼Ð¡C°²¦pÂàÅܦ¨¥\¡A¨º»ò ClientToScreen ·|±NÂàÅܫ᪺¿Ã¹õ®y¼Ð¡A¦s¦^ lpPoint ©Ò«ü¦ì§}ªºµ²ºcÅ餺¡A¦P®É¦^¶Ç­È¬°«D¹s¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¹s¡C

GetSystemMenu API

GetSystemMenu ¥i¥HÅýÀ³¥Îµ{¦¡¦s¨ú¨t²Î¥\¯àªí¡A¥H¨Ñ½Æ»s©Î­×§ï¡C¨ä­ì«¬¦p¤U¡G

invoke  GetSystemMenu,\
        hWnd,\          ; handle of window to own window menu
        bRevert	        ; reset flag

²Ä¤@­Ó°Ñ¼Æ¡AhWnd¡A¬O­n¦s¨ú¨t²Î¥\¯àªí¤§µøµ¡¥N½X¡C

²Ä¤G­Ó°Ñ¼Æ bRevert «ü©w¦p¦ó¦s¨ú¡A¥i¥H¬O¤U¦C¨âºØ¼Æ­È¨ä¤¤¤§¤@¡G

  1. FALSE¡GGetSystemMenu ·|¶Ç¦^ hWnd ªº¨t²Î¥\¯àªí¤§¥\¯àªí¥N½X¡Aº¸«áÀ³¥Îµ{¦¡¥i©I¥s¨ä¥L Win64 API ­×§ï¨t²Î¥\¯àªí¡C
  2. TRUE¡GGetSystemMenu ·|­«³]¨t²Î¥\¯àªí¬°­ì¨Óªº¹w³]ª¬ºA¡A¨Ã¶Ç¦^ 0¡C

AppendMenu API

AppendMenu ¥i¥H±N¤@­Ó¤À¹j½u¡B¿ï¶µ©Î¼u¥X¿ï¶µ²K¥[¨ì«ü©wªº¥D¥\¯àªí¡B¤l¥\¯àªí¡B§Ö±¶¥\¯àªí©Î¨t²Î¥\¯àªíªº§ÀºÝ¡A¤]¥i¥H¨Ï¥Î AppendMenu ¨Ó«ü©w¿ï¶µªº¤º®e¡B¥~Æ[©M¦æ¬°¡CÁöµM AppendMenu ¤w³Q InsertMenuItem ©Ò¨ú¥N¡A¦ý¬O¦pªG¤£»Ý­n InsertMenuItem ½ÆÂøªºÂX®i¥\¯à¡A¤´µM¥i¥H¨Ï¥Î AppendMenu¡CAppendMenu ªº­ì«¬¬O¡G

invoke  AppendMenu,\
        hMenu,\         ; handle to menu to be changed
        uFlags,\        ; menu-item flags
        uIDNewItem,\    ; menu-item identifier or handle of drop-down menu or submenu
        lpNewItem       ; menu-item content

©³¤U¬O³o¨Ç°Ñ¼Æªº»¡©ú¡G

¦pªG AppendMenu ¦¨¥\°õ¦æ¡A¦^¶Ç­È¬°«D¹s¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¹s¡C


§Ö±¶¥\¯àªí

§Ö±¶¥\¯àªí¡]shortcut menu¡^¤]¥s§Ö±¶¿ï³æ©Î¬ð²{¦¡¥\¯àªí¡]popup menu¡A¤]½Ķ¦¨¬ð²{¦¡¿ï³æ¡^¡A¬O¨Ï¥ÎªÌ©ó¤u§@°Ï¥ô¤@³B¡A«ö¤U·Æ¹«¥kÁä©Ò¥X²{ªº¥\¯àªí¡C

¸ê·½´y­zÀɤ¤ªº§Ö±¶¥\¯àªí

¦^¾Ð«e¤@³¹¡A¥D¥\¯àªí¦ì©óµøµ¡¼ÐÃDÄæ¤U¤è¡A¨ä¿ï¶µ©Î¼u¥X¿ï¶µ¬Ò¬°¾î¦V±Æ¦C¡A¦ý¦pªG¨Ï¥ÎªÌÂI¿ï¼u¥X¿ï¶µ¡AÅã¥Ü¥X¨Óªº¤l¥\¯àªí¤¤ªº¿ï¶µ¡A«o¬OÁa¦V±Æ¦C¡C´«¥y¸Ü»¡¡A¦b¸ê·½´y­zÀɤ¤¡AMENU °Ï¶ô¤¤ªº²Ä¤@¼h¥\¯àªí¤¤ªº¿ï¶µ¬O¾î¦V±Æ¦C¡A¦Ó¨ä¥Lªº¤l¥\¯àªí¤¤ªº¿ï¶µ¬OÁa¦V±Æ¦C¡C

«ö¤U·Æ¹«¥kÁä¦ÓÅã¥Üªº§Ö±¶¥\¯àªí¤¤ªº¿ï¶µ¡A¤£½×²Ä´X¼h¡A¨ä¿ï¶µ§¡¬°Áa¦V±Æ¦C¡C¥Ñ©ó³o¼Ëªº½t¬G¡A©Ò¥H­n¦b¸ê·½´y­zÀɤ¤¡AÂÇ¥Ñ MENU °Ï¶ô©w¸q§Ö±¶¥\¯àªí¡A»Ý­nµy·LÅܳq¡C

©Ò¿×¡uÅܳq¡vªº·N«ä¬O»s§@¡uµê°²ªº¡v²Ä¤@¼h¥\¯àªí¡C¨ä¹Lµ{¤j­P¬O¥ý¦b¸ê·½´y­zÀɤ¤¡AMENU °Ï¶ô¤º«Ø¥ß¥u¦³¤@­Ó¼u¥X¿ï¶µªº²Ä¤@¼h¥\¯àªí¡C¦b¼u¥X¿ï¶µ¤º¬O²Ä¤G¼h¥\¯àªí¡A¥¦¤~¬O¯u¥¿ªº§Ö±¶¥\¯àªí©Ò¦b¡C±q²Ä¤G¼h¶}©l¡A´N«ö­ì¨Ó§Ö±¶¥\¯àªíªº³]­p¼¶¼g¡C

¤]´N¬O»¡¡A²Ä¤@¼h¥\¯àªí¥u¬O¦û¤F­Ó¦ì¸m¡AÅý¾î¦V±Æ¦Cªº¿ï¶µ©ñ¦b³o¨à¡A¬O¡uµê°²ªº¡v¡A§Ö±¶¥\¯àªí¬O±q²Ä¤G¼h¶}©l¡A¦A°t¦X¡u¯S®íªº¡v¸ü¤J¤è¦¡´NÁקK¤F²Ä¤@¼h¥\¯àªí¾î¦V±Æ¦Cªº°ÝÃD¤F¡C©Ò¿×¡u¯S®íªº¡v¸ü¤J¤è¦¡¡A¨£¤U­±ªº¡u±q¸ê·½¤¤¸ü¤J§Ö±¶¥\¯àªí¡v¡C©³¤U¬O¥Î MENU °Ï¶ô©w¸q§Ö±¶¥\¯àªíªº®æ¦¡¡G

┌─MenuID  MENU
 BEGIN
   ┌─POPUP text
    BEGIN
      └─END
└─END

¥Ñ¤W­±¥iª¾¡A²Ä¤@¼h¥\¯àªí¡]¥H¤ÑªÅ¦â¬A¦í¡^¥u¦³¤@­Ó¼u¥X¿ï¶µ¡A¨ä¦WºÙ¡Atext¡A¥i¥H¬O¥ô·N¦r¦ê¡A¨ä¹ê¬O¤°»ò¦r¦ê¨Ã¤£­«­n¡A³o¬O¦]¬°§Ö±¶¥\¯àªí¨Ã¤£Åã¥Ü MENU °Ï¶ô¤¤ªº²Ä¤@¼h¥\¯àªí¡C²Ä¤G¼h¥\¯àªí¡]¥H¬õ¦â¬A¦í¡^¤¶©ó²Ä¤G¼hªº BEGIN/END ¤§¶¡¡A¥i¥H»¡¬O²Ä¤@¼hªº¤l¥\¯àªí¡A¦ì©ó¡u⁝¡v³B¡A¦¹³B¤~¬O¯u¥¿§Ö±¶¥\¯àªíªº¤º®e¡C¥¦¥i¥H¬O¿ï¶µ¡G

MENUITEM    text,ID,[option]
MENUITEM    SEPARATOR

©Î¼u¥X¿ï¶µ¡G

POPUP   ¼u¥X¥\¯àªí¦r¦ê
BEGIN
    ⁝
END

¦¹¤GªÌ³£¦b«e¤@³¹±Ô­z¹L¤F¡A¦¹³B¤£­«½Æ¡C

±q¸ê·½¤¤¸ü¤J§Ö±¶¥\¯àªí

¦b²Õ¦X»y¨¥­ì©lµ{¦¡¤¤¡A¥Ñ¸ê·½¸ü¤J§Ö±¶¥\¯àªí¡A¨Ã¤£Åã¥Ü²Ä¤@¼h¥\¯àªí¡A¦Ó¬O¥Ñ²Ä¤G¼h¶}©lÅã¥Ü¡A©Ò¥H©I¥s TrackPopupMenu Åã¥Ü§Ö±¶¥\¯àªíªº²Ä¤@­Ó°Ñ¼Æ¡A¬O²Ä¤G¼h¥\¯àªíªº¥\¯àªí¥N½X¡C

´«¥y¸Ü»¡¡AÀ³¥ý©I¥s LoadMenu ¨Ã¨ú±o¸ê·½´y­zÀÉ MENU ¥\¯àªí¥N½X¡A¦¹¬°²Ä¤@¼h¥\¯àªíªº¥N½X¡CµM«á¦A¥H²Ä¤@¼h¥\¯àªí¥N½X¤Î¦ì¸m 0 ¬°°Ñ¼Æ¡A©I¥s GetSubMenu ¨ú±o¤l¥\¯àªí¥N½X¡A³o­Ó¤l¥\¯àªí¥N½X¨ä¹ê´N¬O²Ä¤G¼hªº¥\¯àªí¥N½X¡A¤]¬O¨Ï¥ÎªÌ¥H·Æ¹«ÂI¿ï¤u§@°Ï¥X²{ªº§Ö±¶¥\¯àªí¥N½X¡C³o¥ó¨Æ¤@¯ë¬O¦b³B²z WM_CREATE °T®§®É§¹¦¨¡A¤]¥i¥H¦b¥Dµ{¦¡¤¤«Ø¥ß¦nµøµ¡«á¡B¦ý©|¥¼¶i¤J°T®§°j°é«e§¹¦¨¡C

­nÅã¥Ü§Ö±¶¥\¯àªí®É¡A©I¥s TrackPopupMenu ªº²Ä¤@­Ó°Ñ¼Æ´N¬O³o­Ó²Ä¤G¼hªº¥\¯àªí¥N½X¡C³q±`¬O¨Ï¥ÎªÌ¦b¤u§@°Ï¥ô¤@³B¡A«ö¤U·Æ¹«¥kÁä¤~·|¥X²{§Ö±¶¥\¯àªí¡A³q±`¬O¦b³B²z WM_RBUTTONUP ©Î WM_RBUTTONDOWN ©I¥s TrackPopupMenu¡C


§Ö±¶¥\¯àªíªº¨Ò¤l¡GDRAW3

¤U­±ªº¨Ò¤l¬O±N¤W¤@³¹©Ò´£¨ìªº¥D¥\¯àªí½d¨Ò¡ADRAW2¡A§ï¼g¦¨§Ö±¶¥\¯àªí¡A§ï¼g«áªº¨Ò¤lºÙ¬° DRAW3¡C¥ý¨Ó¬Ý¬Ý¸ê·½´y­zÀÉ¡ADRAW3.RC¡A¨ä¤º®e»P DRAW2.RC ¤j­P¤@¼Ë¡A¬G¥u¦C¥X¤£¦P¤§³B¡G

1
⁝ 
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
⁝ 
#define IDM_QUIT        3000
    ⁝

DRAW3   MENU
{                       /* ²Ä¤@¼h¥\¯àªí */
  POPUP "§Ö±¶¥\¯àªí"
  {                     /* ²Ä¤G¼h¥\¯àªí */
    MENUITEM "Â÷¶}",IDM_QUIT
    POPUP    "À˵ø"
             {
               MENUITEM   "®y¼Ð",IDM_XY,CHECKED
               MENUITEM   "µeµ§ÃC¦â",IDM_COLOR,CHECKED
             }
    POPUP    "ø¹Ï"
             {          /* ²Ä¤T¼h¥\¯àªí */
               MENUITEM    "¾ò¶ê",IDM_ELLIPSE
               MENUITEM    "¤âø¹Ï",IDM_TRACE     /* ¹w³]¤âø¹Ï */
               MENUITEM    SEPARATOR
               MENUITEM    "¶Â",IDM_BLACK         /* ¹w³]¶Âµ§ */
               MENUITEM    "¬õ",IDM_RED
               MENUITEM    "ºñ",IDM_GREEN
               MENUITEM    "ÂÅ",IDM_BLUE
             }
    MENUITEM "À°§U",IDM_HELP
  }
}

DRAW3   ICON   "DRAW2.ICO"   /* ¹Ï¥Ü */
    ⁝

¦A¨Ó¬Ý¬Ý­ì©lµ{¦¡ DRAW3.ASM ªº¤º®e¡A¥¦»P DRAW2.ASM ¤j¦P¤p²§¡A©Ò¥H©³¤Uªº¤º®e¡A¶È¦C¥X¨ä¤¤¤£¦Pªº¦a¤è¡C§¹¾ãªºÀɮ׽Шì³oùؤU¸ü¡]¦¹À£ÁYÀÉ¥]§t¥»³¹ªº¨â­Ó¨Ò¤l¡^¡C

1
2
⁝ 
28
29
30
⁝ 
56
57
58
59
60
⁝ 
170
⁝ 
188
189
190
191
192
193
⁝ 
211
212
213
214
215
216
217
218
219
⁝ 
231
232
⁝ 
250
251
252
⁝ 
264
265
;DRAW3¬O±NDRAW2ªº¥D¥\¯àªí§ï¦¨§Ö±¶¥\¯àªí
OPTION CASEMAP:NONE
          ⁝
szClassName     DB      "DRAW3",0
szAppName       DB      "¶W²³æø¹Ï",0
szText          DB      "DRAW3¶È¯àø»s¾ò¶ê»P¤âø¹Ï",0dh,0ah,"¡A¥B¤£¯à¦sÀɤ]¤£¯à½s¿è¡C",0
          ⁝
.CODE
;-----------------------------------------------------------------------------------------
WndProc PROC    hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
        LOCAL   ps:PAINTSTRUCT,rect:RECT,buffer[64]:BYTE,tm:TEXTMETRIC,point:POINT
.switch uMsg
          ⁝
  .case WM_CREATE
          ⁝
        mov     hCursor[24],rax
    ;¨ú±o§Ö±¶¥\¯àªíªº¥\¯àªí¥N½X¡A¨Ã¦s©óhMenu¤¤
        invoke  LoadMenu,hInstance,OFFSET szMenuName
        mov     hMenu,rax
        invoke  GetSubMenu,hMenu,0
        mov     hMenu,rax
          ⁝
  .case WM_RBUTTONUP
        mov     r8,r9
        shr     r9,10h          ;R9¡×Y®y¼Ð
        and     r8,0ffffh       ;R8¡×X®y¼Ð
        mov     point.y,r9d
        mov     point.x,r8d
        invoke  ClientToScreen,hWnd,ADDR point
        invoke  TrackPopupMenu,hMenu,TPM_RIGHTALIGN,point.x,point.y,0,hWnd,0

          ⁝
;-----------------------------------------------------------------------------------------
main    PROC
          ⁝
        invoke  RegisterClassEx,ADDR wc
        invoke  CreateWindowEx,0,ADDR szClassName,ADDR szAppName,WS_OVERLAPPEDWINDOW,\
                50,50,500,375,0,0,hInstance,0
          ⁝
;*****************************************************************************************
END     main

±N DRAW3.ASM¡BDRAW3.RC ©ñ¸m©ó¦P¤@¤l¥Ø¿ý¡A²ÕĶ¡B³sµ²ªº¤è¦¡»P DRAW2 ¤@¼Ò¤@¼Ë¡A¥u¦³ÀɦW¤£¦P¦Ó¤w¡A´N¤£¦C¥X¨Ó¤F¡C

¸Ñ»¡ DRAW3

­º¥ý¬Ý DRAW3.RC Àɤº¦³Ãö©ó MENU °Ï¶ô¡C§A·|µo²{¡A¦b³Ì¤W¼hªº¥\¯àªí¦h¥[¤F¤@­Ó¦W¬°¡u§Ö±¶¥\¯àªí¡vªº¼u¥X¿ï¶µ¡]¨£²Ä 18 ¦æ¡^¡A¨ä¾l¬Ò»P DRAW2.RC ¤¤ªº MENU °Ï¶ô¤@¼Ë¡C­ì¦]«Ü²³æ«e­±¤]´£¹L¡A´N¬OÁקKÅã¥Ü²Ä¤@¼hªº¥\¯àªí¡A¦Ó¥Ñ²Ä¤G¼h¶}©lÅã¥Ü¡C

¥t¥~¦b DRAW3.RC ¤¤ÁÙ¦³¤@ÂI»P DRAW2.RC ¤£¦P¡C¦b DRAW2.RC ¤¤ªºÀ°§U¿ï¶µ¡A¬°¤FÅýÀ°§Uªº¦r¼ËÅã¥Ü¦b¥D¥\¯àªí¥kÃä¡A¬G¨ä«á¦³¥[¤W¡uHELP¡v¡C¦ý¬O¦b DRAW3.RC ¤¤¡A³o¨Ç¿ï¶µ³£¬O¹]Áè¤è¦V±Æ¦C¡A¬G¤£¶·¥[¤W¡uHELP¡v¡A§Y¨Ï¥[¤W¤F¡A¤]²@µL¥Î³B¡C

±µ¤U¨Ó¬Ý¬Ý¦p¦ó±q¸ê·½¤¤¸ü¤J§Ö±¶¥\¯àªí¡C¨£ DRAW3.ASM ªº²Ä 189¡ã193 ¦æ¡A¦³¨â¨BÆJ¡A³£¦b³B²z WM_CREATE °T®§¤¤µo¥Í¡G①¥ý©I¥s LoadMenu ±o¨ì²Ä¤@¼h¥\¯àªíªº¥N½X¡C②µM«á¦A¥H¦¹¥N½X¥H¤Î¦ì¸m 0 ¬°°Ñ¼Æ¡A©I¥s GetSubMenu ±o¨ì²Ä 0 ­Ó¦ì¸mªº¤l¥\¯àªí¤§¥N½X¡A¤]¬O§Ö±¶¥\¯àªí¥N½X¡C

³Ì«á¨Ó¬Ý¬Ý¦p¦ó¦b­ì©lµ{¦¡¤¤Åã¥Ü§Ö±¶¥\¯àªí¡C¤@¯ë¦Ó¨¥¡A·í¨Ï¥ÎªÌ¦b¤u§@°Ï«ö¤U·Æ¹«¥kÁä¡A¤~·|Åã¥Ü§Ö±¶¥\¯àªí¡A¦]¦¹¦b DRAW3.ASM ´N¥²¶·³B²z WM_RBUTTONUP ©Î WM_RBUTTONDOWN ¨â«h°T®§ªº¨ä¤¤¤@«h¡A¤@¯ë¬O³B²z«eªÌ¡C¨£²Ä 211¡ã218 ¦æ¡C

DRAW3.ASM ¬O©I¥s TrackPopupMenu ¨ÓÅã¥Ü§Ö±¶¥\¯àªí¡A¦ý¬O TrackPopupMenu ¥Î¨Ó§â§Ö±¶¥\¯àªíÅã¥Ü¦b­þ¨àªº²Ä¤T¡B¥|­Ó°Ñ¼Æ¡A¨ä®y¼Ð¬O¬Û¹ï©ó¿Ã¹õ¥ª¤W¨¤¬°­ìÂI¡F¦Ó WM_RBUTTONUP ©Ò´£¨Ñ¦ì©ó lParam ªº®y¼Ð¡A¬O¬Û¹ï©ó¤u§@°Ï¥ª¤W¨¤¬°­ìÂI¡C¦]¦¹¦b©I¥s TrackPopupMenu ¤§«e¡A¥²¶·¥ý©I¥s ClientToScreen ±N¨äÂà´«¦¨¿Ã¹õ®y¼Ð¡C

¦A¬Ý TrackPopupMenu ªº²Ä¤@­Ó°Ñ¼Æ¡AhMenu¡C³o¬O­nÅã¥Üªº§Ö±¶¥\¯àªí¥N½X¡A«e­±´£¹L¡A¦¹¥\¯àªí¥N½X¨ä¹ê¬O¦b¸ê·½´y­zÀÉ MENU °Ï¶ô¡B²Ä¤@¼h¥\¯àªíªº²Ä¹s­Ó¦ì¸mªº¤l¥\¯àªí¥N½X¡C²Ä¤G­Ó°Ñ¼Æ¡ATPM_RIGHTALIGN¡A·|¨Ï±o·Æ¹«´å¼Ð¦b§Ö±¶¥\¯àªíªº¥kÃä¡C²Ä¤T¡B¥|­Ó°Ñ¼Æ¬O¥Ñ ClientToScreen Âà´««áªº¿Ã¹õ®y¼Ð¡C²Ä¤­­Ó°Ñ¼Æ¡AhWnd¡Aªí¥Ü¸Óµøµ¡¾Ö¦³¦¹§Ö±¶¥\¯àªí¡A¤]´N¬O§Ö±¶¥\¯àªí©Òµo¥Xªº°T®§¡A·|µo°e¨ì hWnd ªºµøµ¡¨ç¦¡¤¤¡A¥[¥H³B²z¡C


¨t²Î¥\¯àªí

¨t²Î¥\¯àªí¡]system menu¡^¤]ºÙ¬°µøµ¡¥\¯àªí¡]window menu¡^©Î±±¨î¥\¯àªí¡]control menu¡^¡A¨Ï¥ÎªÌ¥i¥H¥Î·Æ¹«¥ªÁäÂIÀ»¼ÐÃDÄæ³Ì¥ªÃ䪺¹Ï¥Ü¡A©Î¬O¥Î·Æ¹«¥kÁäÂIÀ»¼ÐÃDÄæ¥ô¤@³B¡A´N·|¥X²{¨t²Î¥\¯àªí¡C§Y¨ÏÀ³¥Îµ{¦¡¨S¦³«Ø¥ß¥ô¦ó¥\¯àªí¡AWindows §@·~¨t²Î¤]·|´£¨Ñ¹w³]ªº¨t²Î¥\¯àªí¡C¹w³]ªº¨t²Î¥\¯àªí¦p¤U¹Ï¬õ¦â®Ø®Ø¦íªº³¡¤À¡A¥]§t¤»­Ó¿ï¶µ¤Î¤@­Ó¤À¹j½u¡C

À³¥Îµ{¦¡¤]¥i¥H³z¹L GetSystemMenu ¨ú±o¨t²Î¥\¯àªí¥N½X¡AµM«á³z¹L©I¥s AppendMenu µ¥ Win64 API ¹ï¨ä²K¥[¿ï¶µ©Î¶i¦æ­×§ï¡A¦p¤W¹Ï¬õ¦â®Ø¥H¥~ªº¥\¯àªí°Ï°ì³£¬OÀ³¥Îµ{¦¡·s²Kªº¡A¨Æ¹ê¤W¡A¤W¹Ï¬O¥»³¹ªº²Ä¤G­Ó¨Ò¤l¡ADRAW4¡Aµy«á¦A±Ô­z¡A²{¦b¨¥Âk¥¿¶Ç¡A¥ý»¡©ú WM_SYSCOMMAND °T®§¡C

WM_SYSCOMMAND °T®§

·|µo¥X WM_SYSCOMMAND °T®§ªº±¡ªp¦³¥|ºØ¡G①·í¨Ï¥ÎªÌ¥H·Æ¹«¥ªÁäÂIÀ»¨t²Î¥\¯àªí¤¤ªº¿ï¶µ¡A¤£½×¬O§@·~¨t²Î¹w³]ªº¿ï¶µÁÙ¬OÀ³¥Îµ{¦¡·s²Kªº¿ï¶µ¡C②·í¨Ï¥ÎªÌ¥H·Æ¹«¥ªÁäÂIÀ»¼ÐÃDÄæ¥k°¼ªº³Ì¤p¤Æ¡B³Ì¤j¤Æ©ÎÃö³¬«ö¶s¡C③¨Ï¥ÎªÌ«ö¤U¨t²Î¥\¯àªí¤¤ªº§U¾ÐÁä©Î¬O¨t²Î¤w©w¸qªº«öÁä¡]¨Ò¦p Alt¡ÏF4¡A«ö¤U¥¦¥i±Nµøµ¡Ãö³¬¡^¡C④À³¥Îµ{¦¡¦b¨t²Î¥\¯àªí²K¥[¿ï¶µ¡A¥B³o¿ï¶µ¦³¬Û¹ïÀ³ªº¥[³tÁä¡A·í¨Ï¥ÎªÌ«ö¤U³o¥[³tÁä¡C

¤Uªí¬O¨t²Îµo¥X WM_SYSCOMMAND °T®§®É¡AwParam¡BlParam ªº·N¸q¡G

¨Æ¥ówParamlParam
16¡ã31 ¦ì¤¸0¡ã15 ¦ì¤¸
¥H·Æ¹«ÂI¿ï¨t²Î¥\¯àªí¤¤ªº¿ï¶µ¿ï¶µÃѧO½XY ®y¼ÐX ®y¼Ð
¥H·Æ¹«ÂI¿ï¼ÐÃDÄæ¥k°¼ªº³Ì¤p¤Æ¡B³Ì¤j¤Æ©ÎÃö³¬«ö¶s¿ï¶µÃѧO½XY ®y¼ÐX ®y¼Ð
«ö¤U§U¾ÐÁä©Î¨t²Î¤w©w¸qªº«öÁä¿ï¶µÃѧO½X00
«ö¤U¦b¨t²Î¥\¯àªí¬Û¹ïÀ³¿ï¶µªº¥[³tÁä¥[³tÁäÃѧO½X10

¤Wªí¤¤ªº wParam ¬O¨Ï¥ÎªÌ©Ò¿ï¾Ü¿ï¶µªº¿ï¶µÃѧO½X©Î¬O«ö¤U¥[³tÁ䪺¥[³tÁäÃѧO½X¡A¦³¨Ç¬O¨t²Î¹w¥ý©w¸q¹Lªº¡A¦³¨Ç«h¬OÀ³¥Îµ{¦¡©w¸qªº¡A¤£½×­þ¤@ºØ¬Ò¥iµø¬°¨Ï¥ÎªÌ¹ïµøµ¡µo¥Xªº¡u«ü¥O¡v¡A«ü¨Ï¨ä¡u¤u§@¡v¡C¤Uªí¬O¨t²Î¹w¥ý©w¸qªºÃѧO½X¡]¥ç¥iºÙ«ü¥O¡^¡G

¨t²Î©w¸qªº¿ï¶µÃѧO½X¼Æ­È»¡©ú
SC_CLOSE0F060H¨Ï¥ÎªÌ¿ï¾Ü¨t²Î¿ï³æªºÃö³¬¿ï¶µ©ÎÂIÀ»¼ÐÃDÄæ¥kÃ䪺Ãö³¬«ö¶s
SC_MAXIMIZE0F030H¨Ï¥ÎªÌ¿ï¾Ü¨t²Î¿ï³æªº³Ì¤j¤Æ¿ï¶µ©ÎÂIÀ»¼ÐÃDÄæ¥kÃ䪺³Ì¤j¤Æ«ö¶s
SC_MINIMIZE0F020H¨Ï¥ÎªÌ¿ï¾Ü¨t²Î¿ï³æªº³Ì¤p¤Æ¿ï¶µ©ÎÂIÀ»¼ÐÃDÄæ¥kÃ䪺³Ì¤p¤Æ«ö¶s

¤W­±¶È¦C¥X¤@¤p³¡¤À¡A¨ä¥Lªº½Ð°Ñ¦Ò MSDN¡A³o¨Ç¿ï¶µÃѧO½Xªº¼Æ­È³£¤j©ó©Îµ¥©ó 0F000H¡C¤@¯ë¦Ó¨¥¡Aµøµ¡¨ç¦¡¤£³B²z¹³¬OÄÝ©ó SC_CLOSE¡BSC_MAXIMIZE¡K¡K³oºØ¨t²Î¹w¥ý©w¸q«ü¥Oªº WM_SYSCOMMAND °T®§¡A¦Ó¬O¥æµ¹ DefWindowProc ³B²z¡C

À³¥Îµ{¦¡¦Û¦æ²K¥[¨ì¨t²Î¥\¯àªíªº¿ï¶µ¡A¨ä¿ï¶µÃѧO½X¥²¶·¤p©ó 0F000H¡A·í¨Ï¥ÎªÌÂI³o¿ï²K¥[ªº¿ï¶µ®É¡A·|µo¥X¿ï¶µÃѧO½X¥²¶·¤p©ó 0F000H ªº WM_SYSCOMMAND °T®§¡AÀ³¥Îµ{¦¡¥²¶·¦b³B²z WM_SYSCOMMAND °T®§®É¡A¥H¦^À³¨Ï¥ÎªÌÂI¿ïªº²K¥[¿ï¶µ¡C

¤]´N¬O»¡¡A­Y¬O¦b¨t²Î¥\¯àªí¤¤²K¥[¤F¿ï¶µ¡A¨º»ò¥²¶·¦b³B²z WM_SYSCOMMAND °T®§ªºµ{¦¡½X¤¤¡A§PÂ_­þ¨Ç¬O¨t²Î¥\¯àªí¤¤­ì¦³ªº¿ï¶µ¡A¥¦­Ì¥Ñ DefWindowProc API ³B²z¡F­þ¨Ç¬O·s²K¥[ªº¿ï¶µ¡A¥¦­Ì¥²¶·¥Ñ WM_SYSCOMMAND °T®§·s¼Wªºµ{¦¡½X¨Ó³B²z¡C


¨t²Î¥\¯àªí¨Ò¤l¡GDRAW4

©³¤Uªº¨Ò¤l¡ADRAW4¡A¬O§â DRAW2 ªº¥D¥\¯àªí²¾¨ì¨t²Î¥\¯àªíùØ¡A¦ý¬O¨ä¤¤ªº¡uÂ÷¶}¡v¿ï¶µ©M¨t²Î¥\¯àªí­ì¨Óªº¡uÃö³¬¡v¨ã¦³¤@¼Ëªº¥\¯à¦]¦¹§R°£¡A¥u¦³§â¡uÀ˵ø¼u¥X¿ï¶µ¡v¡B¡uø¹Ï¼u¥X¿ï¶µ¡v©M¡uÀ°§U¿ï¶µ¡v²¾¨ì¨t²Î¥\¯àªí¡C

DRAW4.ASM ¤Î¨ä¸Ñ»¡

¹ï¨t²Î¥\¯àªí¦Ó¨¥¡ADRAW4 ­n°µªº´N¬O²K¥[³o¤T­Ó¿ï¶µ¡A¨ä¥\¯à´X¥G¤@¼Ë¡A©Ò¥H DRAW4.ASM ªº¤º®e»P DRAW2.ASM ¤j¦P¤p²§¡A©³¤Uªº DRAW4.ASM ¶È¦C¥X¤£¦Pªº³¡¤À¡C

1
2
⁝ 
10
⁝ 
26
27
28
29
30
31
32
⁝ 
42
43
⁝ 
139
140
141
142
143
144
145
⁝ 
173
⁝ 
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
⁝ 
250
251
252
⁝ 
264
265
;DRAW4¬O±NDRAW2ªº¥D¥\¯àªí¤j³¡¤À¿ï¶µ²¾¦Ü¨t²Î¥\¯àªí
OPTION CASEMAP:NONE
          ⁝
IDM_XY          EQU     3001
          ⁝
szIconName      LABEL   BYTE
szClassName     DB      "DRAW4",0
szAppName       DB      "¶W²³æø¹Ï",0
szText          DB      "DRAW4¶È¯àø»s¾ò¶ê»P¤âø¹Ï",0dh,0ah,"¡A¥B¤£¯à¦sÀɤ]¤£¯à½s¿è¡C",0
szViewMenu      DB      "À˵ø",0
szDrawMenu      DB      "ø¹Ï",0
szHelpMenu      DB      "À°§U",0
          ⁝
hDrawSubMenu    HMENU   ?       ;ø¹Ï¤l¥\¯àªí¥N½X
hSysMenu        HMENU   ?       ;¨t²Î¥\¯àªí¥N½X
          ⁝

  .case WM_SYSCOMMAND
        mov     line_pen,0
        mov     ellips_pen,0
    .if r8w>=0f000h
        jmp     deflt
    .elseif r8w==IDM_HELP
          ⁝
  .case WM_CREATE
          ⁝
        mov     hCursor[24],rax
    ;¥Ñ¸ê·½¤¤¸ü¤J¥\¯àªí
        invoke  LoadMenu,hInstance,OFFSET szMenuName
        mov     hMenu,rax
    ;Àò±oÀ˵ø¤l¥\¯àªí¥N½X¤Îø¹Ï¤l¥\¯àªí¥N½X¡A¤À§O¦s©óhViewSubMenu¡BhDrawSubMenu
        invoke  GetSubMenu,hMenu,0
        mov     hViewSubMenu,rax
        invoke  GetSubMenu,hMenu,1
        mov     hDrawSubMenu,rax
    ;±Nø¹Ï¤l¥\¯àªí¤¤ªº¤âø¹Ï¿ï¶µ©M¶Â¦â¿ï¶µ«eÅã¥Ü¶êÂIªº¤Ä¿ï°O¸¹
        invoke  CheckMenuRadioItem,hDrawSubMenu,0,1,1,MF_BYPOSITION
        invoke  CheckMenuRadioItem,hDrawSubMenu,IDM_BLACK,IDM_BLUE,IDM_BLACK,MF_BYCOMMAND
    ;Àò±o¨t²Î¥\¯àªí¥N½X¡A¨Ã¦s©óhSysMenu
        invoke  GetSystemMenu,hWnd,0
        mov     hSysMenu,rax
    ;¦b¨t²Î¥\¯àªí¤¤¨Ì§Ç¥[¤J¤À¹j½u¡BÀ˵ø¤l¥\¯àªí¡Bø¹Ï¤l¥\¯àªí¡BÀ°§U¿ï¶µ
        invoke  AppendMenu,hSysMenu,MF_SEPARATOR,0,0
        invoke  AppendMenu,hSysMenu,MF_POPUP,hViewSubMenu,OFFSET szViewMenu
        invoke  AppendMenu,hSysMenu,MF_POPUP,hDrawSubMenu,OFFSET szDrawMenu
        invoke  AppendMenu,hSysMenu,MF_STRING,IDM_HELP,OFFSET szHelpMenu
          ⁝
        invoke  RegisterClassEx,ADDR wc
        invoke  CreateWindowEx,0,ADDR szClassName,ADDR szAppName,WS_OVERLAPPEDWINDOW,\
                50,50,500,375,0,0,hInstance,0
          ⁝
;*****************************************************************************************
END     main

­º¥ý¬Ý DRAW4.ASM ¬O¦p¦ó±N¿ï¶µ©Î¤l¥\¯àªí¥[¶i¨ì¨t²Î¿ï³æ¤¤¡A¤@¯ë¬O¦b WM_CREATE °T®§¤¤³B²z¡A¥²¶·°µ¤T¥ó¨Æ¡G①Àò±o­n·s¥[¤J¨t²Î¥\¯àªíªº¤l¥\¯àªí¥N½X¡B②Àò±o¨t²Î¥\¯àªí¥N½X¡B③©I¥s AppendMenu ±N¿ï¶µ©Î¤l¥\¯àªí¥[¶i¨t²Î¥\¯àªí¤º¡C¸Ô²Óªº¨BÆJ»¡©ú¦p¤U¡G

①¡B¨£²Ä 192¡ã199 ¦æ¡A©I¥s LoadMenu ¦Û¸ê·½¤¤¸ü¤J¥\¯àªí¡A¦A¨Ì¾Ú¦¹¥\¯àªí¥N½X¤Î¦ì¸m 0¡B1 ¤À§O©I¥s GetSubMenu ¨â¦¸¡A¥HÀò±o¡uÀ˵ø¤l¥\¯àªí¡v¡B¡uø¹Ï¤l¥\¯àªí¡v¥N½X¡A¤À§O¦s©ó hViewSubMenu¡BhDrawSubMenu ÅܼÆùØ¡C¶¶«K±Nø¹Ï¤l¥\¯àªí¤¤ªº¨â­Ó¿ï¶µ¡A¤âø¹Ï¤Î¶Â¡A«e­±¼Ð¥Ü¡u●¡vªº°O¸¹¡C

②¡B¨£²Ä 203¡ã205 ¦æ¡A©I¥s GetSystemMenu Àò±o¨t²Î¥\¯àªíªº¥N½X¡A¦s©ó hSysMenu ÅܼƤº¡C

③¡B¨£²Ä 206¡ã210 ¦æ¡A©I¥s¥|¦¸ AppendMenu ¦b¨t²Î¥\¯àªí¤¤²K¥[¤À¹j½u¡B¤l¥\¯àªí¤Î¿ï¶µ¡C·í²K¥[¤À¹j½u®É¡A

¦]¬°¦b WM_CREATE °T®§¤¤­×§ï¤F¨t²Î¥\¯àªí¡A©Ò¥H¦b main °Æµ{¦¡¤¤¡A©I¥s CreateWindowEx ®É¡A²Ä¤Q­Ó°Ñ¼Æ¤£»Ý­n³]¬°¥\¯àªí¥N½X¡A¬G³]¬°¹s¡]²Ä 251¡ã252 ¦æ¡^¡C

·í¨Ï¥ÎªÌÂI¿ï¨t²Î¥\¯àªí¤¤ªº¥ô¤@¿ï¶µ¡A¤£½×¬O­ì¨ÓªºÁÙ¬O·s¥[¶iªº¡A³£·|µo¥X WM_SYSCOMMAND °T®§¡C¬°¤F¨Ï­ì¨Óªº¿ï¶µ¤´¯à°÷¥¿±`¹B§@¡A¥²¶·¥æ¥Ñ DefWindowProc ³B²z¡A©Ò¥H¦b²Ä 143 ¦æ¡A§PÂ_ WM_SYSCOMMAND ªº wParam ¬O§_¤j©ó©Îµ¥©ó 0F000H¡A¦pªG¬O¡A¨º»ò´N¸õÅD¦Ü deflt ¼Ð°O³B¡A¥Ñ DefWindowProc ³B²z¡C¦pªG¤£¬O¡A¨º´N¨Ì§ÇÀˬd¿ï¶µÃѧO½X¡A¨Ì¾Ú¨Ï¥ÎªÌÂI¿ï¤£¦P¿ï¶µ¡A¤À§O¥[¥H³B²z¡A³o¬qµ{¦¡»P DRAW2 ¤@¼Ë¡A©Ò¥H¨S¦C¦b¤W­±¡C

DRAW4.RC ¤Î¨ä¸Ñ»¡

©³¤U¬O¸ê·½´y­zÀÉ DRAW4.RC ªº¤º®e¡A¦P¼Ë¤]¥u¦C¥X»P DRAW2.RC ¤£¦P¤§³B¡A¨Æ¹ê¤W¥u¦³¤T³B¡G①¦]¬°¨S¦³Â÷¶}¿ï¶µ¡A¤]´N¤£»Ý­n¡u#define IDM_QUIT 3000¡v¡C②¦]¬°¨S¦³Â÷¶}¿ï¶µ¡A©Ò¥H¦b MENU °Ï¶ô§R°£¡uMENUITEM "Â÷¶}",IDM_QUIT¡v¡C③¹Ï¥Ü¦WºÙ§ï¦¨ DRAW4¡A¨£ DRAW4.RC ²Ä 35 ¦æ¡C

1
⁝ 
15
16
17
⁝ 
33
34
35
⁝ 
#define IDM_XY          3001
   ⁝
DRAW4      MENU
{
  POPUP    "À˵ø"
   ⁝
}

DRAW4      ICON   "DRAW2.ICO"   /* ¹Ï¥Ü */
   ⁝

²ÕĶ»P³sµ²

²ÕĶ»P³sµ²ªº¨BÆJ¡A³£©M DRAW2 ¬Û¦P¡A¥u¬OÀɦW¤£¦P¡A°Ñ¦Ò²Ä¤Q¤»³¹¡C¥t¥~¡A³o¤@³¹ªº¨â­Ó¨Ò¤l¨Ã¨S¦³¦C¥X§¹¾ãªºµ{¦¡½X¡A¦p­n¹ï·Ó DRAW2 ÁÙ­ì¥i¯à¤£©ö¡A©ó Mega ©ñ¸m DRAW3¡BDRAW4 ªº§¹¾ã­ì©l½X¡A«ö¦¹³B¤U¸ü¡C


µù¸Ñ

µù¤@¡G¦³Ãö Windows API¡BTrackPopupMenu¡BTPM_NONOTIFY ªº½Õ¬dµ²ªG

µù¤@¬O¨ú¦Ûºô¸ô¤Wªº¤å³¹¡A­ì¤å½Ð¬Ýミルノのブログ¡A¼ÐÃD½Ķ¦¨¤¤¤å¡A´N¬O¡u¦³Ãö Windows API¡BTrackPopupMenu¡BTPM_NONOTIFY ªº½Õ¬dµ²ªG¡v¡C¨ä¤º®e¤j·N¦p¤U¡G

¦b«Ü¦h¤åÄm¤¤´£¨ì¡u¦b©I¥s TrackPopupMenu ®É¡A­Y¥H TPM_NONOTIFY ¬°°Ñ¼Æ¡ATrackPopupMenu ¤£·|µo°e³qª¾°T®§¡v³o±qÀY¨ì§À³£¿ù¤F¡C¨Ã¤£¬O½Ķ¤Wªº¿ù»~¡A¦]¬°¤@¶}©l´N¿ù¤F¡C§@ªÌ¼g¤F­Óµ{¦¡¨Ó¬ã¨s TPM_NONOTIFY ªº¦æ¬°¡Aµo²{·í«ü©w TPM_NONOTIFY ®É¡A±N¤£¦Aµo¥X¥H¤U°T®§¡G

¦ý¤]¦³¥i¯à§@ªÌ©Ò¼¶¼gªºµ{¦¡¨S°»´ú¨ì¡A¤]ÁÙ¦³¨ä¥L°T®§³Q§í¨î¦Ó¥¼µo¥X¡C

¶¶«K»¡¤@¥y¡A¥u»Ý«ü©w TPM_RETURNCMD¡A¶Ç°e¨ì¤÷µøµ¡ªº WM_COMMAND °T®§³Q§í¨î¡C¬Û¤Ï¡A§Y¨Ï«ü©w¤F TPM_NONOTIFY¡AWM_COMMAND ¤]·|µo¥Í¡C¦]¦¹¡A·í¨Ï¥ÎTPM_RETURNCMD®É¡AµL»Ý«ü©w TPM_NONOTIFY¡C