Ch 09 ¹ï¸Ü²°(2)

¤W¤@³¹´£¨ì¹ï¸Ü²°¥]§t¤F³\¦hªº¤lµøµ¡¡A§^¤HºÙ¤§¬°¡y±±¨î¤¸¥ó¡z¡A¤p¤ì°¸§Q¥Î«Ø¥ßµøµ¡ API¡ACreateWindowEx¡A³sÄò«Ø¥ß¤F¼Æ­Ó¦b¹ï¸Ü²°ùتº¤lµøµ¡¡A·íµM³oºØ°µªk¨Ã¤£¬O³Ì¦nªº¤èªk¡AÁcÂø¥B³Â·Ð¡A¤×¨ä¬O¦b¦w±Æ¤lµøµ¡ªº¦ì¸m¡B¤j¤p¡A¨S¦³¸g¹L´X¦¸¸ÕÅç¡AµLªkº¡·N¡C¥»³¹±N§â¹ï¸Ü²°¥[¤J¸ê·½´y­zÀɤº¡A¨Ã¥Î¹Ï§Î¤Æªº¸ê·½½s¿è¾¹½Õ¾ã¹ï¸Ü²°¤¤±±¨î¤¸¥óªº©Ê½è¡A³o¼Ë´N¯à«Ü®e©ö¦a¼¶¼g¹ï¸Ü²°µ{¦¡¤F¡C


¹ï¸Ü²°­±ªO²¤¶

¨Æ¹ê¤W¡A·L³n¦­¤w¦b¸ê·½´y­zÀɤ¤©w¸q¤F¹ï¸Ü²°­±ªO ( dialog template )¡A¨äµ²ºc¦p¤U¡J

name    DIALOG  x, y, cx, cy
STYLE   sytle
FONT    height,name,weight,italic
CAPTION caption_text
CLASS   class_name
BEGIN
 CONTROL   "text", ID, class_name, style, x, y, width, height, exStyle
    ¡K¡K
END

¨ä¤¤²Ä¤@¦æªº name ¬O¹ï¸Ü²°¦WºÙ¡A³o­Ó¦WºÙ±N­n©M CreateDialogParam API °t¦X¡ACreateDialogParam ¬O¥Î¨Ó§â¹ï¸Ü²°­±ªO«Ø¥ß¦U¤lµøµ¡ªº API¡Aµy«á¦A¸Ñ»¡¥L¡Cname ¤§«á¬OÃöÁä¦r¡ADIALOG¡A¥Î¨Óªí¥Ü³o­Ó°Ï¶ô¬O¹ï¸Ü²°­±ªO¡CDIALOG ¤§«áªº x¡By ¬O¹ï¸Ü²°ªº¦ì¸m¡A¦¹¦ì¸m¬O¬Û¹ï©ó¿Ã¹õ¥ª¤W¨¤ªº¦ì¸m¡Ccx¡Bcy ¤À§Oªí¥Ü¹ï¸Ü²°¼e«×»P°ª«×¡C

±µ¤U¨Óªº STYLE¡BFONT¡BCAPTION¡BCLASS ¤À§Oªí¥Ü­·®æ¡B¦r§Î¡B¼ÐÃD¡BÃþ§O¦WºÙ¡C³o¨Ç¹ï¸Ü²°©Ê½èªº´y­z¤¤¡A¥H CLASS ³Ì¬°­«­n¡A¥¦±N­n°t¦X CreateDialogParam API ²£¥Í¾ã­Ó¹ï¸Ü²°¡C±µ¤U¨Ó¥H¤@¹ï BEGIN/END ¥]§t¹ï¸Ü²°¤ºªº¦U­Ó¤l±±¨î¤¸¥ó¡A¨C­Ó¤l±±¨î¤¸¥ó¥H

CONTROL  "text", ID, class_name, style, x, y, width, height, exStyle

ªº§Î¦¡´y­z¡A"text" ¬O±±¨î¤¸¥óªº¹w©w¤å¦r¡AID ¬OÃѧO¸¹½X¡Ax¡By ¬O¤lµøµ¡ªº¦ì¸m¡Awidth¡Bheight ¬O¤lµøµ¡ªº¼e»P°ª¡Astyle ¬O¤lµøµ¡­·®æ¡Cclass_name ¬O¦b¨t²Î¤¤¤w¹w¥ý©w¸qªºµøµ¡Ãþ§O¡A¥i¥H¥Î STATIC ªí¥ÜÀRºAÃþ§O¡ABUTTON ªí¥Ü«ö¶sÃþ§O¡AEDIT ªí¥Ü½s¿è®ØÃþ§O¡ACOMBOBOX ªí¥Ü½Æ¦XÃþ§O¡ALISTBOX ªí¥Ü¦Cªí²°Ãþ§O¡ASCROLLBAR ªí¥Ü±²¶bÃþ§Oµ¥µ¥¡C

¤£¦PÃþ§Oªº¤l±±¥ó¥i¥Îªº­·®æ¤£ºÉ¬Û¦P¡A¨Ò¦p½s¿è®Ø±±¥ó»P«ö¶s±±¥ó¬Ý°_¨Ó¬OºIµM¤£¦Pªº¨âºØªº±±¥ó¡AµM«h¥¦­Ì³£¬O¤lµøµ¡¡A²£¥Í¤èªk¬Û¦P¦ý¨ã¦³¤£¦Pªº­·®æ¡A¦Ó¬Oµ¡Ãþ§OºØÃþ¦Ü¤Ö¦³³o¤»ºØ¡A©Ò¨Ï¥Î­·®æ§ó¦h¡A©Ò¥H­nÁA¸Ñ¥¦­Ì¤£¨Æ¥ó©ö¨Æ¡C¦³®É§Y¨Ï¬O¦PºØµøµ¡Ãþ§O¡A¨ä¥~Æ[»P¨Ï¥Î¤è¦¡¥ç¬Û¥h¬Æ»·¡A¨Ò¦p BUTTON Ãþ§O¤¤¦³ÀËÅç²°¡B¤UÀ£¦¡«ö¶s¡B¶ê§Î«ö¶sµ¥¼ÆºØ±±¨î¤¸¥ó¡C¹³³o¼Ë¨ã¦³¬Û¦Pªºµøµ¡Ãþ§O¡A«o¦]­·®æ¤£¦P¦Ó¥~Æ[»P¨Ï¥Î¤è¦¡¤]¤£¦P¡A¶È¥H­·®æ¨Ó°Ï§O¡A¨Ã¤£¬O¤@¥Ø¤FµMªº°µªk¡C¤U­±ªº¨Ò¤l¤¤¡A²Ä¤@­Óªí¥Ü¤UÀ£¦¡«ö¶s±±¥ó¡A²Ä¤G­Ó¬OÀËÅç²°±±¥ó¡G

CONTROL  "½T©w"    ,1,"BUTTON",BS_PUSHBUTTON,100, 20, 50, 14
CONTROL  "¦V¥k¹ï»ô",2,"BUTTON",BS_CHECKBOX  , 10, 10, 50, 14

¦ý¬O¦pªG¤£¸Ô²ÓÀˬd¨ä«áªº­·®æ¡A«Ü¤£®e©ö§PÂ_¡A¦³®É­·®æ¬O¤S¯ä¤Sªø¡A¨º»ò§PŪ§ó¬°§xÃø¡C©Ò¥H RC.EXE ¤]¤¹³\¥t¤@ºØªí¥Ü¤è¦¡¤l±±¥ó¡G

control-type  "text", ID, x, y, width, height [,styles]

³o®É control-type ´N¯àªí¥Ü¥X¦UºØ¤l±±¥ó»P³¡¤À­·®æ¤F¡A¨Ò¦p¤W­±¨â­Ó¤l±±¥ó´N¥H

PUSHBUTTON  "½T©w"    ,1,100, 20, 50, 14
CHECKBOX    "¦V¥k¹ï»ô",2, 10, 10, 50, 14

ªí¥Ü¡A³o¼Ë´Nª½±µ¦h¤F¡A¥iŪ©Ê¤]¤j¤j´£°ª¤F¡C»Ý­nª`·Nªº¬O¡A¹³ PUSHBUTTON¡BCHECKBOX ³o¨Ç¨Ã¤£¬Oµøµ¡Ãþ§O¡A¥¦­Ì¬Oµøµ¡Ãþ§O¦A¥[¤W¬Y¨Ç­·®æ¦Ó¦¨¡C¤Uªí¬O±`¥Îªº class_name ( ¤lµøµ¡Ãþ§O ) »P control-type ( ±±¨î¤¸¥ó ) Ãö«Y¡G

