Ch 16 ¦A½Í¿ï³æ

¦b²Ä¤»³¹ùØ¡A¤p¤ì°¸¤w¸g½Í¹L¿ï³æªº°ò¥»¥Îªk¡A³o¤@³¹ùرN¤¶²Ð¦p¦ó§ó°Ê¿ï³æ¡B¦p¦ó¦b¿ï³æ¤¤Åã¥Ü BMP ÀÉ¡B¦p¦ó§ïÅÜ¿ï³æ¤¤ªº¦r«¬¡A³Ì«á¹ê§@¤@­Ó MENU2 µ{¦¡¡AÂǥѦ¹µ{¦¡®i¥Ü¿ï³æ©Ê½è¡C


¿ï³æ

¿ï³æªººØÃþ

¿ï³æ¥i¤À¬°¨t²Î¿ï³æ¡B¼u¥X¦¡¿ï³æ»P¥D¿ï³æ¤TºØ¡C¨t²Î¿ï³æ¬O«ü¨Ï¥ÎªÌ¦b¼ÐÃDÄæ³Ì¥ªÃ䪺¹Ï¥Ü«ö¤U·Æ¹«¥ªÁä®É¡A©Ò¥X²{ªº¿ï³æ¡A¦p¤U¹Ï¥ª¤W¨¤¬õ¦â®Ø®Ø©Ò¼Ð¥Ü¡G

¼u¥X¦¡¿ï³æ¬O«ü¨Ï¥ÎªÌ¦bµøµ¡ªº¤u§@°Ï¤¤¡A«ö¤U·Æ¹«¥kÁä¡A©Ò¼u¥Xªº¿ï³æ¡C¦Ó¥D¿ï³æ¬O¦b¼ÐÃDÄæ¤U­±ªº¿ï³æ¡A¦p¤W¹Ï¥k¤W¨¤¥Hµµ¦â®Ø®Ø©Ò®Ø°_¨Óªº³¡¥÷´N¬O¥D¿ï³æ¡C

¥D¿ï³æ¡B¤l¿ï³æ»P¿ï¶µ

¤U¹Ï¬O¤@­Ó±`¨£ªºµøµ¡¡A¦b¼ÐÃDÄæ¤U­±ªº¿ï³æ¡A¤@¯ëºÙ¬°¡y¥D¿ï³æ¡z¡A©Ò¦³¿ï³æ©Î¿ï¶µ³£¥Ñ¥¦¶}©l¡A¦b¤U­±ªº¨Ò¤l¤¤¡A¥D¿ï³æ¥]§tÀɮסB½s¿è¡BÀ˵ø¡B¼v¹³¡B¦â±m¡B»¡©ú¤»­Ó¼u¥X¿ï¶µ ( pop menu )¡C¡y¼u¥X¿ï¶µ¡z¬O«ü³Q¨Ï¥ÎªÌÂI¿ï¤§«á¡A·|¥X²{¥t¤@­Ó¿ï³æ¡A©Ò¥X²{ªº¿ï³æ¬O¥Ñ¬Y­Ó¿ï³æªº¼u¥X¿ï¶µ©Ò¤Þµo¡A¦]¦¹¤@¯ëºÙ¬°¡y¤l¿ï³æ¡z( submenu )¡A¨Ò¦p¡AÂI¿ï¡yÀ˵ø¡z¤§«á¡A·|¥X²{¤@­Ó¡y¤l¿ï³æ¡z¡A©Ò¥HÀ˵ø³QºÙ¬°¼u¥X¿ï¶µ¡A¦Ó¥X²{ªº³o­Ó¿ï³æºÙ¬°¡y¤l¿ï³æ¡z¡A¥]§t¤u¨ã½c¡B¦â¶ô¡Bª¬ºA¦C¡B¤å¦r¤u¨ã¦C¡B¤À¹j½u¡BÁY©ñ¡BÀ˵øÂI°}¹Ïµ¥¶µ¥Ø¡A¨ä¤¤ÁY©ñ¤]¬O¤@­Ó¼u¥X¿ï¶µ¡A¥¦·|¤Þ¥X§t¦³¼Ð·Ç¤j¤p¡B©ñ¤j¡B¦Û­q¡B¤À¹j½u¡BÅã¥Ü®æ½u¡BÅã¥ÜÁY¹Ïªº¤l¿ï³æ ( ¥i¥H§â¥¦·Q¦¨¡y®]¡z¿ï³æ¡A¦ý¬O¦b¤åÄm¤WÁÙ¬OºÙ¥¦¬°¤l¿ï³æ )¡C¦A¦^¨ìÀ˵ø©Ò¼u¥Xªº¤l¿ï³æ¡A¥]§t¤F¤u¨ã½c¡B¦â¶ô¡Bª¬ºA¦C¡B¤å¦r¤u¨ã¦C¡BÀ˵øÂI°}¹Ï¡A¥¦­Ì³£¬O¿ï¶µ ( menuitem )¡A¨Ï¥ÎªÌÂI¿ï¿ï¶µ®É¡A·|¤Þµo¬Y¨Ç¥\¯à¡A¥i¯à¬O¬Y­Ó¹ï¸Ü²°©Î¨ä¥L¥\¯à¡A¤]¥i¯à¬O¬Y­Ó¤l¿ï³æ¡C

¦b¥D¿ï³æ©Î¤l¿ï³æ¤Wªº¨C­Ó¶µ¥Ø³£¦³¤TºØ©Ê½è¡G

  1. ¦WºÙ¡G¦WºÙ¬OÅã¥Ü¦b¿ï³æ¤Wªº¤å¦r¦r¦ê¡C¦³®É¤]¥i¥H¥Î¦ì¤¸¹ÏÅã¥Ü¡C
  2. ÃѧO½X ( ID ) ©Î¿ï³æ¥N½X ( menu handle )¡G·í¨Ï¥ÎªÌ¿ï¾Ü¬Y­Ó¿ï¶µ®É¡A¨t²Î·|§â¸Ó¿ï¶µªºÃѧO½X·|¥]§t¦b WM_COMMAND °T®§ùضǦ^µ¹µøµ¡¨ç¦¡¡F¦ý¬O¨Ï¥ÎªÌ«ö¤U¼u¥X¿ï¶µ®É¡Aªí¥ÜÁÙ¥¼¿ï©w¡A¦]¦¹¼u¥X¿ï¶µ¬O¨S¦³ÃѧO½X¡C·í¨Ï¥ÎªÌ«ö¤U¼u¥X¿ï¶µ¡A¤Þµo¤@­Ó¤l¿ï³æ®É¡A³o­Ó¤l¿ï³æ¦³¤@¿ï³æ¥N½X¡A¦ý¬O¨S¦³ÃѧO½X¡C¦]¬°¦³¥D¿ï³æ©Î¤l¿ï³æ¦³¿ï³æ¥N½X¡A§Ú­Ì¥i¥H¹ï¿ï³æ°µ¤@¨Ç¯S§OªºÃ¸»s¡A¨Ò¦p§ó§ï¿ï¶µ¡B·s¼W¿ï¶µ¡B¥ÎÂI°}¹Ï¥N´À¦r¦êµ¥µ¥¡C¤À¹j½u¶È¥Î©óªí¥Üµøı¤W¤ÀÃþ®ÄªG¤§¥Î¡A©Ò¥H¨S¦³ÃѧO½X¤]¨S¦³¥N½X¡C
  3. ÄÝ©Ê¡G¿ï¶µ¥i¥H¦³¤U­±¤T²ÕÄÝ©Ê¡G(1)±Ò¥Î¡B¸T¥Î¡BµL®Äªº¡A(2)³Q¤Ä¿ïªº¡B¤£³Q¤Ä¿ïªº¡A(3)³Q¿ï¾Üªº¡B¤£³Q¿ï¾Üªº¡C
    ¸T¥Î»PµL®Äªº¿ï¶µ³£¥H¦Ç¦â¦r¦êªí¥Ü¡C¨Ï¥ÎªÌ¤´¥i¥H¥Î·Æ¹«©Î ´å¼ÐÁä²¾¨ì¸T¥Îªº¿ï¶µ¡A¦Ó¸Ó¿ï¶µ·|¥H¤Ï¥ÕÅã¥Ü¡A¦p¤U¹ÏÅã¥ÜÁY¹Ï¿ï¶µ¡F¦ý¬O¨Ï¥ÎªÌµLªk¥Î·Æ¹«©Î´å¼Ð²¾¨ìµL®Äªº¿ï¶µ¨Ï¤§¤Ï¥Õ¡C¤£ºÞ¬OµL®Ä©Î¸T¥Îªº¿ï¶µ¡A³£¤£¯àµo¥X WM_COMMAND °T®§¡A¥u¦³±Ò¥Îªº¿ï¶µ¥i¥Hµo¥X WM_COMMAND¡C
    ³Q¤Ä¿ïªº¿ï¶µ«e·|¦³¤@­Ó°O¸¹¡A¹³¤U¹Ïªº¤u¨ã½c¡B¦â¶ôµ¥¿ï¶µ¡A³o¨Ç³Q¤Ä¿ïªº¥i¥H¤@­Ó©Î¦h­Ó¡C
    ¥t¥~¿ï¶µ¤]¦³³Q¿ï¾Ü©Î¤£³Q¿ï¾ÜªºÄÝ©Ê¡A·í·Æ¹«´å¼Ð²¾¨ì¬Y­Ó¿ï¶µ®É¡A¸Ó¿ï¶µ­I´º·|¥H°ª«G«×¥ú´ÎÅã¥Ü¡A¤å¦r«h¥H¤Ï¥ÕÅã¥Ü¡A«h¦¹¿ï¶µºÙ¬°³Q¿ï¾Üªº¿ï¶µ¡F¤Ï¤§«h¬O¤£³Q¿ï¾Üªº¿ï¶µ¡C

«Ø¥ß¡B­×§ï¿ï³æ

«Ø¥ß¿ï³æªº¤èªk¡A³Ì±`¥Îªº¬O¦b¸ê·½´y­zÀɤ¤«Ø¥ß MENU °Ï¶ô¡AµM«á¥Î LoadMenu ¸ü¤J¨ì°O¾ÐÅ餤¡A¸Ô²Ó±¡§Î½Ð°Ñ¾\²Ä¤»³¹¡C°£¤F³o­Ó¤èªk¥~¡A¤]¥i¥H¦bµ{¦¡¤¤¨Ï¥Î CreateMenu ¥ý«Ø¥ß¤@­ÓªÅªº¿ï³æ¡AµM«á¥Î InsertMenuItem ©Î AppendMenu ¥[¤J¿ï¶µ¡B¥Î SetMenuItemInfo §ïÅܿﶵ©Ê½è¡A¥Î DeleteMenu §R°£¿ï¶µ¡C

CreateMenu »P AppendMenu

­n«Ø¥ß¤@­Ó¿ï³æ¡A»Ý¥Î CreateMenu¡ACreateMenu ¨S¦³¥ô¦ó°Ñ¼Æ¡A¦pªG¥¢±Ñ¡AEAX ¶Ç¦^ NULL¡F¦pªG¦¨¥\¡AEAX ·|¶Ç¦^·s«Ø¥ßªº¿ï³æ¥N½X¡A¦Ó³o­Ó¿ï³æ¤º®e¬OªÅªº¡A·N«ä¬OùØ­±¨S¦³¥ô¦ó¿ï¶µ¡A¥²¶·¦A¥Ñ AppendMenu¡BInsertMenuItem ¥[¤J¿ï¶µ¡C

AppendMenu ªº¥\¥Î¬O¦b¥D¿ï³æ¡B¤l¿ï³æ©Î¼u¥X¦¡¿ï³æ¤¤¦A¥[¤W¤@­Ó¿ï¶µ¡A¨ä­ì«¬¬O¡G

BOOL AppendMenu(
  HMENU   hMenu,        // handle to menu to be changed
  UINT    uFlags,       // menu-item flags
  UINT    uIDNewItem,   // menu-item identifier or handle to drop-down menu or submenu
  LPCTSTR lpNewItem     // menu-item content
);

hMenu ¬O«ü¿ï¶µ­n¥[¦b¨º¤@­Ó¿ï³æ¤¤¡AuFlags «ü¥[¤J¿ï¶µªº¯S©Ê¡A¥i¥H¬O¤U­±«e¥|²Õ¼Æ­È¤§¤@©Î¨ä¤¬¬Û²Õ¦X¡A¦ý¦P¤@²Õ¤§¶¡ªº¼Æ­È¤£¯à¦P®É¨Ï¥Î¡A¨Ò¦p¿ï¶µ¬O¥¿±`±Ò¥Îªº ( MF_ENABLE ) ´N¤£¯à¦P®É¤S¸T¥Îªº ( MF_DISABLED )¡C©³¤U¬O uFlags °Ñ¼Æªº»¡©ú¡G

SetMenu API

­n³]©w¬Y¤@µøµ¡ªº¥D¿ï³æ¡A«h¨Ï¥Î SetMenu¡A¨ä­ì«¬¬°¡G

BOOL SetMenu(
  HWND  hWnd,  // handle to window
  HMENU hMenu  // handle to menu
);

©³¤Uªºµ{¦¡¡AMENU1.ASM¡A»¡©ú¦p¦ó¦bµ{¦¡¤¤¦Ó¤£¬O¦b¸ê·½´y­zÀɤ¤«Ø¥ß¿ï³æ¡A¥H¤Î MF_SEPARATOR¡BMF_MENUBARBREAK¡BMF_MENUBARBREAK ÄÝ©Ê©Ò²£¥Íªº®ÄªG¡C

        .586
        .model  flat,stdcall
        option  casemap:none

include         windows.inc
include         kernel32.inc
include         user32.inc
includelib      kernel32.lib
includelib      user32.lib
;***********************************************************
                .data
hInstance       HINSTANCE       ?
hwnd            HWND            ?
hMenu           HMENU           ?
hSubMenuFile    HMENU           ?
hSubMenuHelp    HMENU           ?
msg             MSG             <?>
wc              WNDCLASSEX      <30h,?,?,0,0,?,?,?,?,0,offset szClassName,?>
szClassName     BYTE            'MENU_TEST',0
szAppName       BYTE            '´ú¸Õ¿ï³æ',0
szFile          BYTE            'ÀÉ®×',0
szNew           BYTE            '¶}·sÀÉ®×',0
szOpen          BYTE            '¶}±ÒÂÂÀÉ',0
szSave          BYTE            'Àx¦sÀÉ®×',0
szSaveAs        BYTE            '¥t¦s·sÀÉ',0
szClose         BYTE            'Ãö³¬ÀÉ®×',0
szPrint         BYTE            '¦C¦L',0
szExit          BYTE            '°h¥X',0
szHelp          BYTE            '»¡©ú',0
szAbout         BYTE            'Ãö©ó',0
szVersion       BYTE            'ª©¥»',0
szQuery         BYTE            'HELP',0
;***********************************************************
        .code
;-----------------------------------------------------------
WndProc proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_COMMAND
        mov     ecx,wParam
    .if cx==106h
        jmp     exit
    .endif

.elseif uMsg==WM_CREATE
        ;«Ø¥ß¤@­ÓªÅªº¿ï³æ¡A³]¦¹¿ï³æ¬°¥D¿ï³æ¡A¨Ã«O¦s¨ä¿ï³æ¥N½X
        invoke  CreateMenu              
        mov     hMenu,eax

        ;¦A«Ø¥ß¨â­ÓªÅªº¿ï³æ¡A¤À§O¬OÀɮפl¿ï³æ»P»¡©ú¤l¿ï³æ¡A¨Ã«O¦s¨ä¿ï³æ¥N½X
        invoke  CreateMenu
        mov     hSubMenuFile,eax
        invoke  CreateMenu
        mov     hSubMenuHelp,eax

        ;¦bÀɮפl¿ï³æ¤¤¥[¤J¦U¿ï¶µ
        invoke  AppendMenu,hSubMenuFile,MF_STRING,100h,offset szNew
        invoke  AppendMenu,hSubMenuFile,MF_STRING,101h,offset szOpen
        invoke  AppendMenu,hSubMenuFile,MF_STRING,102h,offset szSave
        invoke  AppendMenu,hSubMenuFile,MF_STRING,103h,offset szSaveAs
        invoke  AppendMenu,hSubMenuFile,MF_STRING,104h,offset szClose   ;47 Ãö³¬Àɮ׿ﶵ
        invoke  AppendMenu,hSubMenuFile,MF_STRING,105h,offset szPrint
        invoke  AppendMenu,hSubMenuFile,MF_SEPARATOR,NULL,NULL          ;48 ¤À¹j½u    
        invoke  AppendMenu,hSubMenuFile,MF_STRING,106h,offset szExit

        ;¦b»¡©ú¤l¿ï³æ¤¤¥[¤J¦U¿ï¶µ
        invoke  LoadBitmap,hInstance,offset szQuery
        invoke  AppendMenu,hSubMenuHelp,MF_BITMAP,200h,eax
        invoke  AppendMenu,hSubMenuHelp,MF_STRING,201h,offset szVersion

        ;§â¤l¿ï³æ¥[¤J¨ì¥D¿ï³æ¤¤¡AuFlags ¥Î MF_POPUP¡A¦Ó²Ä¤@­Ó°Ñ¼Æ¥Î¥D¿ï³æ¥N½X
        invoke  AppendMenu,hMenu,MF_POPUP,hSubMenuFile,offset szFile
        invoke  AppendMenu,hMenu,MF_POPUP,hSubMenuHelp,offset szHelp

        ;³]©w¦¹µøµ¡ªº¥D¿ï³æ¬° hMenu
        invoke  SetMenu,hWnd,hMenu

.elseif uMsg==WM_DESTROY
exit:   invoke  PostQuitMessage,NULL

.else
        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
.endif
        xor     eax,eax
        ret
WndProc endp
;-----------------------------------------------------------
start:  invoke  GetModuleHandle,NULL
        mov     hInstance,eax
        invoke  GetCommandLine
        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
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        invoke  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        invoke  RegisterClassEx,offset wc
        invoke  CreateWindowEx,NULL,offset szClassName,offset szAppName,\ 
                WS_OVERLAPPEDWINDOW,0,10,200,200,0,NULL,hInstance,NULL 
        mov     hwnd,eax
        invoke  ShowWindow,eax,SW_SHOWDEFAULT
        invoke  UpdateWindow,hwnd
.while  TRUE
        invoke  GetMessage,offset msg,NULL,0,0
.break  .if     !eax
        invoke  TranslateMessage,offset msg
        invoke  DispatchMessage,offset msg
.endw
        mov     eax,msg.wParam
        invoke  ExitProcess,eax
;***********************************************************
        end     start

©³¤U¬O MENU1.RC ¸ê·½´y­zÀɪº¤º®e¡G

HELP    BITMAP  "HELP.BMP"

¥k¹Ï¬O HELP.BMP ÀÉ¡G( neocities.org ¸T¤î§K¶O¨Ï¥ÎªÌ¤W¶Ç *.BMP ®æ¦¡ªº¹ÏÀÉ¡A¬G¤p¤ì°¸±N¨ä§ï¦W¦¨ HELP.PNG¡AŪªÌ¤U¸ü«á¦Û¦æ§ï¦^¨Ó )

¦b¡y©R¥O´£¥Ü¦r¤¸¡z¤¤²ÕĶ¦¹µ{¦¡¡A¿é¤J¤U­±¨â¹D«ü¥O¡G

E:\HomePage\SOURCE>rc menu1.rc [Enter]

E:\HomePage\SOURCE>ml menu1.asm /link menu1.res [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: menu1.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS
"menu1.obj"
"/OUT:menu1.exe"
"menu1.res"

E:\HomePage\SOURCE>

¤W­±µ{¦¡°õ¦æ«á±o¤U¹Ï³Ì¥ªÃ䪺¿ï³æ¡A¦b¤l¿ï³æ¤¤¡A¦³¤@¤À¹j½u¡C­Y§â²Ä 47 ¦æªº¡yMF_STRING¡z§ï¦¨¡yMF_STRING or MF_MENUBREAK¡z¡A¨Ã§R°£²Ä 49 ¦æ¡A¦A²ÕĶ¡A«h±o¨ìªº¿ï³æ¦p¤U¹Ï¥ª¤G¡C¦pªG¦A§â¡yMF_STRING or MF_MENUBREAK¡z§ï¦¨¡yMF_STRING or MF_MENUBARBREAK¡z¡A«h¿ï³æÅܦ¨¤U¹Ï¥k¤G¡C¤U¹Ï³Ì¥kÃä«h¬O¡yMF_BITMAP¡zÄÝ©Ê¡C


MENUITEMINFO µ²ºcÅé

¥Î InsertMenuItem ²K¥[¿ï³æ

AppendMenu ¬O¦b Win 3.1 ®É¥N´N¤w¦³ªº API¡A¦ý¬O¦b Win32 ®É¥N¡A¤w³Q·L³n¦C¬°±N³Q²^¨Oªº API¡A·L³n«Øij¥H InsertMenuItem ¨ú¥N AppendMenu¡CÅU¦W«ä¸q¡AInsertMenuItem ¬O¥Î¨Ó§â¬Y¤@¿ï¶µ¥[¤J¨ì¤@­Ó¤l¿ï³æ©Î¥D¿ï³æùØ¡A¦¹³Bªº¬Y¤@¿ï¶µ¤]¥i¥H¬O¼u¥X¿ï¶µ¡CInsertMenuItem ­ì«¬¬°¡G

BOOL WINAPI InsertMenuItem(
  HMENU          hMenu,
  UINT           uItem,
  BOOL           fByPosition,
  LPMENUITEMINFO lpmii
);

hMenu ¬O«ü¿ï¶µ­n¥[¤J¨ì¨º¤@­Ó¤l¿ï³æ©Î¥D¿ï³æ¤¤¡CfByPosition ¥i¥H¬O FALSE ©Î TRUE¡A·í fByPosition ¬° FALSE ®Éªí¥Ü uItem ¬O¿ï¶µÃѧO½X¡F¬° TRUE ®Éªí¥Ü uItem ¬°¥[¤J¿ï¶µ¦b¿ï³æªº¦ì¸m¡A¦¹¦ì¸m¥Ñ 0 ¶}©l¡C¨Ò¦p¦b MENU1 ªº¨Ò¤lùØ¡AÀɮפl¿ï³æùض}·sÀɮתº¦ì¸m¬O 0¡A¶}±ÒÂÂÀɦì¸m¬O 1¡AÀx¦sÀɮתº¦ì¸m¬O 2¡K¡K¡A¨Ì¦¹Ãþ±À¡C

lpmii ¬O¤@­Ó«ü¼Ð¡A«ü¦V MENUITEMINFO µ²ºcÅ骺¦ì§}¡AMENUITEMINFO ùØ¥]§t¤F¤j³¡¤Àªº¿ï¶µ©Ê½è¡A¬O­Ó½ÆÂøªºµ²ºcÅé¡CMENUITEMINFO µ²ºcÅé¦UÄæ¦ì¦p¤U¡G

MENUITEMINFO    STRUCT
cbSize          UINT     ?
fMask           UINT     ?
fType           UINT     ?
fState          UINT     ?
wID             UINT     ?
hSubMenu        HMENU    ?
hbmpChecked     HBITMAP  ?
hbmpUnchecked   HBITMAP  ?
dwItemData      DWORD    ?
dwTypeData      LPTSTR   ?
cch             UINT     ?
hbmpItem        HBITMAP  ?
MENUITEMINFO    ENDS

²Ä¤@­ÓÄæ¦ì¡AcbSize¡Aªí¥Ü MENUITEMINFO µ²ºcÅé¦û¥Î¦h¤Ö¦ì¤¸²Õ¡A³o¬O»P API ªºª©¥»¦³Ãö¡CfMask ¥i¥H¬O MIIM_BITMAP¡BMIIM_CHECKMARKS¡BMIIM_DATA¡BMIIM_ID¡BMIIM_STATE¡BMIIM_SUBMENU¡BMIIM_TYPE µ¥¼Æ­Èªº¥ô·N²Õ¦X¡A·í fMask ³]¬Y­Ó¼Æ­È®É¡AMENUITEMINFO ªº¬Y­ÓÄæ¦ì¥²¶·³]¦n¡C¨Ò¦p fMask ³]¬° MIIM_ID ®É¡Aªí¥Ü­n³]©w¿ï¶µªºÃѧO½X¡A¦]¦¹ wID Äæ¦ì¥²¶·¦nÃѧO½X¡C¤p¤ì°¸¾ã²z¦¨¤U­±Â²ªí¡A¦p±ýª¾§ó¸Ô²Ó±¡§ÎÁÙ±o°Ñ¾\ MSDN¡G

fMask ¶·³]©wÄæ¦ì »¡¡@¡@¡@©ú
MIIM_BITMAPhbmpItem fMask «ü©w MIIM_BITMAP ®É¡A¥²¶·¦P®É¦b hbmpItem «ü©w¤@­Ó¦ì¤¸¹Ï¥N½X¡Aªí¥Ü¿ï¶µ¥H¤@­Ó¦ì¤¸¹Ïªí¥Ü¡ChbmpItem ¤]¥i¥H¬O¤º«Øªº¦ì¤¸¹Ï¡A¨Ò¦p HBMMENU_MBAR_CLOSE¡BHBMMENU_MBAR_CLOSE_D µ¥µ¥¡F¤]¥i¥H¬O HBMMENU_CALLBACK ( ¦¹®Éµ{¦¡¥²¶·³B²z WM_MEASUREITEM ©Î WM_DRAWITEM °T®§ )¡C
MIIM_BITMAP ¬O Win 2k/98 ¥H«á¥Î¨Ó¨ú¥N MFT_BITMAP ªº¡A¦b MASM32 Ver 7 ©Ò¥]§tªº WINDOWS.INC 1.25a ª©¤¤ªº MENUITEMINFO µ²ºcÅé¡A¨Ã¨S¦³ hbmpItem Äæ¦ì¡A±o¦Û¦æ­×§ï¡C
MIIM_CHECKMARKShbmpChecked
hbmpUnchecked
MIIM_CHECKMARKS ¬O³]©w¦b¿ï¶µ¤å¦r¤§«e¡A¥H¦ì¤¸¹Ï¨Óªí¥Ü¿ï¶µ¬O³Q¤Ä¿ïªº©Î¨S³Q¤Ä¿ïªº¡C¥H hbmpChecked «ü©w³Q¤Ä¿ï®É©ÒÅã¥Üªº¦ì¤¸¹Ï¡F¦Ó¥H hbmpUnchecked «ü©w¥¼³Q¤Ä¿ï®É©ÒÅã¥Üªº¦ì¤¸¹Ï¡ChbmpChecked¡BhbmpUnchecked ³£À³¸Ó¬O¦ì¤¸¹Ï¥N½X¡A¦ý¬O¦pªG hbmpChecked ¬O NULL¡A¦Ó¥B fType ³]¬° MFT_RADIOCHECK ®É¡A«h¥H¤@¶êÂIªí¥Ü³Q¤Ä¿ïªº¿ï¶µ¡F­Y¦b fType ¤]¨S«ü©w¡A«h¥H¤@­Ó¤p¤Ä¤Äªí¥Ü³Q¤Ä¿ïªº¿ï¶µ¡C
MIIM_DATAdwItemData MIIM_DATA ¥i¥H¥Ñµ{¦¡¦Û¦æ©w¸q¼Æ­È¡A¦ý¤p¤ì°¸¤~²¨¾Ç²L¤£ª¾¥i¥H«ç»ò¥Î¡C³]©w MIIM_DATA ®É¡AdwItemData ¥i¥H³]©w¤@­Ó 32 ¦ì¤¸¾ã¼Æ¡C
MIIM_FTYPEfType ¿ï¶µ¥~Æ[¤À¦¨³\¦hºØÃþ¡A¦³¤À¹j½u¡B¦ì¤¸¹Ï¡B¤å¦rµ¥¡A©Ò¥H­n¨ú±o©Î³]©w¤£¦P¥~Æ[®É¡A¥ý§â fMask ³]¬° MIIM_TYPE¡A¦A©ó fType °µ¶i¤@¨B³]©w¡C
MIIM_IDwID ·í fMask ³]©w MIIM_ID ®É¡Aªí¥Ü­n³]©w¿ï¶µªºÃѧO½X¡A¸ÓÃѧO½X¦s©ó wID Äæ¦ì¡C
MIIM_STATEfState ·í fMask ³]©w MIIM_STATE ®É¡Aªí¥Ü³]©w¿ï¶µªºª¬ºA¡A¿ï¶µªºª¬ºA¥i¥H¦³¤U­±´XºØ¡G
  1. ³Q¤Ä¿ï ( MFS_CHECKED ) ©Î¥¼³Q¤Ä¿ï ( MFS_UNCHECKED )¡G§Y¿ï¶µ¤å¦r«e¦³¤p¤Ä¤Ä©Î¨ä¥L²Å¸¹¡C
  2. ¤º©wªº¡GMFS_DEFAULT¡A¤º©wªº¿ï¶µ¤å¦r·|¥H²ÊÅé¦rªí¥Ü¡C
  3. ¸T¥Îªº ( MFS_DISABLED )¡B±Ò¥Îªº ( MFS_ENABLED )¡BµL®Äªº ( MFS_GRAYED )
  4. °ª«G«× ( MFS_HILITE ) ©Î¥¿±`«G«× ( MFS_UNHILITE )ªº¡C
¥H¤W¥|²Õ¡A¨C¤@²Õ¤º¥u¯à¤@¶µ³Q³]©w¡A¨Ò¦p¤£¥i¯à¦³¤@­Ó¿ï¶µ¬O³Q¤Ä¿ïªº¦Ó¦P®É¤S¬O¥¼³Q¤Ä¿ïªº¡C¤£¹L¦b¤@¤l¿ï³æùØ¥i¥H¦P®É¦³¼Æ­Ó¿ï¶µ¬O³Q¤Ä¿ïªº¡A¥t¥~¤Ä¿ï©Î¤£¤Ä¿ïªº¥²¶·ÁÙ­n¥Îµ{¦¡°t¦X³B²z¡A¨t²Î¥u­t³dÅã¥Ü³o¨Çª¬ºA¦Ó¤w¡C
MIIM_STRINGdwTypeData
cch
·í fMask ³]¬° MIIM_STRING ®É¡Aªí¥Ü¥i³]©w©Î¨ú±o¿ï¶µªº¤å¦r¡A¦Ó¿ï¶µªº¤å¦r¦s©ñ¦b dwTypeData ©Ò«üªº¦ì§}ùØ¡Aªø«×¬° cch ( ³æ¦ì¬°¦r¤¸ )¡C
MIIM_SUBMENUhSubMenu ·í fMask ³]¬° MIIM_SUBMENU ®É¡Aªí¥Ü³o­Ó¿ï¶µ¨ä¹ê¬O¤@­Ó¼u¥X¿ï¶µ¡A¦Ó³o­Ó¼u¥X¿ï¶µ­n³Q¥[¶i¤@­Ó¤l¿ï³æùØ¡A³o­Ó¤l¿ï³æ¦b InsertMenuItem ªº²Ä¤@­Ó°Ñ¼Æ hMenu ¤¤³]©w¡C·í³]©w MIIM_SUBMENU ®É¡A¥²¶·§â¦¹¼u¥X¿ï¶µ©Ò¼u¥Xªº¤l¿ï³æ¥N½X¦s¤J hSubMenu Äæ¦ìùØ¡C
MIIM_TYPEfType

dwTypeData
·í fMask ³]¬° MIIM_TYPE ®É¡Aªí¥Ü­n³]©w¿ï¶µ¤º®e¡C¿ï¶µ¤º®e»P¿ï¶µªºÃþ«¬¦³Ãö¡A¿ï¶µÃþ«¬°O¿ý¦b fType ùØ¡A¤£¦PÃþ«¬ªº¿ï¶µ¨ä¤º®e¤£¦P¡A¦Ó¿ï¶µ¤º®e°O¿ý¦b dwTypeData ©Î¨ä¥LÄæ¦ì¡CfType ¥i¥H¦³¤U­±´XºØ¡G
  1. MFT_BITMAP¡G¦¹¿ï¶µ¬°¤@¦ì¤¸¹Ï¡A¸Ó¦ì¤¸¹Ï¥N½X¶·¦s¤J dwTypeData ùØ¡C­nª`·Nªº¬O¦¹¿ï¶µ´N¬O¥H¤@±i¦ì¤¸¹Ï¨Ó¥N´À¤å¦r¦r¦ê¡A¦¹¦ì¤¸¹Ï§O©M³Q¤Ä¿ïªº¦ì¤¸¹Ï·d²V¡A«áªÌ¥u¬O¦b¤å¦r¦r¦ê«e¦³¤@¦ì¤¸¹Ïªí¬O¦¹¿ï¶µ³Q¤Ä¿ï¡C¦b Win 2k/98 ¥H«á¤w³Q MIIM_BITMAP ¨ú¥N
  2. MFT_MENUBARBREAK¡G½Ð°Ñ¦Ò¤W­±¡C
  3. MFT_MENUBREAK¡G½Ð°Ñ¦Ò¤W­±¡C
  4. MFT_SEPARATOR¡G¦¹¿ï¶µ¨ä¹ê¬O¤@¤ô¥­¤À¹j½u¡A¦¹®É dwTypeData ¨ÃµL§@¥Î¡C
  5. MFT_STRING¡G¦¹¿ï¶µ¤º®e¥H¤å¦r¦r¦êªí¥Ü¡A³o¬O³Ì±`¨£ªºÃþ«¬¡CdwTypeData «ü¦V¥H¹s¬°µ²§Àªº¤å¦r¦r¦ê¦ì§}¡Acch ¬°¸Ó¦r¦ê©Ò¦ûªº¦ì¤¸²Õ¼Æ¡A¤£¹L¤p¤ì°¸¹êÅçµ²ªG cch ¦ü¥GµL§@¥Î¡C
  6. MFT_OWNERDRAW¡G¦¹¿ï¶µ¬°¾Ö¦³ªÌ¿ï¶µ¡A©ÎºÙ¦Ûø¿ï¶µ¡A¥ç§Y¥²¶·¥Ñµ{¦¡©Îµ{¦¡³]­p®v¦Û¦æø»s¦¹¿ï¶µ¥~Æ[¡A¦¹®É dwTypeData ¥i¥H¬°µ{¦¡¦Û¦æ©w¸qªº¤@¼Æ­È¡A¦b¬Y¨Ç±¡ªp¤¤¥i¥H¨Ï¥Î¡C¨ã¦³ MFT_OWNERDRAW ªº¿ï¶µ·|¹ïµøµ¡¨ç¦¡µo¥X WM_MEASUREITEM »P WM_DRAWITEM °T®§¡A¤p¤ì°¸µy«á±Ô­z¸Ô±¡¡C
  7. MFT_RADIOCHECK¡G¥Î¶êÂIÅã¥Ü³Q¤Ä¿ïªº¿ï¶µ¡A¦ý¥ý¨M±ø¥ó¸Ó¿ï¶µªº¬O hbmpChecked ¬° NULL¡C
  8. MFT_RIGHTJUSTIFY¡G
  9. MFT_RIGHTORDER¡G¥Ñ¥k¦V¥ª®Ñ¼g¡A¦pªü©Ô§B¤å¡C
¦b Windows 98/Me/2K/XP ¤§«áªº¨t²Î¡AMIIM_BITMAP¡BMIIM_FTYPE¡BMIIM_STRING ¥i¨ú¥N MIIM_TYPE¡C·N«ä¬O¡A¦b Windows 95 ®É¡A¦p­n³]©w¿ï¶µ¤å¦r¡A¥²¶·§â fMask ³]¬° MIIM_TYPE¡A¦A§â fType ³]¬° MFT_STRING¡AµM«á§â dwTypeData ³]¬°¦r¦ê¦ì§}¡F¨ì¤F Windows 98 ¥H«á¡A¥u»Ý§â fMask ³]¬° MIIM_STRING¡A¦A§â dwTypeData ³]¬°¦r¦ê¦ì§}¡C

