Ch 10 ¹ï¸Ü²°(3)


¼Ò¦¡¹ï¸Ü²°»P«D¼Ò¦¡¹ï¸Ü²°

¨Ï¥ÎªÌ¦b¨Ï¥Î³nÅé®É¡A±`±`·|¸g¥Ñ¿ï³æ¿ï¾Ü¬Y¤@¥\¯à«á¡A¦Ó¼u¥X¤@­Ó¹ï¸Ü²°¡A°µ§óºë²Óªº¿ï¾Ü¡C¨Ò¦p¡A¨Ï¥ÎªÌ·Q¦sÀɮɡA¤@¯ë¦b¿ï³æ¿ï¾Ü¡yÀɮסz¡÷¡y¦sÀÉ¡z¤§«á¡A·|¸õ¥X¤@­Ó¹ï¸Ü²°¡A­n¨D¨Ï¥ÎªÌ¿é¤JÀɦW¡Aµ¥¿é¤J§¹¦¨¤§«á¦A«ö¤U¡y¦sÀÉ¡z«ö¶s¡C°²¦p³o­Ó¦sÀɪº¹ï¸Ü²°¨S¦³Ãö³¬¡A¨Ï¥ÎªÌµLªk¨Ï¥Î¤÷µøµ¡¤Wªº¥ô¦ó¥\¯à¡C

¦ý¬O¥t¦³¤@ºØ¹ï¸Ü²°¡A¥i¥H¦b¥¼Ãö³¬ªº±¡§Î¤U¡A¤´¯à¹ï¤÷µøµ¡¶i¦æ¾Þ§@¡C¨Ò¦p¡A­n¦b¤å¥ó¤¤·j´M¯S©w¦r¦ê¡A«ö¤U¿ï³æ¤¤ªº¡ySearch¡z«á¡A·|¼u¥X¤@­Ó¹ï¸Ü²°­n¨D¨Ï¥ÎªÌ¿é¤J­n´M§äªº¦r¦ê¡A¦b¿é¤J§¹²¦¤§«á«ö¤U¡y´M§ä¡z«ö¶s¶}©l´M§ä¡C

«Ü©úÅ㪺¡A¤W­z³o¨âºØ¹ï¸Ü²°¤£¤Ó¤@¼Ë¡C¥Hµ{¦¡³]­p®vªºÆ[ÂI¨Ó¬Ý¡A¹ï¸Ü²°¥i¤À¬°¨âºØ¡A§Y¼Ò¦¡¹ï¸Ü²° ( modal dialog box ) »P«D¼Ò¦¡¹ï¸Ü²° ( modeless dialog box )¡C¼Ò¦¡¹ï¸Ü²°¬O«ü¨Ï¥ÎªÌ¥²¶·±N¹ï¸Ü²°Ãö³¬«á¤~¯àÄ~Äò¾Þ§@­ì¨Óªºµøµ¡¡A´N¹³«e­±´£¨ìªº­n¦sÀɮɼu¥Xªº¹ï¸Ü²°¡C¦Ó«D¼Ò¦¡¹ï¸Ü²°«h¬O¤£¶·Ãö³¬¹ï¸Ü²°¤]¯à¹ï­ìµøµ¡¾Þ§@¡A¨Ò¦p«e­±©Ò´£¨ìªº´M§ä¦r¦êªº¹ï¸Ü²°¡C

«e¤@³¹©Ò«Ø¥ßªº¹ï¸Ü²°¬OÄÝ©ó«D¼Ò¦¡¹ï¸Ü²°¡A±q«e¤@³¹ªºµ{¦¡¥i¥H¬Ý¥X¨Ó¡A«Ø¥ß«D¼Ò¦¡¹ï¸Ü²°¬O§Q¥Î CreateDialogParam API¡AºR·´«D¼Ò¦¡¹ï¸Ü²°«h¨Ï¥Î DestroyWindow API¡C¤S¦]¬°«D¼Ò¦¡¹ï¸Ü²°ªº°T®§°j°é´N¬O­ìµøµ¡ªº°T®§°j°é¡A©Ò¥H«D¼Ò¦¡¹ï¸Ü²°¤£·|§í¨î­ì¨Óµøµ¡ªº°T®§¡A³o¤]´N¬O¬°¦ó«D¼Ò¦¡¹ï¸Ü²°¤£¥ÎÃö³¬¡A¤]¯à¾Þ§@­ìµøµ¡¡A¤]¥¿¦]¬°¦p¦¹¡A±`±`±o¦b°T®§°j°é¤¤¥[¤W IsDialogMessage ¨Ó°Ï§O¨Ï¥ÎªÌªº°Ê§@¬O¹ï­ìµøµ¡ÁÙ¬O¹ï¹ï¸Ü²°¡C

¼Ò¦¡¹ï¸Ü²°¬O§Q¥Î DialogBoxParam API «Ø¥ßªº¡Aµ²§ô«D¼Ò¦¡¹ï¸Ü²°«h¬O±Ä¥Î EndDialog¡C·í«Ø¥ß¼Ò¦¡¹ï¸Ü²°®É¡A¨t²Î·|¬°³o­Ó¹ï¸Ü²°«Ø¥ß¤@­Ó°T®§°j°é¡A¦¹°T®§°j°é§â©Ò±µ¦¬¨ìªº°T®§µo°eµ¹¨t²Î¤º³¡ªº¹ï¸Ü²°ºÞ²z¾¹¡A¹ï¸Ü²°ºÞ²z¾¹¦A©I¥sµ{¦¡ªº¹ï¸Ü²°¨ç¦¡ ( dialog box procedure )¡C¹ï¸Ü²°¨ç¦¡ªº¦a¦ì¬Û·í©óµøµ¡¨ç¦¡¡A¥¦¤]¬O¤@ºØ¡ycall back¡z¨ç¦¡¡A±Mªù³B²z¶Ç»¼µ¹¹ï¸Ü²°ªº°T®§¡A³o¨Ç°T®§¸g¹L¹ï¸Ü²°¨ç¦¡³B²z«á¡A³Ì«á¤´¥²¶·ªð¦^¨t²Î¡A¥²¶·¦³¤@­Ó¶Ç¦^­Èµ¹¨t²Î°µ¬°³B²zªº¨Ì¾Ú¡A¤w¸g³B²z¹Lªº°T®§¶Ç¦^­ÈÀ³³]¬° TRUE¡A¨S¦³³B²z¹Lªº¶Ç¦^­ÈÀ³³]¬° FALSE¡A¨t²Î·|¦Û¦æ³B²z¨S¦³³B²z¹Lªº°T®§¡A¤]¦]¬°³o¤w¦^¨ì¨t²Î¤¤¡A©Ò¥H¤£¥²¦b¹ï¸Ü²°¨ç¦¡¤¤©I¥s DefWindowProc API¡C

¾ã²z¤W­z­ì²z¡A±ý«Ø¥ß¤@­Ó¼Ò¦¡¹ï¸Ü²°¡A¶·©I¥s DialogBoxParam API¡A¥H¤Î«Ø¥ß¹ï¸Ü²°¨ç¦¡¡Cµ²§ô®É¡A±o¦b³B²z WM_CLOSE °T®§¤¤©I¥s EndDialog API ¥Hµ²§ô¼Ò¦¡¹ï¸Ü²°¡C¦Ü©ó«Ø¥ß°T®§°j°é¡Bµù¥Uµøµ¡¡B©I¥s DefWindowProc API ³B²z¤£·P¿³½ìªº°T®§µ¥µ¥¨BÆJ¡A³£¦]¬°¥]§t¦b¨t²Î¤º³¡¡A§¡¬Ù²¤¤F¡A¬G¦Ó´î¤Ö¤F³\¦hµ{¦¡½X¡A¹ïµ{¦¡³]­p®v¨Ó»¡¡A¤è«K¤£¤Ö¡C

DialogBoxParam API

DialogBoxParam ªº­ì«¬¬O¡G

int DialogBoxParam(
    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
   );

¨ä¤¤ hInstance¡BhWndParent ¤À§O¬O¤÷µøµ¡ªº¼Ò²Õ¥N½X¤Îµøµ¡¥N½X¡ClpTemplateName ¹ï¸Ü²°­±ªOªº¦WºÙ¦ì§}¡A³o­Ó¦WºÙ¥²¶·©M¸ê·½Àɤ¤ªº¹ï¸Ü²°­±ªO¦WºÙ¬Û¦P¡ClpDialogFunc ¬O¹ï¸Ü²°¨ç¦¡¤§¦ì§}¡A¹ï¸Ü²°¨ç¦¡±N·|³B²z¨Ï¥ÎªÌ¹ï¹ï¸Ü²°°Ê§@©Ò²£¥Íªº°T®§¡CdwInitParam ¬O¹ï¸Ü²°¨ç¦¡ªºªì©l­È¡A·í¹ï¸Ü²°²£¥Í®É¡A¨t²Î·|¹ï¹ï¸Ü²°µo¥X WM_INITDIALOG °T®§¡A¦¹°T®§¤¤ªº lParam ·|¥Î dwInitParam ¥N´À¡C

EndDialog API

·í¨Ï¥ÎªÌ«ö¤UÂ÷¶}«ö¶sµ²§ô¹ï¸Ü²°µøµ¡®É¡A¹ï¸Ü²°©I¥s EndDialog ¨Óµ²§ô¹ï¸Ü²°¡CEndDialog ªº­ì«¬¬°

BOOL EndDialog(
    HWND    hDlg,       // handle to dialog box
    int     nResult     // value to return
   );

hDlg ¬O­nÃö³¬ªº¹ï¸Ü²°¡AnResult ¬O¥Ñ¹ï¸Ü²°¨ç¦¡ªð¦^¨ì¨t²Î®Éªºªð¦^­È¡C


¦A½Í±±¨î¤¸¥ó

©³¤U¤p¤ì°¸±N»¡©ú´XºØ±±¨î¤¸¥óªº¥Îªk¡A¥]¬A¸s²Õ¤¸¥ó¡B½Æ¦X¤¸¥ó¡B±²¶b¤¸¥óµ¥µ¥¡C

¸s²Õ±±¨î¤¸¥ó ( GROUPBOX control )