µøµ¡Ãþ§O
class name
±±¨î¤¸¥ó
control type
¦WºÙ¤º©w­·®æ
STATIC LTEXT¦V¥ª¹ï»ôªº¦r¦ê SS_LEFT¡AWS_GROUP
CTEXT ¦V¤¤¹ï»ôªº¦r¦ê SS_CENTER¡AWS_GROUP
RTEXT ¦V¥k¹ï»ôªº¦r¦ê SS_RIGHT¡AWS_GROUP
ICON ¹Ï¥Ü±±¥ó SS_ICON
BUTTON PUSHBUTTON ¤UÀ£¦¡«ö¶s BS_PUSHBUTTON¡AWS_TABSTOP
DEFPUSHBUTTON ¤º©w¤UÀ£¦¡«ö¶s BS_DEFPUSHBUTTON¡AWS_TABSTOP
CHECKBOX ÀËÅç²° BS_CHECKBOX¡AWS_TABSTOP
AUTOCHECKBOX ¦Û°ÊÀËÅç²° BS_AUTOCHECKBOX¡AWS_TABSTOP
RADIOBUTTON ¶ê§Î«ö¶s BS_RADIOBUTTON¡AWS_TABSTOP
AUTORADIOBUTTON ¦Û°Ê¶ê§Î«ö¶s BS_AUTORADIOBUTTON¡AWS_TABSTOP
GROUPBOX ¸s²Õ BS_GROUPBOX
EDIT EDITTEXT ½s¿è®Ø ES_LEFT¡AWS_BORDER¡AWS_TABSTOP

ÀRºAµøµ¡Ãþ§Oªº±±¨î¤¸¥ó ( Static Controls )

ÀRºAµøµ¡Ãþ§O¬O¦b¤@¶ô¯x§Î°Ï°ì¤ºÅã¥Ü©T©wªº¤å¦r©Î¹Ï¥Ü¸ê®Æ¡C«e­±´£¨ì¡A¦b¹ï¸Ü²°­±ªO¤¤©w¸q¤l±±¥ó¦³¨âºØ¤è¦¡¡A¤@ºØ¸û§¹¾ã¡A¤@ºØ¸û¨ã¥iŪ©Ê¡C¥H«eºØ¤è¦¡ªí¥Ü®É¡A®æ¦¡¦p¤U¡G

CONTROL     "text", ID, class_name, style, x, y, width, height, exStyle

¦¹®É CONTROL ¬O©T©wªº¡Aclass_name ¤]¬O©T©wªº¡A¥²¬° STATIC¡A¦Ó style ¥i¥H¥Î SS_LEFT¡BSS_CENTER¡BSS_RIGHT ¤À§Oªí¥Ü¤å¦r¦V¤lµøµ¡¥ªÃä¡B¤¤¶¡¡B¥kÃä¹ï»ô ( SS_ ªí¥Ü static style ªº·N«ä )¡C¨Ò¦p

CONTROL     "¿é¤J­^¦T¡G",1,"STATIC", SS_LEFT, 20, 20, 50, 12

¥H«áºØ¤è¦¡ªí¥Ü¤å¦rÀRºA¤¸¥ó®É¡A®æ¦¡¦p¤U¡G

control-type  "text", ID, x, y, width, height [,styles]

control-type ¥i¥H¥Î LTEXT¡BCTEXT¡BRTEXT ¨ä¤¤ªº¥ô¦ó¤@­Ó¡A¨ä·N¸q¤À§Oªí¥Ü¨ä«á©Ò±µªº¤å¦r¦V¥ª¡B¦V¤¤¡B¦V¥k¾a»ô¡A¨ä¹ê´N¤À§O¥Nªí SS_LEFT¡BSS_CENTER¡BSS_RIGHT ­·®æ¡C¦Ü©ó©ÒÅã¥Üªº¤å¦r©ñ¦b text ¤º¡A¨Ã¥H¤@¹ï¡y"¡z¬A°_¨Ó¡AÃѧO¸¹½X¥i¥H¬O 0 ¨ì 65535 ¤§¶¡ªº¥¿¾ã¼Æ¡C¨Ò¦p¡G

LTEXT       "¿é¤J­^¦T¡G", 1, 20, 20, 50, 12

¨ä¹ê³oºØ©w¸q¤l±±¥óªº¤è¦¡©M¤W­±¥Õ¦âªº©w¸q¬O¤@¼Ëªº¡C¦Ü©ó¨ä¥L±`¥Îªº­·®æÁÙ¦³ SS_BLACKFRAME¡BSS_WHITEFRAME µ¥µ¥¡ASS_BLACKFRAME ¬OÅã¥ÜÃä®ØÃC¦â¡A¦¹ÃC¦â©M COLOR_WINDOWFRAME ¬Û¦P¡A¦Ó SS_WHITEFRAME «h¬O©M COLOR_WINDOW ¦P¦â¡C·íµM¦b¤£½Ä¬ðªº±¡§Î¤U¡A³o¨Ç­·®æ¥i¥H¥Î¡y|¡z¨Ï¥L­Ì¤¬¬Û¦s¦b¡C

°²¦p­nÅã¥Ü¹Ï¥Ü®É¡Acontrol-type ¥Î ICON¡A"text" ¬°¹Ï¥Ü¦WºÙ¡A¨Ã¤£¬O¹Ï¥ÜÀɦW¡A¦Ü©ó¹Ï¥Üªº¨Ó·½¬O¥Ñ¸ê·½Àɤ¤¥t¤@­Ó¬q¸¨¡AICON¡A©Ò«ü©w¡A½Ð°Ñ¦Ò²Ä¤C³¹¹Ï¥Ü¸ê·½ªº»¡©ú¡C§A¥i¥H¬Ý¬Ý¨Ò¤l¡A¤p¤ì°¸¤£¦AÂØ­z¤F¡C

«ö¶sµøµ¡Ãþ§Oªº±±¨î¤¸¥ó ( Button Controls )

«ö¶s±±¥ó¦³³\¦hºØ¼Ë¤l¡A³Ì±`¨£ªº¬O¤UÀ£¦¡«ö¶s ( PUSHBUTTON )¡A¥¦¬O¤@­Ó¯x§Î°Ï°ì¡A¥[¤W¥ßÅ骺¥~®Ø¡A§Î¦¨¤@­Ó«ö¶s¡A¥i¨Ñ¨Ï¥ÎªÌ¥H·Æ¹«¥ªÁäÂI¿ï¡C¨ä¥LÁÙ¦³¤º©w¤UÀ£¦¡«ö¶s ( DEFPUSHBUTTON )¡B¶ê§Î«ö¶s ( RADIOBUTTON )¡BÀËÅç²° ( CHECKBOX )¡B¸s²Õ ( GROUPBOX ) µ¥µ¥¡C¦p¤U¹Ï©Ò¥Ü¡G

»¡©ú«ö¶s±±¥ó
³o¤@³¹¥ý¤¶²Ð¤UÀ£¦¡«ö¶s¤Î¤º©w¤UÀ£¦¡«ö¶s¡C¤º©wªº«ö¶s¬O«ü°²¦p¦¹¹ï¸Ü²°ÁÙ§t¦³½s¿è®Ø±±¨î¤¸¥ó®É¡A·í¨Ï¥ÎªÌ«ö¤U Enter Áä®É¡A´N¬Û·í©M¥H·Æ¹«ÂI¿ï¸Ó«ö¶s¤@¼Ë¡C¦b«ö¶s¤Wªº¤å¦r©ñ¦b text ùØ¡A¦P¼Ëªº¡A¤]¬O¥H¤@¹ï¡y"¡z¬A°_¨Ó¡C©w¸q¤UÀ£¬O«ö¶s®É¡A¥i¥H¥Î

PUSHBUTTON  "½T©w", 1, 100, 20, 50, 14
©Î
CONTROL     "½T©w", 1, BS_PUSHBUTTON, 100, 20, 50, 14

ªí¥Ü¡C

½s¿è®ØÃþ§Oªº±±¨î¤¸¥ó ( Edit Controls )

