Ch 12 ¹ï¸Ü²°(5)¤l±±¥óÃC¦â

«e´X³¹´£¨ì¦p¦ó¹ê§@¹ï¸Ü²°¡A¦ý¤p¤ì°¸·Q¡A±z¤]·|·Q¸ÕµÛ§ïÅܳo¨Ç¹ï¸Ü²°©Î¦UºØ¤l±±¨î¤¸¥óªºÃC¦â§a¡H¦b³o¤@³¹ùØ¡A¤p¤ì°¸´N¹ï³o­Ó¥DÃD§@¤@¨Ç²³æªº¤¶²Ð¡C


¨t²ÎÃC¦â

¨Ï¥Î¹L Windows §@·~¨t²Îªº¤H¡A¥²©w·|µo²{¡A¨C­Óµøµ¡´X¥Gªø±o¤@­Ó¼Ë¨à¡A¥]§t¹ï¸Ü²°ªºÃC¦â¡A¨Æ¹ê¤W¤£¶È¹ï¸Ü²°ªºÃC¦â¡A©Ò¦³µøµ¡ªºÃC¦â¡A¥]§t¼ÐÃDÄæ¡B¿ï³æ¡Bª¬ºAÄ檺ÃC¦â¤]³£¬O¤@­Ó¼Ë¨à¡C¬°¤°»ò·|³o¼Ë©O¡H­ì¨Ó¦b Windows §@·~¨t²Î¡A¹ï®à­±¡B¼ÐÃDÄæ¡B±²¶b¡K¡Kµ¥³£¥Î©T©wªºÃC¦â¡AºÙ¬°¨t²ÎÃC¦â¡C¦pªG±z¹ï³o¨ÇÃC¦â¤£º¡·N¡A¤]¥i¥H¦Û¤v­×§ï¨t²ÎÃC¦â¡CWin XP ªº¨Ï¥ÎªÌ¡A¥i¥H¨ì¡y±±¨î¥x¡z¡÷¡yÅã¥Ü¡zªº¡y¥~Æ[¡z¼ÐÅÒ¤¤«ö¡y¶i¶¥¡z«ö¶s§ó§ï¥¦¡A¦b¤U¹Ï¤¤ªº¡y¶µ¥Ø(I)¡z¦¡¤@­Ó½Æ¦X±±¥ó¡A¥i¥H¦b¨ä²M³æ¤¤¿ï¾Ü±z·Q§ïÅܪº¶µ¥Ø¡G

§ó§ï¨t²ÎÃC¦â¡A¤£¬O§ïÅܹï¸Ü²°ÃC¦â³Ì¦nªº¤èªk¡A¦]¬°°²¦p±z¥Î³oºØ¤è¦¡§ïÅܹï¸Ü²°ªºÃC¦â¡A¨º»ò¨t²Î¤¤©Ò¦³¹ï¸Ü²°ªºÃC¦â³£·|ÀH¤§§ïÅÜ¡C¦Ó©³¤Uªº¤èªk¬OÂǥѳB²z°T®§ªº¤è¦¡§ïÅܹï¸Ü²°ªºÃC¦â¡A³o¼Ëªº¸Ü¥u·|§ïÅܹï¸Ü²°µ{¦¡¥»¨­ªºÃC¦â¡A¦Ó¤£·|§ïÅܨä¥Lµøµ¡ªºÃC¦â¡C


¤l±±¥óªºÃC¦â

WM_CTLCOLOR* °T®§

¤p¤ì°¸¦b¤¶²Ð³o¨Ç±±¨î¤¸¥ó®É¡A´¿´£¤Î±±¨î¤¸¥ó¬O Win32 ¨t²Î¤º¤w¸g¹w¥ý©w¸q¦nÃþ§Oªº¤lµøµ¡¡A¦Ó³o¨Ç±±¨î¤¸¥óªºÃ¸»s¡B³B²zµ¥¦æ¬°³£¥Ñ¨t²Î¤º³¡ªº¹ï¸Ü²°ºÞ²z¾¹²ÎÄwºÞ²z±±¨î¡C¤@¯ë¦Ó¨¥¡A¹ï¸Ü²°ºÞ²z¾¹¬O¥Hµù¥U®É¡AWNDCLASSEX µ²ºcÅ餺ªº hbrBackground µe¨ê¬°¹ï¸Ü²°µÛ¦â¡A¨ä¥L¦p½s¿è®Ø¡BÀRºA±±¥óµ¥¤]³£¬O¥H¨t²ÎÃC¦âµÛ¦â¡C

¦ý¬O§Ú­Ì¦³¾÷·|¥i¥H­×§ï³o¨Ç¤º©wªºÃC¦â¡C¹ï¸Ü²°ºÞ²z¾¹·|©I¥s DialogBoxParam API °Ñ¼Æ©Ò«ü©wªº¹ï¸Ü²°¨ç¦¡¨Ó³B²z§Ú­Ì·P¿³½ìªº°T®§ ( ·í¹ï¸Ü²°¨ç¦¡µ²§ô±ýªð¦^¹ï¸Ü²°ºÞ²z¾¹®É¡A³o¨Ç³B²z¹Lªº°T®§¶Ç¦^ TRUE¡A¦Ó¨ä¾l¶Ç¦^ FALSE Åýµ¹¹ï¸Ü²°ºÞ²z¾¹³B²z )¡C°²¦p·Q­n§ó§ï¹ï¸Ü²°ÃC¦â¡A¥²¶·¨Ï¹ï¸Ü²°¨ç¦¡³B²z¤@¨Ç¦³ÃöÃC¦âªº°T®§¡C

³o¨Ç°T®§¬O

¨ä¥L¨Ì¦¹Ãþ±À¡C¹ï¸Ü²°ºÞ²z¾¹¦bø»s±±¨î¤¸¥ó®É¡A©M§Ú­Ì¦b¤u§@°Ïø¹ÏÃþ¦ü¡A³£±o¥ý¨ú±o³o¨Ç±±¨î¤¸¥óªº³]³Æ¤º®e ( device context ) ¥N½X¡AµM«á¦A°w¹ï³o­Ó³]³Æ¤º®e¥N½Xø¹Ï¡C¦pªG§Ú­Ì¤£³B²z WM_CTLCOLOR* °T®§¡A¨º»ò¹ï¸Ü²°³B²zµ{¦¡´N¥H¤º©wªºµe¨êø»s¤å¦rÃC¦â©Î­I´ºÃC¦â¡C¦pªG³B²z WM_CTLCOLOR* °T®§®É¡A¨t²Î¶Çµ¹¹ï¸Ü²°¨ç¦¡ªº WM_CTLCOLOR* °T®§ùØ©Ò¥]§tªº wParam °Ñ¼Æ¡A´N¬O³]³Æ¤º®e¥N½X¡A¦Ó lParam °Ñ¼Æ¬O±±¨î¤¸¥ó¥N½X¡C³]©w¤å¦r¤Î­I´ºÃC¦âªº¤èªk¡A¤@¯ë¬O©I¥s SetTextColor API ³]©w¤å¦rÃC¦â¡A©I¥s SetBkColor API ³]©w­I´ºÃC¦â¡A¨Ã¥B¶Ç¦^¤@­Óµe¨ê¨Ñ¹ï¸Ü²°ºÞ²z¾¹µÛ¦â¡Cª`·N¡AWM_CTLCOLOR* °T®§¤£¶Ç¦^ TRUE¡A¦Ó¬O¶Ç¦^µe¨ê¡C¹ï¸Ü²°ºÞ²z¾¹±N·|¥H¦¹µe¨ê¬°¹ï¸Ü²°ªº¤l±±¥óµÛ¦â¡C

¦ý¬O¡ASetTextColor ©M SetBkColor ¨Ã¤£·|«Ø¥ßµe¨ê¡A©Ò¥H¤@¯ë³£±o¥ý¦bµ²§ô WM_CTLCOLOR* °T®§¤§«e¡A«Ø¥ß¤@­Óµe¨ê¡A¦Ó³o­Óµe¨êªºÃC¦â©M SetBkColor ¬Û¦P¡C«Ø¥ßµe¨êªº®É¾÷¥i¥H¦b³B²z WM_CTLCOLOR* °T®§®É¡A¤]¥i¥H¦b³B²z WM_INITDIALOG ®É¡A¤£¹L¬°¤F½T«O¥u«Ø¥ß¤@­Óµe¨ê¡A³Ì¦n¬O¦b WM_INITDIALOG ®É«Ø¥ß¡C·íµ{¦¡µ²§ô®É¡A¤]´N¬O³B²z WM_CLOSE °T®§®É¡A³o¨Çµe¨ê¤]¥Î¤£µÛ¤F¡AÀ³¸Ó§R°£³o¨Çµe¨ê¡C

SetTextColor ©M SetBkColor API

©³¤U¤¶²Ð SetTextColor¡BSetBkColor ³o¨â­Ó API ªº¥Îªk¡CSetTextColor ¬O¥Î¨Ó¹ï¬Y­Ó³]³Æ¤º®e³]©w¯S©wªºÃC¦â¡A¨ä­ì«¬¬O¡G

COLORREF SetTextColor(
    HDC         hdc,    // handle of device context  
    COLORREF    crColor // text color 
   );

hdc ¬O³]³Æ¤º®e¡A¤@¯ë¥i¥H¦b wParam ¤¤¨ú±o¡AcrColor ¬O±z­n³]©wªºÃC¦â¡A½Ð°Ñ¦Ò²Ä¥|³¹ªº»¡©ú¡CSetTextColor ªº¶Ç¦^­È¬O­ì¨Ó¤å¦rÃC¦â¡C©³¤U¬O SetBkColor ªº­ì«¬¡G

COLORREF SetBkColor(
    HDC         hdc,    // handle of device context  
    COLORREF    crColor // background color value
   );

¨ä°Ñ¼Æ»P¶Ç¦^­È©M SetTextColor ¬Û¦P¡A´N¤£ÂØ­z¤F¡C

«ö¶s­·®æ¡GBS_OWNERDRAW

°£¤F«ö¶s±±¥ó¥H¥~¡A­n§ïÅܤl±±¥óªºÃC¦â«ö·Ó¤W­z¤èªk°µ´N°÷¤F¡A¦ý¬O«ö¶s±±¥óÁÙ±o¦h¤@¨Ç¤âÄò¡C­ì¨Ó«ö§á±±¥ó¤£·|¥D°Êµo¥X WM_CTLCOLORBTN °T®§¡A°£«D¬O«ü©w¤F BS_OWNERDRAW¡C©Ò¥H¥²¶·¦b¸ê·½´y­zÀÉùØ¡A©w¸q«ö¶s­·®æ¬° BS_OWNERDRAW¡C

¦ý¬O¥[¤W¤F BS_OWNERDRAW ­·®æ«á¡A¹ï¸Ü²°ºÞ²z¾¹¤£·|¦hºÞ¶¢¨Æªº³B²z¥ßÅé®ÄªG¤F¡C§Úªº·N«ä¬O¡A¤@¯ëªº«ö¶s«ö¤U¥h®É·|¦³¨H¤U¥hªº®ÄªG¡A©ñÃP®É·|¦³¯B¤W¨Óªº®ÄªG¡A¦ý¬O¦pªG§â«ö¶s±±¥ó¥[¤W¤F BS_OWNERDRAW ­·®æ«á¡A´N¨S¦³³o¨Ç¥ßÅé®ÄªG¤F¡CÁöµM³o¨Ç®ÄªG¨S¤F¡A¦ý¬O¤´¯à¥¿±`¹B§@¡C°²¦p¤´·Q¾Ö¦³³o®ÄªG¡A¨º»ò´N¥²¶·¦Û¦æ³B²z WM_DRAWITEM °T®§¡C¨ã¦³ BS_OWNERDRAW ­·®æªº«ö¶s·|µo¥X WM_DRAWITEM °T®§¡A¦r­±¤Wªº·N«ä¡AWM_DRAWITEM ·N§Y¦Û¦æµe¥X¤l±±¥ó¡C