GROUPBOX ±±¨î¤¸¥ó·|¦b¹ï¸Ü²°¤W²£¥Í¤@­Ó¯x§Î°Ï°ì¡A¨Ã¥B¥Î¶Â½u¼Ð¥Ü°_¨Ó¡A¦¹¥~ÁÙ¥i¥H³]©w¤@­Ó¼ÐÃD¡C¤@¯ë¦Ó¨¥¡A³o­Ó¯x§Î°Ï°ì³ò¦í¼Æ­Ó±±¨î¤¸¥ó¡A³Q³ò¦íªº±±¨î¤¸¥ó³q±`³£¬OÄÝ©ó¦P¤@Ãþªº©ÎªÌ¬O¦@¦P¹F¦¨¬Y­Ó¥Øªºªº¡C¨Ò¦p¤U¹Ï¤¤ªº Word Pad ¡yÀ˵ø¡z¡y¿ï¶µ¡z¹ï¸Ü²°ùØ¡A¥]§t¨â­Ó¸s²Õ±±¥ó¡C¥ª°¼ªº¬O³B²z´«¦æ¤è¦¡¡A¥]§t¤T­Ó¶ê§Î«ö¶s¡A¨Ï¥ÎªÌ¥u¯à¦b³o¤T­Ó«ö¶s¤¤¬D¿ï¨ä¤¤¤§¤@¡C¥k°¼ªº¬OÅã¥Ü¨º´XºØ¤u¨ã¡A¦³¥|­ÓÀËÅç²°±±¥ó¥i¨Ñ¿ï¾Ü¡A¨Ï¥ÎªÌ¥i¥ô·N¬D¿ï¼Æ­Ó¤]¥i¥H¤@­Ó³£¤£¬D¿ï¡C

¸s²Õ±±¥ó

¤p¤ì°¸·Q¡A¤j·§¦]¬°¸s²Õ±±¥ó¤@¯ë¥Î¨Ó¥]¬A³\¦h«ö¶s¡A©Ò¥H Windows ¨t²Î¤]§â¸s²ÕÂkÃþ¬°«ö¶s±±¥ó¡C¤@¯ë¦b¹ï¸Ü²°¼ÒªO¤¤¥i¥H¥Î

GROUPBOX    text, id, x, y, width, height [, style [, extended-style]]
©Î
CONTROL     text, id, "BUTTON", style, x, y, width, height [, extended-style]

¨ä¤¤ text ¬O¸s²Õ±±¥ó¤W¤èªº¤å¦r¡Astyle À³¸Ó¥[¤W BS_GROUPBOX¡A°²¦p±z¥Î²Ä¤@ºØ®æ¦¡©w¸q¡A«h¦]¬°¤w¸g¨Ï¥Î GROUPBOX ÃöÁä¦r¡A¬G¥i¥H¤£¥[¤W BS_GROUPBOX¡C

GROUPBOX ±±¥ó¥i»¡¬O«ö¶s±±¥ó¤¤³Ì¯S®íªº¤@ºØ¡A¦]¬°¥¦¤£³B²z¥ô¦óÁä½L©Î·Æ¹«°T®§¡A¤]¤]¤£°e WM_COMMAND µ¹¤÷µøµ¡¡C°£¤F GROPUBOX ±±¥ó¤§¥~¡A«ö¶s±±¥óÁÙ¦³¶ê§Î«ö¶s±±¥ó ( RADIOBUTTON control )¡BÀˬd²°±±¥ó ( CHECKBOX control ) ¥H¤Î«e¤@³¹©Ò»¡ªº¤UÀ£¦¡«ö¶s ( PUSHBUTTON control ) µ¥µ¥¡C

¶ê§Î«ö¶s±±¨î¤¸¥ó ( RADIOBUTTON control )

¶ê§Î«ö¶s¦p¤W¹Ï©Ò¥Ü¡C¤@¯ë¦Ó¨¥¡A¶ê§Î«ö¶s¬O¥Î¨Ó¦b²³¦h¿ï¶µ¤¤¿ï¾Ü¨ä¤¤¤§¤@¥Îªº¡A¨Ï¥ÎªÌ¤£¯à¿ï¨â­Ó©Î¨â­Ó¥H¤W¡A¤]¤£¯à¤£¿ï¾Ü¡C·í¨Ï¥ÎªÌ¿ï©w²³¦h¶ê§Î«ö¶s¨ä¤¤¤§¤@®É¡Aµ{¦¡·|¦b¶ê§Î«ö¶s¤¤Åã¥Ü¤@¶êÂI¡A´N¦p¦P¤W­z WordPad ªº¡y¿ï¶µ¡z¹ï¸Ü²°¤¤ªº¡y¦Û°Ê´«¦æ¡z¤¤¡A¨Ï¥ÎªÌ¤w¿ï©w¡y¨Ìµøµ¡¦Û°Ê´«¦æ¡zªº±±¥ó¡A¦Ó¨ä¥L±±¥óªº¶êÂI«h¤£Åã¥Ü¡C­n¨Ï¥Î¶ê§Î«ö¶s®É¡A¥i¥ý¦b¹ï¸Ü²°¼ÒªO©w¸q¥¦¡A®æ¦¡¬O

CONTROL     text, id, "BUTTON", style, x, y, width, height [, extended-style]

¶ê§Î«ö¶sªº­·®æ ( style ) ¦³¨âºØ¡ABS_RADIOBUTTON »P BS_AUTORADIOBUTTON¡C¦pªG±z¥Î BS_RADIOBUTTON ­·®æ¡A¨t²Î¨Ã¤£·|¦Û°Ê¦a§â¤w¿ï©wªº¶ê§Î«ö¶s¤¤ªº¶êÂIµe¤W¡A¤]¤£·|§â¥¼¿ï©wªº¶êÂI²M°£±¼¡A¥²¶·¦Û¦æ­t³d¡C³o¼Ë¬O¤@¥ó«Ü³Â·Ðªº¨Æ¡A¤×¨ä¬O¶ê§Î«ö¶s±±¥ó¼Æ¶q¦h®É¡A¦]¦¹ BS_AUTORADIOBUTTON ´N¥¥¨|¦Ó¥Í¤F¡A¥¦·|¦Û°Ê¦aµe¤W¤w¿ï©w±±¥óªº¶êÂI¨Ã²M°£¥¼¿ï©w±±¥óªº¶êÂI¡C

±z¤]¥i¥H¥Î¸û²¼äªº¤è¦¡´y­z¶ê§Î«ö¶s±±¥ó¡G

RADIOBUTTON     text, id, x, y, wdith ,height , [ style ]
AUTORADIOBUTTON text, id, x, y, wdith ,height , [ style ]

¨ä¥L±`¥Îªº­·®æÁÙ¦³ WS_TABSTOP¡BWS_DISABLED¡BWS_GROUP ¤Î BS_TEXTLEFT¡CBS_TEXTLEFT ­·®æ·|¨Ï«ö¶s¤å¦r¦b¶êÂIªº¥ª¤è¡C¤£¹L¨S¦³ BS_RIGHTTEXT ­·®æ¡A¦]¬°¹w³]ªº´N¬O¦p¦¹±Æ¦C¡C°²¦p¨S¦³«ü©w¥ô¦ó­·®æ¡A¤º©wªº­·®æ¬O WS_TABSTOP¡C

¨ã¦³ WS_TABSTOP ­·®æªº±±¥ó¯à°÷Åý¨Ï¥ÎªÌ«ö¤UÁä½L¤Wªº TAB Áä©Î Shft¡ÐTAB Áä¨ÓÀò±o¿é¤JµJÂI¡C·N«ä¬O¡A¨Ï¥ÎªÌ¥i¥H«ö¤U TAB Áä©Î Shft¡ÐTAB Áä¡A¨Ï¿é¤JµJÂI½ü¬y¦b¨C­Ó¨ã¦³ WS_TABSTOP ­·®æªº±±Áä¤W°±¦í¡C

¤÷µøµ¡¥i¥H©I¥s SendMessage API ¹ï¶ê§Î«ö¶sµo¥X°T®§¡CSendMessage ªº­ì«¬¬O¡G

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

¦¹®É Msg °Ñ¼Æ±`¥Îªº¦³ BM_SETCHECK¡BBM_GETCHECK¡BBM_CLICK µ¥°T®§¡CBM_SETCHECK ¬O³]©w¶ê§Î«ö¶s©ÎÀËÅç²°«ö¶s¬O§_³Q¿ï¨ú¡A­Y·Q³]¬°³Q¿ï¨ú«h wParam ¬° BST_CHECKED¡A­Y·Q³]¬°¤£³Q¿ï¨ú«h wParam ¬° BST_UNCHECKED¡C

·í Msg ¬° BM_GETCHECK ®É¡Aªí¥Ü¨ú±o¶ê§Î«ö¶s©ÎÀËÅç²°«ö¶s³Q¿ï¨úªº±¡§Î¡AwParam¡BlParam ¬Ò³]¬°¹s¡A³Q¿ï¨úªº±¡§Î¥Ñªð¦^®É EAX ªí¥Ü¡A­Y EAX ¬° BST_CHECKED ªí¥Ü¶ê§Î«ö¶s©ÎÀËÅç²°«ö¶s³Q¿ï¨ú¡A­Y¬° BST_UNCHECKED ªí¥Ü¨S¦³³Q¿ï¨ú¡C

·í Msg ¬° BM_CLICK ®É¡A¥i¥H¼ÒÀÀ¨Ï¥ÎªÌ¹ï«ö¶s«ö¤U·Æ¹« ( ¦¹°T®§¤]¥i¾A¥Î©ó¤UÀ£¦¡«ö¶s )¡A³o­Ó°T®§·|¨Ï«ö¶s¥ý«á¦¬¨ì WM_LBUTTONDOWN ©M WM_LBUTTONUP °T®§¡A¨Ã¥B¨Ï¤÷µøµ¡¦¬¨ì³qª¾½X¬° BN_CLICKED ªº WM_COMMAND °T®§¡C¨Ï¥Î BM_CLICK ®É¡AwParam¡BlParam À³³]¬°¹s¡A¨Ã¥B¥²¶·¦b¹ï¸Ü²°¬O³B©ó¥¿¦b§@¥Î¤¤¡C

¶ê§Î«ö¶s¤@¯ë¬OÂÇµÛ WM_COMMAND °T®§§i¶D¤÷µøµ¡µo¥Í¤F¤°»ò¨Æ¥ó¡A¦p«e©Ò­z¡AlParam ¬O«ö¶s¥N½X¡AwParam ªº§C¦r²Õ¬O«ö¶sÃѧO½X¡AwParam ªº°ª¦r²Õ¬O³qª¾½X¡C±`¥Îªº³qª¾½X¦³ BN_CLICK ( ªí¥Ü¨Ï¥ÎªÌ¹ï«ö¶s«ö¤@¤U·Æ¹«Áä )¡BBN_DBLCLK ( ¨Ï¥ÎªÌ¹ï«ö¶sÂùÀ»·Æ¹«Áä¡A©M BN_DOUBLECLICKED ¬Û¦P )¡C

COMBOBOX ±±¨î¤¸¥ó

½Æ¦X±±¨î¤¸¥ó ( combo box control ) ¬O½s¿è®Ø»P¦Cªí¨âºØ±±¨î¤¸¥óªºµ²¦X¡CÅý¤p¤ì°¸Á|­Ó¨Ò¤l»¡©ú½Æ¦X¤¸¥ó¡A¤U¹Ï¬O IE ÂsÄý¾¹¦b¶}±ÒÂÂÀɮɩҧe²{ªº¹ï¸Ü²°¡A

½Æ¦X¤¸¥ó
¨ä¤¤¦b¡y¶}±Ò(O)¡J¡zÀRºA¤¸¥óªº¥kÃ䬰´N¬O½Æ¦X¤¸¥ó¡A·í¨Ï¥ÎªÌ«ö¤U½Æ¦X¤¸¥ó¥kÃ䪺¤U©Ô«ö¶s®É¡A·|¥X²{¤@±i²M³æ¡A³o®É½Æ¦X¤¸¥óÅܦ¨¤U¹Ï¡J
²M³æ¤¤§t¦³³\¦h¦r¦ê¿ï¾Ü¶µ¥i¨Ñ¿ï¾Ü¡A¨Ï¥ÎªÌ¥i¥H¿ï¾Ü¨ä¤¤¤@­Ó¡A¦³®É¤]¥i¥H¦b½s¿è®Øùت½±µ¿é¤J¡A¦³®É«h¤£¯à¥Ñ½s¿è®Ø¤¤¿é¤J¡C¦³®É½Æ¦X¤¸¥óªº²M³æ¬Oª½±µÅã¥Ü¦Ó¤£¶·¥Ñ¤U©Ô«ö¶s¾ÞÁa¡C³o¨Ç¥þ³¡¥i¥H¥Ñµ{¦¡³]­p®v¥H­·®æ ( style ) ¨Ó«ü©w¡C