½s¿è®Ø¬O¤@¶ôªø¤è§Î°Ï°ì¡A¨Ñ¨Ï¥ÎªÌ¥HÁä½L¿é¤J¤å¦r¡A¤]¥i¥H¥Î Del Áä¡B°h¦ìÁä ( backspace )¡BCtrl¡ÐC¡BCtrl¡ÐVµ¥Áä°µ§R°£¡B°h¦ì§R°£¡B«þ¨©¡B¶K¤Wµ¥½s¿è°Ê§@¡C­n¨Ï¥Î½s¿è®Ø¤l±±¥ó®É¡Acontrol-type ¥i¥H¥Î EDITTEXT ªí¥Ü¡A¨Ò¦p¡G

EDITTEXT  3,99,45,50,12,ES_NUMBER

¦ý¥Î EDITTEXT ®ÉµLªk³]©w¤º©w¤å¦r¡A¤]´N¬O»¡¿Ã¹õ¤@Åã¥Ü¹ï¸Ü²°®É¡A½s¿è®ØµLªkÅã¥Ü¤å¦r¡A°²¦p­n³]©w¤º©w¤å¦r¡A¨º»ò¥²¶·¨Ï¥Î¤U­±ªº¤èªk¡G

CONTROL   "100",3,"EDIT",ES_NUMBER,99,45,50,12

³o¼Ë¦b¤@Åã¥Ü¹ï¸Ü²°®É¡A½s¿è®Ø¤º´N·|¥X²{¡y100¡z¤F¡C½s¿è®Øªº­·®æ¬O¥H ES_ ( edit style ) ¬°¶}ÀY¡A±`¥Îªº¦³¤U¦C¼ÆºØ¡G

  1. ¤å¦r±Æ¦C¡GES_LEFT¡BES_CENTER »P ES_RIGHT ¤À§O¨Ï½s¿è®Ø¤ºªº¤å¦r¦V¥ª¡B¦V¤¤¡B¦V¥k¹ï»ô¡C
  2. ¤å¦rªº¤j¤p¼g¡GES_LOWERCASE¡BES_UPPERCASE ¤À§O·|Åý¨Ï¥ÎªÌ¿é¤Jªº­^¤å¦r¥À¦Û°Ê¦aÂà´«¦¨¤p¼g©Î¤j¼g¡C¦³®É­nÂà´«¦¨¯S®íªº¦r¶°®É¡A¥i¥Î ES_OEMCONVERT¡C
  3. ¦æ¼Æ¡G¤@¯ë¤£¯S§O³]©w¡A½s¿è®Ø¤º©w¥u¯à¿é¤J¤@¦æ¤å¦r¡A·í¨Ï¥ÎªÌ«ö¤U Enter Áäªí¥Ü¿é¤J§¹¦¨¡C¦pªG­n¿é¤J¦h¦æ¤å¦r¡A¥i¥H¥Î ES_MULTILINE¡A³o¼Ë«ö¤U Enter Áä®É¡A·|¨ì¤U¤@¦æÄ~Äò¿é¤J¡C
  4. ±²¶b¡G·í¨Ï¥ÎªÌ¿é¤Jªº¤å¦r¶W¹L½s¿è®Ø¤j¤p®É¡A¥i¥H¥[¤W ES_AUTOHSCROLL ©M ES_AUTOVSCROLL ¨Ï½s¿è®Ø¦Û°Ê¦a¦V¤ô¥­©Î««ª½±²°Ê¡CES_AUTOVSCROLL ¥u¦³¦b¦³ ES_MULTILINE ­·®æ®É¤~¦³®Ä¡C
  5. ½s®Ø¡G¤º©wªº½s¿è®ØµLÃä®Ø¡A¥i¥H¥[¤W WS_BORDER ¨Ï½s¿è®ØÅܱo¸û¬üÆ[¡C( ª`·N¡A©Ò¦³ªºµøµ¡¥i¥ÎÃä®Ø¡A©Ò¥H¬O WS_ °_ÀY¡A¤£¬O ES_¡C)
  6. ES_NUMBER ­·®æ¡GES_NUMBER ¨Ï±o½s¿è®Ø¶È¯à¿é¤J¼Æ¦r¡C
  7. ES_READONLY ­·®æ¡G¨Ï½s¿è®Ø¤£¯à¿é¤J¤å¦r¡A¦ý¬O¤´¥i¨Ï¥Î¦UºØ½s¿èÁä¡A¦p«þ¨©¡B¶K¤W¡C
  8. ES_PASSWORD ­·®æ¡GÅý¨Ï¥ÎªÌ¿é¤Jªº¤å¦r³£Åã¥Ü¦¨¡y*¡z©Î¶ÂÂI¡A±`¥Î¦b¿é¤J±K½Xªº®É­Ô¡C
  9. ES_NOHIDESEL¡G¤@¯ë½s¿è®Ø¥¢¥h¿é¤JµJÂI®É¡A¥Î·Æ¹«©Ò¿ï¾Ü¤å¦rªº¤Ï¥Õ·|®ø¥¢¡A¦ý¥[¤W ES_NOHIDESEL ­·®æ«á¡A«h§Y¨Ï¥¢¥hµJÂI¤]¤£·|¨Ï¤Ï¥Õ®ø¥¢¡C
  10. ES_WANTRETURN¡G¥i¥HÅý¨ã¦³ ES_MULTILINE ­·®æªº½s¿è®Ø¡A¦b¨Ï¥ÎªÌ«ö¤U Enter Áä®É¡A·s¼W¤U¤@¦æ¡C

¸ê·½½s¿è¾¹

¦p«e³¹©Ò­z¡A¦w±Æ¤l±±¨î¤¸¥óªº¦ì¸m¡B¤j¤p¬O³]­p¹ï¸Ü²°³Ì³Â·Ðªº³¡¥÷¡C³Ì¦n¬O¯à¦³¡y©Ò¨£§Y©Ò±o¡zªº¹ï¸Ü²°½s¿è¾¹¡A¯à¦b®à­±¤W¥H·Æ¹«ÂI¿ï¡B©ì¡B©Ôªº¤èªk¡A´N¯à«Ø¥ß¥X§t¦³¬Û¹ïÀ³ªº¤l±±¨î¤¸¥ó¹ï¸Ü²°ªº¸ê·½ÀÉ¡C

ºô»Úºô¸ô¤W¦³¤@¨Ç¸ê·½½s¿è¾¹¥i¥Hº¡¨¬³o­Ó»Ý¨D¡C¤p¤ì°¸¤¶²Ð¤@­Ó¦@¨É³nÅé¡AResource Builder¡A³o­Ó³nÅé¬O¥Ñ SIComponents ¤½¥q¶}µoªº³nÅé¡A³Ì·sª©¥i¨ì SIComponents ¤½¥q¤U¸ü¡Aª©¥i¥H¨ì The Programmer's Portal ºô­¶¤¤ªº bin tools ¿ï¶µ¤U¸ü¡A©Îª½±µ«ö¦¹³B¤U¸ü¡C±N¦¹À£ÁYÀɸѶ}«á¡A°õ¦æ SETUP.EXE §Y¥i¦w¸Ë¡C

¦w¸Ë§¹²¦¡A°õ¦æ Resource Builder «á¡A¦b Resource Builder µe­±ªº¥ª¤U¤è¦³´X­Ó¸ê·½¿ï¶µ¡AIcon¡BCursor¡BBitmap¡K¡K¡A°²¦p±z·Q«Ø¥ß¹ï¸Ü²°¡A´N§â·Æ¹«²¾¨ì Dialog ¿ï¶µ¡AµM«á«ö¤U·Æ¹«¥kÁä¡A·|¥X²{¤@­Ó¼u¥X¿ï³æ¡A¦A¨Ï·Æ¹«²¾¨ì Add ¤W¡Aªí¥Ü­n¦b¸ê·½ÀɤW¥[¤J¹ï¸Ü²°¡C©ÎªÌ¬O¦b¼ÐÃDÄd¤Uªº¿ï³æ¿ï¾Ü¡yResource¡z¡yAdd¡K¡z¡A¦¹®Éµe­±¦p¤U¡G

¿ï¾Ü¡yAdd¡K¡z«á¡A¤u¨ã¦C·|§ïÅÜ¡A¥Dµe­±¤]·|³Q¤À³Î¦¨¤T³¡¥÷¡A³Ì¥ªÃä¬O¥i¥[¤J¸ê·½Àɪº¿ï¶µ¡A¤¤¶¡¬O¤u§@°Ï ( ¦¹³B´N¬O±z©Ò³]­pªº¹ï¸Ü²°¡A¤]´N¬O±z¤é«á°õ¦æµ{¦¡®É©Ò¬Ý¨ìªºµe­±)¡A³Ì¥kÃä¬O¤u§@°ÏùئU¤¸¥óªº©Ê½è ( Properties )¡A¦p¤U¹Ï©Ò¥Ü¡J
·í±z·Q¥[¤J¤@­Ó±±¨î¤¸¥ó®É¡A¥i¥H¨ì¤u¨ã¦C¿ï¾Ü±±¨î¤¸¥ó¡AµM«á²¾°Ê·Æ¹«¡A¦b±z·Q­nªº©ñ¸m¸Ó±±¨î¤¸¥óªº¦ì¸m¤W«ö¤U·Æ¹«¥ªÁä§Y¥i¡C±z¤]¥i¥H¦b¤u§@°Ï¤¤¿ï¾Ü¨ä¤¤¤@­Ó±±¨î¤¸¥ó¡A½Õ¾ã¨ä¤j¤p¡B¦ì¸m¡C¦p¦¹¨Ì§Ç§â±z­n¥[¤Jªº±±¨î¤¸¥ó²K¤W¡A¦sÀɧY¥i¡C

¬Ý°_¨Ó¦ü¥G«Ü§¹¬ü¡A¤£¹L Resource Builder ¤@ª½¨ì 2.1.2 ª©³£¹ï¤¤¤å¤£¬Û®e¡C¦ý¬O¦³¸Ñ¨Mªº¤èªk¡A¨º´N¬O¦b³]­p±±¨î¤¸¥ó®É¤£­n¨Ï¥Î¤¤¤å¡A¦s¦¨Àɮ׫á ( ¦¹Àɮ׬O¸ê·½´y­zÀÉ¡A¬O¤@ºØ¯Â¤å¦rÀÉ )¡A¦A¥Î¤å®Ñ³B²z¾¹µy¥[­×§ï¡C¤p¤ì°¸§â­è­è³]­p¦nªº¹ï¸Ü²°¦s¦¨ inch.rc ÀÉ¡A¶}±Ò«á¬O¹³¤U­±³o¼Ë¡J

/*********************************************
File: D:\HOMEPAGE\SOURCE\INCH.RC
Generated by Resource Builder 2.0.
*********************************************/
// Below are important 3 lines, don't change them!
/*
OutputExt=res
*/

DIALOG_0 DIALOG 0, 0, 164, 71
STYLE DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |
      WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX 
CAPTION "inch to cm"
FONT 8, "Tahoma"
LANGUAGE LANG_NEUTRAL, 0
BEGIN
  CONTROL "Picture0",0,"STATIC",SS_BLACKFRAME |WS_CHILD |
          WS_VISIBLE ,6,21,32,32
  CONTROL "Label0",1,"STATIC",SS_LEFT |WS_CHILD |
          WS_GROUP |WS_VISIBLE ,53,19,99,18
  CONTROL "input inch:",2,"STATIC",SS_LEFT |WS_CHILD |
          WS_GROUP |WS_VISIBLE ,53,47,41,8
  CONTROL "",3,"EDIT",ES_NUMBER |ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |
          WS_VISIBLE ,99,45,50,12
  CONTROL "Button0",4,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |
          BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,20,61,50,14
  CONTROL "Button1",5,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |
          BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,90,61,50,14
END

¦ý¬O¨ä¤¤¥Õ¦âªº³¡¥÷¬OÄÝ©ó¼ÐÃD©Î«ö¶s¤Wªº¤å¦r¡AÀ³¸Ó´«¦¨¤¤¤å¡A¤p¤ì°¸¥H UtralEdit ±N¥¦­×¹¢¦¨¦Û¤v³ßÅwªº¡A¦P®É¥[¤W¿ï³æ¤Î¹Ï¥Ü¡A³Ì­«­nªº¬O­n¦b¹ï¸Ü²°¬q¸¨³B¥[¤W CLASS ³o¤@¶µ¥²¶·²K¥[¤W¥h¡A¦p¤U­±©Ò¥Ü¡J

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

#define IDM_Exit    2001
#define IDM_Clear   2002
#define IDM_Calc    2003
#define IDM_Help    2004

InchMenu        MENU
BEGIN
  MENUITEM      "Â÷¶}",IDM_Exit
  MENUITEM      "Âk¹s",IDM_Clear
  MENUITEM      "­pºâ",IDM_Calc
  MENUITEM      "»¡©ú",IDM_Help
END

InchIcon        ICON    INCH.ico

InchDlg DIALOG  0,0,170,80
STYLE   DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |
        WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX 
CAPTION "­^¦TÂà´«¦¨¤½¤À"
CLASS   "InchDlgClass"
FONT    9,"·s²Ó©úÅé"
BEGIN
  ICON    "InchIcon",1001,9,8,32,32
  CONTROL "±z¥i¥H¿é¤J­^¦T¡AINCH.EXE ·|´«ºâ¦¨¤½¤À(cm)",1002,"STATIC",
          SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,51,6,110,21
  CONTROL "¿é¤J­^¦T¡J",1003,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |
          WS_VISIBLE ,51,32,43,8
  CONTROL "0",1004,"EDIT",ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |
          WS_VISIBLE ,98,30,38,12
  CONTROL "­pºâ",1005,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |
          WS_CHILD |WS_TABSTOP |WS_VISIBLE ,11,47,50,14
  CONTROL "Â÷¶}",1006,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |
          WS_CHILD |WS_TABSTOP |WS_VISIBLE ,108,47,50,14
END

¦¹¥~ÁÙ¦³¤@¨Ç²Ó¸`¡A¨Ò¦p±±¨î¤¸¥óªºÃѧO¸¹¡B¹ï¸Ü²°ªº°ª«×³£²¤¥[­×¹¢¤F¡C­×¹¢¹L«áªº inch.rc ¦]¬°§t¦³¤¤¤å¡A´NµLªk¦A¥H Resource Builder ­×§ï¤F¡C®Ú¾Ú inch.rc ªº¹ï¸Ü²°­±ªO¤Î¿ï³æ©Ò«Ø¥ßªºµøµ¡¦p¤U¹Ï¡G