WM_DRAWITEM °T®§»P DRAWITEMSTRUCT µ²ºcÅé

WM_DRAWITEM °T®§¬O³B²z·í¨ã¦³ BS_OWNERDRAW ­·®æªº«ö¶s¦Û¦æø»s«ö¶s¹Ï§Îªº°T®§¡C¦pªG«ö¶sªº­·®æ§t¦³¡uBS_OWNERDRAW¡v¡A¨º»ò§@·~¨t²Î©ó¿Ã¹õ¤Wø¥X«ö¶s®É¡A´N·|¹ï¸Ó«ö¶sªº¤÷µøµ¡¤§µøµ¡¨ç¦¡µo¥X¡uWM_DRAWITEM¡v°T®§¡C¨Æ¹ê¤W¡A¤£¶È«ö¶s¡A¨ã¦³ SS_OWNERDRAW ­·®æªºÀRºA±±¥ó¡B¨ã¦³ CBS_OWNERDRAWFIXED ©Î CBS_OWNERDRAWVARIABLE ­·®æªº½Æ¦X®Ø¡B¨ã¦³ LBS_OWNERDRAWFIXED ©Î LBS_OWNERDRAWVARIABLE ­·®æªº²M³æ¥H¤Î¿ï³æ¤]³£·|µo¥X WM_DRAWITEM °T®§¡CWM_DRAWITEM ªº wParam °Ñ¼Æ¬O¤l±±¥óªºÃѧO½X¡A¦ý¬O¦pªG¥Ñ¿ï³æµo¥X WM_DRAWITEM °T®§ªº¸Ü¡AwParam ¬°¹s¡ClParam °Ñ¼Æ¬O¤@­Ó¦ì§}¡A¦¹¦ì§}«ü¦V¤@­ÓºÙ¬° DRAWITEMSTRUCT ªºµ²ºcÅé¡A¥¦¦s¦³³\¦h¨t²Î¤wµ¹©wªº¸ê®Æ¡C

DRAWITEMSTRUCT ¤ºªº¦¨­û·|¥Ñ§@·~¨t²Î¶ñ¤J¾A·íªº¼Æ­È¡A¦Óµ{¦¡³]­p®v¥u­n®Ú¾Ú³o¨Ç¼Æ­Èø»s¦Û¤v·Q­nªº¹Ï¤ù¡CDRAWITEMSTRUCT ªº¦¨­û¦p¤U¡G

DRAWITEMSTRUCT  STRUCT
  CtlType       DWORD     ?
  CtlID         DWORD     ?
  itemID        DWORD     ?
  itemAction    DWORD     ?
  itemState     DWORD     ?
  hwndItem      DWORD     ?
  hdc           DWORD     ?
  rcItem        RECT      <>
  itemData      DWORD     ?
DRAWITEMSTRUCT  ENDS

CtlType ¬O¤l±±¥óÃþ§O¡A¥i¥H¬O ODT_BUTTON¡BODT_COMBOBOX¡BODT_LISTBOX¡BODT_STATIC¡BODT_MENU µ¥µ¥¡A°£¤F ODT_MENU ¬O¿ï³æ¥~¡A¨ä©ó¬O¤l±±¥ó¡CCtlID ¦¡¤l±±¥óªºÃѧO½X¡A¦pªG¬O¿ï³æµo¥Xªº WM_DRAWITEM¡A«h¦¹Äæ¼o±ó¤£¥Î¡C

itemID ¬O¿ï³æ¤¤ªº¿ï¶µÃѧO½X©Î¬O½Æ¦X®Ø©Î²M³æ¤¤ªº¿ï¾Ü¶µÃѧO½X¡C¦pªG½Æ¦X®Ø©Î²M³æ¨S¦³¿ï¾Ü¶µªº¸Ü¡A¦¹Äæ¦ì³Q³]¬°­t­È¡C

itemAction ¬O¨M©w¦p¦óø»s¡A¥i¥H¦³¤U­±¤TºØ¼Æ­È¡GODA_DRAWENTIRE¡BODA_FOCUS¡BODA_SELECT¡C·í¾ã­Ó¤l±±¥ó»Ý­n³Q­«·sø»s®É¡A¦¹Äæ¦ì³Q³]¬° ODA_DRAWENTIRE¡C·í¤l±±¥ó¥¢¥h©Î±o¨ì¿é¤JµJÂI®É¡A¦¹Äæ¦ì³Q³]¬° ODA_FOCUS¡A¦Ü©ó±o¨ìÁÙ¬O¥¢¥hµJÂI¡A±o¹î¬Ý itemState Äæ¦ì¡C·í½Æ¦X®Ø©Î²M³æªº¿ï¾Ü¶µ³Q¿ï¨ì«á®É¡A¦¹Äæ¦ì³Q³]¬° ODA_SELECT¡C