¨Ï¥Î½Æ¦X¤¸¥ó®É¡A­º¥ý±o¦b¹ï¸Ü²°­±ªOùØ©w¸q½Æ¦X¤¸¥ó¡A¨ä®æ¦¡©M«e¤@³¹©Ò­z²¤¦³¤£¦P¡A¨ä®æ¦¡¦p¤U¡G

COMBOBOX  ID, x, y, width, height [,styles]
©Î
CONTROL   text, ID, "COMBOBOX", style, x, y, width, height [, extended-style]

©M«e¤@³¹ªº®æ¦¡¬Û¤ñ¡A½Æ¦X¤¸¥ó¨Ã¨S¦³ "text" ³o¤@Äæ¡A§Y¨Ï±z¥Î²Ä¤GºØ§¹¾ãªº®æ¦¡ªí¥Ü¹w³]ªº "text"¡A¦ü¥G¤]·|³Q©¿²¤¡A¦Ó¨ä¥LÄæ¦ì«h¬O¬Û¦P¡C½Æ¦X¤¸¥ó±`¥Îªº­·®æ ( style ) ¦p¤Uªí¡G

­·®æ »¡¡@¡@¡@©ú
CBS_SIMPLE ¦b¥ô¦ó®É­Ô³£Åã¥Ü²M³æ¡C
CBS_DROPDOWN ¥u¦³¦b¨Ï¥ÎªÌ«ö¤U¥kÃ䪺¤U©Ô¶s®É¡A¤~Åã¥Ü²M³æ
CBS_DROPDOWNLIST ©M CBS_DROPDOWN Ãþ¦ü¡A¦ý¬O¨Ï¥Î¦¹­·®æ®É¡A¨Ï¥ÎªÌµLªk­×§ï½s¿è®Ø¤ºªº¸ê®Æ¡A¶È¯à¥Ñ²M³æ¤¤¿ï¾Ü¡C
CBS_SORT ¨Ï²M³æ¤º¦r¦ê±Æ§Ç
CBS_AUOTHSCROLL ¦b½s¿è®Ø¤ºªº¿é¤J¤å¦r¶W¹L½s¿è®ØÅã¥Ü½d³ò®É¡A¦Û°Ê¤ô¥­±²°Ê¡A­Y¨S¦³«ü©w¦¹­·®æ¡A¶W¹L½d³ò«á´N¤£¯à¦b¿é¤J¸ê®Æ¡C
WS_VSCROLL ¨Ï²M³æ¤º¦r¦ê¯à¦³««ª½±²¶b¡A­Y¨S¦³«ü©w¦¹­·®æ¡A¶W¹L½d³òªº¦r¦ê´N¬Ý¤£¨£¦ÓµLªk¿ï¾Ü¡C
WS_GROUP ¡@
WS_TABSTOP ¨Ï¥ÎªÌ«ö¤UÁä½L¤Wªº TAB Áä¼Æ¦¸«á¡A¯à°÷Åܦ¨¿é¤JµJÂI¡C
WS_DISABLED «ü©w¦¹­·®æ«á¡A¦¹µøµ¡´NµL§@¥Î¦Ó¥¢®Ä

¤W­±ªº¦r­º¡ACBS_¬O combobox style ªºÁY¼g¡AWS_ ¬O window style ªºÁY¼g¡C°²¦p³£¨S¦³«ü©w¥ô¦ó½Æ¦X¤¸¥ó­·®æªº¸Ü¡A¤º©wªº­·®æ¬O CBS_SIMPLE | WS_TABSTOP¡C

¨º»ò­n«ç¼Ë¤~¯à³]©w½Æ¦X¤¸¥ó¤ºªº¿ï¾Ü¶µ©O¡Hµª®×¬O¥Î SendMessage API §â¦r¦ê¿ï¾Ü¶µ·í°µ°T®§¤¤ªº¤@³¡¥÷¦Ó¶Çµ¹½Æ¦X¤¸¥ó¡C«e­±´¿´£¨ì¡A¤÷µøµ¡¥i¥H©M¤lµøµ¡¤¬¬Û¶Ç»¼°T®§¡A¾a SendMessage¡C

·íµ{¦¡³]­p®v­n§â¿ï¾Ü¶µ¶Çµ¹½Æ¦X¤¸¥ó®É¡ASendMessage ¤¤¡AhWnd °Ñ¼Æ¬O½Æ¦X¤¸¥óªºµøµ¡¥N½X¡AMsg ³]¬° CB_ADDSTRING ªí¥Ü¦¹°T®§¬O¦b½Æ¦X¤¸¥óªº²M³æ¤¤¥[¤J¦r¦ê¡AwParam µL§@¥Î³]¬° NULL¡AlParam ¬O¦r¦ê¦ì§}¡A¦¹¦r¦ê¥H¹sµ²§À¡A³o¼Ë´N¥i¥H§â¿ï¾Ü¶µ¦r¦ê¶Çµ¹½Æ¦X±±¨î¤¸¥ó¡C¤p¤ì°¸§â±`¥Îªº¡A¦Ó¥B¥i¥H¥Ñ¤÷µøµ¡¶Çµ¹½Æ¦X¤¸¥óªº°T®§¾ã²z¦p¤Uªí¡G

°T®§ »¡¡@¡@¡@©ú
CB_ADDSTRING §â¿ï¾Ü¶µ¦r¦ê¶ñ¤J½Æ¦X±±¥ó¡A¦¹®É wParam ³]¬° NULL¡AlParam ¬°¦r¦ê¦ì§}¡A¦¹¦r¦ê¶·¥H¹sµ²§À¡C
CB_DELETESTRING ¥Ñ½Æ¦X±±¥óªº²M³æ¤¤§R°£¿ï¾Ü¶µ¦r¦ê¡C¦¹®É wParam ¬°­n§R°£¦r¦êªº²Ä´X¶µ¡A¥Ñ¹s¶}©l¡C¦Ó lParam µL§@¥Î³]¬°¹s¡C
CB_DIR §â¥Ø«e¸ô®|¤U²Å¦X«ü©wÄÝ©Ê»PÀɦWªºÀɮצWºÙ¥[¤J½Æ¦X±±¥ó¤¤¡CÄÝ©Ê¥Ñ wParam «ü©w¡CÀɦW¥Ñ lParam ©Ò«ü¦V¦ì§}ªº¦r¦ê¨M©w¡A¦¹¦r¦ê¥i¥]§t¸U¥Î¦r¤¸¥B¥²¶·¥H¹sµ²§À¡C
CB_FINDSTRING ¨Ï½Æ¦X¤¸¥ó²M³æ¤ºªº¿ï¾Ü¶µ¦r¦ê©M«ü©w¦r¦ê¤ñ¹ï¡A­Y§¹¥þ¬Û¦P©Î«ü©w¦r¦ê¬°¬Y­Ó¿ï¾Ü¶µªº«e­±¼Æ¦r¤¸¡A«h¶Ç¦^¸Ó¿ï¾Ü¶µ¦r¦ê¦b²M³æªº²Ä´X­Ó ( ±q¹s¶}©l )¡A­Y§ä¤£µÛ«h¶Ç¦^ CB_ERR¡CwParam ªí¥Ü¥Ñ²M³æªº²Ä´X­Ó¿ï¾Ü¶µ¶}©l¤ñ¸û¡AlParam ¬°«ü©w¦r¦ê¦ì§}¡A¦¹¦r¦ê¶·¥H¹sµ²§À¡C
CB_GETCOUNT ¨D±o²M³æ¤ºªº¿ï¾Ü¶µ¼Æ¡CwParam¡BlParam §¡µL§@¥Î¡A³]¬°¹s¡C
CB_GETCURSEL ¶Ç¦^²M³æ¤º³Q¿ï¾Üªº¦r¦ê¬O¦b²M³æ¤ºªº²Ä´X­Ó ( ¥Ñ¹s¶}©l )¡C­Y¨Ï¥ÎªÌÁÙ¨S¦³¿ï¦n¡A«h¶Ç¦^ CB_ERR¡CwParam¡BlParam §¡µL§@¥Î¡A³]¬°¹s¡C
CB_GETLBTEXT §â¬Y­Ó¿ï¾Ü¶µ¦r¦ê½Æ»s¨ì«ü©w¦ì§}¡AwParam ¬O²Ä´X­Ó¿ï¾Ü¶µ¡AlParam ¬O«ü©wªº¦ì§}¡C
CB_GETLBTEXTLEN ¶Ç¦^¬Y­Ó¿ï¾Ü¶µ¦r¦êªø«×¡AwParam ¬O²Ä´X­Ó¿ï¾Ü¶µ¡AlParamµL§@¥Î¡A³]¬°¹s¡C
CB_RESETCONTENT ²M°£²M³æ©Ò¦³¿ï¾Ü¶µ¡CwParam¡BlParam §¡µL§@¥Î¡A³]¬°¹s¡C
CB_SELECTSTRING »P CB_FINDSTRING Ãþ¦ü¡A¦ý¬O CB_SELECTSTRING ­Y´M§ä¦¨¥\ÁÙ·|¦b½s¿è®Ø¤ºÅã¥Ü§äµÛªº¿ï¾Ü¶µ¦r¦ê¡C
CB_SETCURSEL ¿ï©w²M³æ¤ºªº¿ï¾Ü¶µ¡A¸Ó¿ï¶µ·|¥H°ª«G«×Åã¥Ü¡A­ì°ª«G«×Åã¥Üªº¿ï¾Ü¶µ«h«ì´_­ìª¬¡CwParam «ü©w²Ä´X­Ó¿ï¾Ü¦r¦ê³Q¿ï©w¡AlParamµL§@¥Î¡A³]¬°¹s¡C