­ì©lÀÉ

©³¤U¬O inch.asm ­ì©l½X¡G

        .386
        .model  flat,stdcall
        option  casemap:none

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

IDC_Icon        equ     1001    ;11 ±±¨î¤¸¥ó¡A¹Ï¥Üªº ID
IDC_String1     equ     1002    ;12 ±±¨î¤¸¥ó¡A¦r¦êªº ID
IDC_String2     equ     1003    ;13 ±±¨î¤¸¥ó¡A¦r¦êªº ID
IDC_Edit        equ     1004    ;14 ±±¨î¤¸¥ó¡A½s¿è®Øªº ID
IDC_Calc        equ     1005    ;15 ±±¨î¤¸¥ó¡A­pºâªº ID
IDC_Exit        equ     1006    ;16 ±±¨î¤¸¥ó¡AÂ÷¶}ªº ID
IDM_Exit        equ     2001    ;17 ¿ï³æ¡AÂ÷¶}ªº ID
IDM_Clear       equ     2002    ;18 ¿ï³æ¡A²M°£ªº ID
IDM_Calc        equ     2003    ;19 ¿ï³æ¡A¬d¸ßªº ID
IDM_Help        equ     2004    ;20 ¿ï³æ¡A»¡©úªº ID
eff_digt        equ     7       ;21 ¿é¤J­^¦T³Ì¤j¦ì¼Æ

WndProc         proto   :HWND,:UINT,:WPARAM,:LPARAM
inch2cm         proto   :DWORD
;***************************************
        .DATA
ClassName       db          'InchDlgClass',0
HelpText        db          'INCH.EXE µ{¦¡¬O¥Î¨Ó§â­^¦T´«ºâ¦¨¤½¤À¡C'
                db          '§A¥i¥H¦b©³¤U¿é¤J­^¦T(¥u¦³«e7¦ì¦³®Ä)¡AµM'
                db          '«á«ö¤U­pºâ«ö¶s¡Aµ{¦¡±N´«ºâ¦¨¤½¤À¡C',0