¥Î GetMenuItemInfo ¨ú±o¿ï¶µ¸ê®Æ¡B¥Î SetMenuItemInfo §ïÅܿﶵ¸ê®Æ

GetMenuItemInfo ¥i¥H¨ú±o¿ï¶µ¸ê®Æ¡A¨ä­ì«¬¬°¡G

BOOL GetMenuItemInfo(
  HMENU hMenu,
  UINT  uItem,
  BOOL  fByPosition,
  LP    lpmii
);

©I¥s GetMenuItemInfo ¤§«e¥ý§â lpmii «ü¦V¤@­Ó MENUITEMINFO µ²ºcÅé¡A­n¨ú±o¿ï¶µªº¨º¤@­Ó¸ê®Æ¡A¥²¶·¥ý¦b MENUITEMINFO µ²ºcÅ骺 fMask ³]©w¦n¡A¦Ó uItem »P fByPosition ©M InsertMenuItem ·N¸q¬Û¦P¡A©I¥s«á¥Ñ¨t²Î¶Ç¨Óªº¿ï¶µ¸ê®Æ´N·|³Q¦s¶i lpmii ©Ò«ü©wªºµ²ºcÅ餤¡C

­n§ïÅܿﶵªº¬Y¤@¸ê®Æ¡A«h¬O©I¥s SetMenuItemInfo¡A¨ä­ì«¬¬°¡G