¤÷µøµ¡¥i¥H¹ï½Æ¦X±±¨î¤¸¥óµo¥X¤Wªí¤¤ªº¦UºØ°T®§¡A½Æ¦X±±¨î¤¸¥ó¤]¥i¥H¹ï¤÷µøµ¡¦^À³°T®§¡Cµ´¤j³¡¥÷ªº±±¨î¤¸¥ó³£¬O¥H WM_COMMAND °T®§±N°T®§¦^À³µ¹¤÷µøµ¡¡A¤Ö¦³¨Ò¥~¡A½Æ¦X¤l±±¥ó¤]¬O¦p¦¹¡C·í½Æ¦X¤l±±¥ó¹ï¤÷µøµ¡¦^À³ WM_COMMAND ®É¡AlParam ¬O¤lµøµ¡¥N½X¡AwParam ªº§C¦r²Õ¬O¤lµøµ¡ÃѧO¸¹½X¡AwParam ªº°ª¦r²Õ«h¬O¨Ï¥ÎªÌ¹ï¤l±±¥óªº°Ê§@ ( ³qª¾½X )¡A¹ï½Æ¦X¤l±±¥ó¨Ó»¡¡A±`¥Îªº³qª¾½X¦³¡G

  1. CBN_DBLCLK¡G¨Ï¥ÎªÌ±q½Æ¦X¤¸¥óªº²M³æ¤¤¿ï©w¬Y¿ï¾Ü¦r¦ê¡C
  2. CBN_DROPDOWN¡G¨Ï¥ÎªÌ«ö¤U½Æ¦X¤¸¥óªº¤U©Ô¶s¡C
  3. CBN_EDITCHANGE¡G¨Ï¥ÎªÌ­×§ï½Æ¦X¤¸¥óªº½s¿è®Ø¤º®e¡C
  4. CBN_ERRSPACE¡G²M³æ¤ºªº¿ï¾Ü¶µ¤Ó¦h¡A¥H­P°O¾ÐÅ餣¨¬¡C
  5. CBN_KILLFOCUS¡G½Æ¦X¤¸¥ó¥¢¥h¿é¤JµJÂI¡A§Y¤£¦b§@¥Î¤¤¡C
  6. CBN_SELCHANGE¡G¨Ï¥ÎªÌÅܧó²M³æ¤º¤w¿ï©wªº¿ï¾Ü¶µ¦r¦ê¡C
  7. CBN_SELENDOK¡G¨Ï¥ÎªÌ¿ï©w¤@­Ó²M³æ¤ºªº¿ï¶µ¡A©Î¿ï©w¤@­Ó²M³æ¤ºªº¿ï¶µ¨Ã¥BÃö³¬²M³æ¡C
  8. CBN_SETFOCUS¡G½Æ¦X¤¸¥óÀò±o¿é¤JµJÂI¡C

SCROLLBAR ±±¨î¤¸¥ó

±²¶b¤¸¥ó¬O¤@¶ô¯x§Î°Ï°ì¡A¨âºÝ¦U¦³¤@­Ó½bÀY¡A¤¤¶¡¦³¤@­Ó¾ÞÁa±ì ( thumb )¡A¥i¥H¦b¦³³±¼vªº·Æ°Ê±ì ( shaded shaft ) ¤W¥H·Æ¹«©ì¦²¡A¦p¤U¹Ï©Ò¥Ü¡J

±²¶b¤¸¥ó©M¤@¯ëµøµ¡ªº±²¶b ( ¦¹±²¶bºÙ¬°µøµ¡±²¶b¡A¥¦¦ì©óµøµ¡ªº¥kÃä©Î¤U­±Ãä¡A·íÅã¥Üªº¸ê®Æ¶q¤Ó¤j¡A¿Ã¹õµLªk®e¤º®É¡A¨Ï¥ÎªÌ±`±`²¾°Êµøµ¡±²¶b¡A¤@¦¸¾\Ū¤@³¡¤Àªº¸ê®Æ ) ÁöµM¦b¥~Æ[¤W¤@¼Ë¡A¦ý¬O¨ä©Ê½è«o¬O¤£¦P¡A±²¶b¤¸¥ó¥»¨­´N¬Oµøµ¡¡A¨ã¦³µøµ¡ªº©Ò¦³¯S©Ê¡F¦Óµøµ¡±²¶b«h¬Oµøµ¡ªº¤@³¡¥÷¡A¤£­n²V²c¤F¡A¤p¤ì°¸¦b²Ä¤Q¤T³¹¦A¸Ô½Íµøµ¡±²¶b¡C«Ø¥ß±²¶b¤¸¥ó¦³¼ÆºØ¤è¦¡¡A¤@¯ë¬O¦b¹ï¸Ü²°­±ªO¤¤´y­z¡A¨ä®æ¦¡¬°¡J

SCROLLBAR id, x, y, width, height [, style [, extended-style]]
©Î
CONTROL   text, id, "SCROLLBAR", style, x, y, width, height [, extended-style]

±²¶b¤¸¥ó¤]©M½Æ¦X¤¸¥ó¤@¼Ë¡A¦pªG±z±Ä¥Î²Ä¤@ºØ¤è¦¡©w¸q¡A«h¤£¥i¥X²{ text¡A¦pªG±Ä¥Î²Ä¤GºØ§¹¾ãªº¤èªk©w¸q¡A«o¥²¶·³]©w text Äæ¦ì¡A¦ý¬O«o·|³Q©¿²¤¡C±²¶b¤¸¥ó±`¥Îªº­·®æ¡A¦h¥H SBS_ ¬°¦r­º¡ASBS_ ¬O scrollbar style ¤§ÁY¼g¡A¤Uªí¦C¥X¤@¨Ç±²¶b¤¸¥óªº­·®æ¡J

­·®æ »¡¡@¡@¡@©ú
SBS_HORZ «Ø¥ß¤ô¥­±²¶b±±¨î¤¸¥ó¡C
SBS_VERT «Ø¥ß««ª½±²¶b±±¨î¤¸¥ó¡C

¨ä¥L¥i¥Îªº­·®æÁÙ¦³ WS_TABSTOP¡BWS_GROUP¡BWS_DISABLED µ¥µ¥¡C­Y¬Ù²¤¡A¤º©w¬° SBS_HORZ¡C

©w¸q¦n±²¶b±±¨î¤¸¥ó«á¡AÁÙ±o¦bµ{¦¡¤¤³]©w±²¶b¾ÞÁa±ì ( thumb ) ¥i²¾°Êªº½d³ò¤Î¾ÞÁa±ìªº°_©l¦ì¸m¡A³o¨Ç¤u§@¤@¯ë¬O¦b¹ï¸Ü²°­è«Ø¥ß¤§ªì¶i¦æ¡A¤]´N¬O¦¬¨ì WM_INITDIALOG °T®§®É§¹¦¨¡C©³¤U»¡©ú¹ï±²¶b±±¥ó±`¥Îªº API¡G

SetScrollRange API

³]©w¾ÞÁa±ìªº½d³ò¥Î SetScrollRange API¡A³o­Ó API ¥i¥H¥Î¦b±²¶b±±¥ó¤W¡A¤]¥i¥H¥Î¦bµøµ¡±²¶b¤W¡A©Ò¥H«ü©w°Ñ¼Æ®É¤£­n²V²c¡A§_«hµLªk¹F¨ì®ÄªG¡CSetScrollRange ªº­ì«¬¬O

BOOL SetScrollRange(
    HWND    hWnd,       // handle of window with scroll bar
    int     nBar,       // scroll bar flag
    int     nMinPos,    // minimum scrolling position
    int     nMaxPos,    // maximum scrolling position
    BOOL    bRedraw     // redraw flag
   );

hWnd ¬O«ü±²¶b±±¥óªºµøµ¡¥N½X©ÎªÌ§t¦³µøµ¡±²¶bªºµøµ¡¥N½X¡CnBar ¬O±²¶bºØÃþ¡A¦³¤TºØ¥i¥H¨Ï¥Î¡G

  1. SB_CTL¡G±²¶b±±¥ó¡A¦¹®É hWnd ¬O«ü±²¶b±±¥óªºµøµ¡¥N½X¡C
  2. SB_HORZ¡G¤ô¥­ªºµøµ¡±²¶b¡A¦¹®É hWnd ¬O«ü§t¦³¦¹µøµ¡±²¶bªºµøµ¡¥N½X¡C
  3. SB_VERT¡G««ª½ªºµøµ¡±²¶b¡A¦¹®É hWnd ¬O«ü§t¦³¦¹µøµ¡±²¶bªºµøµ¡¥N½X¡C

nMinPos¡BnMaxPos ¤À§O¬O³Ì¤p­È©M³Ì¤j­È¡CbRedraw ¥Î¨Óªí¥Ü§ó°Ê¾ÞÁa±ì«á¬O§_­n­«·sø»s¡ATRUE ªí¥Ü­n­«Ã¸¡AFALSE ªí¥Ü¤£¶·­«Ã¸¡A­«·sø»sªº°Ê§@¤£¶·¥Ñµ{¦¡³]­p®v¼¶¼g¡A¨t²Î·|¦Û°Êø»s¡A¸`¬Ù¤F³\¦hºë¤O¡C¦pªG°õ¦æ¦¨¥\¡ASetScrollRange ¶Ç¦^ TRUE¡A§_«h¶Ç¦^ FALSE¡C

SetScrollPos API

³o­Ó API ¬O³]©w¾ÞÁa±ì¦ì¸m¡A­ì«¬¬O¡G

int SetScrollPos(
    HWND    hWnd,       // handle of window with scroll bar
    int     nBar,       // scroll bar flag
    int     nPos,       // new position of scroll box
    BOOL    bRedraw     // redraw flag
   );

hWnd¡BnBar¡BbRedraw ªº·N¸q©M SetScrollRange ªº°Ñ¼Æ¤@¼Ë¡CnPos ¬O«ü·sªº¾ÞÁa±ì¦ì¸m¡A¥²¶·¤¶©ó SetScrollRange °Ñ¼Æªº nMinPos ©M nMaxPos ¤§¶¡¡CSetScrollPos ªº¶Ç¦^­È¦s©ó EAX¡A­Y°õ¦æ¦¨¥\¡A«h EAX ¬°Âªº¾ÞÁa±ì¦ì¸m¡A­Y¥¢±Ñ«h EAX ¬°¹s¡C

GetScrollPos API

GetScrollPos ¬O¥Î¨Ó¨ú±o¾ÞÁa±ì¦ì¸m¡A¨ä­ì«¬¬°¡G

int GetScrollPos(
    HWND    hWnd,       // handle of window with scroll bar
    int     nBar        // scroll bar flags
   );

hWnd ©M nBar ©M«e­±³£¬Û¦P¡C­Y GetScrollPos °õ¦æ¦¨¥\¡A«h EAX ¬°¾ÞÁa±ì¦ì¸m¡A­Y¥¢±Ñ«h EAX ¬° FALSE¡C

«e­z¤@¯ë±±¨î¤¸¥óµo¥X WM_COMMAND °T®§µ¹¤÷µøµ¡¡A¦ý±²¶b±±¨î¤¸¥ó«o¬O­Ó¨Ò¥~¡C±²¶b±±¥ó¤£µo¥X WM_COMMAND ¦Ó¬Oµo¥X WM_HSCROLL »P WM_VSCROLL¡A¨ä±²¶b¬O¤ô¥­§í©Î««ª½¦Ó©w¡F¼Ð·Çµøµ¡¤W¦pªG¦³µøµ¡±²¶b¡A¨Ï¥ÎªÌ¹ïµøµ¡±²¶b°Ê§@®É¡A¤]·|µo¥X WM_HSCROLL »P WM_VSCROLL¡C©³¤U¶È´N WM_HSCROLL °T®§»¡©ú¡C