HelpTitle       db          '»¡©ú',0
ExitText        db          '¬O§_°h¥X¦¹µ{¦¡¡H',0
ExitTitle       db          '¸ß°Ý',0
CalcTitle       db          '´«ºâµ²ªG',0
String1         db          ' ­^¦T ¡× '
String2         db          ' ¤½¤À',0
String3         db          '±z¿é¤J¤F¤£¬O¼Æ¦rªº¦r¤¸¡C',0
CalcText        db          40h dup (' '),0     ;38 ­pºâµ²ªG¦r¦ê
IconName        db          'InchIcon',0        ;39 ¹Ï¥Ü¦WºÙ
MenuName        db          'InchMenu',0        ;40 ¿ï³æ¦WºÙ
DlgName         db          'InchDlg',0         ;41 ¹ï¸Ü²°¦WºÙ
ClearText       db          '0',0
hInstance       HINSTANCE   ?
hDlg            HWND        ?
wc              WNDCLASSEX  <?>
msg             MSG         <?>
factor          dd          254
ten_power       dd          1000000000,100000000,10000000
                dd          1000000,100000,10000,1000,100,10
inch            db          11 dup (0)  ;50 ¨Ï¥ÎªÌ¿é¤J¤§­^¦T¦r¦ê
String1_Len     equ         offset String2-offset String1
String2_Len     equ         offset String3-offset String2
;***************************************
        .CODE
;---------------------------------------
inch2cm proc    uses ebx esi edi inch_addr:DWORD
        local   counter:BYTE    ;57 ¨Ï¥ÎªÌ¿é¤Jªº¼Æ¦r¡A¶È¦³ eff_digt ¦ì¦³®Ä
        local   fraction:BYTE   ;58 ¤p¼Æ¦ì¼Æ
        local   if_frac:BYTE    ;59 ¨Ï¥ÎªÌ¬O§_´¿¿é¤J¤p¼ÆÂI¡A0ªí¥Ü¤£´¿¡A1ªí¥Ü´¿
        sub     eax,eax         ;60 EDX:EAX ±N¦s©ñ¿é¤J¤§­^¦T¼Æªº¤Q¤»¶i¦ì¼Æ
        sub     edx,edx         ;   ¬G¥ý²M°£
        mov     esi,inch_addr   ;62 ¨ú±o¨Ï¥ÎªÌ¿é¤J­^¦T¦r¦ê¤§¦ì§}©ó ESI
        mov     fraction,2      ;63 ¤@­^¦T=2.54cm¡A2.54¦³¨â¦ì¤p¼Æ
        mov     ebx,eax         ;64 ²M°£ EBX °ª¦r²Õ¡AEBX ±N¦s©ñ¨C¦¸¨ú±oªº¼Æ¥Ø
        mov     ecx,10          ;65 ¨C¨ú±o¤@¦ì¼Æ¥²¶·¨Ï EDX:EAX=10*EDX:EAX+EBX
        mov     counter,al      ;66 counter ¬°²{¦b¨ú±o²Ä´X­Ó¦ì¼Æ
        mov     if_frac,al      ;67 ¥ý°²³]¨Ï¥ÎªÌ¨S¦³¿é¤J¤p¼ÆÂI
        mov     edi,offset CalcText

next:   mov     bl,[esi]
        inc     esi
.if bl=='.'
        mov     if_frac,1
        mov     [edi],bl
.elseif bl==0
        jmp     finish
.else
        mov     [edi],bl;78 ¨Ï BL ¦s©ó CalcText ¦r¦ê¤¤
        mul     ecx
        sub     bl,'0'  ;80 ­Y BL<0 ©Î BL>9 ªí¥Ü¨Ï¥Î
        jb      not_n   ;81 ªÌ¿é¤J¤F¤£¬O¼Æ¦rªº¦r¤¸
        cmp     bl,9
        ja      not_n
        add     eax,ebx
        adc     edx,0
  .if if_frac==1
        inc     fraction
  .endif
.endif
        inc     counter
        inc     edi
        cmp     counter,eff_digt
        je      finish
        jmp     next

not_n:  mov     eax,offset String3
        jmp     exit    ;97 °h¥X inch2cm °Æµ{¦¡

finish: mul     factor  ;99 EDX:EAX=EDX:EAX*254

        mov     esi,offset String1
        mov     cx,String1_Len
        rep     movsb

        push    edi     ;105 §â EDX:EAX ¤ºªº¤Q¤»¶i¦ìÂà´«¦¨¤Q¶i¦ì ASCII ¦r¦ê
        mov     edi,offset inch ;106 ¦]¬° inch ¦r¦ê¤w¤£¥Î¡AÅv¥R¬° cm ¦r¦ê
next_power:
        mov     ebx,ten_power[ecx*4]
        div     ebx
        add     al,'0'
        inc     cx
        stosb
        mov     eax,edx
        sub     edx,edx
        cmp     cx,eff_digt+2
        jne     next_power
        add     al,'0'
        stosb

        mov     al,fraction
        mov     ecx,edi
        sub     ah,ah
        sub     ecx,offset inch ;123 ECX=¤½¤À¦r¦êªºªø«×
        cwd
        mov     edx,edi
        sub     ecx,eax         ;126 ECX=¤½¤À¦r¦ê¾ã¼Æ³¡¥÷ªºªø«×
        mov     ebx,eax         ;127 EBX=¤½¤À¦r¦êªº¤p¼Æ³¡¥÷ªø«×
        mov     esi,offset inch ;128 ESI «ü¦V¤½¤À¦r¦ê
        dec     edx             ;129 EDX «ü¦V¤½¤À¦r¦ê¤§§ÀºÝ
        pop     edi
        jcxz    no_int