BOOL SetMenuItemInfo(
  HMENU          hMenu,
  UINT           uItem,
  BOOL           fByPosition,
  LPMENUITEMINFO lpmii
);

¨ã¦³ MFT_OWNERDRAW ªº¿ï¶µ

¦b³\¦h°Ó·~³nÅ餤¡A¦³³\¦hº}«Gªº¿ï³æ¡A¤p¤ì°¸²q´ú³o¨Ç¿ï³æ¥i¯à¬O¥Î¦Ûø¿ï¶µ¨Ó»s§@ªº¡C©Ò¿×¦Ûø¿ï¶µ«üªº¬O¨ã¦³ MFT_OWNERDRAW ­·®æªº¿ï¶µ¡A§í©ÎºÙ¾Ö¦³ªÌ¿ï¶µ¡Cµy«á¤p¤ì°¸±N¥Ü½d¤@­Óµ{¦¡¡AMENU2.ASM¡A¨Ó»¡©ú¦p¦ó»s§@³oºØ¯S§Oªº¿ï³æ¡A¦¹¨è¥ý¨Ó¬Ý¬Ý MENU2 ¿ï³æµe­±¡G

¤W¹Ï¤¤ÃC¦â¤l¿ï³æ¬O¤@¯ë±`¨£ªº¿ï³æ¡A¨ä¤Ä¿ïªº¹Ï§Î¬O¤@¦ì¤¸¹Ï¡ACHECK.BMP¡A¦Ó¤£¥Î¤º©wªº¤Ä¿ï²Å¸¹¡CÀÉ®×»P¦r§Î¤l¿ï³æ³£¨ã¦³ MFT_OWNERDRAW ÄÝ©Ê¡AÀɮפl¿ï³æ¤¤ªº¤å¦r¬O¥Î DrawText µe¤W¥hªº¡A¨ä«e­±ªº¹Ï§Î¤]¬O¦ì¤¸¹Ï¡A¬O¥H BitBlt µe¤W¥hªº¡F¦r§Î¤l¿ï³æ¤¤ªº¤å¦r¤]¬O¥H DrawText µe¤W¥hªº¡Aª`·N¨ì¥L­Ìªº¦r§Î´N¬O¦pÅã¥Üªº¤å¦r¯ë¡F¨ä­I´º«h¬O¤@­Ó¦ì¤¸¹Ï¡A¥H BitBlt µe¤W¥hªº¡C©³¤U»¡©ú¦p¦ó²£¥Í³o¨Ç®ÄªG¡C

WM_MEASUREITEM »P WM_DRAWITEM °T®§

¨ã¦³ MFT_OWNERDRAW Äݩʪº¿ï¶µ©Î¾Ö¦³¦Ûø­·®æªº±±¨î¶µ ( ¨£²Ä 12 ³¹ ) ·|¦b­nø»s¿ï¶µ©Î±±¨î¶µ¤§ªì¡A¹ïµøµ¡¨ç¦¡µo¥X WM_MEASUREITEM °T®§¡A¦¹°T®§¬O¥Î¨ÓÅýµ{¦¡³]­p®v³W¹º¸Ó¿ï¶µ©Î±±¨î¶µªº¤j¤p¡A·íµ{¦¡³B²z§¹ WM_MEASUREITEM °T®§«áÀ³¸Ó¶Ç¦^ TRUE ªð¦^¨t²Î¡AÅý¨t²Î±oª¾§Ú­Ì³B²z¤F¦¹°T®§¡C±µ¤U¨Ó¨t²Î±N·|³B²z¥²­nªº¨Æ¶µ¡A¨Ò¦p¬°¦¹¿ï¶µ©Î±±¨î¶µ«Ø¥ß³]³Æ¤º®e ( device context )¡B«Ø¥ß¥²­nªº¸ê®Æµ²ºcµ¥µ¥¡AµM«á¨t²Î·|¦A¹ïµøµ¡¨ç¦¡µo¥X WM_DRAWITEM °T®§¡Aµ{¦¡¥²¶·¦b¦¹°T®§¤¤¦Û¦æø»s¿ï¶µ©Î±±¨î¶µªº¹Ï§Î¡C¦b WM_DRAWITEM °T®§¤¤¡A·|§â¸Ó¿ï¶µ©Î±±¨î¶µªº³]³Æ¤º®e¤Î¨ä¼e»P°ª¶Ç¨Ó¡A§Ú­Ìªºµ{¦¡©Ò­n°µªº¨Æ´N¦p¦P¹ïµøµ¡¤u§@°Ïø»s¹Ï§Î¤@¯ë¡C·í§¹¦¨ WM_DRAWITEM «á¡A¦P¼Ë¤]­n§â TRUE ¶Ç¦^µ¹¨t²Î¡C

WM_MEASUREITEM °T®§¤¤ªº wParam ¬O±±¨î¶µªºÃѧO½X¡A­Yµo¥X¦¹°T®§ªº¬O¿ï³æ¡A«h wParam ¬°¹s¡CWM_MEASUREITEM °T®§¥t¤@°Ñ¼Æ lParam «h¬O«ü¦V¤@­Ó MEASUREITEMSTRUCT µ²ºcÅé¡Aµ{¦¡³]­p®v¥i¥H¦b¦¹µ²ºcÅ餺¶ñ¤J¾A·íªº©Î¬O±z·Q­nªº¼Æ­È¨Ó³W¹º¿ï¶µ¡AMEASUREITEMSTRUCT ¦¨­û¦p¤U¡G

MEASUREITEMSTRUCT STRUCT 
CtlType           UINT    ?
CtlID             UINT    ?
itemID            UINT    ?
itemWidth         UINT    ?
itemHeight        UINT    ?
itemData          DWORD   ?
MEASUREITEMSTRUCT ENDS

CtlType ¬Oµo¥X WM_MEASUREITEM ªº±±¥ó©Î¿ï¶µ¡A¦¹Äæ¦ì¦b¨t²Î©I¥sµøµ¡¨ç¦¡®É¤w³Q¨t²Î³]©w¦n¤F¡AÂÇ¥H«ü¥Ü¬O½Öµo¥X¦¹°T®§ªº¡A¥i¥H¬O¤U­±¼Æ­È¡G

