¦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
¤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
«Ø¥ß¿ï³æªº¤èªk¡A³Ì±`¥Îªº¬O¦b¸ê·½´yzÀɤ¤«Ø¥ß 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
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
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¸ê·½´yzÀɤ¤«Ø¥ß¿ï³æ¡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 ¸ê·½´yzÀɪº¤º®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¡CY§â²Ä 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
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_BITMAP | hbmpItem | 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_CHECKMARKS | hbmpChecked 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¤Ä¿ïªº¿ï¶µ¡FY¦b fType ¤]¨S«ü©w¡A«h¥H¤@Ó¤p¤Ä¤Äªí¥Ü³Q¤Ä¿ïªº¿ï¶µ¡C |
MIIM_DATA | dwItemData | MIIM_DATA ¥i¥H¥Ñµ{¦¡¦Û¦æ©w¸q¼ÆÈ¡A¦ý¤p¤ì°¸¤~²¨¾Ç²L¤£ª¾¥i¥H«ç»ò¥Î¡C³]©w MIIM_DATA ®É¡AdwItemData ¥i¥H³]©w¤@Ó 32 ¦ì¤¸¾ã¼Æ¡C |
MIIM_FTYPE | fType | ¿ï¶µ¥~Æ[¤À¦¨³\¦hºØÃþ¡A¦³¤À¹j½u¡B¦ì¤¸¹Ï¡B¤å¦rµ¥¡A©Ò¥Hn¨ú±o©Î³]©w¤£¦P¥~Æ[®É¡A¥ý§â fMask ³]¬° MIIM_TYPE¡A¦A©ó fType °µ¶i¤@¨B³]©w¡C |
MIIM_ID | wID | ·í fMask ³]©w MIIM_ID ®É¡Aªí¥Ün³]©w¿ï¶µªºÃѧO½X¡A¸ÓÃѧO½X¦s©ó wID Äæ¦ì¡C |
MIIM_STATE | fState | ·í fMask ³]©w MIIM_STATE ®É¡Aªí¥Ü³]©w¿ï¶µªºª¬ºA¡A¿ï¶µªºª¬ºA¥i¥H¦³¤U±´XºØ¡G
|
MIIM_STRING | dwTypeData cch |
·í fMask ³]¬° MIIM_STRING ®É¡Aªí¥Ü¥i³]©w©Î¨ú±o¿ï¶µªº¤å¦r¡A¦Ó¿ï¶µªº¤å¦r¦s©ñ¦b dwTypeData ©Ò«üªº¦ì§}ùØ¡Aªø«×¬° cch ( ³æ¦ì¬°¦r¤¸ )¡C |
MIIM_SUBMENU | hSubMenu | ·í 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_TYPE | fType 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
|
GetMenuItemInfo ¥i¥H¨ú±o¿ï¶µ¸ê®Æ¡A¨ä쫬¬°¡G
BOOL GetMenuItemInfo( HMENU hMenu, UINT uItem, BOOL fByPosition, LP lpmii );
©I¥s GetMenuItemInfo ¤§«e¥ý§â lpmii «ü¦V¤@Ó MENUITEMINFO µ²ºcÅé¡An¨ú±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 );
¦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
¨ã¦³ MFT_OWNERDRAW Äݩʪº¿ï¶µ©Î¾Ö¦³¦Ûø·®æªº±±¨î¶µ ( ¨£²Ä 12 ³¹ ) ·|¦bnø»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¡AYµ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·Qnªº¼ÆȨӳ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_MENU | 1 | ¨ã¦³ MFT_OWNERDRAW ªº¿ï¶µ |
ODT_LISTBOX | 2 | ¨ã¦³ LBS_OWNERDRAWFIXED ©Î LBS_OWNERDRAWVARIABLE ·®æªº²M³æ |
ODT_COMBOBOX | 3 | ¨ã¦³ CBS_OWNERDRAWFIXED ©Î CBS_OWNERDRAWVARIABLE ·®æªº½Æ¦X®Ø |
ODT_BUTTON | 4 | ¨ã¦³ BS_OWNERDRAW ·®æªº«ö¶s±±¥ó |
ODT_STATIC | 5 | ¨ã¦³ 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
·í¨Ï¥ÎªÌªº·Æ¹«´å¼Ð¦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¦¡¿ï³æ¬O«ü¨Ï¥ÎªÌ¦b¤u§@°Ï¤¤«ö¤U·Æ¹«¥kÁä ( ·íµM±z¤]¥i¥H¥Î¥ªÁä¤Þµo¥¦ ) ©ÒÂÛ¥Xªº¿ï³æ¡A³oºØ¿ï³æµLªk¥Î¸ê·½´yzÀɨƥý©w¸q¡A¥²¶·¥Î CreatePopupMenu API »s§@¡A¦]¦¹¤ñ¸û³Â·Ð¡C¤£¹L©¯¹Bªº¬O¡A¼u¥X¦¡¿ï³æªº¤l¿ï³æ«o¥i¥H¦b¸ê·½´yzÀɤ¤©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 ¥Î¨Ó«Ø¥ß¤@ӪŵL¤@ª«ªº¼u¥X¦¡¿ï³æ¡A¨ä쫬¦p¤U¡G
HMENU CreatePopupMenu(VOID);
¥¦¨S¦³°Ñ¼Æ¡A¦pªG¦¨¥\ªº«Ø¥ß¼u¥X¦¡¿ï³æ¡ACreatePopupMenu ¶Ç¦^©Ò«Ø¥ßªº¼u¥X¦¡¿ï³æ¥N½X¡FY¥¢±Ñ¡A«h¶Ç¦^ NULL¡C
¼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 ¬OnÅã¥Üªº¼u¥X¦¡¿ï³æ¥N½X¡CuFlags ¬O«ü¼u¥X¦¡¿ï³æÅã¥Üªº¦ì¸m»P¨Ï¥ÎªÌ«ö¤U·Æ¹«¥kÁä®É¡A·Æ¹«´å¼Ð¦ì¸mªºÃö«Y¡AuFlags ¥i¥H¬O¤U±¼ÆÈ¡G
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²Î¿ï³æ¤@¯ë¬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 ¬On¨ú±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¼Ð¡CY lParam ¬°¹s¡Aªí¥Ü¨Ï¥ÎªÌ¥Î¼Æ¦rÁä¿ï¾Ü¨t²Î¿ï³æ¡AY¬°¡Ð1¡Aªí¥Ü¨Ï¥ÎªÌ¥Î¥[³tÁä¿ï¾Ü¨t²Î¿ï³æ¡C
©³¤Uªºµ{¦¡¡AMENU2¡Aºt¥Ü¤F¤Wz©Ò´£¨ìªº¤@¨Ç¥DÃD¡A¥]§t«Ø¥ß¥D¿ï³æ¤Î¨ä¤l¿ï³æ¡B«Ø¥ß¼u¥X¦¡¿ï³æ¡Bקï¨t²Î¿ï³æ¡A¦P®É¤]¥Ü½d¤F¦Ûø¿ï¶µ¡C¨ä°õ¦æµe±¦p¤U¹Ï¡G
n¦¨¥\²ÕĶ MENU2¡A»Ýn«Ü¦hÀɮסA¤j³¡¤À¬O¦ì¤¸¹Ï¡A³o¨Ç¦ì¤¸¹Ï¦b¿ï¶µ¤å¦r¤§«e¡A¥¦Ì³£¦b¸ê·½´yzÀÉ¡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
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
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
¬°¤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_DONTCARE | 0 | FW_THIN | 100 |
FW_EXTRALIGHT¡BFW_ULTRALIGHT | 200 | FW_LIGHT | 300 |
FW_NORMAL¡BFW_REGULAR | 400 | FW_MEDIUM | 500 |
FW_SEMIBOLD¡BFW_DEMIBOLD | 600 | FW_BOLD | 700 |
FW_EXTRABOLD¡BFW_ULTRABOLD | 800 | FW_HEAVY¡BFW_BLACK | 900 |
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¤£¨ã¤Wz¯S©Ê¡F¬°¹s®É¡Aªí¥Ü¨ã¦³¤Wz¯S©Ê¡C¦Ü©ó¨ä¥LÄæ¦ì¥»³¹¨Ã¨S¦³¥Î¨ì¡A¤p¤ì°¸¤]¤£¦h»¡¤F¡C¤@¯ë¦Ó¨¥¡An³]©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Åé§@¬°°Ï°ìÅܼƮɡAn¤p¤ß¨Ï¥Î¡A¦³¥i¯à·|Âл\«e¤@Ó°Ï°ìÅܼƤ§È¡C
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
¦ý¦¹³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¥un¨ú±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
±ý¨ú±o¤å¦rÃC¦â¡BI´ºÃ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_MENUTEXT | 07H | ¿ï³æ¤¤¤å¦rÃC¦â |
COLOR_MENU | 04H | ¿ï³æªºI´ºÃC¦â |
COLOR_HIGHLIGHT | 0DH | ³Q¿ï¨ì¿ï¶µªºI´ºÃC¦â |
¦pªG GetSysColor ¦¨¥\¨ú±oÃC¦â¡A¸ÓÃC¦â¦s©ó EAX¡A¦pªG¥¢±Ñ¡A«h¶Ç¦^ NULL¡C
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
¥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_STYLE | dwStyle | dwStyle ¥i¥H¬O¤U±´XºØ¡G
|
MIM_MENUDATA | dwMenuData | À³¥Îµ{¦¡¦Û¦æ©w¸q¤§¼ÆÈ¡C |
MIM_MAXHEIGHT | cyMax | ¿ï¶µ³Ì¤j°ª«×¡A·í¶W¹L®É·|¥X²{±²¶b¡C |
MIM_HELPID | dwContextHelpID | ¡@ |
MIM_BACKGROUND | hbrBack | ¿ï³æªº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Àò±oI´ºµ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¥un¥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
¦p«e©Ò»¡¡A¦b WM_MEASUREITEM °T®§¤¤¡A¥Dn¤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¥XI´º¹Ï¤Î¤å¦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¦â»PI´º¦â¬Û¦P¡A³oÓ¹Lµ{¥i¥Î FillRect¡C
Å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¤@Ó´yz¯x§Îªºµ²ºcÅé¡A¨äÄæ¦ì°Ñ¦Ò²Ä¤T³¹¡Chbr ¬Oµe¨ê¥N½X¡A¦¹µe¨ê±N³Q¥Î¨Ó¶ñ¤J«ez¯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¡AY¸ÓÄæ¦ìªº 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¤å¦rnµ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¤å¦rI´º¦â¡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 ¤§«eI´º¦â´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¶Ü¡HY¤£°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¤Î¤å¦rI´º¦â§Y¥i¡C²Ä¤GºØ±¡§Î¬O·Æ¹«´å¼Ð¤£¦b¿ï¶µ¤W®É¡A¦¹®É°£¤F¥²¶·³]©w¤å¦r¥~¡A¨Ã¤£»Ýn³]©w¤å¦rI´ºÃC¦â¡A³o¬O¦]¬°§ÚÌ·Q§â¤å¦rªºI´º³]¬°³z©úªº¡A³o¼Ë¤~¯à¸û§¹¾ãªºªí²{¥XI´º¦ì¤¸¹Ï¤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 ¬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µ¥µ¥¡Cnµe¥X¦hÅܪº¦r§Î³£±o¥ý«Ø¥ßÅÞ¿è¦r§Î¤~¥i¥H¡A§Y¨Ï±znÅã¥Üªº¦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Á|¨Ò»¡©ú¡GY nEscapement ¬° 900 ®É¡Aªí¥Ü¾ã¦æ¦r¦ê°f®É°w±ÛÂà 90 «×¡FY 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
³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¤Î¤å¦rI´º¥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
MENU2 ªºÁ¿¸Ñ¤jP´N¬O¦p¦¹¡A¦³Ãö¦p¦ó¨Ì¾Ú¬Y¨Ç¸ê®Æ³]©w¿ï³æ¡A¥i°Ñ¦Òªþ¿ý¤@¡@CPUID ¤¶²Ð¡C