nxt_1:  lodsb   ;132 ¨Ï¤Q¶i¦ìªºASCII¦r¦ê¥[¤W¤p¼ÆÂI
.if al=='0'
  .if ah==1     ;134 AH ªí¥Ü¬O§_´¿¥X²{¹L«D¹s¼Æ¦r¡A¥X²{¹L¬° 1
        stosb   ;135 ­Y¤w¥X²{¹L«D¹s¼Æ¦r¡A¤§«á¦A¥X²{ªº¹s­n¦s°_¨Ó
  .endif
.else
        mov     ah,1    ;138 ­Y¾ã¼Æ³¡¥÷¥X²{²Ä¤@­Ó«D¹sªº¼Æ¦r¡A³]©w AH ¬° 1
        stosb
.endif
        loop    nxt_1
.if ah==0
no_int: stosb   ;143 ¦pªG¾ã¼Æ³¡¥÷¬°¹s¡A¥[¤W¡y0¡z
.endif

.if ebx!=0
nxt_2:  cmp     byte ptr [edx],'0'
        jne     fnd_nz
        dec     ebx
        or      ebx,ebx
        jz      fnd_nz
        dec     edx
        jmp     nxt_2
.endif
fnd_nz: mov     ecx,ebx
        jcxz    no_pt
        mov     al,'.'
        stosb
.if ecx!=0
        rep     movsb
.endif
no_pt:  mov     esi,offset String2
        mov     ecx,String2_Len
        rep     movsb
        mov     eax,offset CalcText
exit:   ret
inch2cm endp
;---------------------------------------
deal_calc       proc    ;169 ³B²z¡y­pºâ¡z«ö¶sªº°Æµ{¦¡
        invoke  GetDlgItemText,hDlg,IDC_Edit,offset inch,eff_digt+1
        invoke  inch2cm,offset inch
        invoke  MessageBox,hDlg,eax,offset CalcTitle,MB_OK
        ret
deal_calc       endp
;---------------------------------------
start:  invoke  GetModuleHandle,NULL
        mov     hInstance,eax
        mov     wc.cbSize,SIZEOF WNDCLASSEX
        mov     wc.style,CS_HREDRAW or CS_VREDRAW
        mov     wc.lpfnWndProc,offset WndProc
        mov     wc.cbWndExtra,DLGWINDOWEXTRA
        mov     wc.hInstance,eax
        mov     wc.hbrBackground,COLOR_BTNFACE+1 
        mov     wc.lpszMenuName,offset MenuName
        mov     wc.lpszClassName,offset ClassName
        invoke  LoadIcon,hInstance,offset IconName
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        invoke  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        invoke  RegisterClassEx,offset wc       ;191
        invoke  CreateDialogParam,hInstance,offset DlgName,NULL,NULL,NULL
        mov     hDlg,eax
        invoke  ShowWindow,hDlg,SW_SHOWNORMAL
        invoke  UpdateWindow,hDlg
        invoke  GetDlgItem,hDlg,IDC_Edit        ;196
        invoke  SetFocus,eax
.while TRUE
        invoke  GetMessage,offset msg,NULL,0,0
.break .if (!eax)
        invoke  IsDialogMessage,hDlg,offset msg
  .if eax==FALSE
        invoke  TranslateMessage,offset msg
        invoke  DispatchMessage,offset msg
  .endif
.endw
        mov     eax,msg.wParam
        invoke  ExitProcess,eax
;---------------------------------------
WndProc proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_DESTROY
        invoke  PostQuitMessage,NULL
.elseif uMsg==WM_COMMAND
        mov     eax,wParam 
  .if   lParam==0
;216 ¥H¤U¬O³B²z¨Ï¥ÎªÌ«ö¤U¬Y­Ó¿ï³æªºµ{¦¡
    .if ax==IDM_Calc
        call    deal_calc
    .elseif ax==IDM_Clear
        invoke  SetDlgItemText,hWnd,IDC_Edit,offset ClearText   ;220 Âk¹s
    .elseif ax==IDM_Help
        invoke  MessageBox,hWnd,offset HelpText,offset HelpTitle,MB_OK
    .elseif ax==IDM_Exit
        invoke  MessageBox,hWnd,offset ExitText,offset ExitTitle,\
                MB_YESNO or MB_ICONQUESTION
      .if eax==IDYES
        invoke  DestroyWindow,hWnd
      .endif
    .endif
  .else
;231 ¥H¤U¬O³B²z¨Ï¥ÎªÌÂI¿ï±±¨î¤¸¥óªºµ{¦¡
        mov     edx,wParam
        shr     edx,16
    .if dx==BN_CLICKED
      .if ax==IDC_Calc
        call    deal_calc
      .elseif ax==IDC_Exit
        invoke  SendMessage,hWnd,WM_COMMAND,IDM_Exit,0  ;238 ¶Ç»¼°T®§µ¹¹ï¸Ü²°
      .endif
    .endif
  .endif
.else
        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
.endif
        xor     eax,eax 
        ret

WndProc endp
;***************************************
        end     start

©³¤U¬O inch.mak ÀɮסG

ALL:inch.exe

inch.exe : inch.asm inch.res
        ml /coff inch.asm /link inch.res

inch.res : inch.rc inch.ico
        rc inch.rc

²ÕĶ®É¡A¦b©R¥O´£¥Ü¤U¿é¤J

D:\HomeHapg\SOURCE>nmake -f inch.mak [Enter]

§Y¥i±o¨ì inch.exe¡C


¸Ñ»¡

°²¦p§Ú­Ì¥Î¹ï¸Ü²°­±ªO«Ø¥ß¹ï¸Ü²°¥H¤Î¨ä¤ºªº¤l±±¥óªº¸Ü¡A«ÜÅãµMªº¥²¶·¥Î¤@­Ó API ¨Ó³B²z³o¨Ç¨Æ±¡¡A¨º´N¬O CreateDialogParam ©M DialogBoxParam¡C¦¹³B¥ý½Í CreateDialogParam¡C

·í§Ú­Ì¨Ï¥Î¸ê·½½sĶ¾¹¡ARC.EXE¡A½sĶ¸ê·½´y­zÀɮɡA°²¦p¦¹¸ê·½´y­zÀɤº§t¦³¹ï¸Ü­±ªOªº¸Ü¡A¨º»ò RC.EXE ·|²£¥Í¤@¬q¤G¶i¦ì¸ê®Æµ²ºc¡A¥]§t DLGTEMPLATEEX¡BFONTINFOEX ¥H¤Î DLGITEMTEMPLATEEX¡CDLGTEMPLATEEX µ²ºc¤º¥]§t¤F¤÷µøµ¡ªº¸ê®Æ¡ADLGITEMTEMPLATEEX ¥]§t¤F¤lµøµ¡ªº¸ê®Æ¡AFONTINFOEX «h¬O¬°¦¹¹ï¸Ü²°«ü©w¦r«¬¡C³o¹ï¸Ü²°ªº¦WºÙ´N¬O¦b¸ê·½´y­zÀɤ¤ªº¹ï¸Ü²°¦WºÙ¡A¨äÃþ§O¤]¦b¸ê·½´y­zÀɤ¤´y­z¡C

·íµM¡A°²¦p±z¨S¦³¦b¸ê·½´y­zÀÉ©w¸q±±¨î¤¸¥ó¡A©ÎªÌ¨S¦³©w¸q¦r«¬¡A¨º»ò´N¨S¦³ DLGITEMTEMPLATEEX ©Î¬O FONTINFOEX µ²ºc¡A¤£¹LµL½×¦p¦ó¡A¥u­n¦³ DIALOG °Ï¬q¡A´N·|¦³¤@­Ó DLGTEMPLATEEX µ²ºc¡CµM«á§Ú­Ì¥H CreateDialogParam API ¨Ì¦¹µ²ºc«Ø¥ß¦U­Ó¤lµøµ¡¡C

CreateDialogParam ­º¥ý·|Àˬd¬O§_«ü©w¦r«¬¡A¦pªG¦³ªº¸Ü·|®Ú¾Ú FONTINFOEX ªº¤º®e²£¥ÍÅÞ¿è¦r«¬¡AµM«á¦A¥H DLGTEMPLATEEX ¤ºªº¸ê®Æ¡A©I¥s CreateWindowEx API «Ø¥ß¹ï¸Ü²°µøµ¡¡A¦A¨Ì¾Ú¨C­Ó DLGITEMTEMPLATEEX ¤ºªº¸ê®Æ¡A©I¥s CreateWindowEx «Ø¥ß¦U­Ó¤lµøµ¡±±¥ó¡Cµ¥¹ï¸Ü²°¤Î©Ò¦³¤lµøµ¡³£¤w²£¥Í«á¡ACreateDialogParam ·|µo¥X WM_INITDIALOG °T®§µ¹¹ï¸Ü²°¡A¦¹°T®§ªº lParam ¥i¥H¥Ñ CreateDialogParam API ªº²Ä 5 ­Ó°Ñ¼Æ¡AdwInitParam «ü©w¡C

CreateDialogParam API

CreateDialogParam API ªº­ì«¬¦p¤U¡G

HWND CreateDialogParam(
    HINSTANCE   hInstance,      // handle to application instance
    LPCTSTR     lpTemplateName, // identifies dialog box template
    HWND        hWndParent,     // handle to owner window
    DLGPROC     lpDialogFunc,   // pointer to dialog box procedure
    LPARAM      dwInitParam     // initialization value
   );

¤U­±¬O CreateDialogParam °Ñ¼Æ»¡©ú¡G

²Ä¤@­Ó°Ñ¼Æ¡AhInstance¡A¬O°õ¦æ¹ê¨Ò¥N½X¡C

²Ä¤G­Ó°Ñ¼Æ¬O lpTemplateName¡A¥¦«ü¦V¤@­Ó¥H NULL µ²§Àªº¦r¦ê¡A³o­Ó¦r¦ê´N¬O¹ï¸Ü²°¦WºÙ¡A¤]´N¬O¦b¸ê·½´y­zÀɤ¤¦b DIALOG ©Ò«ü©wªº¦WºÙ¡CCraeteDialogParam ·|¨Ì¾Ú¦¹¦WºÙ¡A¦b EXE Àɤº´M§ä¥H³o­Ó¹ï¸Ü²°¬°¦WºÙªº DLGTEMPLATEEX µ²ºc¡AµM«á¦A¥H³o­Óµ²ºcªº¸ê®Æ«Ø¥ß¦U¤lµøµ¡¡C

²Ä¤T­Ó°Ñ¼Æ¬O¾Ö¦³³o­Ó¹ï¸Ü²°ªº¤÷µøµ¡¥N½X¡A°²¦p¨S¦³¤÷µøµ¡ªº¸Ü¡A´N³]¬° NULL¡C

²Ä¥|­Ó°Ñ¼Æ¡AlpDialogFunc¡A¬O¤@­Ó¦ì§}¡A«ü¦V¹ï¸Ü²°¨ç¦¡¦ì§}¡A¹ï¸Ü²°¨ç¦¡¤]ÄÝ©ó¤@ºØ¦^©I¨ç¦¡ ( call back function )¡A¥¦¬O¥Î¨Ó³B²z¹ï¸Ü²°°T®§ªº¡C¦ý¬O¦b³o­Ó¨Ò¤lùØ¡A¦¹¨ç¦¡³Q¬Ù²¤¤F¡A¦Ó¬O³Q WNDCLASSEX µ²ºcÅ餤ªº lpfnWndProc ©Ò«ü©w¡C

²Ä¤­­Ó°Ñ¼Æ¬O«ü©w¹ï¸Ü²°©Ò¦¬¨ì WM_INITDIALOG °T®§ªº lParam¡C