Ãþ«¬¼Æ­È·N¡@¡@¸q
ODT_MENU1 ¨ã¦³ MFT_OWNERDRAW ªº¿ï¶µ
ODT_LISTBOX2 ¨ã¦³ LBS_OWNERDRAWFIXED ©Î LBS_OWNERDRAWVARIABLE ­·®æªº²M³æ
ODT_COMBOBOX3 ¨ã¦³ CBS_OWNERDRAWFIXED ©Î CBS_OWNERDRAWVARIABLE ­·®æªº½Æ¦X®Ø
ODT_BUTTON4 ¨ã¦³ BS_OWNERDRAW ­·®æªº«ö¶s±±¥ó
ODT_STATIC5 ¨ã¦³ SS_OWNERDRAW ­·®æªºÀRºA±±¥ó

CtlID ¬Oµo¥X WM_MEASUREITEM °T®§ªº±±¥óÃѧO½X¡A¦¹Äæ¦ì¹ï¿ï¶µ¬OµL®Äªº¡C

itemID ¬Oµo¥X WM_MEASUREITEM °T®§ªº¿ï¶µÃѧO½X¡C·í¨ã¦³ CBS_OWNERDRAWVARIABLE ­·®æªº½Æ¦X®Ø¤¤ªº²M³æ©Î¨ã¦³ LBS_OWNERDRAWVARIABLE ­·®æªº²M³æùØ­±ªº¿ï¾Ü¶µµo¥X WM_MEASUREITEM ®É¡AitemID Äæ¦ì¬O¦b²M³æ¤¤ªº¦ì¸m¡A¦¹¦ì¸m¥Ñ¹s¶}©lºâ°_¡CCtlID¡BitemID ³£¬O¦b¨t²Î©I¥sµøµ¡¨ç¦¡®É¡A´N¤w¨Ì¾Úµ{¦¡©Ò³]©w¤§­È³]¦n¶Çµ¹µøµ¡¨ç¦¡¡C

itemWidth¡B itemHeight ¬O¦Ûø¿ï¶µ©Î¨ä¥L¨ã¦³¦Ûø±±¥óªº¼e»P°ª¡Cµ{¦¡¥²¶·¦bµ²§ôµøµ¡¨ç¦¡ªð¦^¨t²Î¤§«e¡A³]¦n³o¨â­ÓÄæ¦ì¡A§_«h¨t²Î´N¤£ª¾¹D¿ï¶µ©Î±±¨î¶µªº¤j¤p¡A«K·|µLªkÅã¥Ü¥X¨Ó¡C¹ï¿ï¶µ¦Ó¨¥¡AitemData ¬O¥Ñµ{¦¡©Ò©w¸qªº 32 ¦ì¤¸¼Æ­È¡C

¦b WM_DRAWITEM °T®§¤¤¡Aµ{¦¡³]­p®v±o¨Ì¾Ú DRAWITEMSTRUCT µ²ºcÅ骺¸ê®Æø»s¿ï¶µ¡CDRAWITEMSTRUCT µ²ºcÅé¦ì©ó WM_DRAWITEM ªº lParam ©Ò«ü¦ì§}¤§³B¡A¦¹µ²ºcÅ骺¦UÄæ¦ì¤w¦b²Ä 12 ³¹»¡©ú¹L¤F¡A½Ð°Ñ¾\¸Ó³¹¡A¦¹³B¤]¤£­«½Æ¤F¡CWM_DRAWITEM ªº¥t¤@°Ñ¼Æ wParam ·N¸q»P WM_MEASUREITEM ¬Û¦P¡A¦]¦¹¤£¦AÂØ­z¡C¦b DRAWITEMSTRUCT µ²ºcÅ餤¡A¸û­«­nªºÄæ¦ì¬O hdc ©M rcItem¡Chdc ¬O«ü­nø»sªº±±¨î¶µ©Î¿ï¶µªº³]³Æ¤º®e¥N½X¡A¨ú±o³o­Ó¥N½X«á¡A§Ú­Ì«K¥i¦b±±¨î¶µ©Î¿ï¶µµe¤W¹Ï§Î¡B¦r¦ê¡B¦ì¤¸¹Ïµ¥¡A¤@¦p§Ú­Ì¹ï¤u§@°Ï ( client area ) ø»s¹Ï§Î¤@¯ë¡C¨Ò¦p·Q¨Ï¥Î¯S®í¦r§Î®É¡A±o¥ý¥Î CreateFont «Ø¥ß¤@ÅÞ¿è¦r§Î¡AµM«á¥Î SelectObject ¿ï¾Ü¦¹¦r§Î¡AµM«á¦A¥Î DrawText ø»s¥X¤å¦r¦r¦ê¡CrcItem ¬O«ü±±¨î¶µ©Î¿ï¶µªº°ª»P¼e¡A§Ú­Ì©Òø»sªº¹Ï§Î¡B¦r¦ê¡B¦ì¤¸¹Ïµ¥³£±N·|Åã¥Ü©ó rcItem ©Ò«üªº RECT µ²ºcÅ餺ªº¯x§Î¤§¤¤¡C¤£¹L¹ï¿ï³æ¦Ó¨¥¡AÁÙ¦³¤@³B±oª`·N¡C¤@­Ó¤l¿ï³æùØ­±¥i¯à¦³¦h­Ó¿ï¶µ¨C­Ó¿ï¶µ°ª«×¥i¯à¤£¦P¡A¥i¥H¦b WM_MEASUREITEM ¤¤³]©w¡A¦ý¬O³Ì«á¦b WM_DRAWITEM ¤¤µe¥X¿ï¶µ®É¡A¾ã­Ó¤l¿ï³æ³£µø¬°¤@­Ó³]³Æ¤º®e( device context )¡A¨ä°ª«×¬O¦U¿ï¶µªºÁ`©M¡C

¦Ûø¿ï¶µªº°ª«G«×¥ú´Î

·í¨Ï¥ÎªÌªº·Æ¹«´å¼Ð¦b¿ï³æ²¾°Ê®É¡A·|¦³¤@­Ó°ª«G«×¥ú´Îªí¥Ü·Æ¹«²¾¨ì¨º¤@­Ó¦ì¸m¡A¨Ò¦p¤W¹Ï¤¤ªº MENU2 ¬O¥H¤@­ÓÂŦâ¥ú´Îªí¥Ü¡C¦b¤@¯ë¿ï¶µùØ¡A³o¶µ¤u§@¬O¥Ñ¨t²Î¨Ó°µ¡A¦ý¬O¦b¦Ûø¿ï¶µùØ«o¥²¶·¥Ñµ{¦¡¦Û¦æÅã¥Ü¡C

·í·Æ¹«´å¼Ð²¾¨ì¬Y­Ó¿ï¶µ®É¡A¸Ó¿ï¶µ·|³Q¨t²Î³]¬°³Q¿ï¾Ü¨ìªº¡A¦¹ª¬ºA·|³Q¶Ç¨ì¦Ûø¿ï¶µ¤¤ DRAWITEMSTRUCT µ²ºcÅ骺 itemState Äæ¦ìùØ¡A¨Ã¨Ï itemState ³]¬° ODS_SELECTED ( ¨ä¹ê ODS_SELECTED ¬O itemState Äæ¦ìªº²Ä¹s­Ó¦ì¤¸³]¬°¤@ )¡C¦]¦¹µøµ¡¨ç¦¡¦b³B²z WM_DRAWITEM °T®§®É¡A¥i¥HÀˬd³o­ÓÄæ¦ì¬O§_³Q³]©w¡A¦pªG³Q³]©w¥i¥H¥Î°ª«G«×­I´º¦â ( §Y°ª«G«×¥ú´Î ) ªí¥Ü¡F¤Ï¤§«h¥Î¿ï³æ¤º©wªº­I´ºÃC¦âªí¥Ü¡C¹ê»Úªº°µªk¥i¥H°Ñ¦Ò MENU2.ASM ªº¨Ò¤l¡C


¼u¥X¦¡¿ï³æ ( popup menu )

¼u¥X¦¡¿ï³æ¬O«ü¨Ï¥ÎªÌ¦b¤u§@°Ï¤¤«ö¤U·Æ¹«¥kÁä ( ·íµM±z¤]¥i¥H¥Î¥ªÁä¤Þµo¥¦ ) ©ÒÂÛ¥Xªº¿ï³æ¡A³oºØ¿ï³æµLªk¥Î¸ê·½´y­zÀɨƥý©w¸q¡A¥²¶·¥Î CreatePopupMenu API »s§@¡A¦]¦¹¤ñ¸û³Â·Ð¡C¤£¹L©¯¹Bªº¬O¡A¼u¥X¦¡¿ï³æªº¤l¿ï³æ«o¥i¥H¦b¸ê·½´y­zÀɤ¤©w¸q¡A¦]¦¹¥i¥H²¤Æ¤@¨Ç°ÝÃD¡C¥Î CreatePopupMenu «Ø¥ß¦nªº¼u¥X¦¡¿ï³æ¤]¬O¤@­ÓªÅªº¿ï³æ¡A¥²¶·¥Î AppendMenu¡BInsertMenuItem µ¥ API §â¼u¥X¿ï³æ¡B¿ï¶µµ¥¥[¶i¼u¥X¦¡¿ï³æùØ¡A¤]¥i¥H¥Î ModifyMenu¡BSetMenuItemInfo §ïÅܿﶵªº¯S©Ê¡K¡K¡A³o¨Ç³£»P¥D¿ï³æ¬Û¦P¡C

CreatePopupMenu API

CreatePopupMenu ¥Î¨Ó«Ø¥ß¤@­ÓªÅµL¤@ª«ªº¼u¥X¦¡¿ï³æ¡A¨ä­ì«¬¦p¤U¡G

HMENU CreatePopupMenu(VOID);

¥¦¨S¦³°Ñ¼Æ¡A¦pªG¦¨¥\ªº«Ø¥ß¼u¥X¦¡¿ï³æ¡ACreatePopupMenu ¶Ç¦^©Ò«Ø¥ßªº¼u¥X¦¡¿ï³æ¥N½X¡F­Y¥¢±Ñ¡A«h¶Ç¦^ NULL¡C

TrackPopupMenu API

¼u¥X¦¡¿ï³æªº¤Þµo¤è¦¡¡A¤@¯ë¬O¥Ñ¨Ï¥ÎªÌ¦b¤u§@°Ï«ö¤U·Æ¹«¥kÁä¡AµM«á¨t²Î«KÅã¥Ü¥X¼u¥X¦¡¿ï³æ¡C¦]¦¹¤@¯ëµ{¦¡¬O¦b WM_RBUTTONDOWN °T®§¤¤Åã¥Ü¼u¥X¦¡¿ï³æ¡AÅã¥Üªº¤è¦¡¬O©I¥s TrackPopupMenu ©Î TrackPopupMenuEx API¡CTrackPopupMenu ­ì«¬¬O¡G

BOOL TrackPopupMenu(
  HMENU hMenu,         // handle to shortcut menu
  UINT  uFlags,        // screen-position and mouse-button flags
  int   x,             // horizontal position, in screen coordinates
  int   y,             // vertical position, in screen coordinates
  int   nReserved,     // reserved, must be zero
  HWND  hWnd,          // handle to owner window
  CONST RECT *prcRect  // ignored
);

¨ä¤¤ hMenu ¬O­nÅã¥Üªº¼u¥X¦¡¿ï³æ¥N½X¡CuFlags ¬O«ü¼u¥X¦¡¿ï³æÅã¥Üªº¦ì¸m»P¨Ï¥ÎªÌ«ö¤U·Æ¹«¥kÁä®É¡A·Æ¹«´å¼Ð¦ì¸mªºÃö«Y¡AuFlags ¥i¥H¬O¤U­±¼Æ­È¡G

  1. TPM_CENTERALIGN¡BTPM_LEFTALIGN¡BTPM_RIGHTALIGN¡G«ü·Æ¹«´å¼Ð¦b¼u¥X¦¡¿ï³æªº¤¤¶¡¡B¥ªÃäÃä½u¡B¥kÃäÃä½u¤W¡C¦¹¤T­Ó¼Æ­Èªí¥Ü·Æ¹«´å¼Ð¦b¿ï³æ X ¶bªº¨º¤@­Ó¦a¤è¡C
  2. TPM_BOTTOMALIGN¡BTPM_TOPALIGN¡BTPM_VCENTERALIGN ¡G«ü·Æ¹«´å¼Ð¦b¼u¥X¦¡¿ï³æªº¤UÃäÃä½u¡B¤¤¶¡¡B¤WÃäÃä½u¤W¡C¦¹¤T­Ó¼Æ­Èªí¥Ü·Æ¹«´å¼Ð¦b¿ï³æ X ¶bªº¨º¤@­Ó¦a¤è¡C
  3. TPM_NONOTIFY¡BTPM_RETURNCMD¡G
  4. TPM_RIGHTBUTTON¡BTPM_LEFTBUTTON¡G¦pªG³]©w TPM_RIGHTBUTTON¡Aªí¥Ü·Æ¹«¥ª¶¡©Î¥kÁ䧡¥i¿ï«ö¿ï¶µ¡F¦pªG³]©w TPM_LEFTBUTTON¡A´N¥u¦³·Æ¹«¥ªÁä¥i¿ï«ö¿ï¶µ¡C

x¡By ¬O«ü«ö¤U·Æ¹«¥ªÁä©Î¥kÁä®É¡A·Æ¹«´å¼Ð©Ò¦b¦ì¸mªº X ®y¼Ð¤Î Y ®y¼Ð¡A¦¹³Bªº®y¼Ð­ìÂI¬O¿Ã¹õ¥ª¤W¨¤¡CnReserved ¬O«O¯dÄæ¦ì¡A¥²¶·¬O¹s¡C³Ì«á¤@­Ó¬O«ü¦Vµ²ºcÅé RECT ªº«ü¼Ð¡AprcRect¡A¤]³Q«O¯d¡A¥i³]¬°¹s¡C


¨t²Î¿ï³æ ( window menu )

¨t²Î¿ï³æ¤@¯ë¬O¦b¼ÐÃDÄæ³Ì¥ªÃ䪺¹Ï¥ÜùØ¡A·í¨Ï¥ÎªÌ¥H·Æ¹«¥ªÁä©Î¥kÁä«ö¤U¦¹¹Ï¥Ü®É©Ò¼u¥Xªº¿ï³æ´N¬O¨t²Î¿ï³æ¡C­×§ï¨t²Î¿ï³æ¥²¶·¥ý¥Î GetSystemMenu ¨ú±o¨t²Î¿ï³æ¥N½X¡AGetSystemMenu ­ì«¬¦p¤U¡G