·í WM_HSCROLL °T®§¶Çµ¹¤÷µøµ¡®É¡A¦pªGµ{¦¡­n³B²z³o­Ó°T®§¡A³Ì«á­n¶Ç¦^ TRUE¡A§_«h¶Ç¦^ FALSE¡CWM_HSCROLL ¤¤¡A­Y lParam ¬° NULL¡A«hªí¥Ü¦¹°T®§¥Ñ¼Ð·Çµøµ¡ªºµøµ¡±²¶bµo¥X¡F­Y¤£¬° NULL¡Aªí¥Ü¥Ñ±²¶b±±¥óµo¥X¡A¨ä¼Æ­È¬°±²¶b±±¥óªºµøµ¡¥N½X¡CwParam ªº°ª¦r²Õ¬O±²¶b¾ÞÁa±ì¦ì¸m¡A§C¦r²Õ¬O¬O¨Ï¥ÎªÌ¹ï±²¶bªº°Ê§@¡A±`¥Îªº¦³¤U­±¼ÆºØ¡F

  1. SB_LEFT¡G¾ÞÁa±ì³Q²¾¨ì³Ì¥ªÃä¡C
  2. SB_RIGHT¡G¾ÞÁa±ì³Q²¾¨ì³Ì¥kÃä¡C
  3. SB_LINELEFT¡G¾ÞÁa±ì³Q¦V¥ª²¾¤@®æ¡C
  4. SB_LINERIGHT¡G¾ÞÁa±ì³Q¦V¥k²¾¤@®æ¡C
  5. SB_THUMBPOSITION¡G¨Ï¥ÎªÌ¥H·Æ¹«©ì©ñ¾ÞÁa±ì¡C

½d¨Ò¡GUNIT_CVT

©³¤U¤p¤ì°¸¤¶²Ð¤@­Ó¨Ò¤l¡AUNIT_CVT.EXE¡A¥Î¥¦¨Ó»¡©ú¼Ò¦¡¹ï¸Ü²°ªº«Ø¥ß»P§ó¦hªº¤l±±¨î¤¸¥óªº¨Ï¥Î¡A¥]§t½Æ¦X¤¸¥ó¡B±²¶b¤¸¥ó ( scroll bar control )¡B¸s²Õ¤¸¥ó ( group box control )¡CUNIT_CVT.EXE ¬O¤@­Óªø«×¡B½è¶q¡B·Å«×ªº¤½¨î»P­^¨î³æ¦ìÂà´«µ{¦¡¡A·íµ{¦¡°õ¦æ®É¡AÅã¥Üµe­±¦p¤U¹Ï¡G

¥Dµøµ¡

¦pªG¨Ï¥ÎªÌ«ö¤U¡yªø«×¡z¿ï³æ«á¡A·|¥X²{¤@­Ó¼Ò¦¡¹ï¸Ü²°¡A¦p¤U¹Ï¡G

¤@­Ó¼Ò¦¡¹ï¸Ü²°¡Gªø«×´«ºâ¹ï¸Ü²°
¡A¨ä¤¤¡y¿ï¾Ü´«ºâ¤è¦¡¡z¬O¸s²Õ¤¸¥ó¡A¥]§t¡y­^¨î´«ºâ¦¨¤½¨î³æ¦ì¡z©M¡y¤½¨î´«ºâ¦¨­^¨î³æ¦ì¡z¨â­Ó¶ê§Î«ö¶s ( AUTORADIOBUTTON )¡C¦pªG«ö¤U¡y½è¶q¡z¿ï³æ¡A«h¥X²{ªº¼Ò¦¡¹ï¸Ü²°¦p¤U¹Ï¡G
¤@­Ó¼Ò¦¡¹ï¸Ü²°¡G½è¶q´«ºâ¹ï¸Ü²°
¡A¨ä¤¤¡y70¡zªº±±¨î¤¸¥ó´N¬O¤@­Ó½Æ¦X¤¸¥ó¡C¦pªG«ö¤U¡y·Å«×¡z¿ï³æ¥X²{ªº¹ï¸Ü²°¦p¤U¹Ï¡G
¤@­Ó¼Ò¦¡¹ï¸Ü²°¡G·Å«×´«ºâ¹ï¸Ü²°
¡A¥]§t¤@­Ó±²¶b¤¸¥ó¡C

UNIT_CVT.ASM ¤º®e¦p¤U¡G

        .386
        .model  flat,stdcall
        option  casemap:none

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

IDM_Exit        equ     2001    ;011 ¿ï³æÃѧO½X¶}©l
IDM_L           equ     2002
IDM_M           equ     2003
IDM_T           equ     2004
IDC_MText1      equ     2101    ;015 ±±¨î¤¸¥óÃѧO½X¶}©l
IDC_MText2      equ     2102
IDC_MCB         equ     2103
IDC_MP2K        equ     2104
IDC_MK2P        equ     2105
IDC_MCvt        equ     2106
IDC_MExit       equ     2107
IDC_MOpt        equ     2108
IDC_TSB         equ     2201
IDC_TText       equ     2202
IDC_TOpt        equ     2203
IDC_TF2C        equ     2204
IDC_TC2F        equ     2205
IDC_TExit       equ     2206
IDC_LFeet       equ     2301
IDC_LText1      equ     2302
IDC_LInch       equ     2303
IDC_LText2      equ     2304
IDC_LCm         equ     2305
IDC_LText3      equ     2306
IDC_LCvt        equ     2307
IDC_LExit       equ     2308
IDC_LOpt        equ     2309
IDC_LI2C        equ     2310
IDC_LC2I        equ     2311
nSBMin          equ     0       ;040 ±²¶b±±¨î¤¸¥óªº³Ì¤p­È
nSBMax          equ     150     ;041 ±²¶b±±¨î¤¸¥óªº³Ì¤j­È
nSBMiddle       equ     (nSBMax+nSBMin)/2       ;042±²¶b±±¨î¤¸¥óªº¹w³]­È

;¨ç¦¡­ì«¬«Å§i
WndProc         proto   :HWND,:UINT,:WPARAM,:LPARAM
LenDlgProc      proto   :HWND,:UINT,:WPARAM,:LPARAM
MassDlgProc     proto   :HWND,:UINT,:WPARAM,:LPARAM
TempDlgProc     proto   :HWND,:UINT,:WPARAM,:LPARAM
LenConvert      proto   :HWND
MassConvert     proto   :HWND
TempConvert     proto   :HWND
CvtST0_to_Str   proto   :LPSTR

;***************************************
        .DATA

UnitCvtClass    db          'UnitCvtClass',0
AppName         db          '³æ¦ì´«ºâ',0
ExitText        db          '¬O§_°h¥X¦¹µ{¦¡¡H',0
ExitTitle       db          '¸ß°Ý',0
IconName        db          'UnitCvtIcon',0
MenuName        db          'UnitCvtMenu',0     ;062 ¿ï³æ¦WºÙ
LenDlgName      db          'LenDlg',0          ;063 ¹ï¸Ü²°¦WºÙ
MassDlgName     db          'MassDlg',0
TempDlgName     db          'TempDlg',0
wc              WNDCLASSEX  <?>
msg             MSG         <?>
hInstance       HINSTANCE   ?
hMenu           HMENU       ?
hwnd            HWND        ?
hwnd_TSB        HWND        ?
nSBPos          dw          ?

bOption         db          7
;bit0¡G1­^¦T´«ºâ¦¨¤½¤À  bit1¡G1­^½S´«ºâ¦¨¤½¤ç  bit2¡G1µØ¤ó´«ºâ¦¨Äá¤ó
;      0¤½¤À´«ºâ¦¨­^¦T        0¤½¤ç´«ºâ¦¨­^½S        0Äá¤ó´«ºâ¦¨µØ¤ó

buffer          db          64 dup (0)
ten             dw          10
factor_c2f_diff dw          32          ;080 ¢K¡×1.8¢J¡Ï32
factor_c2f      dd          1.8
factor_i2c      dd          2.54        ;082 ¤@­^¦T¡×2.54¤½¤À
factor_p2k      dd          0.454       ;083 ¤@­^½S¡×0.454¤½¤ç
inch_per_foot   dw          12          ;084 ¤@­^§`¡×12­^¦T
combobox_str    db          ' 70',0,' 75',0,' 80',0,' 85',0
                db          ' 90',0,' 95',0,'100',0,'105',0
                db          '110',0,'115',0,'120',0,'125',0
                db          '130',0,'135',0,'140',0,'145',0
strPound        db          '­^½S'
strKg           db          '¤½¤ç'
strEqual        db          '¡×'
strDC           db          '¢J'
strDF           db          '¢K'
;***************************************
        .CODE
;---------------------------------------
start:  invoke  GetModuleHandle,NULL    ;097 µ{¦¡¶}©l
        mov     hInstance,eax
        mov     wc.cbSize,SIZEOF WNDCLASSEX
        mov     wc.style,CS_HREDRAW or CS_VREDRAW
        mov     wc.lpfnWndProc,offset WndProc           ;101 µøµ¡¨ç¦¡¦ì§}
        mov     wc.cbWndExtra,DLGWINDOWEXTRA
        mov     wc.hInstance,eax
        mov     wc.hbrBackground,COLOR_BTNFACE+1 
        mov     wc.lpszMenuName,offset MenuName
        mov     wc.lpszClassName,offset UnitCvtClass
        invoke  LoadIcon,hInstance,offset IconName      ;107 ¨ú±o¹Ï¥Ü
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        invoke  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        invoke  LoadMenu,hInstance,offset MenuName      ;112 ¨ú±o¿ï³æ
        mov     hMenu,eax
        invoke  RegisterClassEx,offset wc               ;114 µù¥Uµøµ¡Ãþ§O
        invoke  CreateWindowEx,NULL,offset \            ;115 «Ø¥ß¥Dµøµ¡
                UnitCvtClass,offset AppName,\
                WS_OVERLAPPEDWINDOW,0,0,300,100,0,hMenu,hInstance,NULL        
        mov     hwnd,eax
        invoke  ShowWindow,hwnd,SW_SHOWNORMAL
        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         ;128 µ²§ôµ{¦¡
;---------------------------------------
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
;136 ¥H¤U¬O³B²z¨Ï¥ÎªÌ«ö¤U¬Y­Ó¿ï³æªºµ{¦¡
    .if ax==IDM_L
        invoke  DialogBoxParam,hInstance,offset \       ;138 «ö¤U¡yªø«×¡z¿ï³æ
                LenDlgName,hWnd,addr LenDlgProc,NULL
    .elseif ax==IDM_M
        invoke  DialogBoxParam,hInstance,offset \       ;141 «ö¤U¡y½è¶q¡z¿ï³æ
                MassDlgName,hWnd,offset MassDlgProc,NULL
    .elseif ax==IDM_T
        invoke  DialogBoxParam,hInstance,offset \       ;144 «ö¤U¡y·Å«×¡z¿ï³æ
                TempDlgName,hWnd,offset TempDlgProc,NULL
    .elseif ax==IDM_Exit
        invoke  MessageBox,hWnd,offset ExitText,offset \;147 «ö¤U¡yÂ÷¶}¡z¿ï³æ
                ExitTitle,MB_YESNO or MB_ICONQUESTION
      .if eax==IDYES
        invoke  DestroyWindow,hWnd
      .endif
    .endif
  .endif
.else
        invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
.endif
        xor     eax,eax 
        ret
WndProc endp    ;160 µøµ¡¨ç¦¡µ²§ô
;---------------------------------------
LenDlgProc      proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_INITDIALOG         ;163 ªì©l¤Æªø«×´«ºâ¹ï¸Ü²°
        invoke  GetDlgItem,hWnd,IDC_LI2C  ;164 ¨ú±o¡y­^¨îÂà´«¦¨¤½¨î³æ¦ì¡zªºµøµ¡¥N½X
        invoke  SendMessage,eax,BM_SETCHECK,BST_CHECKED,NULL    ;165 ¹w³]¦¹¤lµøµ¡
        or      bOption,1
        invoke  GetDlgItem,hWnd,IDC_LFeet
        invoke  SetFocus,eax
.elseif uMsg==WM_CLOSE          ;169 Ãö³¬ªø«×´«ºâ¹ï¸Ü²°
        invoke  EndDialog,hWnd,NULL