·í CreateDialogParam ¦¨¥\«Ø¥ß¹ï¸Ü²°«á¡A·|¦b EAX ¼È¦s¾¹¤¤¶Ç¦^¹ï¸Ü²°¥N½X¡A¦bµ{¦¡ªº²Ä 193 ¦æ¦s¤J hDlg ÅܼÆùØ¡C³o­Ó¹ï¸Ü²°¥N½X´N¹³«e´X³¹ªºµøµ¡¥N½X¤@¼Ë¡A©¹«á°²¦p­n¹ï¦¹¹ï¸Ü²°¾Þ§@¡A¥²¶·¥Î¨ì hDlg¡C

GetDlgItem API

²Ä 196 ¦æ¬O¨ú±o¤lµøµ¡¡A½s¿è®Ø¡Aªºµøµ¡¥N½X¡A³o¬O¬°¤F¤@«Ø¥ß¦n¹ï¸Ü²°¤Î¦U¤lµøµ¡¡A´N¯àÅý½s¿è®Ø¦¨¬°§@¥Î¤¤ªºµøµ¡¡A¤è«K¨Ï¥ÎªÌ¿é¤J¡C¨ú±o¤lµøµ¡¥N½X¥i¥Î GetDlgItem API¡A¨ä­ì«¬¬°¡G

HWND GetDlgItem(
    HWND    hDlg,       // handle of dialog box
    int     nIDDlgItem  // identifier of control
    );

GetDlgItem ¦³¨â­Ó°Ñ¼Æ¡AhDlg ¬O«ü­n¨ú±o¦b¨º¤@­Ó¹ï¸Ü²°¤ºªº¤lµøµ¡¡AÀ³¸Ó¶ñ¤J¸Ó¹ï¸Ü²°ªº¥N½X¡CnIDDlgItem ¬O­n¨ú±oªº¤lµøµ¡ÃѧO½X¡C¦pªG GetDlgItem ¦¨¥\¡A«h EAX ·|¶Ç¦^¤lµøµ¡ªºµøµ¡¥N½X¡C¦bµ{¦¡²Ä 197 ¦æ¡A¦A¥H SetFocus API ³]©w½s¿è®Ø¬°§@¥Î¤¤ªº¤lµøµ¡¡C

°T®§°j°é»P IsDialogMessage API

µ{¦¡²Ä 198 ¦æ¨ì²Ä 206 ¦æ¬O°T®§°j°é¡A©M¥H«e¤£¦Pªº¬O¦h¤F©I¥s IsDialogMessage API ³o¤@¦æ¡C¦h¤F³o¤@¦æ¬O¥Î¨Ó³B²z¨Ï¥ÎªÌ«ö¤U¤è¦VÁä©ÎªÌ TAB Áä®É¡A¥i¥H¨Ï¦U­Ó¤lµøµ¡½ü¬yÅܦ¨§@¥Î¤¤¡A°²¦p±z¤£·QÅý¨Ï¥ÎªÌ³o¼Ë°µ¡A¤]¥i¥H¤£¥[¤W³o¬qµ{¦¡¡C©³¤U¬O IsDialogMessage ªº­ì«¬¡G

BOOL IsDialogMessage(
    HWND    hDlg,       // handle of dialog box
    LPMSG   lpMsg       // address of structure with message
   );

«Ü©úÅ㪺¡AhDlg ¬O«ü­n³B²zªº¹ï¸Ü²°¥N½X¡AlpMsg ¬O«ü°T®§µ²ºcÅ骺¦ì§}¡C·í¨Ï¥ÎªÌ«ö¤U¤è¦VÁä©ÎªÌ TAB Áä®É¡AIsDialogMessage ·|¦Û¦æ³B²z¡A¨Ï¿é¤JµJÂI¦Û°ÊÂಾ¡A¨Ã¥B©I¥s TranslateMessage ©M DispatchMessage ³o¨â­Ó API¡A¦A¶Ç¦^ TRUE¡A©Ò¥H³Q IsDialogMessage ³B²z¹Lªº°T®§´N¤£»Ý­n¦A TranslateMessage ©M DispatchMessage ¤F¡C°²¦p¨Ï¥ÎªÌ¤£¬O«ö¤U¤è¦VÁä©Î TAB Áä¡A¨º»ò°T®§´N¤£·|³Q IsDialogMessage ³B²z¡A¨Ã¥B¶Ç¦^ FALSE¡C

µ{¦¡²Ä 210 ¦æ¶}©l¶i¤Jµøµ¡¨ç¦¡¡A³o­Óµ{¦¡ªºµøµ¡¨ç¦¡¦³«Ü¤j¤@³¡¥÷¬O³B²z WM_COMMAND ªº¡C»P«e´X³¹¤@¼Ë¡A¦b WM_COMMAND °T®§¤¤¡AÀˬd lParam ¬°¹sªí¥Ü¨Ï¥ÎªÌ«ö¤U¿ï³æ¡A¤£¬°¹sªí¥Ü¨Ï¥ÎªÌ«ö¤U±±¨î¤¸¥ó¡C¿ï³æªº³B²z¤è¦¡«e´X³¹¤w¸g»¡©ú¡A¦¹³B¤£ÂØ­z¡A©³¤U¶È»¡©ú¿ï¾Ü¡yÂk¹s¡z¿ï³æªº²z¤è¦¡¡C

SetDlgItemText API

²Ä 220 ¦æ¡A¨Ï¥ÎªÌ¿ï¾Ü¡yÂk¹s¡z®É¡Aµ{¦¡¥²¶·¨Ï½s¿è®Ø¤ºªº¼Æ­ÈÅܬ°¹s¡C½è¨¥¤§¡Aµ{¦¡¥²¶·¹ï±±¨î¤¸¥ó³]©w¼ÐÃD©Î¤å¦r¦Ó¨Ï½s¿è®Ø±±¨î¤¸¥ó¤§¼Æ­ÈÅܬ°¹s¡A³o¶µ¤u§@¥i¥H¥Î SetDlgItemText API ¹F¦¨¡C©³¤U¬O SetDlgItemText ¤§­ì«¬¡G

BOOL SetDlgItemText(
    HWND    hDlg,       // handle of dialog box
    int     nIDDlgItem, // identifier of control
    LPCTSTR lpString    // text to set
   );

SetDlgItemText ªº°Ñ¼Æ¤]Åã¦Ó©ö¨£¡AhDlg ¬°¹ï¸Ü²°¥N½X¡AnIDDlgItem ¬°¹ï¸Ü²°¤¤ªº±±¨î¤¸¥óÃѧO½X¡AlpString ¬°­n¶Ç»¼¤§¦r¦ê¦ì§}¡A¦¹¦r¦ê¶·¥H NULL µ²§À¡CSetDlgItemText ¯à§â lpString ©Ò«ü¦ì§}¤§¦r¦ê¡A¶Çµ¹ hDlg ©Ò¥Nªí¹ï¸Ü²°¤ºªº nIDDlgItem ±±¨î¤¸¥ó¡C

¨Æ¹ê¤W¡A¨Ã¤£¬O¥u¦³³o¤@ºØ¤èªk¥i¥H§â°T®§¶Ç»¼µ¹½s¿è®Ø¡A¨Ï½s¿è®Ø¤§¤º®eÅܬ°¡y0¡z¡C½s¿è®Ø¥H¤Î¦UºØ±±¨î¤¸¥ó³£¬O¦b¹ï¸Ü²°ùتº¤lµøµ¡¡A©Ò¥H¥i¥H§â¥¦­Ì·í°µµøµ¡³B²z¡A´«¥y¸Ü»¡¡A¹ïµøµ¡ªº°Ê§@¤]¥i¥H¥[½Ñ©ó±±¨î¤¸¥ó¤W¡C¦b Win32 ¨t²Î¤¤¡A¥i¥H¥Î SendMessage API ¹ïµøµ¡µo¥X°T®§¡C

SendMessage API

SendMessage API ªº­ì«¬¬°¡G

LRESULT SendMessage(
    HWND    hWnd,       // handle of destination window
    UINT    Msg,        // message to send
    WPARAM  wParam,     // first message parameter
    LPARAM  lParam      // second message parameter
   );

hWnd ¬Oµøµ¡¥N½X¡A·N§Y°T®§±Nµo°e¨ì¸Óµøµ¡¥N½X©Ò«üªºµøµ¡µ¡¡CMsg ¬O°T®§ºØÃþ¡CwParam¡BlParam ¬O§ó¶i¤@¨Bªº°T®§¸ê®Æ¡A»P°T®§ºØÃþ¦³Ãö¡C¦b³o­Ó¨Ò¤l¤¤¡A­n¹ï½s¿è®Øµo°e°T®§¦Ó¨Ï¨ä¤º®eÅܬ°¡y0¡z¥i¥H²Ä 220 ¦æ§ï¦¨

        invoke  GetDlgItem,hWnd,IDC_Edit
        invoke  SendMessage,eax,WM_SETTEXT,0,offset ClearText

¨Ï¥Î WM_SETTEXT ®É¡AwParam ­n³]¬°¹s¡AlParam ¬O«ü¦V¥H¹sµ²§Àªº¦r¦ê¦ì§}¡Aµøµ¡¤º®e±N·|Åܦ¨¸Ó¦r¦ê¡CWM_SETTEXT ªº¹ï¶H¦pªG¬O¤@¯ëµøµ¡¡A±N·|­×§ï¼ÐÃDÄ檺¤º®e¡F¦pªG¬O«ö¶sÃþ§Oªº±±¥ó¡A±N­×§ï«ö¶s¤Wªº¤å¦r¡F¦pªG¬O½s¿è®ØÃþ§Oªº±±¥ó¡A±N­×§ï½s¿è®Øªº¤º®e¡F¦pªG¬OÀRºAÃþ§Oªº±±¥ó¡A±N­×§ï¨ä¤å¦r¡C