HMENU GetSystemMenu(
  HWND  hWnd,    // handle to window to own window menu
  BOOL  bRevert  // reset flag
); 

¨ä¤¤ hWnd ¬O­n¨ú±o¨t²Î¿ï³æ¥N½Xªºµøµ¡¥N½X¡CbRevert ¥i¥H¬O FALSE ©Î TRUE¡AFALSE «ü¥Ü¨t²Î¨ú±o¨t²Î¿ï³æ¥N½X¡FTRUE ªí¥Ü¨t²Î­«³]¨t²Î¿ï³æÅܬ°¤º©wª¬ºA¡C©Ò¿×¤º©wª¬ºA«üªº¬O¨t²Î¿ï³æ­ì¥»¥]§tªº¡yÁÙ­ì¡z¡B¡y²¾°Ê¡z¡B¡y¤j¤p¡z¡B¡y³Ì¤p¤Æ¡z¡B¡y³Ì¤j¤Æ¡z¡B¤À¹j½u¡B¡yÃö³¬¡z¤C­Ó¿ï¶µ¡C¦pªG¨t²Î¿ï¶µ´¿³Q­×§ï¹L¡A°õ¦æ

invoke  GetSystemMenu,hWnd,TRUE

«á¡A·|«ì´_­ì¨Ó¤º©wª¬ºA¡Cµ{¦¡¥i¥H¥Î InsertMenuItem¡BSetMenuItem¡BAppendMenu¡BInsertMenu¡BModifyMenu µ¥ API ¨Ó­×§ï¨t²Î¿ï³æ¡C

¤@¯ë¿ï³æ¤¤ªº¿ï¶µ¡A³Q¨Ï¥ÎªÌÂI¿ï«á¡A·|µo¥X WM_COMMAND °T®§¡Aµøµ¡¨ç¦¡³B²z³o­Ó°T®§¡A¥H§¹¦¨¨Ï¥ÎªÌ»Ý¨D¡F¦ý¬O¨t²Î¿ï³æ¤ºªº¿ï¶µ¨Ã¤£µo¥X WM_COMMAND¡A¦Ó¬Oµo¥X WM_SYSCOMMAND °T®§¡CWM_SYSCOMMAND °T®§¤¤ªº wParam ¬O¨Ï¥ÎªÌ©ÒÂI¿ïªº¿ï¶µÃѧO½X¡A¥i¯à¬O¤U­±¼Æ­È¡G

ÃÑ¡@§O¡@½X¤Q¤»¶i¦ì¼Æ »¡¡@©ú
SC_SIZE 0f000h
SC_MOVE 0f010h ²¾°Êµøµ¡
SC_MINIMIZE 0f020h ³Ì¤p¤Æµøµ¡
SC_MAXIMIZE 0f030h ³Ì¤j¤Æµøµ¡
SC_NEXTWINDOW 0f040h
SC_PREVWINDOW 0f050h
SC_CLOSE 0f060h Ãö³¬µøµ¡

¥J²ÓÆ[¹î¡A³o¨ÇÃѧO½X¥Ñ 0F000h ¶}©l¡A¦]¦¹·íµ{¦¡¦b¨t²Î¿ï³æ¤º²K¥[¿ï¶µ®É¡A¨ä¿ï¶µªºÃѧO½X³Ì¦n¬O¤p©ó 0F000h¡C¦¹¥~·í¨t²Î¿ï³æµo¥X WM_SYSCOMMAND °T®§®É¡A¦pªG³o¨Ç¨t²Î¤º©wªº¿ï¶µ¤£¥Ñµ{¦¡³B²zªº¸Ü¡A³£À³¥æ¥Ñ DefWindowProc ³B²z¡A¦pªG¤£³o»ò°µªº¸Ü¡A¨º»ò¨t²Î¿ï³æ±NµLªk¨Ï¥Î¡C

lParam ¤º¦s¦³¨Ï¥ÎªÌ¦b¨t²Î¿ï³æ«ö¤U·Æ¹«®É¡A·Æ¹«´å¼Ðªº®y¼Ð¡A¸û§Cªº 16 ¦ì¤¸¬O X ®y¼Ð¡A¸û°ªªº 16 ¦ì¤¸¬O Y ®y¼Ð¡C­Y lParam ¬°¹s¡Aªí¥Ü¨Ï¥ÎªÌ¥Î¼Æ¦rÁä¿ï¾Ü¨t²Î¿ï³æ¡A­Y¬°¡Ð1¡Aªí¥Ü¨Ï¥ÎªÌ¥Î¥[³tÁä¿ï¾Ü¨t²Î¿ï³æ¡C


MENU2

©³¤Uªºµ{¦¡¡AMENU2¡Aºt¥Ü¤F¤W­z©Ò´£¨ìªº¤@¨Ç¥DÃD¡A¥]§t«Ø¥ß¥D¿ï³æ¤Î¨ä¤l¿ï³æ¡B«Ø¥ß¼u¥X¦¡¿ï³æ¡B­×§ï¨t²Î¿ï³æ¡A¦P®É¤]¥Ü½d¤F¦Ûø¿ï¶µ¡C¨ä°õ¦æµe­±¦p¤U¹Ï¡G

MENU2 ªº­ì©l½X

­n¦¨¥\²ÕĶ MENU2¡A»Ý­n«Ü¦hÀɮסA¤j³¡¤À¬O¦ì¤¸¹Ï¡A³o¨Ç¦ì¤¸¹Ï¦b¿ï¶µ¤å¦r¤§«e¡A¥¦­Ì³£¦b¸ê·½´y­zÀÉ¡AMENU2.RC¡AùØ­±©w¸q¡G

MENU_TEST   ICON    "MENU.ICO"
NewFile     BITMAP  "NEWFILE.BMP"
OpenFile    BITMAP  "OPENFILE.BMP"
SaveFile    BITMAP  "SAVEFILE.BMP"
Exit        BITMAP  "EXIT.BMP"
Check       BITMAP  "CHECK.BMP"
BK          BITMAP  "BK.BMP"

MENU2.RC ¤º©Ò§tªº¦ì¤¸¹ÏÀÉ¡B¹Ï¥ÜÀɤº®e¦p¤U¹Ï¡G


¤p¤ì°¸±N³o¤C­ÓÀɮ׳s¦P MENU2.ASM¡BMENU2.RC¡BMENU2.MAK ¥´¥]¦¨¤@­ÓÀ£ÁYÀÉ¡AMENU2.RAR¡C²ÕĶ®É¡A§â MENU2.RAR ¤º©Ò¦³Àɮ׸ÑÀ£ÁY¨ì¦P¤@¤l¥Ø¿ý¡A¨Ã©ó¡y©R¥O´£¥Ü¦r¤¸¡z¤¤°õ¦æ¤U­±«ü¥O¡G

E:\HomePage\SOURCE>nmake -f menu2.mak [Enter]

Microsoft (R) Program Maintenance Utility   Version 1.50
Copyright (c) Microsoft Corp 1988-94. All rights reserved.

        rc MENU2.rc
        ml MENU2.asm /link MENU2.res
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: MENU2.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS
"MENU2.obj"
"/OUT:MENU2.exe"
"MENU2.res"

E:\HomePage\SOURCE>

­YµLªk¥¿½T²ÕĶ¡AÀ³¸Ó¬O±zªºÀô¹Ò¨Ã¥¼³]©w¦n¡A½Ð°Ñ¦Ò²Ä¹s³¹ªº³]©w²ÕĶÀô¹Ò¡C©³¤U¤p¤ì°¸Â²³æªº¸Ñ»¡ MENU2.ASM¡A±z¥i¤U¸ü MENU2.RAR ÀÉ¡A¹ï·ÓµÛ¥H¤U»¡©úÅçÃҬݬݡG


¦b WM_CREATE °µ¤F¨º¨Ç¨Æ¡H

MENU2 ¦b WM_CREATE °T®§¤¤¡A¤j·§³£¬O¨ú±o¤@¨Ç¸ê®Æ¡A¥]¬A¨ú±o¦r§Î¸ê®Æ¡B¨ú±o¿ï³æ¤å¦r¤Î­I´ºÃC¦â¡B¨ú±oÀɮפl¿ï³æªº¦ì¤¸¹Ï¤j¤p¡A±µ¤U¨Ó«K¬O«Ø¥ß¦U¤l¿ï³æ¥H¤Î¨ä¤º¿ï¶µ¡C

GetTextMetrics API

¬°¤Fµe¥X¯S©w¦r§Î¡A¥H¤Î¨M©w¦r§Î¤l¿ï³æªº¤j¤p¡A¤p¤ì°¸¦b WM_CREATE ¤¤©I¥s¤F GetTextMetrics ¥H¨ú±o²{¦bÅã¥Üªº¦r§Î©Ê½è¡CGetTextMetrics ªº­ì«¬¬O¡G

BOOL GetTextMetrics(
  HDC          hdc,   // handle to device context
  LPTEXTMETRIC lptm   // pointer to text metrics structure
);

¦r§Î¬O GDI ª«¥ó¤§¤@¡A¦]¦¹¥²¶·¥ý¨ú±o³]³Æ¤º®e ( device context¡AÁY¼g¬° DC ) ¤§«á¤~¯àÀò±o¦r§Î¸ê®Æ¡C¦b Windows §@·~¨t²Î¤¤¨C­Óµøµ¡ªº¦r§Î¥i¥H¤£¦P¡A¦Ó¦b¦P¤@­Óµøµ¡ùؤ]¥i¯à¦³¨â­Ó¥H¤Wªº³]³Æ¤º®e¡A¨Ò¦p¤u§@°Ï©Î°O¾ÐÅé³]³Æ¤º®e¡A¦]¦¹­n¨úªº¬Y­Óµøµ¡ªº¦r§Î¸ê®Æ±o¥ý¨ú±o³]³Æ¤º®e¡C¦b WM_PAINT °T®§¤¤¡A¥H BeginPaint ¨ú±o³]³Æ¤º®e¥N½X¡A¥H EndPaint ÄÀ©ñ¡F¦b¨ä¥L°T®§¤¤¥Î GetDC ¨ú±o³]³Æ¤º®e¥N½X¡AµM«á¥H ReleaseDC ÄÀ©ñ³]³Æ¤º®e ( µy«á¦A´£ )¡CGetTextMetrics ªº²Ä¤@­Ó°Ñ¼Æ´N¬O¥Ñ GetDC ©Î BeginPaint ©Ò±o¨ìªº³]³Æ¤º®e¥N½X¡C²Ä¤G­Ó°Ñ¼Æ¬O¤@­Ó«ü¼Ð¡A«ü¦V¤@­ÓºÙ¬° TEXTMETRIC ªºµ²ºcÅé¦ì§}¡A·í GetTextMetrics ¦¨¥\ªºÀò±o¦r§Îªº¸ê®Æ®É¡A·|¦b¦¹µ²ºcÅé¶ñ¤W¦r§Îªº¸ê®Æ¡A¨Ã©ó EAX ¼È¦s¾¹¤¤¶Ç¦^¤@­Ó«D¹s­È¡CTEXTMETRIC µ²ºcÅé¤]¬O¤@­Ó«Ü½ÆÂøªºµ²ºcÅé¡A¨ä¦UÄæ¦ì»¡©ú¦p¤U¡A¨Ã°Ñ¦Ò¥k¤U¹Ï¡G

TEXTMETRIC              STRUCT
tmHeight                DWORD   ?
tmAscent                DWORD   ?
tmDescent               DWORD   ?
tmInternalLeading       DWORD   ?
tmExternalLeading       DWORD   ?
tmAveCharWidth          DWORD   ?
tmMaxCharWidth          DWORD   ?
tmWeight                DWORD   ?
tmOverhang              DWORD   ?
tmDigitizedAspectX      DWORD   ?
tmDigitizedAspectY      DWORD   ?
tmFirstChar             BYTE    ?
tmLastChar              BYTE    ?
tmDefaultChar           BYTE    ?
tmBreakChar             BYTE    ?
tmItalic                BYTE    ?
tmUnderlined            BYTE    ?
tmStruckOut             BYTE    ?
tmPitchAndFamily        BYTE    ?
tmCharSet               BYTE    ?
TEXTMETRIC              ENDS

¥Ñ¤W¹Ï¥k«Ü²M·¡¬Ý¥X tmHeight¡BtmAscent¡BtmDescent¡BtmInternalLeading¡BtmExternalLeading ©Ò¥Nªíªº·N¸q¡CtmAveCharWidth¡BtmMaxCharWidth ¤À§O¥Nªí¦r¤¸¥­§¡¼e«×»P³Ì¤j¼e«×¡A¹ï©w¼e¦rÅé¦Ó¨¥¡A¨Ò¦p¡yCourier New¡z©Î¤¤¤å¦r¡A¨ÓÁ¿¡A³o¨âªÌ¬O¬Û¦Pªº¡F¦ý¤£©w¼e¦rÅé¡A¨Ò¦p¡yTimes New Roman¡z¡A¦Ó¨¥¡A¨C­Ó¦r¥Àªº¼e«×¥¼¥²¤@¼Ë¡A¨Ò¦p¡yi¡z»P¡ym¡z´N¤£¦P¼e¡CtmWeight ¬O«ü¦r§Î²Ê²Ó¡A¥i¥H¥Ñ 0 ¨ì 900¡A¨C 100 ¬°¤@³æ¦ì¡A¼Æ­È¶V¤j¦rÅé¶V²Ê¡A¨£¤Uªí¡G

²Ê¡@²Ó¼Æ­È ²Ê¡@²Ó¼Æ­È
FW_DONTCARE0 FW_THIN100
FW_EXTRALIGHT¡BFW_ULTRALIGHT200 FW_LIGHT300
FW_NORMAL¡BFW_REGULAR400 FW_MEDIUM500
FW_SEMIBOLD¡BFW_DEMIBOLD600 FW_BOLD700
FW_EXTRABOLD¡BFW_ULTRABOLD800 FW_HEAVY¡BFW_BLACK900