.elseif uMsg==WM_COMMAND        ;171 «ö¤U±±¨î¤¸¥ó
        mov     eax,wParam
        mov     edx,eax
        shr     edx,16
  .if dx==BN_CLICKED            ;175 «ö¤U«ö¶s
    .if ax==IDC_LCvt            ;176 «ö¤U¡y´«ºâ¡z«ö¶s
        invoke  LenConvert,hWnd
    .elseif ax==IDC_LExit       ;178 «ö¤U¡yÂ÷¶}¡z«ö¶s
        invoke  EndDialog,hWnd,NULL
    .elseif ax==IDC_LI2C        ;180 «ö¤U¡y­^¨îÂà´«¦¨¤½¨î³æ¦ì¡z«ö¶s
        or      bOption,1
    .elseif ax==IDC_LC2I        ;182 «ö¤U¡y¤½¨îÂà´«¦¨­^¨î³æ¦ì¡z«ö¶s
        and     bOption,0feh
    .endif
  .endif
.else
        mov     eax,FALSE       ;187 ¥¼³B²zªº°T®§¶Ç¦^ FALSE
        ret
.endif
        mov     eax,TRUE        ;190 ¤w³B²z¹Lªº°T®§¶Ç¦^ TRUE
        ret
LenDlgProc      endp
;---------------------------------------
MassDlgProc     proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
        LOCAL   hwnd_MCB:HWND
.if uMsg==WM_INITDIALOG         ;196 ªì©l¤Æ¡y½è¶q´«ºâ¡z¹ï¸Ü²°
        invoke  GetDlgItem,hWnd,IDC_MP2K
        invoke  SendMessage,eax,BM_SETCHECK,BST_CHECKED,NULL
        or      bOption,2
        invoke  GetDlgItem,hWnd,IDC_MCB ;200 ¨ú±o½Æ¦X¤¸¥óµøµ¡¥N½X
        mov     hwnd_MCB,eax
        mov     ecx,10h
        mov     edx,offset combobox_str ;203 EDX «ü¦V­n¶ñ¤J½Æ¦X¤¸¥óªº¦r¦ê¦ì§}
nxt:    push    ecx
        push    edx
        invoke  SendMessage,hwnd_MCB,CB_ADDSTRING,NULL,edx
        pop     edx
        pop     ecx
        add     edx,4
        loop    nxt
        invoke  SendMessage,hwnd_MCB,CB_SETCURSEL,ecx,ecx
        invoke  GetDlgItem,hWnd,IDC_MCB
        invoke  SetFocus,eax
.elseif uMsg==WM_CLOSE
        invoke  EndDialog,hWnd,NULL     ;214 ºR·´½è¶q´«ºâ¹ï¸Ü²°
.elseif uMsg==WM_COMMAND
        mov     eax,wParam
        mov     edx,eax
        shr     edx,16
  .if dx==BN_CLICKED                    ;220 ¨Ï¥ÎªÌ«ö¤U«ö¶s
    .if ax==IDC_MCvt                    ;221 «ö¤U¡y´«ºâ¡z«ö¶s
        invoke  MassConvert,hWnd
    .elseif ax==IDC_MExit               ;223 «ö¤U¡yÂ÷¶}¡z«ö¶s
        invoke  EndDialog,hWnd,NULL
    .elseif ax==IDC_MP2K                ;225 «ö¤U¡y­^½S´«ºâ¦¨¤½¤ç¡z«ö¶s
        or      bOption,2
    .elseif ax==IDC_MK2P                ;227 «ö¤U¡y¤½¤ç´«ºâ¦¨­^½S¡z«ö¶s
        and     bOption,0fdh
    .endif
  .endif
.else
        mov     eax,FALSE       ;232 ¥¼³B²zªº°T®§¶Ç¦^ FALSE
        ret
.endif
        mov     eax,TRUE        ;235 ¤w³B²z¹Lªº°T®§¶Ç¦^ TRUE
        ret
MassDlgProc     endp
;---------------------------------------
TempDlgProc     proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_INITDIALOG         ;240 ªì©l¤Æ¡y·Å«×´«ºâ¡z¹ï¸Ü²°
        invoke  GetDlgItem,hWnd,IDC_TF2C
        invoke  SendMessage,eax,BM_SETCHECK,BST_CHECKED,NULL
        or      bOption,4
        invoke  GetDlgItem,hWnd,IDC_TSB
        mov     hwnd_TSB,eax
        invoke  SetScrollRange,eax,SB_CTL,nSBMin,nSBMax,TRUE
        invoke  SetScrollPos,hwnd_TSB,SB_CTL,nSBMiddle,TRUE
        mov     nSBPos,nSBMiddle
        invoke  SetFocus,hwnd_TSB
.elseif uMsg==WM_CLOSE          ;250 Ãö³¬¡y·Å«×´«ºâ¡z¹ï¸Ü²°
        invoke  EndDialog,hWnd,NULL
.elseif uMsg==WM_COMMAND        ;252 ¥Ñ«ö¶s¶Ç¨Óªº°T®§
        mov     eax,wParam
        mov     edx,eax
        shr     edx,16
  .if dx==BN_CLICKED            ;256 «ö¤U«ö¶s
    .if ax==IDC_TExit           ;257 «ö¤U¡yÂ÷¶}¡z«ö¶s
        invoke  EndDialog,hWnd,NULL
    .elseif ax==IDC_TF2C        ;259 «ö¤U¡yµØ¤ó·Å«×´«ºâ¦¨Äá¤ó·Å«×¡z«ö¶s
        or      bOption,4
    .elseif ax==IDC_TC2F        ;261 «ö¤U¡yÄá¤ó·Å«×´«ºâ¦¨µØ¤ó·Å«×¡z«ö¶s
        and     bOption,0fbh
    .endif
  .endif
.elseif uMsg==WM_HSCROLL        ;265 ¥Ñ±²¶b±±¨î¤¸¥ó¶Ç¨Óªº°T®§
        mov     edx,lParam
  .if edx==hwnd_TSB
        mov     eax,wParam
        mov     edx,eax
        shr     edx,16
    .if ax==SB_THUMBPOSITION    ;271 ·Æ°Ê±²¶b
        mov     nSBPos,dx
    .elseif ax==SB_RIGHT        ;273 ¦b·Æ°Ê±²¶b«ö¤U End Áä
        mov     nSBPos,nSBMax
    .elseif ax==SB_LEFT         ;275 ¦b·Æ°Ê±²¶b«ö¤U Home Áä
        mov     nSBPos,0
    .elseif ax==SB_LINERIGHT    ;277 ¦b·Æ°Ê±²¶b«ö¤UÁä½L¥kÁä
        inc     nSBPos
      .if nSBPos>nSBMax
        mov     nSBPos,nSBMax
      .endif
    .elseif ax==SB_LINELEFT     ;282 ¦b·Æ°Ê±²¶b«ö¤UÁä½L¥ªÁä
      .if nSBPos!=nSBMin
        dec     nSBPos
      .endif
    .endif
        invoke  SetScrollPos,hwnd_TSB,SB_CTL,nSBPos,TRUE        ;287 ­«·s³]©w±²¶b¦ì¸m
        invoke  TempConvert,hWnd;288 Âà´«
  .endif
.else
        mov     eax,FALSE
        ret
.endif
        mov     eax,TRUE 
        ret
TempDlgProc     endp
;---------------------------------------
;§â FPU ªº ST0 Åܦ¨ ASCIIZ ¦r¦ê(¶È¤@¦ì¤p¼Æ) ;298
;¿é¤J¡ÐAddr_Str¡G¦r¦ê¦ì§}
;      ST0¡G­nÂà´«ªº¼Æ¦r
;¿é¥X¡ÐEAX¡G¦r¦ê¤§¤U¤@¦ì§}
CvtST0_to_Str   proc    uses edi Addr_Str:LPSTR
        LOCAL   pBCD:TBYTE
        LOCAL   bIfZero:BYTE
;bIfZero ¬O¬°¤F¦L¥Xªº®æ¦¡©Ò³]­p¡A¨Ò¦p·í¼Æ­È¬° 0100 ®É¡A²Ä¤@
;­Ó¹s¤£¥²¦L¥X¨Ó¡A¦ý¬O²Ä¤G¡B¤T­Ó¹s«h¥²¶·¦L¥X¨Ó¡A·í¥X²{²Ä¤@­Ó
;«D¹sªü©Ô§B¼Æ¦r®É¡AbIfZero=1¡Aªí¥Ü¥H«á¥X²{ªº¹s­nÅã¥Ü¥X¨Ó
        mov     edi,Addr_Str    ;308 EDI=¦r¦ê¦ì§}
        lea     ecx,pBCD        ;309 ECX=À£ÁYªº BCD ¦ì§}
        mov     edx,ecx
        fimul   ten
        fbstp   pBCD
        add     ecx,9           ;313 ¥Ñ°ª¦ì§}¶}©l
        mov     al,ss:[ecx]     ;314 Àˬd¥¿­t¸¹
.if al==80h
        mov     ax,0d0a1h       ;316 '¡Ð'¦r¦ê
        stosw
.endif
        dec     ecx
        mov     bIfZero,0       ;320 ¥ý°²³]°ª¦ì¼Æ¬°¹s
n_dgt:  mov     al,ss:[ecx]
.if al!=0
  .if bIfZero==0        ;323 ­Y bIfZero=0¡Aªí¥Ü¤§«eªº°ª¦ì¼Æ³£¬°¹s
        test    al,0f0h ;324 ­Y bIfZero=0 ¥B AL¤£¬°¹s¡A«h¥ýÀˬd AL
        jnz     h_nz    ;325 °ª¦ì¤¸¬O§_¬°¹s¡A­Y¬°¹s¡A«h§C¦ì¤¸¥²¤£
        add     al,30h  ;326 ¬°¹s¡AAL ¥[¤W 30H «á¦s¤J
        stosb
  .else
h_nz:   mov     ah,al
        shr     al,4
        and     ah,0fh
        add     ax,3030h
        stosw
  .endif
        mov     bIfZero,1
.else
  .if bIfZero!=0        ;337 ­Y AL=0¡A«hÀˬd bIfZero ¬O§_¬°¹s
        jmp     h_nz    ;338 ­Y bIfZero ¤£¬°¹s¥B AL=0¡Aªí¥Ü¦¹¹s¬O¦b°ª¦ì
  .endif                ;339 ¼Æ¦³«D¹sªü©Ô§B¼Æ¦r¥X²{¤§«á¡A¶·¦s¤J©ó¦r¦ê¤¤
.endif
        dec     ecx
        cmp     ecx,edx
        ja      n_dgt
        mov     al,[ecx]
        mov     ah,al
        shr     al,4
        add     al,'0'  ;347 AL=­Ó¦ì¼Æ
        stosb
        mov     al,'.'  ;349 AL=¤p¼ÆÂI
        stosb
        mov     al,ah
        and     al,0fh  ;352 AL=¤p¼ÆÂI¤U¤@¦ì
.if al==0
        dec     edi
.else
        add     al,'0'
        stosb
.endif
        mov     al,0
        stosb
        mov     eax,edi ;361 EAX=¦r¦êµ²§À¦ì§}ªº¤U¤@¦ì§}
        ret