¥t¥~¡ASendMessage »P SetDlgItemText ³£¥i­×§ï¤l±±¥ó¤º®e¡A®t§O¦b SendMessage ¶·¥ý¨ú±o¤l±±¥ó¥N½X¡A¦Ó SetDlgItemText «h­n¨ú±o¤l±±¥óÃѧO½X¡C¤@¯ë¦Ó¨¥¡A¦b¹ï¸Ü²°ùØ¡A¦UºØ¤l±±¥óÃѧO½X¥ß§Y¥i¥Ñ¸ê·½ÀÉùتºÃѧO½X±oª¾¡A©Ò¥H¤@¯ë¨Ï¥Î SetDlgItemText ¸û¬°¤è«K¡C

ÁÙ¦³¤@¨Ç±`¥Îªº°T®§¥i¥Hµo°eµ¹½s¿è®Ø¡A±±¨î¬Y¨Ç½s¿è®Øªº¦æ¬°¡A³o¨Ç°T®§´X¥G¥H EM_ ¶}ÀY¡A·N§Y edit message ªº·N«ä¡C±`¥Îªº¦p¤Uªí¡G

°T¡@¡@®§ wParam lParam »¡¡@¡@©ú
EM_SETLIMITTEXT ªø«× 0 ³]©w½s¿è®Ø©Ò¯à¿é¤Jªº­­¨î¡A­Y wParam ³]¬°¹s
¡@¡@¹ï Win 9x/Me ¦Ó¨¥¡A³æ¦æ½s¿è®Ø¬O 32766 ¦ì¤¸²Õ¡A¦h¦æ½s¿è®Ø¬O 65535 ¦ì¤¸²Õ¡C
¡@¡@¹ï NT/2k/XP ¦Ó¨¥¡A³æ¦æ½s¿è®Ø¬O 7FFFFFFEH ¦ì¤¸²Õ¡A¦h¦æ½s¿è®Ø¬O 0FFFFFFFFH ¦ì¤¸²Õ¡C
EM_GETLIMITTEXT 0 0 ¨ú±o½s¿è®Ø©Ò¯à½s¿èªº³Ì¤j­­«×¡A¥H¦r¤¸¬°³æ¦ì¡C
EM_SETPASSWORDCHAR ¦r¤¸ 0 ³]©wÅã¥Ü±K½Xªº¦r¤¸¡C­Y¬° 0¡A«h ES_PASSWORD ·|³Q²M°£¡C
EM_GETPASSWORDCHAR 0 0 ¨ú±oÅã¥Ü±K½Xªº¦r¤¸¡C­Y SendMessage ¶Ç¦^ NULL¡Aªí¥Ü¬°³]©wÅã¥Ü±K½X¦r¤¸¡C
EM_GETLINE ¦æ½s¸¹ ½w½Ä°Ï¦ì§} ±N©Ò©Ò«ü©wªº¦æ½s¸¹¤º®e«þ¨©¨ì½w½Ä°Ï¡C¦¹¦æ½s¸¹¥H¹s¶}©l¡C
EM_GETLINECOUNT 0 0 ¨ú±o¦h¦æ½s¿è®Ø¤§¦æ¼Æ¡C­Y¬° 1¡Aªí¥Ü½s¿è®Ø©|¥¼¿é¤J¸ê®Æ©Î¶È¤@¦æ¸ê®Æ¡C
WM_SETTEXT 0 ¦r¦ê¦ì§} ³]©wµøµ¡ªº¼ÐÃDÄæ¡C¦pªG§ïµøµ¡ªºÃþ§O¬O¡yedit¡z¡A«h­×§ï½s¿è®Ø¤º®e¡C¦pªG¸Óµøµ¡ªºÃþ§O¬O¡ybutton¡z¡A«h­×§ï«ö¶s¤Wªº¤å¦r¡C¦pªG¸Óµøµ¡ªºÃþ§O¬O¡ystatic¡z¡A«h­×§ï¦r¦ê¡K¡K

«ö¤U«ö¶s¡Aµo¥X WM_COMMAND °T®§

µ{¦¡²Ä 232 ¦æ¨ì²Ä 241 ¦æ¬O³B²z¨Ï¥ÎªÌ«ö¤U±±¨î¤¸¥óªºµ{¦¡¡C°Ñ·Ó²Ä¤»³¹ªº¸ê®Æ¡A°²¦p¨Ï¥ÎªÌ¥H·Æ¹«ÂI¿ï«ö¶s¡A¨º»ò¨t²Î·|µo¥X WM_COMMAND ¶Ç»¼°T®§µ¹¤÷µøµ¡¡C¦¹®É¦b WM_COMMAND °T®§¤ºªº wParam ¸û§Cªº 16 ¦ì¤¸¬O«ö¶sªºÃѧO¸¹½X¡A¸û°ªªº 16 ¦ì¤¸¬O¨Ï¥ÎªÌªº°Ê§@¡A³o­Ó°Ê§@±`¨£ªº¦³¨âºØ¡G¤@ºØ¬O BN_CLICKED¡Aªí¥Ü¨Ï¥ÎªÌ¼h«ö¤U¹L³o­Ó«ö¶s¡F¥t¤@ºØ¬O BN_DOUBLECLICKED¡Aªí¥Ü¨Ï¥ÎªÌ´¿ÂùÀ»¹L¦¹«ö¶s¡C

³o¬qµ{¦¡¹ê§@©ó²Ä 235 ¦æ»P²Ä 236 ¦æ¡C¤p¤ì°¸¥ýÀˬd¬O§_«ö¤U«ö¶s ( wParam ¸û§Cªº 16 ¦ì¤¸¬O§_¬° BN_CLICKED )¡A¦AÀˬd«ö¤U¨º¤@­Ó«ö¶s¡AIDC_Calc ©Î IDE_Exit¡C

²Ä 239 ¦æ¡A³o¤@¦æ¬O³B²z¨Ï¥ÎªÌ«ö¤U¡yÂ÷¶}¡z±±¨î¤¸¥ó¡A³o¤@¬qµ{¦¡¨ä¹ê©M¨Ï¥ÎªÌ¥Ñ¿ï³æ¿ï¾ÜÂ÷¶}¬O¬Û¦Pªº¡C©Ò¥H¬°¤FÁקK­«½Æ¡A¤p¤ì°¸¥Î¤F¤@­Ó§Þ¥©¡A§Yµ{¦¡¹ï¦Û¤vµo¥X WM_COMMAND °T®§¡A¦Ó¦¹°T®§¤¤ªº wParam ¤Î lParam ¤À§O¶ñ¤WÂ÷¶}¿ï³æªºÃѧO¸¹½X¥H¤Î¹s¡A¨º»ò¦b¶i¤J¤U¤@¦¸°T®§°j°é®É¡Aµ{¦¡·|¦Û¦æ®·®»¨ì WM_COMMAND¡A¦Ó´N¦n¹³¨Ï¥ÎªÌ¥Ñ¿ï³æ¿ï¾Ü¡yÂ÷¶}¡z¤@¼Ë¡C


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