tmOverhang ¬O«ü©w¦r¤¸ªºÃB¥~¼e«×¡A¥¦¬O¥Î©ó²ÊÅé¦r»P±×Åé¦r®É©Ò¦h¦û¥Îªº¼e«×¡CtmItalic¡BtmUnderlined¡BtmStruckOut ¤À§Oªí¥Ü¦r§Î¬°±×Åé¡B©³½u¡B§R°£½u¡F·í¬°¹s®É¡A¤£¨ã¤W­z¯S©Ê¡F¬°¹s®É¡Aªí¥Ü¨ã¦³¤W­z¯S©Ê¡C¦Ü©ó¨ä¥LÄæ¦ì¥»³¹¨Ã¨S¦³¥Î¨ì¡A¤p¤ì°¸¤]¤£¦h»¡¤F¡C¤@¯ë¦Ó¨¥¡A­n³]©w©Î¨ú±o¤å¦r¤j¤p¡A¥u»Ý¥Î¨ì tmHeight Äæ¦ì¡C

TEXTMETRIC ¨Æ¹ê¤W¦³¨âºØª©¥»¡AANSI »P UNICODE¡A¨âºØ¦¨­û¤£¤Ó¬Û¦P¡A¤U­±¥ªÃ䪺¬O ANSI ª©¡A¥kÃä«h¬O¸U°ê½Xª©¥»¡G

TEXTMETRICA             STRUCT                  TEXTMETRICW            STRUCT
  tmHeight              DWORD     ?             tmHeight               DWORD     ?
  tmAscent              DWORD     ?             tmAscent               DWORD     ?
  tmDescent             DWORD     ?             tmDescent              DWORD     ?
  tmInternalLeading     DWORD     ?             tmInternalLeading      DWORD     ?
  tmExternalLeading     DWORD     ?             tmExternalLeading      DWORD     ?
  tmAveCharWidth        DWORD     ?             tmAveCharWidth         DWORD     ?
  tmMaxCharWidth        DWORD     ?             tmMaxCharWidth         DWORD     ?
  tmWeight              DWORD     ?             tmWeight               DWORD     ?
  tmOverhang            DWORD     ?             tmOverhang             DWORD     ?
  tmDigitizedAspectX    DWORD     ?             tmDigitizedAspectX     DWORD     ?
  tmDigitizedAspectY    DWORD     ?             tmDigitizedAspectY     DWORD     ?
  tmFirstChar           BYTE      ?             tmFirstChar            WORD      ?
  tmLastChar            BYTE      ?             tmLastChar             WORD      ?
  tmDefaultChar         BYTE      ?             tmDefaultChar          WORD      ?
  tmBreakChar           BYTE      ?             tmBreakChar            WORD      ?
  tmItalic              BYTE      ?             tmItalic               BYTE      ?
  tmUnderlined          BYTE      ?             tmUnderlined           BYTE      ?
  tmStruckOut           BYTE      ?             tmStruckOut            BYTE      ?
  tmPitchAndFamily      BYTE      ?             tmPitchAndFamily       BYTE      ?
  tmCharSet             BYTE      ?             tmCharSet              BYTE      ?
TEXTMETRICA             ENDS                    TEXTMETRICW            ENDS

¥Ñ¤W­±ªº¤ñ¸û¥iª¾¡AANSI ª©¦@¦û 53 ­Ó¦ì¤¸²Õ¡A¦Ó¸U°ê½Xª©¥»¦û¤F 57 ­Ó¦ì¤¸²Õ¡A¨âªÌ³£¬O©_¼Æ­Ó¦ì¤¸²Õ¡C¦]¦¹¦b§â TEXTMETRIC µ²ºcÅé§@¬°°Ï°ìÅܼƮɡA­n¤p¤ß¨Ï¥Î¡A¦³¥i¯à·|Âл\«e¤@­Ó°Ï°ìÅܼƤ§­È¡C

GetDC »P ReleaseDC API

GetDC ¥i¥H¨ú±oµøµ¡¤u§@°Ïªº³]³Æ¤º®e¥N½X¡A¨ä­ì«¬¬°¡G

HDC GetDC(
  HWND hWnd   // handle to a window
);

¥¦¥u¦³¤@­Ó°Ñ¼Æ¡A´N¬Oµøµ¡¥N½X¡A¦pªG¦¨¥\¡A«h EAX ¼È¦s¾¹¶Ç¦^¦¹µøµ¡¤u§@°Ïªº³]³Æ¤º®e¥N½X¡F¦pªG¥¢±Ñ¡AEAX ¶Ç¦^ NULL¡C¦pªG hWnd ³]¬° 0¡A¨º»ò GetDC ±N¶Ç¦^¾ã­Ó¿Ã¹õªº³]³Æ¤º®e¥N½X¡A¥ç§Y®à­±ªº³]³Æ¤º®e¥N½X¡A¦b Win 98/2K ¤§«áªº¨t²Î¤¤¡A¦pªG hWnd ¬°¹s¡A«h¶Ç¦^²Ä¤@­Ó¿Ã¹õªº³]³Æ¤º®e¥N½X¡C·í¤£¶·Ã¸¹Ï®É¡A¥²¶·©I¥s ReleaseDC ÄÀ©ñ³]³Æ¤º®e¡A¥H¸`¬Ù¨t²Î¸ê·½¡AReleaseDC ªº­ì«¬¬O

int ReleaseDC(
  HWND hWnd,  // handle to window
  HDC  hDC    // handle to device context
);

­Y¦¨¥\ÄÀ©ñ³]³Æ¤º®e¡A«h EAX ¶Ç¦^ TRUE¡A§_«h¶Ç¦^ NULL¡C

¦b MENU2 ªº WM_CREATE °T®§¤¤¡AÁÙ­n¨ú±o¨t²Îªº¬Y¨ÇÃC¦â¡A¦p¿ï³æ­I´º¦â¡B¿ï³æ¤å¦rÃC¦âµ¥µ¥¡A³o¨ÇÃC¦â±N¦bµe¥X¦Ûø¿ï¶µ®É¶î¤W¥ú´ÎÃC¦â¤Î¤å¦rÃC¦â¤§¥Î¡A¦Ü©ó­n¨ú±o¨º¨ÇÃC¦â¡A½Ð°Ñ¦Ò¤U¹Ï¡G

§Ú­Ì§â¨C­Ó¿ï¶µ¬Ý¦¨¤@¶ô¯x§Î°Ï°ì¡A¤å¦r¬O¥Ñ³\¦h½uµe¤W¥hªº¡A¦b½u»P½u¤§¶¡ªºªÅ»Ø¬O­I´º¡A¥i¥Î SetBkColor ³]©wÃC¦â¡F¦Ó¤å¦rªºÃC¦â¥i¥Î SetTextColor ³]©w¡C­nª`·Nªº¬O¡ASetBkColor ¥u¯à³]©w¥]³ò¦b¤å¦rªº­I´ºÃC¦â¡A¤]´N¬O¤W¹Ï¤¤¬õ¦â¯x§Î½d³ò¤ºªºÃC¦â¡A¯x§Î¤§¥~ªºÃC¦âµLªk¥Ñ SetBkColor ³]©w ( ¯x§Î¤§¥~§Y¬°¥ú´Î )¡A¦]¦¹±o¥t¥~¥Î FillRect API ¨Ó°µ³o¥ó¨Æ¡C¤£¹L¦b WM_CREATE °T®§¶¥¬qùØ¡A§Ú­Ì¶È¶È¥u­n¨ú±oÃC¦â¨Ã¦s©ó´X­ÓÅܼÆùØ¡A¥H«K¦b©I¥s SetBkColor¡BSetTextColor ®É¨Ï¥Î¡A¦P®É¤]­n¨ú±oµe¨ê¥H©I¥s FillRect ®É¨Ï¥Î¡C¦Ó¥²¶·µ¥¨ì³B²z WM_DRAWITEM °T®§®É¡A¤~¯u¥¿¦a¥H©I¥s SetBkColor¡BSetTextColor ³]¦nÃC¦â¡A©I¥s DrawText¡BFillRect ¯u¥¿¦a§â¤å¦r¡B¥ú´Îªºµe¥X¨Ó¡A¨£µy«áªº¡y¦b WM_MEASUREITEM »P WM_DRAWITEM ¨â°T®§¤¤°µ¤F¨º¨Ç¨Æ¡H¡z¡C( ¦¹³B¤S¬O¤@¨Ò¡ADOS µ{¦¡³]­p»P Windows «Ü¤£¤@¼Ë¡C)

¦ý¦¹³B¥ý»¡©ú­n¨ú±oªº¥|ºØÃC¦â¡G¥¼³Q¿ï¨ìªº¤å¦rÃC¦â¡B¥¼³Q¿ï¨ìªº­I´ºÃC¦â¡B³Q¿ï¨ìªº¤å¦rÃC¦â¤Î³Q¿ï¨ìªº­I´ºÃC¦â¡A¤£¹LÆ[¹î¤W¹Ï¡A±z·|µo²{¥¼³Q¿ï¨ìªº­I´ºÃC¦â»P³Q¿ï¨ìªº¤å¦r¦P¦â¡A©Ò¥H¹ê»Ú¤W¥u­n¨ú±o¤TºØÃC¦â¡A¬Ò¥H GetSysColor ¨ú±o¡A¦s©ó dwTextColor¡BdwSelBkColor¡BdwSelTextColor¡C°£¦¹¤§¥~¡A¬°¤F¦b WM_DRAWITEM °T®§¤¤µe¥X¥ú´Î¡AÁÙ±o«Ø¥ß¨â­Óµe¨ê¡A¥H«K¦b WM_DRAWITEM °T®§¤¤©I¥s FillRect ¤§¥Î¡C³o¨â­Óµe¨ê¤À§O¬O hbrMenuBkHiligh ¤Î mi.hbrBack¡A«eªÌ¬O³Q¿ï¨ì¿ï¶µªº­I´ºµe¨ê¡A¤p¤ì°¸¥H³Q¿ï¨ìªº¿ï¶µ­I´ºÃC¦â¡A§Y dwSelBkColor¡A«Ø¥ß hbrMenuBkHiligh µe¨ê¡A³o­Ó¤u§@¥i¥H©I¥s CreateSolidBrush API §¹¦¨¡C

GetSysColor API

±ý¨ú±o¤å¦rÃC¦â¡B­I´ºÃC¦â³o¨Ç¸ê®Æ¥iÂǥѩI¥s GetSysColor API ¨ú±o¡AGetSysColor ­ì«¬¬°¡G

DWORD GetSysColor(
  int nIndex   // display element
);

GetSysColor ¥u¦³¤@­Ó°Ñ¼Æ¡AnIndex¡A¥¦ªí¥Ü­n¨ú±o¨º¤@­Óª«¥óªºÃC¦â¡AMENU2 ¤¤¨Ï¥Îªºª«¥ó¦C¦b¤Uªí¡G

nIndex¼Æ­È ·N¡@¡@¸q
COLOR_MENUTEXT07H ¿ï³æ¤¤¤å¦rÃC¦â
COLOR_MENU04H ¿ï³æªº­I´ºÃC¦â
COLOR_HIGHLIGHT0DH ³Q¿ï¨ì¿ï¶µªº­I´ºÃC¦â

¦pªG GetSysColor ¦¨¥\¨ú±oÃC¦â¡A¸ÓÃC¦â¦s©ó EAX¡A¦pªG¥¢±Ñ¡A«h¶Ç¦^ NULL¡C

CreateSolidBrush API

CreateSolidBrush ¬O¥Î¨Ó«Ø¥ß¬Y¤@ÃC¦âªºµe¨ê¡A¨ä­ì«¬¬°¡G

HBRUSH CreateSolidBrush(
  COLORREF crColor   // brush color value
);

¦¹ API ¥u¦³¤@­Ó°Ñ¼Æ¡AcrColor¡Aªí¥Ü©Ò«Ø¥ßµe¨êªºÃC¦â¡C¦pªG¦¨¥\ªº«Ø¥ßµe¨ê¡A«h¶Ç¦^µe¨ê¥N½X¡F¤Ï¤§¥¢±Ñ®É¡AEAX ¬° NULL¡C

GetMenuInfo API

¥t¤@­Ó¥¼³Q¿ï¨ìªº­I´ºµe¨ê¬O¦p¦ó¨ú±oªº©O¡H¤p¤ì°¸¬O¥Î©I¥s GetMenuInfo API ±o¨ì¡C¨Æ¹ê¤W GetMenuInfo ¥i¥H±o¨ì³\¦h¿ï³æªº¸ê®Æ¡AGetMenuInfo ªº­ì«¬¬°¡G

BOOL GetMenuInfo(
  HMENU       hmenu,      // handle for a menu
  LPCMENUINFO lpcmi,      // pointer to a MENUINFO structure
);

­n¨ú±o¸ê®Æªº¿ï³æ©ñ¦b²Ä¤@­Ó°Ñ¼Æ¡A©I¥s«áªð¦^ªº¸ê®Æ¦s©ó²Ä¤G­Ó°Ñ¼Æ©Ò«üªº¦ì§}¡C³o­Ó¦ì§}¬O¤@­ÓºÙ¬° MENUINFO ªºµ²ºcÅé¡A¨äÄæ¦ì»¡©ú¦p¤U¡G

MENUINFO        STRUCT
cbSize          DWORD   ?
fMask           DWORD   ?
dwStyle         DWORD   ?
cyMax           UINT    ?
hbrBack         HBRUSH  ?
dwContextHelpID DWORD   ?
dwMenuData      DWORD   ?
MENUINFO        ENDS

MENUINFO ªºµ²ºcÅ餧©ó GetMenuInfo ªºÃö«Y¡A©M MENUITEMINFO ¤§©ó GetMenuItemInfo ªºÃö«Y¬O¤@¼Ëªº¡A³o¨â­Óµ²ºcÅé¤]Ãþ¦ü¡CMENUINFO ¤¤ªº cbSize ¬O¦¹µ²ºcÅé¦û¥Îªº¦ì¤¸²Õ¼Æ¡A¥Î©ó¨t²Î¤À¿ëª©¥»¤§¥Î¡CfMask ¬O¥Î«ü¥Ü GetMenuInfo ¨Ó¨ú±o¨º¤@­ÓÄæ¦ì¤§¥Î¡A¸Ô²Ó±¡§Î¦p¤Uªí¡A·í±z§â fMask ³]¬° MIM_STYLE ®É¡Aªí¥Ü GetMenuInfo ±N¨ú±o dwStyle ªº¸ê®Æ¡F·í fMask ³]¬° MIM_MENUDATA ®É¡Aªí¥Ü GetMenuInfo ¨ú±o dwMenuData ªº¸ê®Æ¡C