CvtST0_to_Str   endp    ;363
;---------------------------------------
LenConvert      proc    hWnd:HWND
        LOCAL   inch:DWORD
        LOCAL   cm:DWORD
        LOCAL   cw:WORD
        mov     cl,bOption
        and     cl,1    ;370 CL=1ªí¥Ü­^¨îÂà´«¦¨¤½¨î¡A§_«h¬°¤½¨îÂà´«¦¨­^¨î
.if cl==1
        invoke  GetDlgItemInt,hWnd,IDC_LFeet,NULL,FALSE ;372 EAX=­^§`
        mul     inch_per_foot   ;373 ­^¦T=12*­^§`+­^¦T
        mov     inch,eax
        invoke  GetDlgItemInt,hWnd,IDC_LInch,NULL,FALSE
        add     inch,eax
        fild    inch
        fmul    factor_i2c      ;378 ¤½¤À=2.54*­^¦T
        invoke  CvtST0_to_Str,offset buffer
        invoke  SetDlgItemText,hWnd,IDC_LCm,offset buffer
.else
        invoke  GetDlgItemInt,hWnd,IDC_LCm,NULL,FALSE
        mov     cm,eax
        fstcw   cw
        mov     ax,cw
        or      cw,0c00h        ;386 ­n±o¨ì­^§`¡A¬G¦V¹s±Ë¥h
        push    eax             ;387 «O¦s­ì±±¨î¦r²Õ
        fldcw   cw              ;--st --;--st1--;--st2--;
        fild    inch_per_foot   ;  12   ;
        fild    cm              ;  cm   ;  12   ;
        fdiv    factor_i2c      ; inch  ;  12   ;
        fld     st              ; inch  ; inch  ;  12   ;
        fdiv    st,st(2)        ;  ft   ; inch  ;  12   ;
        frndint                 ;int(ft); inch  ;  12   ;
        invoke  CvtST0_to_Str,offset buffer
        invoke  SetDlgItemText,hWnd,IDC_LFeet,offset buffer
        fprem                   ;inch\12;  12   ;
        invoke  CvtST0_to_Str,offset buffer
        invoke  SetDlgItemText,hWnd,IDC_LInch,offset buffer
        pop     eax             ;  12   ;
        fcomp   cm
        mov     cw,ax           ;402 «ì´_±±¨î¦r²Õ
        fldcw   cw
.endif
        ret
LenConvert      endp
;---------------------------------------
MassConvert     proc    hWnd:HWND
        LOCAL   nComboBox:DWORD
        invoke  GetDlgItemInt,hWnd,IDC_MCB,NULL,FALSE
        mov     nComboBox,eax   ;411 EAX=½Æ¦X¤¸¥ó¤¤ªº¼Æ­È
        fild    nComboBox
        invoke  CvtST0_to_Str,offset buffer     ;413 ¶ñ¤J½Æ¦X¤¸¥ó¤§¼Æ­È
        dec     eax
        push    edi
        mov     edi,eax         ;416 EDI=¦s¤J¦ì§}
        fild    nComboBox
        mov     al,bOption
        mov     ecx,offset strPound     ;419 ¥ý°²³]­^½S´«¦¨¤½¤ç
        and     al,2                    ;420 AL=2 ªí¥Ü­^½S´«¦¨¤½¤ç
        mov     edx,offset strKg
.if al==2
        fmul    factor_p2k      ;423 1½S=0.454kg
.else
        xchg    ecx,edx         ;425 ­Y¤½¤ç´«¦¨­^½S«h¥æ´« ECX¡BEDX
        fdiv    factor_p2k
.endif
        mov     eax,[ecx]       ;428 ¶ñ¤J ECX ©Ò«üªº¦r¦ê
        stosd
        mov     ecx,offset strEqual
        mov     ax,[ecx]        ;431 ¶ñ¤J¡y¡×¡z
        stosw
        mov     eax,edi
        pop     edi
        push    edx
        invoke  CvtST0_to_Str,eax       ;436 ¶ñ¤J´«ºâ«á¤§¼Æ­È
        pop     edx
        dec     eax
        mov     ecx,[edx]
        mov     [eax],ecx
        add     eax,4
        mov     byte ptr [eax],0
        invoke  SetDlgItemText,hWnd,IDC_MText2,offset buffer
        ret
MassConvert     endp
;---------------------------------------
TempConvert     proc    hWnd:HWND
        LOCAL   nSBPosition:DWORD
        invoke  GetDlgItem,hWnd,IDC_TSB
        invoke  GetScrollPos,eax,SB_CTL ;450 ¨ú±o±²¶b¦ì¸m
        mov     nSBPosition,eax
        fild    nSBPosition
        invoke  CvtST0_to_Str,offset buffer     ;453 ¦s¤J±²¶b¼Æ­È
        dec     eax
        push    edi
        mov     edi,eax
        fild    nSBPosition
        mov     al,bOption
        mov     ecx,offset strDF
        and     al,4
        mov     edx,offset strDC
.if al==4
        fisub   factor_c2f_diff ;463 ¢J=(¢K-32)/1.8
        fdiv    factor_c2f
.else
        xchg    ecx,edx
        fmul    factor_c2f
        fiadd   factor_c2f_diff ;468 ¢K=1.8¢J+32
.endif
        mov     ax,[ecx]
        stosw
        mov     ecx,offset strEqual
        mov     ax,[ecx]
        stosw
        mov     eax,edi
        pop     edi
        push    edx
        invoke  CvtST0_to_Str,eax
        dec     eax
        pop     edx
        mov     cx,[edx]
        mov     [eax],cx
        inc     eax
        inc     eax
        mov     byte ptr [eax],0
        invoke  SetDlgItemText,hWnd,IDC_TText,offset buffer
        ret
TempConvert     endp
;***************************************
        end     start

UNIT_CVT.RC ¤º®e¦p¤U¡G

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

#define IDM_Exit        2001
#define IDM_L           2002
#define IDM_M           2003
#define IDM_T           2004
#define IDC_MText1      2101
#define IDC_MText2      2102
#define IDC_MCB         2103
#define IDC_MP2K        2104
#define IDC_MK2P        2105
#define IDC_MCvt        2106
#define IDC_MExit       2107
#define IDC_MOpt        2108
#define IDC_TSB         2201
#define IDC_TText       2202
#define IDC_TOpt        2203
#define IDC_TF2C        2204
#define IDC_TC2F        2205
#define IDC_TExit       2206
#define IDC_LFeet       2301
#define IDC_LText1      2302
#define IDC_LInch       2303
#define IDC_LText2      2304
#define IDC_LCm         2305
#define IDC_LText3      2306
#define IDC_LCvt        2307
#define IDC_LExit       2308
#define IDC_LOpt        2309
#define IDC_LI2C        2310
#define IDC_LC2I        2311

UnitCvtMenu     MENU
BEGIN
  MENUITEM      "Â÷¶}",IDM_Exit
  MENUITEM      "ªø«×",IDM_L
  MENUITEM      "½è¶q",IDM_M
  MENUITEM      "·Å«×",IDM_T
END

UnitCvtIcon     ICON    unit_cvt.ico

LenDlg  DIALOG  0,0,207,84
STYLE   DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME
CAPTION "ªø«×´«ºâ"
FONT    9,"·s²Ó©úÅé"
BEGIN
  EDITTEXT      IDC_LFeet,5,48,34,12
  LTEXT         "­^§`",IDC_LText1,43,50,17,10
  EDITTEXT      IDC_LInch,63,48,34,12
  LTEXT         "­^¦T¡×",IDC_LText2,102,50,26,10
  EDITTEXT      IDC_LCm,127,48,50,12
  LTEXT         "¤½¤À",IDC_LText3,183,50,21,10
  PUSHBUTTON    "´«ºâ",IDC_LCvt,34,64,50,14
  PUSHBUTTON    "Â÷¶}",IDC_LExit,118,64,50,14
  GROUPBOX      "¿ï¾Ü´«ºâ¤è¦¡",IDC_LOpt,7,0,179,44
  AUTORADIOBUTTON   "­^¨î´«ºâ¦¨¤½¨î³æ¦ì",IDC_LI2C,19,12,152,12
  AUTORADIOBUTTON   "¤½¨î´«ºâ¦¨­^¨î³æ¦ì",IDC_LC2I,19,27,152,12
END

MassDlg DIALOG  0,0,170,118
STYLE   DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME 
CAPTION "½è¶q´«ºâ"
FONT    9,"·s²Ó©úÅé"
BEGIN
  LTEXT         "¿ï¾Ü¼Æ¦r",IDC_MText1,20,61,66,12
  COMBOBOX      IDC_MCB,91,59,65,70,CBS_DROPDOWNLIST |WS_VSCROLL
  PUSHBUTTON    "´«ºâ",IDC_MCvt,23,95,50,14
  PUSHBUTTON    "Â÷¶}",IDC_MExit,99,96,50,14
  LTEXT         " ",IDC_MText2,20,77,160,12
  GROUPBOX      "¿ï¾Ü´«ºâ¤è¦¡",IDC_MOpt,20,1,131,54
  AUTORADIOBUTTON   "­^½S´«ºâ¦¨¤½¤ç",IDC_MP2K,32,14,102,12
  AUTORADIOBUTTON   "¤½¤ç´«ºâ¦¨­^½S",IDC_MK2P,32,33,102,12
END

TempDlg DIALOG  0,0,164,132
STYLE   DS_SETFONT |WS_POPUP |WS_CAPTION |WS_VISIBLE |WS_SYSMENU |WS_THICKFRAME
CAPTION "·Å«×´«ºâ"
FONT    9,"·s²Ó©úÅé"
BEGIN
  SCROLLBAR     IDC_TSB,7,62,150,8
  PUSHBUTTON    "Â÷¶}",IDC_TExit,96,106,50,14
  LTEXT         " ",IDC_TText,7,83,146,12
  GROUPBOX      "¿ï¾Ü´«ºâ¤è¦¡",IDC_TOpt,10,4,143,51
  AUTORADIOBUTTON   "µØ¤ó·Å«×´«ºâ¦¨Äá¤ó·Å«×",IDC_TF2C,27,17,105,12
  AUTORADIOBUTTON   "Äá¤ó·Å«×´«ºâ¦¨µØ¤ó·Å«×",IDC_TC2F,27,34,105,12
END

UNIT_CVT.MAK ¤º®e¦p¤U¡G

ALL:unit_cvt.exe

unit_cvt.exe:unit_cvt.asm unit_cvt.res
    ml /coff unit_cvt.asm /link /SUBSYSTEM:WINDOWS unit_cvt.res

unit_cvt.res:unit_cvt.rc
    rc unit_cvt.rc

»¡©ú