itemState ¬O¤@­Ó 32 ¦ì¤¸ªº¾ã¼Æ¡A·í¿ï³æ©Î¤l±±¥ó³Q§ïÅܮɡA¨ä¤¤¬Y¨Ç¦ì¤¸·|³Q³]©w¡A©Î²M°£¡C±`¥Îªº¦ì¤¸¦p¤U¡G

  1. ODS_CHECKED¡G·í¿ï³æªº¿ï¶µ³Q¿ï¤¤®É¡A¦¹Äæ¦ì³Q³]©w ODS_CHECKED ¡A¥u¦³¿ï³æ¤~¥i¯à³]©w¦¹ºX¼Ð¡C
  2. ODS_DISABLED¡G·í¤l±±¥ó¤£¯à±µ¨ü·Æ¹«©ÎÁä½L¿é¤J®É¡A¦¹Äæ¦ì³Q³]¬° ODS_DISABLED¡C
  3. ODS_FOCUS¡G·í¤l±±¥óÀò±o¿é¤JµJÂI®É¡A³]©w¦¹¦ì¤¸¡C
  4. ODS_GRAYED¡G·í¿ï³æªº¿ï¶µ³Q³]¬°µL§@¥Î®É¡C¥u¦³¿ï³æ¤~¥i¯à³]©w¦¹¦ì¤¸¡C
  5. ODS_SELECTED¡G·í¤l±±¥ó³Q¿ï¾Ü®É¡A³]©w¦¹¦ì¤¸¡C
  6. ODS_COMBOBOXEDIT¡G·í½Æ¦X®Ø±±¥óªº½s¿è¤å¦r³Q¿ï¾Ü ( ¤Ï¥Õ ) ®É¡A¦¹Äæ¦ì³]¬° ODS_COMBOBOXEDIT¡C
  7. ODS_DEFAULT¡G¤º©wªº¡C

hwndItem ¬O¤l±±¥óªº¥N½X¡A¦pªG WM_DRAWITEM ¬O¿ï³æ©Òµo¥Xªº¡A¦¹Äæ¦ì¬O¿ï³æ¥N½X¡Chdc ¬O­nø»sªº¤l±±¥ó³]³Æ¤º®e¥N½X¡CrcItem ¬O hdc ªº½d³ò¡A¦³Ãö RECT ªº¸ê®Æ«¬ºA¡A½Ð°Ñ¦Ò²Ä¤T³¹ªº»¡©ú¡CitemData ¬O©M¿ï³æ¡B½Æ¦X®Ø±±¥ó¡B²M³æ±±¥ó¦³Ãö¡A·í ctlType ¬° ODT_BUTTON ©Î ODT_STATIC ®É¡AitemData ¬°¹s¡C


¤@­Ó¨Ò¤l¡GDEC2HEX.ASM

´£¤F³o»ò¦h¦³Ãö¹ï¸Ü²°ªºÃC¦â¡A¤£¹ê§@¤@­Ó¹ê¦b¤âÄo¡A©Ò¥H²³æ¼g¤F¤@­Óµ{¦¡»¡©ú¡C

DEC2HEX ¥\¥Î

³o­Óµ{¦¡¬O¥Î¨ÓÂà´«¤Q¶i¦ì»P¤Q¤»¶i¦ì¡A³Ì¦h¥i¥HÂà´« 64 ¦ì¤¸ªº¥¿¼Æ¡A°õ¦æ®Éµe­±¦p¤U¡G

DEC2HEX.EXE °õ¦æµe­±
±z¥i¥H«ö¤U¡yDEC->HEX¡z«ö¶s©Î¡yHEX->DEC¡z«ö¶s¿ï¾Ü§@¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì©Î¤Q¤»¶i¦ìÂà´«¦¨¤Q¶i¦ì¡A·í±z¿ï©w«á¡A¤W­±ªºÀRºA±±¥ó·|Åã¥Ü¥X§@¨º¤@ºØÂà´«¡A¦P®É©³¤U©@°Ø¦âªº¼Æ¦r«ö¶s¤]·|§@§ó°Ê¡A¥ç§Y¦pªG±z¿ï©w¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì¡A¨º»ò¡yA¡z¨ì¡yF¡z«ö¶s¬OµL§@¥Îªº¡A©Ò¥Hµ{¦¡±N¨Ï±o¡yA¡z¨ì¡yF¡z«ö¶s¤Wªº¼Æ¦r®ø¥¢¡AÅܦ¨©M­I´º¤@¼Ëªº©@°Ø¦â¡C

­ì©lÀɤº®e

Æ[¬Ý³o­Ó¹ï¸Ü²°¡A«Ü©úÅ㪺¡A¹ï¸Ü²°­I´º¡BÀRºA¤¸¥ó¡B«ö¶s¤¸¥óªº¤å¦rÃC¦â©Î­I´ºÃC¦â³£¤w§ó§ï¡C©³¤U¥ý¬Ý¬Ý­ì©lÀÉ¡ADEC2HEX.ASM¡G

        .386
        .model  flat,stdcall
        option  casemap:none

DlgProc         proto   :DWORD,:DWORD,:DWORD,:DWORD
Convert         proto
Dec2Hex         proto   :DWORD
Hex2Dec         proto   :DWORD
DrawBTN         proto   :DWORD,:DWORD
DrawEdge        proto   :DWORD,:DWORD,:DWORD,:DWORD,\
                        :DWORD,:DWORD,:DWORD

include         windows.inc
include         user32.inc
include         kernel32.inc
include         gdi32.inc
includelib      user32.lib
includelib      kernel32.lib
includelib      gdi32.lib

IDS_NS          equ     2000
IDE_NUM         equ     2500
IDB_N0          equ     3000
IDB_N1          equ     3001
IDB_N2          equ     3002
IDB_N3          equ     3003
IDB_N4          equ     3004
IDB_N5          equ     3005
IDB_N6          equ     3006
IDB_N7          equ     3007
IDB_N8          equ     3008
IDB_N9          equ     3009
IDB_NA          equ     3010
IDB_NB          equ     3011
IDB_NC          equ     3012
IDB_ND          equ     3013
IDB_NE          equ     3014
IDB_NF          equ     3015
IDB_H2D         equ     3100
IDB_D2H         equ     3101
IDB_AC          equ     3102
IDB_ANS         equ     3103
IDB_CVT         equ     3104

IDM_EXIT        equ     4000
IDM_CLEAR       equ     4001

DLG_BK_COLOR    equ     0ffccffh        ;048 ²H¯»¬õ¦â
STATIC_COLOR    equ     09900ffh        ;049 ®ç¬õ¦â
EDIT_BK_COLOR   equ     099cccch        ;050 ´Ä¦â
EDIT_TEXT_COLOR equ     0               ;051 ¶Â¦â
BTN_BK_COLOR    equ     0113366h        ;052 ©@°Ø¦â
BTN_TEXT_COLOR  equ     0ffffffh        ;053 ¥Õ¦â

;************************************************
                .data
hInstance       HINSTANCE       ?
CommandLine     LPSTR           ?
DlgName         db              'D2HDlg',0
fNumSys         db              0               ;060 0¡G¤Q¶i¦ìÅܤQ¤»¶i¦ì
                                                ;061 1¡G¤Q¤»¶i¦ìÅܤQ¶i¦ì
hwndEdit        HWND            ?               ;062 ½s¿è®Ø¤lµøµ¡¥N½X
hwndBTN         HWND            10h dup (?)     ;063 «ö¶s¤lµøµ¡¥N½X
hwndStatic      HWND            ?               ;064 ÀRºA¤lµøµ¡¥N½X
hbrBTN          HBRUSH          ?               ;065 «ö¶sªºµe¨ê¥N½X
hbrDlg          HBRUSH          ?               ;066 ¹ï¸Ü²°ªºµe¨ê¥N½X
hbrStatic       HBRUSH          ?               ;067 ÀRºA¤lµøµ¡ªºµe¨ê¥N½X
hbrEdit         HBRUSH          ?               ;068 ½s¿è®Øªºµe¨ê¥N½X
szAnswer        db              32 dup (?)      ;069 µª®×¦s©ñ³B
nTenPwr         dd              1000000000,100000000,10000000,1000000
                dd              100000,10000,1000,100,10,1
szNumber        db              ?,0
szD2H           db              '¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì',0
szH2D           db              '¤Q¤»¶i¦ìÂà´«¦¨¤Q¶i¦ì',0
fConvert        db              0               ;075 0¡G¥¼«ö¤U¡yConvert¡z
                                                ;076 1¡G¤w«ö¤U¡yConvert¡z
sNumber         db              '0123456789ABCDEF'
szIcon          db              'Dec2Hex',0
;************************************************
                .code
start:  invoke  GetModuleHandle,NULL
        mov     hInstance,eax
        invoke  DialogBoxParam,hInstance,offset DlgName,0,offset DlgProc,0
        invoke  ExitProcess,eax                 ;84 µ²§ôµ{¦¡
;------------------------------------------------
;¨Ï AL ¤ºªº¼Æ¦rÅܦ¨ ASCII ½X¡CAL ­ì¤º®e¬° 0¡ã0fh
ConvertBIN2ASCII        proc
        add     al,30h
        cmp     al,3ah  ;89
        jb      @f
        add     al,7
@@:     ret             ;92
ConvertBIN2ASCII        endp
;------------------------------------------------
;¨Ï CL ¤ºªº ASCII ½XÂà´«¦¨¼Æ¦r¡CCL ­ì¤º®e¬° 30h¡ã39h¡B41h¡ã46h
ConvertASCII2BIN        proc
        sub     cl,'0'
        cmp     cl,9
        jbe     @f
        sub     cl,7
@@:     ret
ConvertASCII2BIN        endp
;------------------------------------------------
;µe¥X«ö¶sÃä®Ø¡C¤U¹Ï¬O«ö¶s¥~Æ[¡A¦ý¤£·Ó¤ñ¨Òø»s¡Cncx ¬O«ö¶sªº¼e«×¡Ancy
;¬O«ö¶sªº°ª«×¡AÃä®Ø¦³¨â¼h¡A¦A¥H±×Ãä¤À¥ª¤W¡B¥k¤U¨âÃä¡A¬G¦³¥|ºØÃC¦â
;¢z¡X¡X¡X¡X¡X¡X¡X¡X¡X¢{
;¡ýnColor1         ¡þ¡ý
;¡ý ¢z¡X¡X¡X¡X¡X¡X¢{ ¡ý
;¡ý ¡ýnColor3   ¡þ¡ý ¡ý
;¡ý ¡ý ¢z¡X¡X¡X¢{ ¡ý ¡ý
;¡ý ¡ý ¡ý      ¡ý ¡ý ¡ý
;¡ý ¡ý ¡ý  AC  ¡ý ¡ý ¡ý
;¡ý ¡ý ¡ý      ¡ý ¡ý ¡ý
;¡ý ¡ý ¢|¡X¡X¡X¢} ¡ý ¡ý
;¡ý ¡ý¡þ   nColor4¡ý ¡ý
;¡ý ¢|¡X¡X¡X¡X¡X¡X¢} ¡ý
;¡ý¡þ         nColor2¡ý
;¢|¡X¡X¡X¡X¡X¡X¡X¡X¡X¢}
DrawEdge        proc    hdc:HDC,ncx:DWORD,ncy:DWORD,nColor1:DWORD,\
                        nColor2:DWORD,nColor3:DWORD,nColor4:DWORD
        LOCAL   hOldPen:DWORD
        LOCAL   hNewPen:DWORD
        dec     ncx     ;123 ¦]¬°¶Ç¤Jªº ncx¡Bncy ¬O«ö¶s¼e«×¡A¦ýµeÃä®Ø
        dec     ncy     ;124 ®É¥Ñ¡A®y¼Ð¹s¶}©l¡A©Ò¥H ncx¡Bncy ³£´î¥h¤@
        invoke  CreatePen,PS_SOLID,0,nColor1    ;125 ¥~¼h¥ª¤W¨¤Ãä®Øªºµeµ§
        mov     hNewPen,eax
        invoke  SelectObject,hdc,eax            ;127 ¿ï¾Ü¦¹µeµ§
        mov     hOldPen,eax                     ;128 Àx¦sµeµ§¡A¥H§Q«ì´_
        invoke  MoveToEx,hdc,0,ncy,NULL
        invoke  LineTo,hdc,0,0
        invoke  LineTo,hdc,ncx,0
        invoke  DeleteObject,hNewPen
        invoke  CreatePen,PS_SOLID,0,nColor2    ;133 ¥Ñ 133¡ã138 ¦æ¡Aµe¥~¼h
        mov     hNewPen,eax                     ;134 ¥k¤U¨¤Ãä®Ø
        invoke  SelectObject,hdc,eax
        invoke  LineTo,hdc,ncx,ncy
        invoke  LineTo,hdc,0,ncy
        invoke  DeleteObject,hNewPen            ;138

        dec     ncx
        dec     ncy
        invoke  CreatePen,PS_SOLID,0,nColor3    ;142 ¥Ñ 142¡ã148 ¦æ¡Aµe¤º¼h
        mov     hNewPen,eax                     ;143 ¥ª¤W¨¤Ãä®Ø
        invoke  SelectObject,hdc,eax
        invoke  MoveToEx,hdc,1,ncy,NULL
        invoke  LineTo,hdc,1,1
        invoke  LineTo,hdc,ncx,1
        invoke  DeleteObject,hNewPen            ;148
        invoke  CreatePen,PS_SOLID,0,nColor4    ;149 ¥Ñ 149¡ã154 ¦æ¡Aµe¤º¼h
        mov     hNewPen,eax                     ;150 ¥k¤U¨¤Ãä®Ø
        invoke  SelectObject,hdc,eax
        invoke  LineTo,hdc,ncx,ncy
        invoke  LineTo,hdc,1,ncy
        invoke  DeleteObject,hNewPen
        invoke  SelectObject,hdc,hOldPen        ;155 «ì´_­ìµeµ§
        ret
DrawEdge        endp
;-------------------------------------------------
DrawBTN proc    nID_BTN:WPARAM,lp:LPARAM
        LOCAL   dis:DRAWITEMSTRUCT
.if (nID_BTN>=IDB_N0)||(nID_BTN<=IDB_NF)        ;161 ¶È³B²z¼Æ¦r«ö¶s
        push    esi
        lea     edx,dis
        mov     esi,lp
        mov     ecx,12
next:   lodsd                   ;166 ªì©l¤Æ dis¡A·N§Y§â±q¨t²Î¶Ç¨Ó¡A¦ì©ó
        mov     [edx],eax       ;167 lParam ©Ò«üªº DRAWITEMSTRUCT ¦ì
        add     edx,4           ;168 §}¤ºªº¼Æ­È¡A¦s¤J dis §½³¡ÅܼÆùØ
        loop    next
        pop     esi

;¥H¤U¤C¦æµe¥X«ö¶sÃä®Ø
 .if (dis.itemState&ODS_SELECTED)       
        invoke  DrawEdge,dis.hdc,dis.rcItem.right,\
                dis.rcItem.bottom,0,336699h,0,99ccffh
 .else
        invoke  DrawEdge,dis.hdc,dis.rcItem.right,\
                dis.rcItem.bottom,0ffffffh,0,99ccffh,336699h
 .endif

        invoke  IsWindowEnabled,dis.hwndItem
        or      eax,eax         ;182 Àˬd«ö¶s¬O§_¥i±µ¨ü¿é¤J¡A­Y¤£¥i
        jz      Disable_BTN     ;183 ¡A«h¸õ¨ì Disable_BTN ³B
        mov     ecx,nID_BTN     ;184 ¦¹¤T¦æ¡Aºâ¥X­n¦b«ö¶s¤W¦L¥X¤°»ò¼Æ¦r
        sub     ecx,IDB_N0
        add     ecx,offset sNumber
;¥H¤U¤­¦æ¦b«ö¶s¤¤Åã¥Ü¥X¤å¦r ( 0¡ãF )
 .if (dis.itemState&ODS_SELECTED)
        invoke  TextOut,dis.hdc,21,5,ecx,1	;189 ¤U¨H
 .else
        invoke  TextOut,dis.hdc,20,4,ecx,1	;191 ¤W¯B
 .endif

Disable_BTN:
.endif
        ret
DrawBTN endp
;------------------------------------------------
DlgProc proc    hDlg:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.if uMsg==WM_INITDIALOG
        invoke  LoadIcon,hInstance,offset szIcon
        invoke  SendMessage,hDlg,WM_SETICON,ICON_SMALL,eax
        invoke  GetDlgItem,hDlg,IDE_NUM
        mov     hwndEdit,eax

;207 ¥H¤U 12 ¦æ¡A¨ú±o¦U¼Æ¦rªº«ö¶s¥N½X¡A¨Ã¦s©ó hwndBTN °}¦CùØ
        mov     edx,IDB_N0
        sub     ecx,ecx
nxtBTN: push    edx
        push    ecx
        invoke  GetDlgItem,hDlg,edx
        pop     ecx
        mov     hwndBTN[ecx*4],eax
        pop     edx
        inc     ecx
        inc     edx
        cmp     cx,16
        jb      nxtBTN

        invoke  Dec2Hex,hDlg    ;221 ³]©w¬°¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì
        mov     fNumSys,0       ;222 ¬G fNumSys ³]¬°¹s
        mov     fConvert,0      ;223 ³]©w¥¼«ö¤U Convert «öÁä
        invoke  CreateSolidBrush,DLG_BK_COLOR
        mov     hbrDlg,eax      ;225 ³]©w¹ï¸Ü²°­I´ºµe¨ê
        invoke  CreateSolidBrush,DLG_BK_COLOR
        mov     hbrStatic,eax   ;227 ³]©wÀRºA¤¸¥óªºµe¨ê
        invoke  CreateSolidBrush,EDIT_BK_COLOR
        mov     hbrEdit,eax     ;229 ³]©w½s¿è®Øµe¨ê
        invoke  CreateSolidBrush,BTN_BK_COLOR
        mov     hbrBTN,eax      ;231 ³]©w¼Æ¦r«öÁäµe¨ê

.elseif uMsg==WM_CTLCOLORDLG    ;233 ³B²z¹ï¸Ü²°­I´ºÃC¦â
        mov     eax,hbrDlg
        ret

.elseif uMsg==WM_CTLCOLORSTATIC
        mov     ecx,lParam      ;238 Àˬd¬O§_¬O½s¿è®Ø¶Ç¨Óªº°T®§
        cmp     ecx,hwndEdit    ;239 ­Y¬O¡A«h¸õ¨ì edit_color ¼Ð°O
        je      edit_color
;³B²zÀRºA¤¸¥ó¤å¦rÃC¦â¤Î­I´ºÃC¦â
        invoke  SetTextColor,wParam,STATIC_COLOR
        invoke  SetBkColor,wParam,DLG_BK_COLOR
        mov     eax,hbrStatic
        ret

.elseif uMsg==WM_CTLCOLOREDIT   ;247 ³B²z½s¿è®Ø¤å¦rÃC¦â¤Î­I´ºÃC¦â
edit_color:
        invoke  SetTextColor,wParam,EDIT_TEXT_COLOR
        invoke  SetBkColor,wParam,EDIT_BK_COLOR
        mov     eax,hbrEdit
        ret

.elseif uMsg==WM_CTLCOLORBTN    ;254 ³B²z¼Æ¦r«öÁä¤å¦rÃC¦â¤Î­I´ºÃC¦â
        invoke  SetTextColor,wParam,BTN_TEXT_COLOR
        invoke  SetBkColor,wParam,BTN_BK_COLOR
        mov     eax,hbrBTN
        ret

.elseif uMsg==WM_DRAWITEM       ;260 ³B²z WM_DRAWITEM °T®§
        invoke  DrawBTN,wParam,lParam

.elseif uMsg==WM_CLOSE
exit:   invoke  DeleteObject,hbrDlg     ;264 §R°£µe¨ê
        invoke  DeleteObject,hbrStatic
        invoke  DeleteObject,hbrEdit
        invoke  DeleteObject,hbrBTN
        invoke  EndDialog,hDlg,NULL

.elseif uMsg==WM_COMMAND
        mov eax,wParam
;¥H¤U¬O¨Ï¥ÎªÌÂI¿ï¿ï³æ
 .if lParam==0
   .if ax==IDM_CLEAR
        invoke  SetDlgItemText,hDlg,IDE_NUM,NULL
   .elseif ax==IDM_EXIT
        jmp     exit
   .endif
 .else
;¥H¤U¬O¨Ï¥ÎªÌ¿ï«ö«ö¶s
        mov     edx,wParam
        shr     edx,16          ;282 DX=³qª¾½X
   .if dx==BN_CLICKED           ;283 AX=¤l±±¥ó¤§ÃѧO½X
     .if ax==IDB_H2D
        invoke  Hex2Dec,hDlg    ;285 ³]©w¡yA¡z¡ã¡yF¡z«ö¶s¥i±µ¨ü¿é¤J
        or      fNumSys,1
        invoke  InvalidateRect,hDlg,NULL,FALSE
     .elseif ax==IDB_D2H
        invoke  Dec2Hex,hDlg    ;289 ³]©w¡yA¡z¡ã¡yF¡z«ö¶s¤£±µ¨ü¿é¤J
        and     fNumSys,0
        invoke  InvalidateRect,hDlg,NULL,FALSE
     .elseif ax==IDB_AC
        invoke  SetDlgItemText,hDlg,IDE_NUM,NULL
     .elseif ax==IDB_ANS
        mov     fConvert,1
        invoke  SetWindowText,hwndEdit,offset szAnswer
     .elseif ax==IDB_CVT
        call    Convert
        mov     fConvert,1      ;299 ³]©w fConvert
     .elseif (ax>=IDB_N0)&&(ax<=IDB_NF)
;¦pªG fConvert ºX¼Ð¬°¤@¡A«h³]©w½s¿è®Ø¤§¤º®e¬° NULL
      .if fConvert==1
        push    eax
        invoke  SetDlgItemText,hDlg,IDE_NUM,NULL
        mov     fConvert,0      ;305 ²M°£ fConvert
        pop     eax
      .endif
        sub     ax,IDB_N0
        call    ConvertBIN2ASCII
        mov     ecx,offset szNumber
        mov     szNumber,al
        invoke  SendMessage,hwndEdit,EM_REPLACESEL,TRUE,ecx
     .endif
   .endif
 .endif     
.else
        mov     eax,FALSE
        ret
.endif
        mov     eax,TRUE
        ret
DlgProc endp
;------------------------------------------------
;¤Q¶i¦ì¨îÅܦ¨¤Q¤»¶i¦ì¨î¡A«ö¶s0¡ã9±Ò°Ê¡AA¡ãF¤£±Ò°Ê
Dec2Hex proc    hwnd:HWND
        sub     ecx,ecx ;326 ECX=0¡ãF¡Aªí¥Ü²Ä´X­Ó«ö¶s
nxt_d:  push    ecx
        mov     edx,hwndBTN[ecx*4]
.if cl<0ah
        invoke  EnableWindow,edx,TRUE
.else
        invoke  EnableWindow,edx,FALSE
.endif
        pop     ecx
        inc     ecx
        cmp     cl,16
        jb      nxt_d
;338 ³Ì¤j¬°4294967295¡A¦@¤Q¦ì¼Æ
        invoke  SendMessage,hwndEdit,EM_SETLIMITTEXT,10,0
        invoke  SetDlgItemText,hwnd,IDS_NS,offset szD2H
        ret
Dec2Hex endp
;------------------------------------------------
;¤Q¤»¶i¦ì¨îÅܦ¨¤Q¶i¦ì¨î¡A«ö¶s0¡ãF§¡±Ò¥Î
Hex2Dec proc    hwnd:HWND
        sub     ecx,ecx
nxt_h:  push    ecx
        mov     edx,hwndBTN[ecx*4]
        invoke  EnableWindow,edx,TRUE
        pop     ecx
        inc     ecx
        cmp     cl,16
        jb      nxt_h
;354 ³Ì¤j¬°FFFFFFFF¡A¦@ 8 ¦ì¼Æ
        invoke  SendMessage,hwndEdit,EM_SETLIMITTEXT,8,0
        invoke  SetDlgItemText,hwnd,IDS_NS,offset szH2D
        ret
Hex2Dec endp
;------------------------------------------------
;§â½s¿è®Ø¤§¤º®eÂà´«¦¨¤Q¶i¦ì©Î¤Q¤»¶i¦ì
;¥ý¨ú±o½s¿è®Ø¤º®e¡A¦A¨Ì¾Ú fNumSys ºX¼Ð¤§­È§PÂ_¬O¤Q¶i¦ì´«¦¨¤Q¤»¶i¦ì
;ÁÙ¬O¤Q¤»¶i¦ì´«¦¨¤Q¶i¦ì¡C
Convert proc
        local   buffer[16]:BYTE ;364 buffer ¦s©ñ¨Ï¥ÎªÌ©Ò¿é¤J¤§¦r¦ê
        local   nLenBuffer:DWORD;365 ¨Ï¥ÎªÌ¿é¤J¤§¦r¦êªø«×

        invoke  GetWindowText,hwndEdit,addr buffer,16
.if eax!=0      ;368 ­Y½s¿è®Ø¤º®e¤§ªø«×¬°¹s¡A¤£°µ¥ô¦ó¨Æ
        mov     nLenBuffer,eax
        push    esi
        push    edi
        lea     esi,buffer
        mov     edi,offset szAnswer
        mov     ecx,eax
        rep     movsb           ;375 ¥ý§â¿é¤J¦r¦ê«þ¨©¨ì szAnser ¦r¦êùØ

        sub     eax,eax         ;377 EAX ¦s©ñ¨Ï¥ÎªÌ©Ò¿é¤J¤§¼Æ­È¡A¥ýÂk¹s
        lea     esi,buffer
  .if fNumSys==0
@@:     mov     cl,10           ;380 ¤Q¶i¦ìÅܤQ¤»¶i¦ì
        mul     ecx             ;381 ¥ý­pºâ¿é¤J¦r¦ê©Òªí¥Üªº¼Æ­È¡A¨Ã
        mov     cl,[esi]        ;382 ¦s©ó EAX ùØ
        inc     esi
        sub     cl,'0'
        add     eax,ecx
        dec     nLenBuffer
        jnz     @b
        mov     edx,eax
        mov     ax,3d64h        ;389 ¦s¤J¡yd=¡z
        stosw
        mov     ecx,8           ;391 ´«¦¨¤Q¤»¶i¦ì®É¡A³Ì¦h 8 ¦ì¼Æ
@@:     rol     edx,4           ;392 ¨C 4 ¦ì¤¸ªí¥Ü¤@¦ì¤Q¤»¶i¦ì¼Æ
        mov     al,dl           ;393 ¨Ï EAX ¤ºªº¤Q¤»¶i¦ì¼Æ¦s©ó
        and     al,0fh          ;394 EDI ©Ò«üªº¦r¦ê
        call    ConvertBIN2ASCII
        stosb
        loop    @b
        mov     al,'h'          ;398 ¦s¤J¡yh¡z
        stosb
  .else
@@:     shl     eax,4           ;401 ¤Q¤»¶i¦ìÅܤQ¶i¦ì
        mov     cl,[esi]
        call    ConvertASCII2BIN
        add     eax,ecx
        inc     esi
        dec     nLenBuffer
        jnz     @b
        mov     word ptr[edi],3d68h
        inc     edi
        inc     edi
        mov     ecx,10
        mov     esi,offset nTenPwr
@@:     mov     ecx,[esi]
        sub     edx,edx
        div     ecx
        add     esi,4
        call    ConvertBIN2ASCII
        stosb
        mov     eax,edx
        loop    @b
        mov     al,'d'
        stosb
  .endif
        mov     al,0
        stosb
        pop     edi
        pop     esi
        invoke  SetWindowText,hwndEdit,offset szAnswer
.endif
        ret
Convert endp
;************************************************
end     start

¸ê·½´y­zÀÉ¡ADEC2HEX.RC ªº¤º®e¬O¡G

#include "c:\masm32\include\resource.h"

#define D2HMenu 1000

#define IDS_NS  2000
#define IDE_NUM 2500
#define IDB_N0  3000
#define IDB_N1  3001
#define IDB_N2  3002
#define IDB_N3  3003
#define IDB_N4  3004
#define IDB_N5  3005
#define IDB_N6  3006
#define IDB_N7  3007
#define IDB_N8  3008
#define IDB_N9  3009
#define IDB_NA  3010
#define IDB_NB  3011
#define IDB_NC  3012
#define IDB_ND  3013
#define IDB_NE  3014
#define IDB_NF  3015
#define IDB_H2D 3100
#define IDB_D2H 3101
#define IDB_AC  3102
#define IDB_ANS 3103
#define IDB_CVT 3104

#define IDM_EXIT        4000
#define IDM_CLEAR       4001

D2HMenu         MENU
BEGIN
  MENUITEM      "Â÷¶}",IDM_EXIT
  MENUITEM      "²M°£",IDM_CLEAR
END

D2HDlg  DIALOG  0,0,123,132
STYLE   DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU
FONT    9,"Arial"
MENU    D2HMenu
CAPTION "¤Q¶i¦ì»P¤Q¤»¶i¦ì´«ºâ"
BEGIN
  CONTROL    "¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì",IDS_NS,"STATIC",SS_LEFT,8,4,108,12
  CONTROL    ""   ,IDE_NUM,"EDIT",WS_BORDER|ES_READONLY,8,16,108,12
  PUSHBUTTON "DEC -> HEX",IDB_D2H, 8,34,52,12,WS_CHILD
  PUSHBUTTON "HEX -> DEC",IDB_H2D,64,34,52,12,WS_CHILD
  PUSHBUTTON "C"  ,IDB_NC ,  8, 50, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "D"  ,IDB_ND , 36, 50, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "E"  ,IDB_NE , 64, 50, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "F"  ,IDB_NF , 92, 50, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "8"  ,IDB_N8 ,  8, 66, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "9"  ,IDB_N9 , 36, 66, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "A"  ,IDB_NA , 64, 66, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "B"  ,IDB_NB , 92, 66, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "4"  ,IDB_N4 ,  8, 82, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "5"  ,IDB_N5 , 36, 82, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "6"  ,IDB_N6 , 64, 82, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "7"  ,IDB_N7 , 92, 82, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "0"  ,IDB_N0 ,  8, 98, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "1"  ,IDB_N1 , 36, 98, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "2"  ,IDB_N2 , 64, 98, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "3"  ,IDB_N3 , 92, 98, 24,12,WS_CHILD|BS_OWNERDRAW
  PUSHBUTTON "AC" ,IDB_AC ,  8,114, 24,12,WS_CHILD
  PUSHBUTTON "ANS",IDB_ANS, 36,114, 24,12,WS_CHILD
  PUSHBUTTON "Convert",IDB_CVT, 64,114,52,12,WS_CHILD
END

Dec2Hex ICON    DEC2HEX.ICO

¦Ó makefile ÀɮסADEC2HEX.MAK Àɪº¤º®e¦p¤U¡G

ALL:DEC2HEX.EXE

DEC2HEX.EXE : DEC2HEX.ASM DEC2HEX.RES
        ML /coff DEC2HEX.ASM /link DEC2HEX.RES

DEC2HEX.RES : DEC2HEX.RC DEC2HEX.ICO
        RC DEC2HEX.RC

¤U­±¬O¹Ï¥ÜÀÉ¡ADEC2HEX.ICO¡G


DEC2HEX ¸Ñ»¡

DEC2HEX ¨Ï¥Î¼Ò¦¡¹ï¸Ü²°¡A¦b¥Dµ{¦¡¤¤©I¥s DialogBoxParam API «Ø¥ß¹ï¸Ü²° ( ¨£µ{¦¡²Ä 83 ¦æ )¡A³o¼Ë¸`¬Ù¤F¤£¤Öµ{¦¡½X¡A§A¥i¥H¬Ý¨ì¥Dµ{¦¡¶È¶È 4 ¦æ ( ²Ä 81¡ã84 ¦æ )¡C±µ¤U¨Ó¬O¨â­Ó°Æµ{¦¡¡AConvertBIN2ASCII¡BConvertASCII2BIN ¤À§O³B²z¤@¨Ç·Ðº¾ªº¼Æ­ÈÂà´«¡A¦b³o¨â­Ó°Æµ{¦¡¤¤¦³¤@­Ó¯S§Oªº¼Ð°O¦WºÙ¡y@@:¡z¡A­È±o¤@´£¡C

@@ ¼Ð°O

²Õ¦X»y¨¥­ì©l½X¤¤¥Î¨ì¼Ð°OªºÀW²v¤ñ C/C++¡BPASCAL µ¥°ª¶¥»y¨¥¦h±o¦h¡A³o¬O¦]¬°²Õ¦X»y¨¥¤¤±`±`»Ý­n¤ñ¸û¡A¤ñ¸û«ü¥O¤§«á´N¬O¨Ì±ø¥ó¸õÅD¡A©Ò¥H¬°³o¨Ç¼Ð°O¨ú­Ó¤£­«½Æªº¦WºÙÅܱo¤ñ¸û§xÃø¡A©ó¬O±`±`¦³¤H ( ·íµM¤]¥]§t¤p¤ì°¸ ) ´N¬°³o¨Ç¼Ð°O¨ú­Ó a01¡Ba02¡Ba03¡K¡K³o¼Ëªº¦WºÙ¡C¸U¤@¥H«á­×§ïµ{¦¡¡A­n¦b¤¤¶¡¦w´¡¤@­Ó¼Ð°O®É¡A´N·|¥X²{ a01_1 ³o¼Ë¬ð¤aªº¦W¦r¡C§Ú­Ìµo²{³o¨Ç¼Ð°O±`±`¥u¥Î¤@¦¸¡A©Ò¥H¨ú­ÓµLÃöºò­nªº¦WºÙ¤]µL§«¡A©ó¬O·L³n¦b±À¥X MASM 6.x ®É¡A¨Ï¥Î @@: ¼Ð°O¥H¸Ñ¨M³oºØ°ÝÃD¡C

@@: ¼Ð°O¬O©M

        jmp     @f
        ©Î
        jmp     @b

°t¦X¨Ï¥Îªº¡A·íµM @@: ¤]¥i¥H°t¦X±ø¥ó¸õÅD ja/jb/je/jz¡K¡Kµ¥«ü¥O¨Ï¥Î¡C·í¨Ï¥Î jmp @f ®É¡Aµ{¦¡±N·|¦V«e ( ¥ç§Y©¹°O¾ÐÅé¦ì§}¤jªº¤è¦V ) ´M§ä¨ì²Ä¤@­Ó @@: ¼Ð°O³B¡AÄ~Äò°õ¦æ¡F¦P²z¡A¦pªG¨Ï¥Î jmp @b ´N¬O¦V«á´M§ä¨ì²Ä¤@­Ó @@: ³B°õ¦æ¡C©Ò¥H¤@­Óµ{¦¡¤¤ @@: ¼Ð°O¡Bjmp @f ©M jmp @b §¡¥i¥H¥X²{«Ü¦h¦¸¡A²ÕĶ¾¹¯à¦Û°Ê¦a´M§ä­n¸õÅD¨ì¨º¤@­Ó¦ì§}¡A¥u¤£¹L¨Ï¥Î®É­nª`·N¡A¥H§K¦]¬°¼Ð°O¦W³£¬O @@:¡A¦Ó¨Ï @b ©M @f ·d²V¡C

¦b DEC2HEX.ASM µ{¦¡²Ä 89¡ã92 ¦æ¬°

        cmp     al,3ah
        jb      @f      ;90
        add     al,7
@@:     ret             ;92

·N§Y­Y AL ¤p©ó 3AH ®É¡A´N¦V«e¸õ¨ì²Ä 87 ¦æ¡CConvertASCII2BIN °Æµ{¦¡¤]¨Ï¥Î @@: ¼Ð°O¡A¥i°Ñ¦Ò¬Ý¬Ý¡C

DrawBTN °Æµ{¦¡

±µ¤U¨Óªº³o¨â­Ó°Æµ{¦¡¡ADrawBTN »P DrawEdge¡Aªº¥\¥Î¬Oµe¥X«ö¶s¡C¦p«e©Ò­z¡A·í«ö¶s±±¥ó¨ã¦³ BS_OWNERDRAW ­·®æ®É¡A§Ú­Ì¥i¥H¦b¹ï¸Ü²°¨ç¦¡³B²z WM_DRAWITEM °T®§¡Aø»s¦Û¤v©Ò·Q­nªí²{ªº«ö¶s¡Cµ{¦¡²Ä 261 ¦æ©I¥s DrawBTN ø»s¦Û©wªº«ö¶s¥~Æ[¡ADrawBTN ¦³¨â­Ó°Ñ¼Æ¡A§Y WM_DRAWITEM °T®§ªº°Ñ¼Æ wParam »P lParam¡A§Ú­Ì±N­n¾a³o¨â­Ó°Ñ¼Æªº¸ê®Æµe¥X«ö¶s¥~Æ[¡C

¤@¶i¤J DrawBTN °Æµ{¦¡®É¡A¥ýÀˬd¬O§_¥Ñ¼Æ¦r«ö¶sµo¥Xªº WM_DRAWITEM¡A¦pªG¬Oªº¸Ü´N¨Ì¾Ú lParam ªº¦ì§}¡A§â¨t²Î´£¨Ñªº DRAWITEMSTRUCT µ²ºcÅ餺ªº¸ê®Æ¡A«þ¨©¨ì°Ï°ìÅܼơAdis µ²ºcÅ餺 ( µ{¦¡²Ä 162¡ã170 ¦æ )¡C±µ¤U¨Ó©I¥s DrawEdge °Æµ{¦¡µe¥XÃä®Ø ( µ{¦¡²Ä 173¡ã179 ¦æ )¡AÃä®ØªºÃC¦â¬O¨Ï«ö¶s¥i¥H¬Ý°_¨Ó¦³À£¤U©Î¤W¯B¥ßÅé®ÄªGªºÃöÁä¡A§Ú­Ì¥i¥HÀˬd dis ¤ºªº itemState Äæ¦ì ( µ{¦¡²Ä 173 ¦æ )¡A¦pªG ODS_SELECTED ¦ì¤¸³Q³]©w¡Aªí¥Ü«ö¶s³QÀ£¤U¡A§_«h«ö¶s³QÃP¶}¡C¦p¦ó¨Ï«ö¶s¨ã¥ßÅé®ÄªGªº¸Ô²Ó¹Lµ{¡A®eµy«á¦A±Ô­z¡C

±µ¤U¨Óªº²Ä 181 ¨ì²Ä 194 ¦æ¬O¦b«ö¶s¤W¦L¥X¡y0¡z¡ã¡yF¡zªº¼Æ¦r¨Ó¡A¦ý¬O¦pªG¬O¤£¯à±µ¦¬·Æ¹«°T®§ªº«ö¶s ( ¨Ò¦p¤Q¶i¦ì´«¦¨¤Q¤»¶i¦ì®É¡A´N¤£¯à¿é¤J¡yA¡z¡ã¡yF¡z¼Æ¦r¡A³o¨Ç«ö¶s´N¤£¯à±µ¦¬·Æ¹«°T®§ ) ´N¤£Åã¥Ü¥X¼Æ¦r¨Ó¡AÀˬd«ö¶s¬O§_¥i±µ¦¬·Æ¹«©ÎÁä½L¿é¤J¡A¥i¥H¥Î IsWindowEnabled¡C

IsWindowEnabled API

³o­Ó API ¬O¥Î¨ÓÀˬd«ü©wªºµøµ¡¬O§_¯à±µ¨ü·Æ¹«©ÎÁä½L¿é¤J¡C¥¦ªº­ì«¬¦p¤U¡G

BOOL IsWindowEnabled(
  HWND  hWnd     // handle to window to test
);

hWnd ¬O­nÀË´úªºµøµ¡¥N½X¡A¦pªG¯à±µ¨ü¿é¤J«h EAX ¶Ç¦^¤@­Ó«D¹s¼Æ­È¡A§_«h¶Ç¦^¹s¡C

²Ä 182 ¦æÀˬd EAX ¬O§_¬°¹s¡A­Y¬°¹s¡A¤£¶·Åã¥Ü¼Æ¦r¡Aª½±µ¸õ¨ì BTN_Disable: ¼Ð°O³Bµ²§ô DrawBTN °Æµ{¦¡§Y¥i¡F­Y¤£¬°¹sªí¥Ü¥i¥H±µ¦¬·Æ¹«¿é¤J ( ¦¹®Éªí¥Ü¤Q¤»¶i¦ìÂà´«¦¨¤Q¶i¦ì )¡A¡yA¡z¡ã¡yF¡z¼Æ¦r«ö¶s¤Wªº¼Æ¦r´N­nÅã¥Ü¥X¨Ó¡A¤èªk¬O©I¥s TextOut Åã¥Ü¥X¨Ó¡C

TextOut API

³o­Ó API ·|¥H¿ï©wªº­I´ºÃC¦â¡B¤å¦rÃC¦â¡B¦r§Î¦b«ü©wªº¦ì¸mÅã¥Ü¤@­Ó¦r¦ê¡C¨ä­ì«¬¬O¡G

BOOL TextOut(
  HDC     hdc,          // handle to device context
  int     nXStart,      // x-coordinate of starting position
  int     nYStart,      // y-coordinate of starting position
  LPCTSTR lpString,     // pointer to string
  int     cbString      // number of characters in string
);

hdc ¬O«ü³]³Æ¤º®e ( ¨£²Ä¤T³¹ )¡AnXStart¡BnYStart ¬O«ü¦r¦ê­nÅã¥Ü¦b¨º¤@­Ó¦ì¸m¡AlpString ¬O­nÅã¥Üªº¦r¦ê¦ì§}¡AcbString ¬O­nÅã¥Üªº¦r¦êªø«×¡C¦Ü©ó«ö¶s¤å¦rÃC¦â¡B­I´ºÃC¦â¦b³B²z WM_CTLCOLORBTN °T®§®É³]©wªº¡A¤]´N¬O²Ä 255¡B256 ¦æ¥H SetTextColor¡BSetBkColor ³]©w¡C¦¹¥~¬°¤F¦b«ö¤U«ö¶s®É¡A¨Ï«ö¶s¨ã¦³¥ßÅé®ÄªG¡A©Ò¥H¦b²Ä 189 ¦æ¨Ï¤å¦rµyµy¦V¥k¤U¤è²¾¤@­ÓÂI¡C

DrawEdge °Æµ{¦¡

«e­±´¿´£¨ì¡A¬°¤FÅý«ö¶s¨ã¦³À£¤U®Éµyµy¤U¨H¡A©ñ¶}®Éµyµy¤W¯Bªº¥ßÅé®ÄªG¡A¥²¶·¹ï«ö¶sÃä®Øµy·L­×¹¢¤@µf¡ADrawEdge °Æµ{¦¡´N¬O°õ¦æ³o¬q¥ô°È¡C

°²·Q«ö¶s¬O¤@­Ó«ó«óªºªø¤èÅé¡A¥ú½u±q¥ª¤W¤è·Ó®g¥¦¡A¥ª¤W¤èªº°Ï°ìÀ³¸Ó¸û«G¡A¥k¤U¤è¥ú½u·Ó¤£¨ì¡A¸û·t¡C¦ý¬O·í«ö¶s³QÀ£¤U¨H¤J­pºâ¾÷­±ªO¤U­±®É¡A¥ª¤W¤è¤Ï¦Ó·Ó¤£¨ì¥ú½u¡AÅÜ·t¡F¥k¤U¤è«o¯à·Ó¨ì¥ú½u¡AÅÜ«G¡C©Ò¥H·í«ö¶s¨S³Q«ö¤U®É¡A¥ª¤W¨¤»P¥k¤U¨¤¦³¨âºØ¤£¦PªºÃC¦â¡A¦ý¬°¤F¤£³o»ò¬ð¤a¡A¤p¤ì°¸±Äº¥¦¸ÅÜ«G¤ÎÅÜ·t¡A©Ò¥H¥ª¤W¨¤¥Î¨âºØÃC¦â¡A§Y³vº¥ÅÜ«G¡F¥k¤U¨¤¤]¬O¦p¦¹¡A¥i¥H°Ñ¦Ò¤U¹Ï¡F

¤W¹Ï¬O«ö¶s¥¼«ö¤U®É«áªº¼Ë¤l¡A¥ª¤W¨¤¥Î nColor1¡BnColor3 ¨âºØÃC¦âªí¥Ü¡F¥k¤U¨¤¥Î nColor2¡BnColor4 ªí¥Ü¡C·í«ö¶s³Q«ö¤U«á¡A¤]¥Î¤W­±¥|ºØÃC¦âªí¥Ü¡A¥u¬O¥ª¤W¨¤ÅÜ·t¦Ó¥k¤U¨¤ÅÜ«G¡C

¹ê§@¤Wµe¥X©ú·t¤£¦PªºÃC¦â¡A´N¥Î¤£¦PÃC¦âªº½u±øµe¥X¨Ó§Y¥i¡Cµe¥X¤£¦PÃC¦âªº½u±ø±o¥ý«Ø¥ßµeµ§¡B¿ï¾Üµeµ§µ¥¨BÆJ¡A½Ð°Ñ¦Ò²Ä¤­³¹ªº»¡©ú¡C¦Ü©ó½u¬qªºªø«×«h¬O¥Î°Ñ¼Æ ncx¡Bncy ¨M©w¡Ancx¡Bncy ªí¥Ü«ö¶sªºªø¼e¡A¦s©ó DRAWITEMSTRUCT ªº rcItem Äæ¦ìùØ¡C

¹ï¸Ü²°¨ç¦¡

±µ¤U¨Ó´N¬O¹ï¸Ü²°¨ç¦¡¡ADEC2HEX ³B²z WM_INITDIALOG¡BWM_CTLCOLORDLG¡BWM_CTLCOLORSTATIC¡BWM_CTLCOLOREDIT¡BWM_CTLCOLORBTN¡BWM_DRAWITEM¡BWM_COMMAND¡BWM_CLOSE ³o¤K­Ó°T®§¡C

¦b³B²z WM_INITDIALOG °T®§®É¡A­º¥ýµo°e WM_SETICON °T®§³]©w¹Ï¥Ü ( ²Ä 202¡B203 ¦æ )¡AµM«á¨ú±o½s¿è®Ø¥H¤Î¦U«ö¶sªº¥N½X¡A¤p¤ì°¸§â½s¿è®Ø¥N½X¦s©ó hwndEdit ÅܼÆùØ¡A§â¤Q¤»­Ó«öÁä¥N½X¦s¦b hwndBTN ©Ò²Õ¦¨ªº°}¦C¤¤¡C¦b¦¹µyµy»¡©ú hwndBTN ªºµ²ºc¡AhwndBTN[0] ¦s¤J«öÁä¡y0¡zªºµøµ¡¥N½X ( ¤l±±¨î¤¸¥ó¤]¬O¤@ºØµøµ¡ )¡AhwndBTN[4] ¦s¤J«öÁä¡y1¡zªºµøµ¡¥N½X¡K¡K¨Ì¦¹Ãþ±À¡C¦¹³B ECX ¥i¥H¥Î§@©w§}¡A¦¹³B ECX ºÙ¬°°ò©³¼È¦s¾¹¡A½Ð°Ñ¦Ò²Õ¦X»y¨¥²Ä¤T¤Q³¹¡C

±µ¤U¨Ó WM_INITDIALOG °T®§ÁÙ³]©w fNumSys ¥H¤Î fConvert ³o¨â­ÓÅܼơCfNumSys ¬O¥Î¨Ó³]©w¨Ï¥ÎªÌ¿ï¾Ü¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì¡AÁÙ¬O¤Q¤»¶i¦ìÂà´«¦¨¤Q¶i¦ì¡A¦pªG¬O«eªÌ«h³]¬°¹s¡A«áªÌ«h³]¬°¤@¡C¤@¶}©l°õ¦æµ{¦¡®É¡A¤º©w­È¬°¹s¡Aªí¥Ü­n¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì¡A¦pªG¨Ï¥ÎªÌ«ö¤U¡yHEX->DEC¡z«ö¶s¡A¨º»ò´N³]©w¬°¤Q¤»¶i¦ìÂà´«¦¨¤Q¶i¦ì¡AfNumSys ¤]­n³]¬°¤@¡A¦P®É¤]³]©w«ö¶s¡yA¡z¡ã¡yF¡z¥i¥H±µ¦¬·Æ¹«©ÎÁä½L¿é¤J¡A¥i¥H°Ñ¦Òµ{¦¡²Ä 285 ¨ì²Ä 287 ¦æ¡C­Y¨Ï¥ÎªÌ«ö¤U¡yDEC->HEX¡z«ö¶s¡A¨º»ò´N³]©w¬°¤Q¶i¦ìÂà´«¦¨¤Q¤»¶i¦ì¡AfNumSys ¤]­n³]¬°¹s¡A¦P®É¤]³]©w«ö¶s¡yA¡z¡ã¡yF¡z¤£±µ¦¬·Æ¹«©ÎÁä½L¿é¤J¡A¥i¥H°Ñ¦Òµ{¦¡²Ä 289 ¨ì²Ä 291 ¦æ¡C

ÅÜ¼Æ fConvert ¬O«ö¤U¡yConvert¡z«ö¶s«á¡A¨¾¤î¨Ï¥ÎªÌ±µµÛ«ö¤U¼Æ¦r«ö¶s¡A¥H­P©ó¨Ï±o½s¿è®Øµe­±²V¶Ã¦Ó³]ªº¤@­ÓºX¼Ð¡C¤@¯ë­pºâ¾÷¿é¤Jºâ¦¡¤§«á¦A«öµ¥©óÁä«K·|©ó¿Ã¹õ¤W¥X²{µª®×¡A³o®É¦pªGÁÙ­n¦A­pºâ¥t¤@­Óºâ¦¡¡A¤£»Ý­n¦A«ö¤U²M°£Áä¡A¥i¥Hª½±µ«ö¤U¼Æ¦rÁä¤]¯à²M°£¿Ã¹õ¤Wªºµª®×¦P®É¿é¤J³Ì°ª¦ìªº¼Æ¦r¡ADEC2HEX ¤]¼Ò¥é³o­Ó¥\¯à¡C¦ý¬O¦¹³B¥X²{¤@­Ó°ÝÃD¡A¦pªG«ö¤U¼Æ¦rÁ䤧«e³£²M°£½s¿è®Øªº¤º®e¡A¨º»ò¦pªG­n¿é¤J¡y12¡zªº¡y2¡z®É¡A´N·|§â¡y1¡zµ¹²M°£¤F¡C©Ò¥H¤p¤ì°¸³]¤F fConvert ³o­ÓÅܼơA·í«ö¤U¡yConvert¡z«ö¶s«á¡A·|§â fConvert ³]©w¤@ ( µ{¦¡²Ä 299 ¦æ )¡A¦¹«á¦pªG«ö¤Uªº¥ô¦ó¼Æ¦rÁä«K·|²M°£½s¿è®Ø¡AµM«á¦A§â fConvert ²M°£ ( µ{¦¡²Ä 305 ¦æ )¡Aµ{¦¡¥u­nÀˬd fConvert¡A­Y¬°¤@¡A´N²M°£½s¿è®Ø¡F­Y¬°¹s¡A«h¤£²M°£½s¿è®Ø¡C

±µµÛ WM_INITDIALOG °T®§ÁÙ¦bµ{¦¡²Ä 224 ¨ì 231 ¦æ³]©w¤F¹ï¸Ü²°¡BÀRºA¤¸¥ó¡B½s¿è®Ø¡B¼Æ¦r«ö¶sµe¨ê¡A¦A¦s¤J¬Û¹ïÀ³ªºÅܼÆùØ¡AhbrDlg¡BhbrStatic¡BhbrEdit¡BhbrBTN¡C

±µµÛ²Ä 233 ¦æ¨ì²Ä 258 ¦æ¬O³B²z WM_CTLCOLOR* °T®§ªº¡A´N¦p«e­z­ì²z¡A´N¤£¸Ô­z¤F¡A¶È¬D¯S®íªº»¡©ú¡C¨ä¤¤§ïÅܹï¸Ü²°­I´º¸û¬°Â²³æ¡A¥u­n§â³o­Óµe¨ê¥N½X¶Ç¦^§Y¥i¡C

°ßŪ½s¿è®Ø©Òµo¥Xªº WM_CTLCOLOR*

¦b³o­Óµ{¦¡ùج°¤F¥uÅý¨Ï¥ÎªÌ¿é¤J¡y0¡z¡ã¡yF¡z¼Æ¦r¡A©Ò¥H½s¿è®Ø¨ã¦³°ßŪ ( ES_READONLY )­·®æ¡C®Ú¾Ú MSDN¡A¨ã¦³ ES_READONLY ­·®æªº½s¿è®Ø¥H¤Î¤£¯à±µ¨ü·Æ¹«©ÎÁä½L¿é¤Jªº½s¿è®Ø¡Aµo¥X WM_CTLCOLORSTATIC ¦Ó¤£¬O WM_CTLCOLOREDIT¡A©Ò¥H²Ä 238¡ã240 ¦æÀˬd WM_CTLCOLORSTATIC ªº lParam ¬O§_¬°½s¿è®Øµo¥Xªº¡A¦pªG¬Oªº¸Ü«h¸õ¦Ü²Ä 248 ¦æ³B²z¡C

³Ì«áÁÙ¨S»¡©úªº¬O WM_COMMAND °T®§¡A³o­Ó°T®§³B²z¤F©Ò¦³«ö¶s³QÀ£¤U«á¡A©Òµo¥Íªº¨Æ¡A½Ð°Ñ¦Ò²Ä¤»³¹ªº»¡©ú¡CDEC2HEX ¤ñ¸û¯S§Oªº¬O¡yDEC->HEX¡z©M¡yHEX->DEC¡z¨â­Ó«ö¶s¡A«ö¤U¤§«á¡A·|¨Ï±o¬Y¨Ç«ö¶sµLªk±µ¦¬·Æ¹«»PÁä½Lªº¿é¤J¡C°Æµ{¦¡ Dec2Hex ©M Hex2Dec ´N³B²z³o­Ó¨Æ±¡¡A©Ò­n¥Îªº API ¬O EnableWindow¡C

EnableWindow API

EnableWindow API ¬O¥Î¨Ó³]©w¤l±±¥ó¬O§_¯à±µ¦¬·Æ¹«»PÁä½Lªº¿é¤J¡A¨ä­ì«¬¬O¡G

BOOL EnableWindow(
    HWND    hWnd,   // handle to window
    BOOL    bEnable // flag for enabling or disabling input
   );

hWnd ¬O¤l±±¥ó¥N½X¡AbEnable «ü©w¤l±±¥ó¬O§_¯à±µ¨üÁä½L»P·Æ¹«¿é¤J¡A¯àªº¸Ü¥Î TRUE¡A¤£¯àªº¸Ü¥Î FALSE¡C


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