fMask¨ú±oÄæ¦ì»¡¡@¡@©ú
MIM_STYLEdwStyle dwStyle ¥i¥H¬O¤U­±´XºØ¡G
  1. MNS_AUTODISMISS¡G·Æ¹«´å¼Ð¦b¿ï³æ¥~¬ù¤Q¬í«á¡A¿ï³æ·|¦Û°Ê®ø¥¢¡C
  2. MNS_CHECKORBMP¡G
  3. MNS_MODELESS¡G«D¼Ò¦¡ ( modeless ) ¿ï¶µ¡A
  4. MNS_NOCHECK¡G¦b¿ï¶µ¥ª°¼¤£¯d¤Ä¿ï²Å¸¹ªºªÅ¶¡¡C
MIM_MENUDATAdwMenuDataÀ³¥Îµ{¦¡¦Û¦æ©w¸q¤§¼Æ­È¡C
MIM_MAXHEIGHTcyMax¿ï¶µ³Ì¤j°ª«×¡A·í¶W¹L®É·|¥X²{±²¶b¡C
MIM_HELPIDdwContextHelpID¡@
MIM_BACKGROUNDhbrBack¿ï³æªº­I´ºµe¨ê

³o­Ó MENUINFO µ²ºcÅéÁÙ¦³³¡¥÷¤º®e¤p¤ì°¸©|¥¼·dÀ´¡A¤£¹L¹ï©ó§Ú­Ì­n¨ú±o¥¼³Q¿ï¾Ü¨ìªº­I´ºµe¨ê¤w¸g¨¬°÷¤F¡A´N¹³¤U­±µ{¦¡¤ù¬q¡G

MENUINFO        STRUCT
cbSize          DWORD   ?
fMask           DWORD   ?
dwStyle         DWORD   ?
cyMax           UINT    ?
hbrBack         HBRUSH  ?
dwContextHelpID DWORD   ?
dwMenuData      DWORD   ?
MENUINFO        ENDS
.data
mi      MENUINFO    <?>
¡K¡K¡K¡K¡K¡K¡K¡K
        mov     mi.cbSize,SIZEOF MENUINFO
        mov     mi.fMask,MIM_BACKGROUND
        invoke  GetMenuInfo,hMenu,OFFSET mi

¦¹³B¤p¤ì°¸¶È¬°¤FÀò±o­I´ºµe¨ê¡A¥H«K¦b¿ï¶µ¥¼³Q¿ï¾Ü®Éµe¥X¥ú´ÎÃC¦â¡C¦]¦¹¦b fMask ³]¬° MIM_BACKGROUND¡A«h·|¦b hbrBack ¶Ç¦^¥¼³Q¿ï¨ìªº­I´ºµe¨ê¡A³o­Ó­I´ºµe¨ê©M¥¼³Q¿ï¨ìªº¥ú´Îµe¨ê¬O¬Û¦Pªº¡C¦¹¥~ MENUINFO µ²ºcÅé¨Ã¨S¦³¦¬¿ý¦b WINDOWS.INC Àɮפ¤¡A¦]¦¹±o¦Û¦æ¦b­ì©lÀɤ¤©w¸q¡C

±µ¤U¨Óªºµ{¦¡¬O¨ú±o¦r§Î¤l¿ï³æùتº¦U¿ï¶µ­I´º¦ì¤¸¹Ï¤j¤p¡A³o®É¥i¥Î GetObject ¨ú±o¡A½Ð°Ñ¦Ò²Ä 13 ³¹ªº»¡©ú¡C¨ú±o¦r§Î­I´º¦ì¤¸¹Ï¡ABK.BMP¡A¼e»P°ª«á¡A¤À§O¦s¦b dwFontWidth¡BdwFontHeight¡A¤£¹L¦r§Î¤l¿ï³æ¤¤¦³¤­­Ó¿ï¶µ¡A©Ò¥H¨C¦¸¥u»ÝÅã¥Ü¤­¤À¤§¤@ªº°ª«×´N°÷¤F¡A¤p¤ì°¸§â dwFontHeight °£¥H¤­¤§«áªº°Ó¦s©ó dwFontHighSlit ÅܼÆùØ¡Aµ¥ WM_DRAWITEM ®Éµe¦b¿ï¶µªº³]³Æ¤º®eùØ¡C

±µ¤U¨Ó WM_CREATE °T®§¤¤³B²zªº´N¬O«Ø¥ß¥D¿ï³æ¡B¼u¥X¦¡¿ï³æ¤Î­×§ï¨t²Î¿ï³æ¡C¦b«Ø¥ß¥D¿ï³æ®É¡A¤À§O©I¥s¨â­Ó°Æµ{¦¡¡ACreateSubMenuFile¡BCreateSubMenuView¡A«Ø¥ßÀɮפl¿ï³æ¤ÎÀ˵ø¤l¿ï³æ¡C¦b CreateSubMenuFile ùØ¡A©I¥s¥|¦¸ LoadBitmap »P GetObject ¥H«K¥Ñ¸ê·½¤¤Àò±o¦ì¤¸¹Ï¥N½X ( ¦¹¦ì¤¸¹Ï¬O¥Î¨Ó¦bÀɮפl¿ï³æ¤¤¡AÅã¥Ü©ó¤å¦r«eªº¦ì¤¸¹Ï ) ¤Î¨ä¼e»P°ª¡A¨Ã¨Ï¦ì¤¸¹Ï¥N½X¦s¤J hbmpFile °}¦CùØ¡A¨Ï¦ì¤¸¹Ïªº¼e»P°ª¤À§O¦s¤J dwFileWidth¡BdwFileHeight ¨â°}¦C¤¤¡C©¹«á¦bø¥X¦ì¤¸¹Ï®É¡A¥u­n¥H¿ï¶µ¦ì¸m©Î¿ï¶µÃѧO½X·í°µ¨Ì¾Ú¡A´N¥i¥H¥Ñ°}¦C¤¤¬d¥X¦ì¤¸¹Ï¥N½X©M¨ä¼e»P°ª¡CCreateSubMenuFile °Æµ{¦¡¦P®É¤]­pºâ¿ï¶µªº²Ö¿n°ª«×¡A¨C­Ó¿ï¶µªº°ª«×¬O¦ì¤¸¹Ï°ª«×¦A¥[ 4¡A¥[¥|ªº¥Øªº¬O¨Ï¦ì¤¸¹Ï¤W¤U¦UªÅ¨âÂI¡AµM«á¦s©ó ybmPosition °}¦CùØ¡A³o­Ó°}¦C¥Î¨Ó¦s©ñ¨C­Ó¿ï¶µ¦b¿ï³æ¤¤°_©l°ª«×¦ì¸m¡A¥H«K¦b WM_DRAWITEM ®Éµe¥X¦ì¤¸¹Ï¤Î¤å¦r¡C¦¹³B¦³­Ó°ÝÃD¡A¤p¤ì°¸¤@ª½µLªk¦³®Ä¸Ñ¨M¡A¨º´N¬O¦p¦ó¨ú±o¤À¹j½u°ª«×¡A¦p¦³¥ý¶iª¾¹D¡A³Â·Ð§iª¾¡A¤p¤ì°¸¤£³Ó·P¿E¡C

±µµÛ CreateSubMenuFile °Æµ{¦¡¤¤ªº¤u§@¬O¦bÀɮפl¿ï³æ¤¤²K¥[¦Ûø¿ï¶µ¡A¦¹®É¥u»Ý­n³]©w¦n MENUITEMINFO ªº fType Äæ¦ì¬° MFT_OWNERDRAW §Y¥i¦A©I¥s InsertMenuItem §Y¥i¡A¤£»Ý­n¦b¦¹³Bµe¥X¿ï¶µ¤º®e¡A¦Ó¬Oµ¥³B²z WM_DRAWITEM ®É¦A°µ³o¥ó¨Æ¡C«Ø¥ßÀ˵ø¤l¿ï³æ¤]Ãþ¦ü¡A¤p¤ì°¸´N¤£¦A¦h»¡¤F¡C


¦b WM_MEASUREITEM »P WM_DRAWITEM ¨â°T®§¤¤°µ¤F¨º¨Ç¨Æ¡H

¦p«e©Ò»¡¡A¦b WM_MEASUREITEM °T®§¤¤¡A¥D­n¤u§@¬O³]©w¿ï¶µ°ª«×»P¼e«×¡A¤p¤ì°¸§Q¥Î EDX §@¬°«ü¦V MEASUREITEMSTRUCT µ²ºcÅ骺¦ì§}¡AµM«á§Q¥Î

        mov     MEASUREITEMSTRUCT.itemWidth[edx],ecx    ;¦ì¤¸¹Ïªº¼e
        mov     MEASUREITEMSTRUCT.itemHeight[edx],eax   ;¦ì¤¸¹Ïªº°ª

§â¦ì¤¸¹Ïªº¼e»P°ª¦s¤J MEASUREITEMSTRUCT µ²ºcÅ骺 itemWidth »P itemHeight Äæ¦ì¡C¦¹³B¥Hµ²ºcÅé¸ê®Æ«¬ºA¬°°¾²¾¦ì§}¡A°ò·Ç¦ì§}¬° EDX¡A´«¥y¸Ü»¡¦¹¨â¦æ¹ê»Ú¤W¬O¡G

        mov     [edx+0ch],ecx
        mov     [edx+10h],eax

¤W­±ªº 0ch¡B10h §Y¬°¬Û¹ï©ó MEASUREITEMSTRUCT µ²ºcÅé°_©l¦ì§}ªº itemWidth¡BitemHeight °¾²¾¦ì§}¡C­ì²z½Ð°Ñ¦Ò²Õ¦X»y¨¥²Ä 19 ³¹ªº»¡©ú¡C

¦Ü©ó¦b WM_DRAWITEM °T®§¤¤¡A´N¬Oø»s¥X¦U­Ó¦Ûø¿ï¶µ¡C­º¥ý«e¤K¦æ¬O§â lParam ©Ò«ü DRAWITEMSTRUCT µ²ºcÅ骺¸ê®Æ½Æ»s¨ì dis ¤¤¡A±µ¤U¨Ó°µªº¨Æ±¡¬O¨Ì·Ó¿ï¶µÃѧO½X ( ¿ï¶µÃѧO½X¦s©ó DRAWITEMSTRUCT µ²ºcÅ骺 itemID Äæ¦ìùØ ) ¤À¦¨¨âºØ¡G¤@ºØ¬O¦bÀɮפl¿ï³æªº¿ï¶µ¡A¦¹ºØ¸û³æ¯Â¡A©Ò­n°µªº¨Æ¬Oµe¥X¤å¦r«e¦ì¤¸¹Ï¥H¤Î¤å¦r¡C²Ä¤GºØ¬O¦b¦r§Î¤l¿ï³æªº¿ï¶µ¡A¦¹ºØ¿ï¶µ¥²¶·µe¥X­I´º¹Ï¤Î¤å¦r¡Aµe¥X¤å¦r®ÉÁÙ±o¨Æ¥ý³]¦n©Ò¥Î¦r§Î¡C¤£ºÞ¬O¨º¤@ºØ¿ï¶µ¡A³£­nµe¥X¦ì¤¸¹Ï¤Î¥ú´Î¡A¦]¦¹¥ý¥Î CreateCompatibleDC «Ø¥ß¤@¬Û¦Pªº¸Ë¸m¤º®e¡AµM«á¥Îµe¥X¯x§Îªº¤è¦¡¼ÒÀÀ¥ú´Î¡A¦Ó¦¹¥ú´ÎªºÃC¦â»P­I´º¦â¬Û¦P¡A³o­Ó¹Lµ{¥i¥Î FillRect¡C

FillRect API

ÅU¦W«ä¸q¡AFillRect ¬O¦b¤@¶ô¯x§Î°Ï°ì¶ñ¤JÃC¦â¡G

int FillRect(
  HDC    hDC,           // handle to device context
  CONST  RECT *lprc,    // pointer to structure with rectangle
  HBRUSH hbr            // handle to brush
);

hDC ¬O«ü³]³Æ¤º®e¥N½X¡A±z©Î³\ı±o©_©Ç¡A¦¹³B¬J¨S¦³©I¥s BeginPaint¡A¤]¨S¦³ GetDC¡A¨º»ò¨º¨Óªº hDC ©O¡HÁÙ°O±o¤§«e´£¨ì WM_DRAWITEM ªº lParam °Ñ¼Æ¤¤«K¥]§t¤F³]³Æ¤º®e¥N½X¡C©Î³\±z¥i¥H·Q¹³¡G·í Windows ­nµe¥X¤@¯ëªº¿ï¶µ®É¡A¨ä¤º³¡¥²©w¤]¦³¤@³]³Æ¤º®e¨Ñ¨t²Îø»s¤§¥Î¡A¦ý¬O¹J¨ì¨ã¦³ MFT_OWNERDRAW Ãþ«¬ªº¿ï¶µ®É¡A«o¬O¥æ¥Ñµ{¦¡ªºµøµ¡¨ç¦¡¦Û¦æø»s¡A¦]¦¹ÂÇ¥Ñ WM_DRAWITEM ªº DRAWITEMSTRUCT µ²ºcÅé±Nø»s©Ò»Ý¸ê®Æ¶Çµ¹µøµ¡¨ç¦¡¡A¨ä¤º«K¥]§t¤F³]³Æ¤º®e¥N½X¤Î³]³Æ¤º®eªº½d³ò¡C

lprc ¬O«ü¦V¤@­Ó´y­z¯x§Îªºµ²ºcÅé¡A¨äÄæ¦ì°Ñ¦Ò²Ä¤T³¹¡Chbr ¬Oµe¨ê¥N½X¡A¦¹µe¨ê±N³Q¥Î¨Ó¶ñ¤J«e­z¯x§Î½d³ò¤º¡A³o­Óµe¨ê¤]´N¬O§Ú­Ì¦b WM_CREATE ©Ò«Ø¥ßªº hbrMenuBkHiligh »P mi.hbrBack¡A¦Ü©ó­n¨Ï¥Î¨º¤@ºØ¡A¥Ñ·Æ¹«¬O§_²¾¨ì¸Ó¿ï¶µ¤W¨M©w¡A³o­Ó¥i¥H¥Ñ DRAWITEMSTRUCT ¤¤ªº itemState Äæ¦ì¨M©w¡A­Y¸ÓÄæ¦ìªº ODS_SELECTED ³Q³]©w ( ¬° 1 ®É ) ªí¥Ü·Æ¹«²¾¨ì¸Ó¿ï¶µ¤W­±¡A¦¹®É»Ý¥Î hbrMenuBkHiligh¡A¤Ï¤§«h¥Î mi.hbrBack¡C