³o­Óµ{¦¡¦@¬ù 500 ¦æ¡A¹ïªì¾ÇªÌ¦Ó¨¥ºâ¬O¬Û·í¤jªºµ{¦¡¡A©Ò¥H¤p¤ì°¸¶È»¡©ú·sªº³¡¥÷¤Î¥D­nµ²ºc¡A¥H§K°g¥¢¦b²Ó¸`³¡¥÷¡C³o­Óµ{¦¡ªºµ{¦¡½X°Ï¬q¥i¤À¬°¥Dµ{¦¡ ( ²Ä 97¡ã128 ¦æ)¡Bµøµ¡¨ç¦¡ ( ²Ä 130¡ã160 ¦æ )¡B¤T­Ó¹ï¸Ü²°¨ç¦¡ ( LenDlgProc¡BMassDlgProc¡BTempDlgProc )¡B¤T­ÓÂà´«°Æµ{¦¡ ( LenConvert¡BMassConvert¡BTempConvert ) ¤Î CvtST0_to_Str °Æµ{¦¡ ( ²Ä 298¡ã363 ¦æ )¡A¦@¤E¬qµ{¦¡²Õ¦¨¡C

¥Dµ{¦¡²Ä 101 ¦æ«ü©wµøµ¡¨ç¦¡¡AµM«á²£¥Í¤÷µøµ¡¦A¶i¤J°T®§°j°é¡Cµøµ¡¨ç¦¡©Ò³B²zªº°T®§¡A¤j³¡¤À¬O³B²z¨Ï¥ÎªÌ«ö¤U¿ï³æªº°Ê§@¡A¨Ò¦p·í¨Ï¥ÎªÌ«ö¤U¿ï³æªº¡yªø«×¡z¿ï³æ®É¡A´N¦bµe­±¤W²£¥Í¤@­Ó¼Ò¦¡¹ï¸Ü²°¡Aªø«×´«ºâ¹ï¸Ü²° ( LenDlg )¡A¦p«e©Ò­z¡A²£¥Í¼Ò¦¡¹ï¸Ü²°¥Î DialogBoxParam API¡A¦Ó¨ä¹ï¸Ü²°¨ç¦¡¬° LenDlgProc ( ²Ä 138 ¦æ )¡C¦P¼Ë¦a¡A·í¨Ï¥ÎªÌ«ö¤U¡y½è¶q¡z©Î¡y·Å«×¡z®É¡A¤]·|²£¥Í¹ïÀ³ªº¹ï¸Ü²°¥H¤Î»P¸Ó¹ï¸Ü²°³Q²°ªº¹ï¸Ü²°¨ç¦¡ ( ²Ä 141¡ã145 ¦æ )¡C

¦b UNIT_CVT.EXE µ{¦¡ùØ¡A¤T­Ó¹ï¸Ü²°¨ç¦¡©Ò³B²zªº°T®§¥u¦³ WM_INITDIALOG¡BWM_CLOSE¡BWM_COMMAND ©M WM_HSCROLL ¥|ºØ¦Ó¤w¡A³o¨Ç¤w³Q¹ï¸Ü²°¨ç¦¡³B²z¹Lªº°T®§¡A¦bªð¦^¨t²Î¤§«e ( ÁÙ°O±o¶Ü¡H¹ï¸Ü²°¨ç¦¡¤]¬O¤@ºØ call back ¨ç¦¡ ) ¥²¶·¶Ç¦^ TRUE µ¹¨t²Î¡A¹ï©|¥¼³B²z¹Lªº°T®§¡A«h¶Ç¦^ FALSE ¥æ¥Ñ¨t²Î³B²z¡C

¦b LenDlg ¹ï¸Ü²°ùØ¡A¦³¨â­Ó¶ê§Î«ö¶s¡B¤T­Ó½s¿è®Ø¡B¨â­Ó¤UÀ£¦¡«ö¶s¤ñ¸û­«­n¡A¦b LenDlgProc ¹ï¸Ü²°¨ç¦¡ùØ¡A¥D­n¤]´N¬O³B²z³o´X­Ó¤l±±¥ó¡C­º¥ý¦b WM_INITDIALOG °T®§ùØ ( §Y¹ï¸Ü²°²£¥Í¤§ªì )¡A¥ý°²©w´«ºâ¤è¦¡¬°­^¨îÂà´«¦¨¤½¨î³æ¦ì¡A¬G³]©w¨ä¤l±±¥óÃѧO½X©Òªí¥Üªº¶ê§Î«ö¶s³Q¿ï¨ú ( ²Ä 164¡ã165 ¦æ )¡C¦¹¥~¡A¬°¤F¤è«K¤p¤ì°¸³]¤@­ÓÅÜ¼Æ bOption¡A¥¦¥Î¨Ó°O¿ý´«ºâ¤è¦¡¡C¦b WM_INITDIALOG ³Ì«á³]©w½s¿è®Ø¨ú±o¿é¤JµJÂI¡C

¦b WM_COMMAND °T®§ùØ­n³B²zªº´N¬O¨â­Ó¶ê§Î«ö¶s¤Î¨â­Ó¤UÀ£¦¡«ö¶s³Q¨Ï¥ÎªÌÂI¿ï©ÎÀ£¤U®Éªº±¡§Î¡C·í¨Ï¥ÎªÌÀ£¤U¡y´«ºâ¡z¤UÀ£¦¡«ö¶s®É¡A¶i¤J LenConvert °Æµ{¦¡ ( ²Ä 176¡ã177 ¦æ )¡A³o­Ó°Æµ{¦¡·|¨Ì¾Ú bOption ©Ò°O¸üªº´«ºâ¤è¦¡¡A¨ú±o½s¿è®Ø¤§¤º®e¡A°µ¤½¨îªºªø«×³æ¦ì»P­^¨î¤§¶¡ªº´«ºâ¡A¸Ô²Ó±¡§Î¤p¤ì°¸´Nµy«á¦A»¡©ú¡C³B²z¨Ï¥ÎªÌ¿ï¨ú¡y­^¨îÂà´«¦¨¤½¨î³æ¦ì¡z©Î¡y¤½¨îÂà´«¦¨­^¨î³æ¦ì¡z¤ñ¸û²³æ¡A¦]¬°³o¨â­Ó¶ê§Î«ö¶s¤w³]¬° BS_AUTORADIOBUTTON¡A©Ò¥H§Y¨Ï¨Ï¥ÎªÌ¿ï¨ú¥t¤@­Ó¡A¨t²Î¯à¦Û¦æ³B²z¶ê§Î«ö¶s¤¤ªº¶êÂI¬O§_µe¤W©ÎÀ¿±¼¡Aµ{¦¡¥u­n¤Á´« bOption §Y¥i ( ²Ä 180¡ã183 ¦æ )¡C

LenConvert °Æµ{¦¡­º¥ý®Ú¾Ú bOption ªº¤º®e§PÂ_¡y­^¨îÂà´«¦¨¤½¨î³æ¦ì¡z©Î¡y¤½¨îÂà´«¦¨­^¨î³æ¦ì¡z¡A¤£ºÞ¬O¨º¤@ºØ¡A³£­n¨ú±o½s¿è®Ø¤ºªº¼Æ¦rµM«á¸g¹L¹Bºâ«á¡A¦A©ó¥t¤@­Ó½s¿è®ØÅã¥Ü¥X¨Ó¡C­n¨ú±o½s¿è®Ø¤º¼Æ¦r¡A¦b²Ä¤K³¹®É¥Î GetWindowText API¡A¨ú±o¦r¦ê¤§«á¦A¹Bºâ¦¨¼Æ­È¡A³o«Ü³Â·Ð¡A³o¦¸±Ä¥Î GetDlgItemInt¡C

GetDlgItemInt API

GetDlgItemInt ¥i¥H§â¤l±±¥ó¤ºªº¤å¦rÂà´«¦¨¾ã¼Æ¡A°O¿ý¦b EAX ùضǦ^¨Ó¡A¨ä­ì«¬¬°¡G

UINT GetDlgItemInt(
 HWND hDlg,         // handle to dialog box
 int  nIDDlgItem,   // control identifier
 BOOL *lpTranslated,// points to variable to receive success/failure indicator
 BOOL bSigned       // specifies whether value is signed or unsigned
   );

hDlg ¬O¹ï¸Ü²°µøµ¡¥N½X¡AnIDDlgItem ¬O·Q­n¨ú±o¼Æ¦rªº¤l±±¥óÃѧO½X¡AlpTranslated ¬O¶Ç¦^­Èªº¦ì§}¡A¦¹¶Ç¦^­È¥u¬Oªí¥Ü¦Û¤l±±¥ó¨ú±oªº¸ê®Æ¬O§_¯à¦¨¥\ªºÂà´«¦¨¬°¼Æ­È¡A­Y¦¨¥\«h lpTranslated ©Ò«ü¦ì§}ªº¤º®e·|³Q³]©w¬° TRUE¡A§_«h³Q³]¬° FALSE¡A°²¦p lpTranslated ³]¬° NULL ®É¡Aªí¥Ü¤£¶Ç¦^Âà´«¬O§_¥¿½T¡CbSigned ªí¥Ü¬O§_­n¨ú¥¿­t¸¹¡A³]¬° TRUE ®Éªí¥Ü§â¤l±±¥ó¤º¤å¦rÂà´«¦¨¦³¸¹¼Æ¡A¦¹®É­Y²Ä¤@­Ó¦r¤¸¬°¡y-¡z¡A«h EAX ±N¶Ç¦^¤Gªº¸É¼Æ¡Aªí¥Ü­t¼Æ¡F­Y¤l±±¥ó¤å¦r§t¦³«Dªü©Ô§B¼Æ¦r¦r¤¸®É¡A·|²£¥Í¿ù»~¡CbSigned ³]¬° FALSE ®É¡Aªí¥Ü¶ÈÂà´«¦¨¥¿¼Æ¡A­Y¤l±±¥ó§t¦³¡y-¡z¦r¤¸©Î¨ä¥L«Dªü©Ô§B¼Æ¦r¦r¤¸®É¡A·|²£¥Í¿ù»~¡C¿ù»~²£¥Í®É¡AEAX ·|³Q³]¬° FALSE¡C

°²¦p¨Ï¥ÎªÌ¿ï¾Ü¡y­^¨îÂà´«¦¨¤½¨î³æ¦ì¡zªº¸Ü¡ALenConvert §Q¥Î GetDlgItemInt ¨ú¥X­^§` ( IDC_LFeet ) ¤Î­^¦T¤l±±¥ó ( IDC_LInch ) ªº¼Æ­È¡A¦A¥þ³¡´«ºâ¦¨­^¦T ( ¤@­^§`µ¥©ó 12 ­^¦T )¡A¦A´«ºâ¦¨¤½¤À¡A³Ì«áÅã¥Ü©ó¤½¤À¤l±±¥ó ( IDC_LCm )¡C­Y¨Ï¥ÎªÌ¿ï¾Ü¡y¤½¨îÂà´«¦¨­^¨î³æ¦ì¡z¡A«h¦Û¤½¤À¤l±±¥ó¨ú¥X¤½¤À¼Æ¡A¥ýÂà´«¦¨­^¦T¡A­^¦T°£¥H 12¡A°Ó¬°­^§`¼Æ¡AÅã¥Ü©ó­^§`¤l±±¥ó¡F¾l¬°­^¦T¼Æ¡AÅã¥Ü©ó­^¦T¤l±±¥ó¡C³o¬qµ{¦¡¹ê§@©ó²Ä 372 ¦æ¨ì²Ä 405 ¦æ¡C

¦Ü©ó MassConvert »P TempConvert °Æµ{¦¡ªº¤º®e¤j­P»P LenConvert ¬Û¦ü¡C¥u¬O¦b TempConvert °Æµ{¦¡¤¤¡A¥Ñ±²¶b±±¥ó¨ú¥X¼Æ­È®É¡A¥Î GetScrollPos API¡C¨ä¾lµ{¦¡À³¸Ó¤£Ãø¡A¥u¬O¦³ÂI¨àªø¡A±z¥u­n¦³ÂI­@¤ß¡A¬Û«H¥i¥H¸Ñ¨M¡C


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