¦b´yøÀɮפl¿ï³æùتº¿ï¶µ®É¡A¥ý¨ú±o¿ï¶µÃѧO½X¡A¿ï¶µÃѧO½X´î¥h 100h §Y¬°¿ï¶µ¦ì¸m¡A¦A­¼¥H¥|§Y±o¿ï¶µ¦b lpszFile¡BhbmpFile¡BdwFileWidth¡BdwFileHeight¡BybmPosition ¦U°}¦C¦ì§}¡A±µ¤U¨Ó´N¬O§â¿ï¶µ¤å¦r¦ì§}±À¤J°ïÅ|¡A±µµÛ©I¥s SelectObject ¿ï¾Ü¦ì¤¸¹Ï¥N½X ( ¦¹¥N½X¥Ñ hbmpFile Àò±o )¡A±µµÛ´N¬O©I¥s BitBlt §â°O¾ÐÅé³]³Æ¤º®e«þ¨©¨ì¿ï¶µ³]³Æ¤º®eùØ¡A¨ä¦ì¤¸¹Ï¤j¤p¥Ñ dwFileWidth¡BdwFileHeight ¨â°}¦C¨ú±o¡A¦Ó­n«þ¨©¨ì¿ï¶µ³]³Æ¤º®eªº¦ó³B«h¥Ñ ybmPosition °}¦C¨ú±o¡C±µµÛ³]©w¤å¦r­nµe¦b¦ó³B¡A¤p¤ì°¸³]¬°¦b¦ì¤¸¹Ï¤§«á¤»ÂIªº¦a¤è¡A¥Ñµ{¦¡

        add     dis.rcItem.left,6
        add     dis.rcItem.left,eax

¹F¦¨¡Cºò±µµÛ¬O³]©w¤å¦rÃC¦â»P¤å¦r­I´º¦â¡A¤À§O©I¥s SetTextColor »P SetBkColor ¨â­Ó Win32 API¡Cµ{¦¡¦p¤U¡G

        test    dis.itemState,ODS_SELECTED
        jz      n_sel0
        mov     ecx,dwSelTextColor
        push    dwSelBkColor
        jmp     @f
n_sel0: mov     ecx,dwTextColor
        push    dwSelTextColor          ;¨S³Q¿ï¾Üªº­I´º¦â§Y¬°³Q¿ï¨ìªº¤å¦rÃC¦â
@@:     invoke  SetTextColor,dis.hdc,ecx
        push    dis.hdc
        call    SetBkColor

³Ì«á¤@¦æ¤p¤ì°¸¨Ã«D¥Î

        invoke  SetBkColor,dis.hdc,­I´ºÃC¦â

³o¬O¦]¬°¦b©I¥s SetTextColor ¤§«e­I´º¦â´N¤w¸g³Q±À¤J°ïÅ|¤F ( ¦]¬°·Æ¹«´å¼Ð¬O§_¦b¿ï¶µ¤W¡A©ÒÅã¥Ü­I´º¦â¤£¦P¡A¦]¦¹±À¤J¤£¦P¤§ÃC¦â¡A¨£¬õ¦âªº¨º¨â¦æ )¡CÁÙ°O±o¡Ainvoke ¬O¤@­Ó°²«ü¥O¡A¥i¥H¤À¦¨³\¦h push «ü¥O¤Î¤@­Ó call «ü¥O¶Ü¡H­Y¤£°O±oªº¸Ü¡A½Ð°Ñ¦Ò²Ä¤@³¹¡C¤p¤ì°¸³o¼Ë¼g¬O¬°¤F¸`¬Ù´X­Ó¦ì¤¸²Õ¡A·íµM³o¼Ë·|³y¦¨ºûÅ@¤£©ö¡A³o¬O²Õ¦X»y¨¥ªº¯SÂI¡A¤£¶È¦b DOS µ¥ 16 ¦ì¤¸ªº Assembly ¦p¦¹¡A¦b Win32 Assembly ¤]·|¦³³o¼Ëªº¯S¦â¡C¦pªG¤£³o¼Ë¼gªº¸Ü¡A¤]¥i¥H¹³¤U­±³o¼Ë¡G

        test    dis.itemState,ODS_SELECTED
        jz      n_sel0
        mov     ecx,dwSelTextColor
        mov     edx,dwSelBkColor
        jmp     @f
n_sel0: mov     ecx,dwTextColor
        mov     edx,dwSelTextColor
@@:     push    edx
        invoke  SetTextColor,dis.hdc,ecx
        pop     edx
        invoke  SetBkColor,dis.hdc,edx

¤£¹L¦û¥Î¦ì¤¸²Õ¸û¦h¡A³t«×µyºC ( ¥i¯àºC­Ó´X©`¬í§a¡H)¡C

¦b´yø¦r§Î¤l¿ï³æ®É¡A¥ý¨ú±o¿ï¶µ¤å¦r¦ì§}¡A¦P¼Ë¤]±À¤J°ïÅ|¡A¦A¨Ì¦¹¦ì§}¤§¦r§Î«Ø¥ßÅÞ¿è¦r§Î¡A¥Î SelectObject ¿ï¾Ü¦¹·s«Ø¥ßªºÅÞ¿è¦r§Î¡C±µµÛ¨Ì¾Ú·Æ¹«´å¼Ð¬O§_¦b¿ï¶µ¤W¤À¦¨¨âºØ±¡§Î¡C²Ä¤@ºØ¬O·Æ¹«´å¼Ð¦b¿ï¶µ¤W¡A¦¹®É¥u»Ý³]©w¤å¦r¤Î¤å¦r­I´º¦â§Y¥i¡C²Ä¤GºØ±¡§Î¬O·Æ¹«´å¼Ð¤£¦b¿ï¶µ¤W®É¡A¦¹®É°£¤F¥²¶·³]©w¤å¦r¥~¡A¨Ã¤£»Ý­n³]©w¤å¦r­I´ºÃC¦â¡A³o¬O¦]¬°§Ú­Ì·Q§â¤å¦rªº­I´º³]¬°³z©úªº¡A³o¼Ë¤~¯à¸û§¹¾ãªºªí²{¥X­I´º¦ì¤¸¹Ï¤Wªº¬ü¤k¡A©Ò¥H¦¹³B²o¯A¤F¨â­Ó¤u§@¡G¥Î BitBlt µe¥X¦ì¤¸¹Ï¡A¥Î SetBkMode ³]©w³z©úªº­I´ºÃC¦â¡C±µµÛ¤£ºÞ·Æ¹«´å¼Ð¬O§_¦b¿ï¶µ¤W¡A³£¥²»Ý³]©w¤å¦rÃC¦â¡C³Ì«á¦Aµe¥X¤å¦r§Y¥i¡C©³¤U¬O³o¬qµ{¦¡©Ò¥Î¨ìªº Win32 API¡C

CreateFont API

CreateFont ¬O¥Î¨Ó«Ø¥ß¤@­ÓÅÞ¿è¦r§Î¡C¦pªGŪªÌ´¿¥Î¹L Lotus SmartSuite Word Pro¡BMS Word µ¥¤å®Ñ³nÅé¡A·Q¥²´¿¥Î¹L¦UºØ¤£¦Pªº¦r§Î¡C¤@ºØÅÞ¿è¦r§Î¥i¦³¤TºØ©Ê½è¡G¦r§Î¦WºÙ¡B¦r§Î¤j¤p¡B¦r§Î­·®æ¡C¤@¯ë¨Ï¥ÎªÌ¥i¯à·|¥ý¿ï¨º¤@ºØ¦r§Î¦WºÙ¡A¨Ò¦p¡yCourier New¡z¡B¡y·s²Ó©úÅé¡zµ¥¡AµM«á¬O¦r§ÎÂI¼Æ¤j¤p¡A±µµÛ¬O¦r§Î­·®æ¡A¨Ò¦p§_±×Åé¡Bµ§µe²Ê²Ó¡B¬O§_¦³©³½uµ¥µ¥¡C­nµe¥X¦hÅܪº¦r§Î³£±o¥ý«Ø¥ßÅÞ¿è¦r§Î¤~¥i¥H¡A§Y¨Ï±z­nÅã¥Üªº¦r§Î³£¬O¦W¬° Times New Roman¡A¦ý¤@¬O±×Åé¡B¤@¬O§t¦³©³½u¡A¨º»ò±z¤]»Ý«Ø¥ß¨â­ÓÅÞ¿è¦r§Î¡AµM«á¦bµe¥X¦r¦ê«e¡A¥Î SelectObject ¿ï¾Ü¤£¦PªºÅÞ¿è¦r§Î¡A¦A¥H DrawText µe¥X¡CÅÞ¿è¦r§Î¦b¤£¨Ï¥Î®É¡AÀ³¸Ó¥Î DeleteObject ±N¥L§R°£¡A¥H§K¯Ó¶O¹L¦h¸ê·½¡C¤@¯ë¨Ó»¡¡A·í¿ï¥Î¤@­Ó·sªºÅÞ¿è¦r§Î®É¡AªºÅÞ¿è¦r§Î¤j·§´N¥Î¤£µÛ¤F¡A«ê¦n SelectObject ´N¬O¶Ç¦^ªºÅÞ¿è¦r§Î¡A¦]¦¹¤p¤ì°¸´N¥ß§Y±NªºÅÞ¿è¦r§Î§R°£¤F¡C»¡¤F³o»ò¦h¡A©³¤U¨Ó¬Ý¬Ý CreateFont ªº­ì«¬¡G

HFONT CreateFont(
  int     nHeight,             // logical height of font
  int     nWidth,              // logical average character width
  int     nEscapement,         // angle of escapement
  int     nOrientation,        // base-line orientation angle
  int     fnWeight,            // font weight
  DWORD   fdwItalic,           // italic attribute flag
  DWORD   fdwUnderline,        // underline attribute flag
  DWORD   fdwStrikeOut,        // strikeout attribute flag
  DWORD   fdwCharSet,          // character set identifier
  DWORD   fdwOutputPrecision,  // output precision
  DWORD   fdwClipPrecision,    // clipping precision
  DWORD   fdwQuality,          // output quality
  DWORD   fdwPitchAndFamily,   // pitch and family
  LPCTSTR lpszFace             // pointer to typeface name string
);

nEscapement¡BnOrientation ¬O«ü°f®É°w±ÛÂ઺¨¤«×¡A¥H 0.1 «×¬°³æ¦ì¡CÁ|¨Ò»¡©ú¡G­Y nEscapement ¬° 900 ®É¡Aªí¥Ü¾ã¦æ¦r¦ê°f®É°w±ÛÂà 90 «×¡F­Y nOrientation ¬° 450¡A«h¬O¨C­Ó¦r°f®É°w±ÛÂà 45 «×¡C( ¦ý¬O nEscapement ¦ü¥G¤£¹³ MSDN ©Ò»¡ªº³o¼Ë¡A¤p¤ì°¸¸Õ¤£¥X¨Ó¡AÁٽнѦì«e½ú§iª¾­ì¦]¡C )

fnWeight ¬O«ü¦r§Îªº²Ê²Ó¡A»P TEXTMETRIC µ²ºcÅ餤ªº tmWeight Äæ¦ì·N¸q¬Û¦P¡C±µ¤U¨Óªº fdwItalic¡BfdwUnderline¡BfdwStrikeOut ¤À§Oªí¥Ü¬O§_±×Åé¡B¦³©³½u¡B¦³§R°£½u¡A¦pªG±×Åé¡B¦³©³½u¡B¦³§R°£½uªº¸Ü«h¥Î TRUE¡A§_«h¬° FALSE¡CfdwCharSet ªí¥Ü¦r¤¸¶°¡A¥i¥H¬O ANSI_CHARSET¡BBALTIC_CHARSET¡BCHINESEBIG5_CHARSET ( ¥¿Å餤¤å BIG-5 ½X )¡BDEFAULT_CHARSET¡BEASTEUROPE_CHARSET¡BGB2312_CHARSET¡BGREEK_CHARSET¡BHANGUL_CHARSET¡BMAC_CHARSET¡BOEM_CHARSET¡BRUSSIAN_CHARSET¡BSHIFTJIS_CHARSET¡BSYMBOL_CHARSET¡BTURKISH_CHARSET¡A¦pªG¬O NT/2K ¥H¤Wªºª©¥»¡AÁÙ¥i¥H¥Î HEBREW_CHARSET¡BARABIC_CHARSET¡BTHAI_CHARSET¡ClpszFace ¬O«ü¦V¤@­Ó¥H NULL ¬°µ²§Àªº¦r¦ê¡A¦¹¦r¦ê«ü©w¦r§Î¦WºÙ¡C

¦pªG¦¨¥\ªº«Ø¥ßÅÞ¿è¦r§Î¡AEAX ·|¶Ç¦^·sªºÅÞ¿è¦r§Î¥N½X¡F§_«h¶Ç¦^ NULL¡C¦¹ÅÞ¿è¦r§Î¥N½X´N¬O§Y±N³Q SelectObject ©Ò¿ï¤J¨ì³]³Æ¤º®eùتº¡C

SetBkMode API

³o­Ó API ¬O¥Î¨Ó³]©w¤å¦rªº­I´º¡B«D PS_SOLID µeµ§¡B¬Y¨Çµe¨ê¤¤­I´ºªº¼Ò¦¡¡C¬Y¨Çµeµ§ ( ¨Ò¦pµê½uµeµ§ ) ©Îµe¨ê ( ±×½u¹Ï®× ) ªº­I´º¥H¤Î¤å¦r­I´º¥i¥HÅã¥XÃC¦â©Î¬O¤£¨ü¼vÅTªº¡CSetBkMode ­ì«¬¬°¡G

int SetBkMode(
  HDC hdc,      // handle of device context
  int iBkMode   // flag specifying background mode
);

iBkMode ¥i¥H¦³¨âºØ¿ï¾Ü¡GOPAQUE »P TRANSPARENT¡A«eªÌ¬°¤£³z©úªº¡A¥ç§YÅã¥Ü­I´ºÃC¦â¡F«áªÌ¬°³z©úªº¡A¥ç§Y¤£¨ü­I´º¦â¤§¼vÅT¡C


«á°O

MENU2 ªºÁ¿¸Ñ¤j­P´N¬O¦p¦¹¡A¦³Ãö¦p¦ó¨Ì¾Ú¬Y¨Ç¸ê®Æ³]©w¿ï³æ¡A¥i°Ñ¦Òªþ¿ý¤@¡@CPUID ¤¶²Ð¡C


¦^¨ì­º­¶¡A ¨ì²Ä¤Q¤­³¹¡A ¨ì²Ä¤Q¤C³¹