Ch 06 ¥[¤W¿ï³æ

³o¤@³¹¡A¤p¤ì°¸±N»¡©ú¦p¦ó¦bµ{¦¡¤¤¥[¤J¿ï³æ ( menu )¡C¦ý¬O­º¥ý¡A¥ý¨Ó¬Ý¬Ý¤°»ò¬O¿ï³æ¡H¤p¤ì°¸·Q¡A¥u­n©M±zÁ¿¤F¿ï³æ¦b¨º¨à¡A±z´Nª¾¹D¿ï³æ¬O¤°»ò¤F¡A¤@¯ë¦Ó¨¥¡A¿ï³æ¬O¦b¦ì©ó¼ÐÃDÄæ¤U¤è¡A¤U¹Ï¥H¤p§@®a¬°¨Ò»¡©ú¿ï³æ¦b¨º¨à¡A

¤°»ò¬O¿ï³æ

³o¼Ë±z¬O§_©ú¥Õ¤°»ò¬O¿ï³æ¤F¡H«e­±ªº´X­Ó¨Ò¤l³£¨S¦³¿ï³æ¡A¦b³o¤@³¹ùØ¡A¤p¤ì°¸±N»¡©ú¦p¦ó¬°µ{¦¡¥[¤W¿ï³æ¡C


Win32 µ{¦¡ªº¶}µo

¿ï³æ¬O¸ê·½ªº¤@³¡¥÷

Win 32 ¥i°õ¦æÀɨƹê¤W¥i¤À¬°¨â³¡¥÷ ( µù¤@ )¡A¡yµ{¦¡½X¡z»P¡y UI ¸ê·½¡z¡CUI ¸ê·½¡A¬O«ü©Òªí²{¥Xªº¨Ï¥ÎªÌ¬É­± ( user interface )¡C³o¨Ç¸ê·½¥]§t¿ï³æ ( menu )¡B¹Ï¥Ü ( icon )¡B´å¼Ð ( cursor )¡B¦ì¤¸¹Ï ( bitmap )¡B¦r«¬ ( font )¡B¹ï¸Ü²° ( dialog box )¡Bª©¥»¸ê°T ( version ) µ¥µ¥¡C²£¥Í³o¨Ç¸ê·½©Ò¨Ï¥Îªº³nÅ餣ºÉ¬Û¦P¡A©Ò±o°ÆÀɦW¤]¤£¤@¼Ë¡A¨Ò¦p¤@¯ë¥H *.ICO °ÆÀɦWªí¥Ü¹Ï¥ÜÀÉ¡B¥H *.CUR °ÆÀɦWªí¥Ü´å¼ÐÀÉ¡K¡K¡C³o¨Ç¸ê·½³Ì«á³£¥²¶·¦b¤@­ÓºÙ¬°¡y¸ê·½´y­zÀÉ¡z( resource-definition script file¡A°ÆÀɦW³q±`¬O *.RC ) ªº¤å¦rÀÉùØ´y­z¡C¸ê·½´y­zÀɦA¥æ¥Ñ¸ê·½½sĶµ{¦¡ ( RC.EXE ) ½sĶ¦¨¸ê·½ÀÉ ( ¸ê·½Àɪº°ÆÀɦW³q±`¬O *.RES )¡A³Ì«á¸ê·½ÀÉ¡B¥ØªºÀÉ¥H¤Îµ{¦¡®w¦A¥Ñ³sµ²¾¹ ( LINK.EXE ) ³sµ²¨Ã²£¥Í¥i°õ¦æÀÉ ( *.EXE )¡C¨ä¬yµ{¦p¤U¹Ï¡J

Win32 ¶}µo®É¬ÛÃöÀÉ®×

»s§@¿ï³æ

¿ï³æªº»s§@¤èªk¤ñ¸û²³æ¡A¥¦¤£¹³¹Ï¥Ü©Î´å¼Ð»Ý­n¥Î¨ìÃB¥~ªºÀɮסA¥¦¥i¥Hª½±µ¦b¸ê·½´y­zÀÉ ( *.RC ) ¤¤ª½±µ¥H¤å¦r´y­z¡C¨ä®æ¦¡¦p¤U¡J

¿ï³æ¦WºÙ    MENU
{
        ¡K¡K¡K
}

¿ï³æ¦WºÙ¥i¥H¬O¥ô·N¦r¦ê¡A³o­Ó¦r¦ê¬O±N¨Ó¶ñ¤J¨ìµ{¦¡ùتº WNDCLASSEX µ²ºcÅé lpszMenuName Äæ¦ì©Î¬O¶ñ¤J CreateWindowEx API ªº°Ñ¼Æùتº¡A¥¦¬O¥Î¨Ó«ü©w¿ï³æªºÃѧO²Å¸¹¡C¦b¤j¬A¸¹¤§¶¡ ( ¤]¥i¥H¥Î BEGIN/END ¥N´À¤j¬A¸¹ ) ¬Oµ{¦¡³]­p®v©Ò­n©w¸qªº¿ï³æ¡A¤@¯ë¦Ó¨¥¿ï³æùتº¿ï¶µ¥i¤À¬°¨âºØ¡A¤@ºØ¬O¨Ï¥ÎªÌ¥H·Æ¹«¿ï«ö«á¡AÁÙ·|¦A¥X²{§ó¦hªº¿ï¶µ¨Ñ¨Ï¥ÎªÌ¬D¿ï¡A³oºØ¿ï¶µ³q±`¦b¿ï¶µ«á­±·|¦³¡y¡K¡z¡A¹³³oºØ¿ï¶µ¬O¥H POPUP ¨Ó©w¸q¡C¥t¤@ºØ¬O¨Ï¥ÎªÌ¿ï«ö«á´Nª½±µ°õ¦æªº¿ï¶µ¡A¨S¦³§ó¶i¤@¨Bªº¤l¿ï¶µ¡A¹³³oºØ¿ï¶µ¥H MENUITEM ©w¸q¡C³o¨âºØ¿ï¶µªº®æ¦¡¬°¡J

POPUP   ¿ï¶µ¦WºÙ
{
        MENUITEM    ¿ï¶µ¦WºÙ, ID ¼Æ­È [,option]
        ¡K¡K
}

¦b POPUP ¤§«á©Î¦b MENUITEM ¤§«áªº¡y¿ï¶µ¦WºÙ¡z¬O¥H¨â­Ó¡y"¡z¬°¬É¡A§¨¦b¤¤¶¡ªº¦r¦êªí¥Ü¡A³o­Ó¦r¦ê±NÅã¥Ü¦b¿ï³æ¤W­±¡C¦b³o¦r¦êùØ¥i¥H¥[¤W¡y&;¡z¡Aªí¥Ü¨ä«á©Ò±µªº¤@­Ó¦r¤¸·|¥[¤W©³½u¡A¦Ó¦¹¦r¤¸¬°§Ö±¶Áä¡C©Ò¿×§Ö±¶Á䪺·N«ä¬O·í¨Ï¥ÎªÌ«ö¤U Alt Á䤣©ñ¡A¦A«ö¤U¡y&¡z«á©Ò±µªº¦r¤¸ ( ¦¹¦r¤¸©Òªí¥Üªº«öÁä ) ´N¬Û·í©ó¥H·Æ¹«¿ï«ö¤@¼Ë¡C

¡yID ¼Æ­È¡z( ¿ï¶µÃѧO½X ) ¬O¥i¥H¥ô·Nµ¹©wªº¾ã¼Æ¡A¦ý¥²¶·¬O°ß¤@ªº¡A§_«h·|³y¦¨¨â­Ó¿ï¶µ¨ã¦³¤@¼Ëªº¥\¯à¡C¬°¤F¼W¥[¥iŪ©Ê¡A¥i¥H¦b¸ê·½´y­zÀɪº¤@¶}©l¡A¥H¡y#define¡z©w¸q±`¼Æ¨Ó¥N´À¦¹ ID ¼Æ­È¡A·íµM¦¹±`¼Æªº¦WºÙ¥²¶·¯àÅý¤H¤@¥Ø¤FµM¡C

option ¬Oªí¥Ü¿ï¶µªºÄÝ©Ê¡A±`¥ÎªºÄݩʦ³¡J

¿ï¶µ¦WºÙ¤]¥i¥H¨Ï¥Î SEPARATOR¡A°²¦p¨Ï¥Î SEPARATOR ®É¡A¤£¶·¥[¤W¡y"¡z¡ASEPARATOR ªí¥Ü¦b¤l¿ï³æ·|¥X²{¤@­Ó¤À¹j½u¡C

WM_COMMAND °T®§

·í¨Ï¥ÎªÌ«ö¤U§Ö±¶Áä¡B¿ï³æ©Î±±¨î¤¸¥ó ( µy«á´X³¹¦A½Í ) µ¥ª«¥ó®É¡A¨t²Î·|§â WM_COMMAND °T®§¶Çµ¹µ{¦¡¡C

  1. °²¦p¨Ï¥ÎªÌ¥Ñ¿ï³æ¤W¿ï¾Ü¤@­Ó¿ï¶µ¡AlParam ¬°¹s¡AwParam ¸û§Cªº 16 ¦ì¤¸¬°¿ï¶µÃѧO½X¡A¸û°ªªº 16 ¦ì¤¸¬°¹s¡C
  2. °²¦p¨Ï¥ÎªÌ«ö¤U±±¨î¤¸¥ó®É¡AlParam ¤£¬°¹s¦Ó¬O¤lµøµ¡¥N½X¡AwParam ¸û§Cªº 16 ¦ì¤¸¬°±±¨î¤¸¥óÃѧO¸¹½X¡A¸û°ªªº 16 ¦ì¤¸¬°¨Ï¥ÎªÌªº°Ê§@¡A¤@¯ëºÙ¬°³qª¾½X ( notification code )¡C
  3. °²¦p¨Ï¥ÎªÌ«ö¤U§Ö±¶Áä¡AlParam ¬°¹s¡AwParam ¸û§Cªº 16 ¦ì¤¸¬°§Ö±¶ÁäÃѧO¸¹½X¡A¸û°ªªº 16 ¦ì¤¸¬°¤@¡C

¾ã²z¦p¤Uªí¡J

 wParam °ª¦r²Õ wParam §C¦r²ÕlParam
¨Ï¥ÎªÌ«ö¤U¿ï³æ 0¿ï¶µÃѧO½X 0
¨Ï¥ÎªÌ«ö¤U§Ö±¶Áä 1§Ö±¶ÁäÃѧO½X 0
¨Ï¥ÎªÌ«ö¤U±±¨î¤¸¥ó ³qª¾½X
(§Y¨Ï¥ÎªÌ°Ê§@)
±±¨î¤¸¥óÃѧO½X ¤lµøµ¡¥N½X

·íµøµ¡¨ç¦¡³B²z§¹ WM_COMMAND «á¡AÀ³¸Ó§â¶Ç¦^­È³]¬° 0 ¤§«á¡A¦Aªð¦^¨t²Î¡CÁÙ°O±o¶Ü¡Hµøµ¡¨ç¦¡¬O³Q¨t²Î©Ò©I¥sªº¡A©Ò¥H·íµM¤]¥²¶·ªð¦^¨t²Î¤~¦æ¡C


µe½u¬q»P¾ò¶ê

©³¤U¤p¤ì°¸±N¼¶¼g¤@­Óµ{¦¡¡A¥i¥Ñ¿ï³æ¿ï¾Üµe¥X½u¬q»P¾ò¶ê¡A¦b¦¹¥ý¤¶²Ðµe¥X³o¨â­Ó¹Ï§Îªº¤èªk¡C§Ú·Q¤Z¬O¾Ç¹L²Ê²L´X¦óªº¤HÀ³¸Ó³£ª¾¹D¨âÂI¨M©w¤@ª½½u¡AWin32 API ¤]¬O¦p¦¹¡A­nµe¥X½u¬q±o¥ý¨M©w°_ÂI¡A¦A¥Ñ°_ÂIµe¨ì²×ÂI¡C

LineTo API

³o­Ó API ¬O¦bµøµ¡¤¤¡A¥Ñ¡y²{¦bªºÂI¡z( §Y°_ÂI ) ¥H²{¦bªºµeµ§µe¤@±øª½½u¨ì«ü©wªºÂI ( §Y²×ÂI )¡C­ì«¬¬°

BOOL LineTo(
    HDC     hdc,    // device context handle 
    int     nXEnd,  // x-coordinate of line's ending point  
    int     nYEnd   // y-coordinate of line's ending point  
   );

hdc ¬O¸Ë¸m¤º®e¥N½X¡AnXEnd ©M nYEnd ¤À§O¬O²×ÂIªº X ®y¼Ð»P Y ®y¼Ð¡C¨º»ò«e¤å©Ò´£¡y²{¦bªºÂI¡z¬O¤°»ò©O¡H±z¥i¥H³o¼Ë·Q¹³¡A¨C·í«Ø¥ß¤@­Óµøµ¡®É¡A¨t²Î·|¦b¦¹µøµ¡¤¤«ü©w¤@­ÓÂI§@¬°¡y²{¦bªºÂI¡z¡A¦Ó©³¤U MoveToEx API ¥i¥H§ïÅÜ¡y²{¦bªºÂI¡z¡C¥t¥~·í©I¥s§¹ LineTo API «á¡A¡y²{¦bªºÂI¡z·|§ïÅܦ¨ nXEnd »P nYEnd ©Ò«üªºÂI¡C

MoveToEx API

MoveToEx API ¬O¥Î¨Ó§ïÅÜ¡y²{¦bªºÂI¡z¡A¨ä­ì«¬¬°¡J

BOOL MoveToEx(
    HDC     hdc,    // handle of device context 
    int     X,      // x-coordinate of new current position  
    int     Y,      // y-coordinate of new current position  
    LPPOINT lpPoint // address of old current position 
   );

X »P Y ´N¬O§ïÅܫ᪺¡y²{¦bªºÂI¡zªº®y¼Ð¡ClpPoint ¬O«ü¦V¤@­Ó POINT µ²ºcÅé¦ì§}¡A¦¹µ²ºcÅé±N¦b MoveToEx ªð¦^«á¦s©ñªº¡y²{¦bªºÂI¡zªº®y¼Ð¡A°²¦p¥H NULL ¥N´À POINT µ²ºcÅé¦ì§}¡A«hªí¥Ü¤£¶·¶Ç¦^ªº¡y²{¦bªºÂI¡zªº®y¼Ð¡C

Ellipse API

ÅU¦W«ä¸q¡A³o­Ó API ¬O¥Î¨Óµe¥X¾ò¶ê¡C¨t²Î©Ò¥Îªº¤èªk¬O¡A¥ý¨M©w¤@­Ó¯x§Î¡AµM«á¨t²Î·|¦Û°Ê¦aÀ°§Ú­Ìµe¥X³o­Ó¯x§Îªº¤º¤Á¾ò¶ê¨Ó¡C Ellipse ªº­ì«¬¬O¡J

BOOL Ellipse(
    HDC hdc,        // handle to device context 
    int nLeftRect,  // x-coord. of bounding rectangle's upper-left corner 
    int nTopRect,   // y-coord. of bounding rectangle's upper-left corner  
    int nRightRect, // x-coord. of bounding rectangle's lower-right corner  
    int nBottomRect // y-coord. bounding rectangle's f lower-right corner  
   );

hdc ¬O¸Ë¸m¤º®e¥N½X¡CnLeftRect ©M nTopRect ¤À§O¬O¯x§Îªº¥ª¤W¨¤ªº X ®y¼Ð»P Y ®y¼Ð¡FnRightRect ©M nBottomRect ¤À§O¬O¯x§Îªº¥k¤U¨¤ªº X ®y¼Ð»P Y ®y¼Ð¡C¦¹¥~³o­Ó¨ç¦¡·|¦Û°Ê¦a¥H²{¦bªºµeµ§µe¥X¾ò¶êªºÃä½u¡A¦P®É¥Î²{¦bªºµ§¨ê´À¾ò¶ê¤º³¡µÛ¦â¡C

°²¦p±z¤£§Æ±æ¨Ï¾ò¶ê¤º³¡µÛ¦âªº¸Ü¡A¥u¦n¨Ï¥ÎÅܳqªº¤èªk¡A·Q¹³¾ò¶ê¨ä¹ê¬O¥Ñ¨â­Ó¥b¾ò¶ê²Õ¦X¦Ó¦¨ªº¡Aµe¥X³o¨â­Ó¥b¾ò¶êªº©·§Î¥i¥Î Arc API¡C

Arc API

³o­Ó API ±ý¥Î¨Óµe¥X¾ò¶ê©·§Îªº¤@³¡¥÷¡A¨ä­ì«¬¬°

BOOL Arc(
    HDC hdc,        // handle to device context 
    int nLeftRect,  // x-coordinate of bounding rectangle's upper-left corner
    int nTopRect,   // y-coordinate of bounding rectangle's upper-left corner
    int nRightRect, // x-coordinate of bounding rectangle's lower-right corner
    int nBottomRect,// y-coordinate of bounding rectangle's lower-right corner
    int nXStartArc, // first radial ending point 
    int nYStartArc, // first radial ending point 
    int nXEndArc,   // second radial ending point 
    int nYEndArc    // second radial ending point 
   );

hdc ¬O¸Ë¸m¤º®e¥N½X¡CnLeftRect ©M nTopRect ¤À§O¬O¯x§Îªº¥ª¤W¨¤ªº X ®y¼Ð»P Y ®y¼Ð¡FnRightRect ©M nBottomRect ¤À§O¬O¯x§Îªº¥k¤U¨¤ªº X ®y¼Ð»P Y ®y¼Ð¡CnXStartArc ©M nYStartArc ¬O©·½u°_ÂIªº X ®y¼Ð©M Y ®y¼Ð¡FnXEndArc ©M nYEndArc ¬O©·½u²×ÂIªº X ®y¼Ð©M Y ®y¼Ð¡C°_ÂI©M²×ÂI¤£¤@©w­n¦b©·½u¤W¡A¨t²Î·|¦Û°Êªº­pºâ¾ò¶ê¤¤¤ß¨ì°_ÂI©Ò¦¨ªºª½½u¶}©lµe¥X¾ò¶ê¡A¨Ã¥B¥H°f®É°w¤è¦Vµe¨ì¾ò¶ê¤¤¤ß¨ì²×ÂI©Ò³s¦¨ªº½u¬°¤î¡A½Ð°Ñ¦Ò¤U¹Ï¡J

Arc API ¤§»¡©ú
¹Ï¤¤¥u¦³¹ê½uªº¾ò¶ê·|³Qµe¦b¿Ã¹õ¤W¡A¾ò¶ê¤¤¤ß¨ì°_ÂI©M¾ò¶ê¤¤¤ß¨ì²×ÂI³o¨â±øª½½u¡A¤£·|µe¥X¨Ó¡C


½d¨Ò¡J¤p¤pø¹Ïµ{¦¡¡ADRAW.EXE

DRAW.EXE ªº¨Ï¥Î¤èªk»Pµ²ªG

©³¤U¤p¤ì°¸¼¶¼g¤@­Ó¤p¤pø¹Ïµ{¦¡¡ADRAW.EXE¡A¥¦¦³¨â­Ó«Ü²³æªº¿ï³æ¡A²Ä¤@­Ó¬O¡yÂ÷¶}¡z¡A²Ä¤G­Ó¬O¡yø¹Ï¡z¡C¨Ï¥ÎªÌ«ö¤UÂ÷¶}¡A´N·|¸õ¥X¤@­Óµøµ¡°Ý§A¬O§_½T©w¡A­Y«ö¤U¡y¬O¡z¡A´NÂ÷¶}¤p¤pø¹Ïµ{¦¡¡C

¦Ü©ó¡yø¹Ï¡zùØÁÙ¦³¤»­Ó¤l¿ï³æ¤Î¤@­Ó¤À¹j½u¡A³o¤»­Ó¤l¿ï³æ¯àµe¥Xª½½u¡B¾ò¶ê¥H¤Î·Æ¹«²¾°Êªº­y¸ñ¡A¨Ã¯à§ïÅܬõ¡Bºñ¡BÂŤTÃC¦â¡C·í¿ï¾Üª½½u®É¡A¥²¶·¥ý¥H·Æ¹«¥ªÁä¿ï°_ÂI¦A¿ï²×ÂI¡Aµ{¦¡«K·|¥H·í¤UªºÃC¦âµe¥Xª½½u¡C­Y¿ï¾Ü¾ò¶ê¡A¥²¶·¥ý¥H·Æ¹«¥ªÁä¿ï¾Ü¤@­Ó¯x§Îªº¥ª¤W¨¤³»ÂI¡A¦A¿ï¾Ü¥k¤U¨¤³»ÂI¡Aµ{¦¡·|¥H·í¤UÃC¦âµe¥X³o­Ó¯x§Îªº¤º¤Á¾ò¶ê§Î¡C¦pªG¨Ï¥ÎªÌ¿ï¾Ü¡y¤âø¹Ï¡z¡A«h¨Ï¥ÎªÌ¥²¶·¥H·Æ¹«¥ªÁä¿ï¾Ü¤@°_ÂI¡Aªí¥Ü±Nµeµ§©ñ¤U¡Aµ{¦¡«K·|µe¥X·Æ¹«²¾°Ê¤§­y¸ñ¡C©³¤U¬O¤âø¹Ïªº°õ¦æµe­±¡J

¤p¤pø¹Ïµ{¦¡

DRAW.RC »P DRAW.ASM ­ì©lµ{¦¡

©³¤U¬O³o­Óµ{¦¡ªº¸ê·½´y­zÀÉ¡ADRAW.RC¡Aªº­ì©lµ{¦¡¡C¸ê·½´y­zÀɤ£¤@©w­n©Mµ{¦¡½Xªº­ì©lµ{¦¡¦P¦W¡A§Úªº·N«ä¬O¡A±zªº¸ê·½´y­zÀɤ]¥i¥H¤£­n¨ú¦W¬° DRAE.RC¡A¦ý¬O³o¼Ë°µ«K©óºÞ²z¡C

#define IDM_Exit        10
#define IDM_Line        21
#define IDM_Ellipse     22
#define IDM_Trace       23
#define IDM_Red         24
#define IDM_Green       25
#define IDM_Blue        26

DRAW    MENU
{

MENUITEM    "Â÷¶}(&E)",IDM_Exit

POPUP   "ø¹Ï(&D)"
        {
        MENUITEM    "½u¬q(&L)",IDM_Line
        MENUITEM    "¾ò¶ê(&E)",IDM_Ellipse
        MENUITEM    "¤âø¹Ï(&T)",IDM_Trace
        MENUITEM    SEPARATOR
        MENUITEM    "¬õ(&R)",IDM_Red
        MENUITEM    "ºñ(&G)",IDM_Green
        MENUITEM    "ÂÅ(&B)",IDM_Blue
        }

}

©³¤U¬Oµ{¦¡½Xªº­ì©lµ{¦¡¡ADRAW.ASM¡J

        .386
        .model  flat,stdcall
        option  casemap:none
include         windows.inc
include         user32.inc
include         gdi32.inc
include         kernel32.inc
includelib      user32.lib
includelib      gdi32.lib
includelib      kernel32.lib

IDM_Exit        equ     10      ;12 ¿ï¶µÃѧO½X
IDM_Line        equ     21
IDM_Ellipse     equ     22
IDM_Trace       equ     23
IDM_Red         equ     24
IDM_Green       equ     25
IDM_Blue        equ     26
red_color       equ     0ffh    ;19 ÃC¦â
green_color     equ     0ff00h
blue_color      equ     0ff0000h

WndProc         proto   :HWND,:UINT,:WPARAM,:LPARAM

        .DATA
ClassName       db          'SimpleWinClass',0
AppName         db          '¤p¤pø¹Ïµ{¦¡',0
AskExit         db          '¬O§_°h¥X¦¹µ{¦¡¡H',0
AskExitTitle    db          '¸ß°Ý',0
MenuName        db          'DRAW',0    ;30 ¿ï³æ¦WºÙ¬°'DRAW'
PenDown         db          FALSE       ;31 FALSE¡Jµeµ§ÄaªÅ¡ATRUE¡Jµeµ§Ä²¯È
command         dw          IDM_Line    ;32 ¨Ï¥ÎªÌ¥Ñ¿ï³æ¿ï¾Üªº©R¥O
color           dd          red_color   ;33 ¨Ï¥ÎªÌ¥Ñ¿ï³æ¿ï¾ÜªºÃC¦â
hMenu           HMENU       ?           ;34 ¿ï³æ¥N½X
hInstance       HINSTANCE   ?
hwnd            HWND        ?
wc              WNDCLASSEX  <30h,?,?,0,0,?,?,?,?,0,offset ClassName,?>
msg             MSG         <?>
start_point     POINT       <?>         ;39 °_ÂI®y¼Ð
end_point       POINT       <?>         ;40 ²×ÂI®y¼Ð

        .CODE
start:  invoke  GetModuleHandle,NULL
        mov     hInstance,eax
        mov     wc.style,CS_HREDRAW or CS_VREDRAW
        mov     wc.lpfnWndProc,offset WndProc
        mov     eax,hInstance
        mov     wc.hInstance,eax
        mov     wc.hbrBackground,COLOR_WINDOW+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        invoke  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        invoke  LoadMenu,hInstance,offset MenuName      ;55 ¨ú±o¿ï³æ¥N½X
        mov     hMenu,eax
        invoke  RegisterClassEx,offset wc
        invoke  CreateWindowEx,NULL,offset ClassName,\ 
                offset AppName,WS_OVERLAPPEDWINDOW,0,\
                0,400,400,0,hMenu,hInstance,NULL        ;60 ¥[¤W¿ï³æ
        mov     hwnd,eax
        invoke  ShowWindow,hwnd,SW_SHOWNORMAL
        invoke  UpdateWindow,hwnd

.while  TRUE
        invoke  GetMessage,offset msg,NULL,0,0
.break  .if     !eax
        invoke  DispatchMessage,offset msg
.endw        
        mov     eax,msg.wParam
        invoke  ExitProcess,eax
;---------------------------------------
;­pºâ EAX ¤ºªº®y¼Ð¡A¦s©ó EDX ©Ò«üªº¦ì§}¡AEAX¡J°ª¦ì¤¸¬° Y ®y¼Ð¡A§C¦ì¤¸¬° X ®y¼Ð
get_crd proc
        push    eax
        and     eax,0ffffh
        mov     [edx],eax
        pop     eax
        shr     eax,10h
        mov     [edx+4],eax
        ret
get_crd endp
;---------------------------------------
WndProc proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
        local   rectangle:RECT
        local   PS:PAINTSTRUCT
        local   hdc:HDC
        local   newPen:DWORD
        local   oldPen:DWORD
.if     uMsg==WM_COMMAND
        mov     eax,wParam
        mov     PenDown,FALSE   ;92 ¥u­n¿ï¾Ü¿ï³æ«á´N³]¬° FALSE
        .if     ax==IDM_Exit
                jmp     exit
        .elseif (ax==IDM_Line)||(ax==IDM_Ellipse)||(ax==IDM_Trace)
                mov     command,ax
        .elseif ax==IDM_Red
                mov     color,red_color
        .elseif ax==IDM_Green
                mov     color,green_color
        .elseif ax==IDM_Blue
                mov     color,blue_color
        .endif

.elseif uMsg==WM_LBUTTONDOWN                    ;105 «ö¤U·Æ¹«¥ªÁä
        .if     (command==IDM_Line)||(command==IDM_Ellipse)
                .if     PenDown
                        mov     eax,lParam      ;108 µeµ§Ä²¯È®É
                        mov     edx,offset end_point
                        call    get_crd
                        invoke  GetClientRect,hWnd,addr rectangle
                        invoke  InvalidateRect,hWnd,addr rectangle,FALSE
                .else
                        mov     eax,lParam      ;114 µeµ§´£°_®É
                        mov     edx,offset start_point
                        call    get_crd
                .endif

        .elseif command==IDM_Trace              ;119 ¤âø¹Ï
                .if     (!PenDown)              ;120 Àˬdµeµ§¬O§_ÄaªÅ
                        mov     eax,lParam      ;121 ÄaªÅ
                        mov     edx,offset start_point
                        call    get_crd         ;123 ¨ú±o°_ÂI
                .endif                   
        .endif
        xor     PenDown,1       ;118 ¤Á´«µeµ§´£°_©ÎIJ¯È

.elseif uMsg==WM_MOUSEMOVE
        .if     (command==IDM_Trace)&&(PenDown)
                mov     eax,lParam              ;122 ¨ú±o²×ÂI®y¼Ð
                mov     edx,offset end_point
                call    get_crd
                invoke  GetClientRect,hWnd,addr rectangle
                invoke  InvalidateRect,hWnd,addr rectangle,FALSE
        .endif

.elseif uMsg==WM_PAINT
        .if     command==IDM_Line
                invoke  BeginPaint,hWnd,addr PS
                mov     hdc,eax
                invoke  CreatePen,PS_SOLID,1,color
                mov     newPen,eax
                invoke  SelectObject,hdc,newPen
                mov     oldPen,eax
                invoke  MoveToEx,hdc,start_point.x,start_point.y,NULL
                invoke  LineTo,hdc,end_point.x,end_point.y
                invoke  SelectObject,hdc,oldPen
                invoke  DeleteObject,newPen
                invoke  EndPaint,hdc,addr PS
        .elseif command==IDM_Ellipse
                invoke  BeginPaint,hWnd,addr PS
                mov     hdc,eax
                invoke  CreatePen,PS_SOLID,1,color
                mov     newPen,eax
                invoke  SelectObject,hdc,newPen
                mov     oldPen,eax
                mov     eax,start_point.x
                add     eax,end_point.x
                shr     eax,1
                push    eax
                invoke  Arc,hdc,start_point.x,start_point.y,\   ;161 µe¥X¥b¾ò¶ê
                        end_point.x,end_point.y,eax,400,eax,0
                pop     eax
                invoke  Arc,hdc,start_point.x,start_point.y,\   ;164 µe¥t¤@¥b¾ò¶ê
                        end_point.x,end_point.y,eax,0,eax,400
                invoke  SelectObject,hdc,oldPen
                invoke  DeleteObject,newPen
                invoke  EndPaint,hdc,addr PS
        .elseif command==IDM_Trace
                invoke  BeginPaint,hWnd,addr PS
                mov     hdc,eax
                invoke  CreatePen,PS_SOLID,1,color
                mov     newPen,eax
                invoke  SelectObject,hdc,newPen
                mov     oldPen,eax
                invoke  MoveToEx,hdc,start_point.x,start_point.y,NULL
                invoke  LineTo,hdc,end_point.x,end_point.y
                invoke  SelectObject,hdc,oldPen
                invoke  DeleteObject,newPen
                invoke  EndPaint,hdc,addr PS
                mov     eax,end_point.x     ;181 ¨Ï²×ÂIÅܤU¦¸ªº°_ÂI
                mov     edx,end_point.y
                mov     start_point.x,eax
                mov     start_point.y,edx
        .else
                jmp     def
        .endif

.elseif uMsg==WM_CLOSE
exit:   invoke  MessageBox,NULL,offset AskExit,\
                offset AskExitTitle,MB_YESNO or MB_ICONQUESTION
        .if     eax==IDYES
                invoke  DestroyWindow,hWnd
        .endif

.elseif uMsg==WM_DESTROY
        invoke  PostQuitMessage,NULL

.else
def:    invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
.endif
        xor     eax,eax
        ret
WndProc endp

end     start

²ÕĶ¤èªk

­n»s§@¥X DRAW.EXE ¥i°õ¦æÀÉ¡A³sµ²¾¹ ( LINK.EXE ) ¥²¶·³sµ²¥ØªºÀÉ»P¸ê·½ÀÉ¡A¬G²ÕĶ¤è¦¡©M¥H«e¤£¤Ó¬Û¦P¡C

  1. ¥ý½sĶ¸ê·½´y­zÀÉ¡A«Ø¥ß DRAW.RES ÀÉ¡C
  2. ¦A²ÕĶ­ì©lÀÉ¡C¦]¬° ML.EXE ·|¥h©I¥s LINK.EXE¡A©Ò¥H ML.EXE ¥²¶·§â LINK.EXE ©Ò»Ý¤§°Ñ¼Æ¶Çµ¹ LINK.EXE¡A¥[¤W¡y/link DRAW.RES¡z¡Aªí¥Ü­n³sµ² DRAW.OBJ ¥H¤Î DRAW.RES ¨âÀÉ¡C( DRAW.OBJ ¥Ñ ML.EXE ¦Û°Ê¶Çµ¹ LINK.EXE )

¹ê»Ú¾Þ§@¹Lµ{¦p¤U¡C°²¦p±zµLªk¥¿½T²ÕĶ¡A¥i¯à¬OÀô¹ÒÅܼƿù»~¡A½Ð¦Û¦æ°Ñ¦Ò²Ä¹s³¹¦³Ãö¦b Win32 ¼¶¼g²Õ¦X»y¨¥µ{¦¡ªº·Ç³Æ¤u§@¡C

e:\homepage\source>rc DRAW.RC [Enter]  ¡÷°²¦p¸ê·½´y­zÀɽsĶ¦¨¥\¡A«hµL¥ô¦ó°T®§

e:\homepage\source>ml DRAW.ASM /link DRAW.RES [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

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

/SUBSYSTEM:WINDOWS
"DRAW.obj"
"/OUT:DRAW.exe"
"DRAW.RES"

e:\homepage\source>

³o¼Ë´N¥i¥H±o¨ì DRAW.EXE ¤F¡C¥t¥~½Ð°Ñ¦Òµù¤G¡A¦³¥t¥~¤@­Ó¸û¤è«Kªº¤èªk²£¥Í¥i°õ¦æÀÉ¡C


µ{¦¡»¡©ú

¤p¤ì°¸·Q¸ê·½´y­zÀɤ¤ªº¿ï³æÀ³¤w¤£¥Î¦A»¡©ú¡A«e­±¤w¦³±Ô­z¤F¡C©³¤U»¡©úµ{¦¡½Xªº­ì©lÀÉ¡C

­«­nªºÅܼƻP±`¼Æ

²Ä 12 ¦æ¨ì²Ä 18 ¦æ©w¸q¿ï¶µÃѧO½Xªº¼Æ­È¡A¦¹¼Æ­È©M¸ê·½´y­zÀɤ¤ªº¿ï¶µÃѧO½X¬Û¦P¡A³o¨Ç¼Æ­È³£¤£·|§ïÅÜ¡A¬G¥Î equ °²«ü¥O³]©w¬°±`¼Æ¡C

²Ä 19 ¦æ¨ì²Ä 21 ¦æ¬O©w¸qÃC¦â¡A½Ð°Ñ¦Ò«e¤@³¹¡C

²Ä 31 ¦æ¬O°O¿ýµeµ§¬O§_ÄaªÅ©ÎIJ¯Èªº PenDown ÅܼơC²Ä 32 ¦æ¬O¦s©ñ²{¦b¨Ï¥ÎªÌ¿ï¾Ü¨º¤@­Ó¿ï¶µªºÅܼơAcommand¡A³Ì²³æªº¤è¦¡´N¬O¦¹ÅܼƤ§­È©M¿ï¶µÃѧO½X¤@¼Ë¡C¤]´N¬O»¡¡A¨Ï¥ÎªÌ¿ï¾Üµe½u¡Acommand ±N³Q³]¬° IDM_Line¡A¨Ï¥ÎªÌ¿ï¾Üµe¾ò¶ê¡Acommand ±N³Q³]¬° IDM_Ellipse¡K¡K¡A¨£µ{¦¡²Ä 96 ¦æ¡C

²Ä 34 ¦æ¬OÀx¦s¨Ï¥ÎªÌ©Ò¿ï¾ÜªºÃC¦â¡Aµ{¦¡¤@¶}©l®É¡A¤º©w¬°¬õ¦â¡A§Y 0FFH¡Cµ{¦¡²Ä 35 ¦æ¬O¦s©ñ¿ï³æ¥N½X¡A³o­ÓÅܼƵy«á¦A»¡©ú¡Cµ{¦¡²Ä 39¡B40 ¦æ¬O¦s©ñ°_ÂI»P²×ÂI ( µeª½½u©Î¤âø¹Ï®É¥Î ) ©Î¯x§Îªº¥ª¤W¨¤³»ÂI»P¥k¤U¨¤³»ÂI ( µe¾ò¶ê®Éªº¥~¤Á¯x§Î¥Î ) ªº®y¼Ð¡C

¥[¤J¿ï³æ

­ì©lµ{¦¡±µ¤U¨Óªº³¡¥÷©M¥H«e¤j­P¤@¼Ë¡A¥u¦³¦b²Ä 55¡B56¡B58 ¦æ¤£¤Ó¬Û¦P¡A³o¬O¬°¤F­n¥[¤J¿ï³æªºÃö«Y¡C¦¹³B¤p¤ì°¸¥H LoadMenu API ¨Ó¸ü¤J¿ï³æ¡A·íµ{¦¡°õ¦æ®É¡A¿ï³æ¤wÀHµÛµ{¦¡¥ÑºÏºÐ²¾¤J°O¾ÐÅ餤¡A¦ý¦pªG±z¤£³qª¾¨t²Î­n¸ü¤J¿ï³æ¨Ï¨ä»P§Ú­Ìªºµ{¦¡³s±µ°_¨Óªº¸Ü¡A¨º»ò¿ï³æ¤£¶ÈµL§@¥Î¡A¦P®Éµe­±¤W¤]¤£·|Åã¥Ü¿ï³æ¡CLoadMenu API ªº¥\¯à´N¦b¦¹¡C

LoadMenu API

LoadMenu ªº­ì«¬¬°¡J

HMENU LoadMenu(
    HINSTANCE   hInstance,  // handle of application instance
    LPCTSTR     lpMenuName  // menu name string or menu-resource identifier
   );

hInstance ¬°µ{¦¡ªº¼Ò²Õ¥N½X¡AlpMenuName «ü¦V¿ï³æ¦WºÙªº¦ì§}¡A¿ï³æ¦WºÙ¥²¶·¥H NULL µ²§À¡A¨Ã¥B¦¹¦WºÙÀ³¸Ó­n©M¸ê·½´y­zÀɤ¤ªº¿ï³æ¦WºÙ²Å¦X¡C

¨ä¹ê¬°µ{¦¡¥[¤J¿ï³æÁÙ¦³¤@ºØ¤èªk¡A§âµ{¦¡²Ä 34¡B55¡B56 ¦æ§R°£¡Aµ{¦¡²Ä 60 ¦æªº hMenu §ï¦¨ NULL¡AÅܦ¨

        invoke  CreateWindowEx,NULL,offset ClassName,\ 
                offset AppName,WS_OVERLAPPEDWINDOW,0,\
                0,400,400,0,NULL,hInstance,NULL

¥t¥~¦bµù¥Uµøµ¡Ãþ§O¤§«e ( §Y©I¥s RegisterClassEx ¤§«e )¡A§â wc µ²ºcÅ餺ªº lpszMenuName ¶ñ¤W§Ú­Ì©Ò©w¸qªº MenuName¡A©ó¬O¦h¤@¦æ

        mov     wc.lpszMenuName,offset MenuName

³o¨âºØ¤èªk³£¯à²£¥Í¿ï³æ¡A©Ò¤£¦Pªº¬O¥H«eªÌªº¤èªk©Òµù¥Uªºµøµ¡Ãþ§O¤£§t¿ï³æ¡A©Ò¥H¨C¦¸«Ø¥ß·sµøµ¡®É³£¤£·|¦³¿ï³æ¥²¶·¦Û¦æ³]¥ß¡A·íµM±z¤]¥i¥H¬°¨C­Óµøµ¡³]¥ß¤£¦P¿ï³æ¡C¦Ü©ó«áªÌ©Òµù¥Uªºµøµ¡Ãþ§O¤w¥]§t¿ï³æ¡A¬G¥H¦¹µøµ¡Ãþ§O©Ò«Ø¥ßªºµøµ¡¤£¥Î¦A«ü©w¿ï³æ¡A¨C­Óµøµ¡´N·|¦³¬Û¦Pªº¿ï³æ¤F¡C

»¡©úµøµ¡¨ç¦¡µ²ºc

³o­Óµøµ¡¨ç¦¡¥E¬Ý¤§¤U¦ü¥G«Ü½ÆÂø¡A¦ý¨ä¹ê¥J²Ó¤ÀªR¡A´Nµo²{¨Ã¤£¹³·Q¹³±o¨º»òÃø¡C³o­Óµøµ¡¨ç¦¡¨ä¹ê¬O¦³³\¦h¼h .if/.elseif/.else/.ednif ±_ª¬°²«ü¥O²Õ¦¨ªº¡A³Ì¥~¤@¼h¬O¦b´ú¸Õ¦UºØ§Ú­Ìµ{¦¡¦³¿³½ìªº°T®§¡A¥]§t WM_COMMAND¡BWM_LBUTTONDOWN¡BWM_MOUSEMOVE¡BWM_PAINT¡BWM_CLOSE¡BWM_DESTROY¥H¤Î©I¥s¤º©wªº³B²z°T®§ªº DefWindowProc API¡C§Ú­Ì¨Ã¤£¯à¹³¦b DOS ¨t²Î¤Uªº«ä¦Ò¤è¦¡¼¶¼gµ{¦¡¡A­n®É®É°O±o©Ò¿×ªº¡y¥H¨Æ¥óÅX°Ê¡A¥H°T®§¬°°ò¦¡zªº«ä¦Ò¤è¦¡¡A¤]´N¬O¦UºØ©PÃä³]³ÆIJµo°T®§®É¡A³B²z¬Û¹ïÀ³ªºª¬ªp©ÎªÌ¤]¥i¯à¬O¨CIJµo¤@­Ó°T®§¡A¥i¯à·|¤Þ°_IJµo¥t¤@­Ó°T®§¡C©Ò¥H¥i¯à¤@­Ó¥\¯à·|©î¶}¦b¦n´X­Ó°T®§¤¤³B²z¡C

Á|­Ó¨Ò¤l¨Ó»¡¡A¨Ò¦pµe¥X½u¬q³o­Ó¥\¯à¡A·í¨Ï¥ÎªÌ¥Ñ¿ï³æ¤¤¿ï¾Üµe¥X½u¬q®É¡A±µ¤U¨Ó¥i¯à·|¥H·Æ¹«¥ªÁä¿ï¾Ü½u¬qªº°_ÂI¡A¦A¨Ó¬O§â·Æ¹«²¾¨ì½u¬qªº²×ÂI¡A¦A«ö¤U·Æ¹«¥kÁä¿ï©w²×ÂI¡C©Ò¥H§Y¨Ï¦pµe½u¬q³o¼Ëªº¥\¯à¤]¥²¶·©î¶}¨Ó¡A¦b²Ä¤@¦¸ WM_LBUTTONDOWN ®É¼g¥X³B²z°_ÂIªºµ{¦¡¡A¦b²Ä¤G¦¸ WM_LBUTTONDOWN ®É¼g¥X³B²z²×ÂI¡A¿ï¦n²×ÂI«á¡A´N¥i¥H¹ïµøµ¡µo¥X WM_PAINT ªº°T®§¡A­n¨Dµe¥X½u¬q¨Ó¡C©Ò¥H¤S¦³¤@¬qµ{¦¡¬O¦b WM_PAINT ùØ¡A³o¬qµ{¦¡¬O¹ê»Úµe¥X½u¬qªºµ{¦¡¡C

¦P¼Ëªºµe¥X¾ò¶ê¤]¬O¤@¼Ë¡A¥²¶·¤À¦¨¦n´X¦¸°T®§³B²z§¹¦¨¡C¦b²Ä¤@¦¸ WM_LBUTTONDOWN ®É³B²z¯x§Î¥ª¤W¨¤³»ÂI¡A²Ä¤G¦¸ WM_LBUTTONDOWN ®É³B²z¥k¤U¨¤³»ÂI¡A¦P®Éµo¥X WM_PAINT µe¥X¾ò¶ê¡C

³o¼Ë¦ü¥G«Ü§¹¬ü¡A¦ý¬O¦³¨â­Ó°ÝÃD²£¥Í¤F¡A²Ä¤@¡Aµe½u¬q»Pµe¾ò¶ê³£¦b WM_PAINT §¹¦¨¡A¨º»ò¦p¦ó¤À¿ë¬Oµe½u¬q©ÎªÌ¬Oµe¾ò¶ê©O¡H²Ä¤G¡A¤]¦³¥i¯à¨Ï¥ÎªÌ¥Ñ¿ï³æ¤¤¿ï¾Üµe¥X½u¬q«á¡A«o¤S«á®¬¤F¡A·Q¥H¤â¨Ó´yø¡A¤S¦p¦ó¸Ñ¨M©O¡H¤p¤ì°¸ªº°µªk¬O§âµe¥X¹Ï§Îªº¿ï¶µÀx¦s¦b command ÅܼÆùØ¡A³o­ÓÅܼƤ£¦ý¥i¥H¸Ñ¨M¨Ï¥ÎªÌ¤¤¶¡¤Ï®¬ªº°ÝÃD¥~¡AÁÙ¥i¥H¤À¿ëµe¥X¨º¤@ºØ¹Ï§Î¡C

¸Ñ¨M¤Fµe¥X¨º¤@ºØ¹Ï§Î«á¡AÁÙ¦³¤@­Ó°ÝÃD¡A¨Ò¦p¦bµeª½½u®É¡A³£¤w WM_LBUTTONDOWN ¨Ó¨ú±o°_ÂI»P²×ÂI¡A¨º»ò«ç»òª¾¹D¬O°_ÂIÁÙ¬O²×ÂI©O¡Hµª®×¦bµ{¦¡²Ä 31 ¦æªº PenDown ÅܼơCµ{¦¡¤@¶}©l®É¡A³o­ÓÅܼƬO³]¬° FALSE¡A§A¥i¥H·Q¹³ PenDown ¤§·N¬Oµeµ§©ñ¤U¸IIJ¯È¡C·í¨ä¬° FALSE ªí¥Üµeµ§ÄaªÅ¡A¦¹®É·íµMµLªk¦bµe¯È¤Wµe¥X½u±ø¨Ó¡A·í¨ä¬° True ®Éªí¥Üµeµ§¸IIJ¯È±i¡A©Ò¥H¥iµe¥X½u±ø¨Ó¡C

·í¨Ï¥ÎªÌ¿ï¾Üµe½u©Î¾ò¶ê®É¡A¤@¶}©l PenDown ¬° FALSE¡A°²¦p¦¹®É¨Ï¥ÎªÌ«ö¤U·Æ¹«¥ªÁä¤Þµo WM_LBUTTONDOWN¡Aªí¥Ü¦¹®Éµeµ§¥¿­n©ñ¤U¡A¬G¬°°_ÂI¡F­Y¤Þµo WM_LBUTTONDOWN ®É PenDown ¬° TRUE ªí¥Üµeµ§¤w¸g©ñ¤U¸IIJ¯È¡A©Ò¥H¦¹¨è¿ï¾Üªº¬O²×ÂI¡C¤£ºÞ¦b¤Þµo WM_LBUTTONDOWN ®É¡APenDown ¬° TRUE ©Î¬° FALSE¡APenDown ³£­n³]©w¬°¨ä¬Û¤Ï­È¡A¥H«Kµeµ§¦A´£°_©Î¦A©ñ¤U¡C

°£¦¹¤§¥~¡APenDown ÁÙ¦³²Ä¤G­Ó§@¥Î¡A¥Î¨Ó°O¿ý·í¨Ï¥ÎªÌ¿ï¾Ü¤âø¹Ï«á¡A¦A²¾°Ê·Æ¹«®É¡Aµeµ§¬O§_¤w¸g©ñ¤UIJ¯È¤F¡A­Y PenDown ¬° False ªí¥Üµeµ§ÄaªÅ²¾°Ê¡A¨S¦³±µÄ²¯È¤@¼Ë¡A¦¹®É¤£»Ýµe¥X­y¸ñ¨Ó¡F­Y PenDown ³]¬° TRUE¡A·Q¹³µeµ§¤w¸g©ñ¤U±µÄ²¯È±i¡A¦¹®É²¾°Ê·Æ¹«´N¹³²¾°Êµeµ§¡A­nµe¥X­y¸ñ¡C

¤âø¹Ï ( µe­y¸ñ )

DRAW.ASM ©Òµe¥X¨Óªº­y¸ñ¤ñ«e¤@³¹¦n¬Ý¦h¤F¡A¦Ó¥B½u¥þ³£³s¦b¤@°_¡A¨ä¹ê­ì²z«Ü²³æ¡C¤p¤ì°¸§â³o¨Ç­y¸ñ·Q¹³¦¨¬O¥Ñ³\¦hµu½u¬q³s±µ¦Ó¦¨ªº¡C¦b¹ê§@¤W¡A¤p¤ì°¸§Q¥Î WM_MOUSEMOVE ¨ú±o·Æ¹«²¾°Ê®ÉÂIªº®y¼Ð¡A¦A§â³o¨ÇÂI³s¦¨½u§Y¥i¡Cµ{¦¡²Ä 122 ¨ìµ{¦¡²Ä 124 ¦æ´N¬O¨úªº·Æ¹«²¾°Ê®Éªº®y¼Ð¡A¨Ã¦s©ó end_point¡AµM«á¤Þµo WM_PAINT °T®§¡A¥H«Kµe¥X¨C¤@¬qµu½u¬q¨Ó¡C¦b WM_PAINT ùØ¡AÀˬd¬O§_¬°¤âø¹Ïªº¥\¯à ( ²Ä 169 ¦æ )¡A¬Oªº¸Ü´N³s±µ°_ÂI¨ì²×ÂI¡A¨Ã§â°_ÂI§ï¦¨²×ÂI¡A¥H«K¤U¦¸¨ú±o·Æ¹«²¾°Ê®Éªº®y¼Ð®Éªº°_ÂI¡C

¤âø¹Ïªº°_ÂI«h¬O¦b WM_LBUTTONDOWN ®É¨ú±o¡A¦bµ{¦¡ªº²Ä 119 ¦æ¨ì 123 ¦æ¡A¤p¤ì°¸´N¤£¦A²Ó»¡¤F¡C


µù¤@¡F¦b¤p¤ì°¸ªººô¯¸¤¤¡A¦³Ãö Win32 Àô¹Ò¤U©Ò¼¶¼gªº²Õ¦X»y¨¥µ{¦¡¡A¤j³¡¤À³£¬O·|Åã¥Üµøµ¡¡A¥L­Ì©Î¦h©Î¤Ö³£·|¨Ï¥Î GDI ¥H«K¦b®à­±¤WÅã¥Üµøµ¡¡A³o¨Çµ{¦¡¬O§t¦³ UI ¸ê·½ªº¡C¦ý¬OÁÙ¦³¤@ºØ Win32 µ{¦¡¡AºÙ¬° console µ{¦¡¡A¥L­Ì¬O¦b DOS ¼Ò¦¡¤U°õ¦æªº©Î¬O¦b Win XP ªº CMD.EXE ¤º°õ¦æªº¡A¥L­Ì¨S¦³º}«Gªº¹Ï§Î¬É­±¡A¤]¤£§t UI ¸ê·½¡A¦ý¬O¥L­Ì¤´ÄÝ©ó 32 ¦ì¤¸ªºµ{¦¡¡C

Console µ{¦¡©M DOS µ{¦¡¬O¤£¦Pªº¡CConsole µ{¦¡¬O 32 ¦ì¤¸ªº¡AÁöµM¨S¦³º}«Gªº¹Ï§Î¬É­±¡A¦ý¬O¤´¥i¥H©I¥s«D GDI ªº Win32 API¡A¦¹¥~¥Lªº®æ¦¡¤]©M©Ò¦³¦³º}«G¹Ï§Î¬É­±ªº Win32 µ{¦¡¤@¼Ë¡A³£¬OÄÝ©ó·L³n·s©w¸qªº¥i°õ¦æÀɮ榡¡A§Y©Ò¿×ªº PE ®æ¦¡ ( portable executable )¡C

µù¤G¡J·í§Ú­Ì©Ò¼¶¼gªºµ{¦¡Åܤj®É¡A©Ò»Ý¬ÛÃöÀɮפ]±N·|Åܦh¡A¦bµo®iµ{¦¡¹Lµ{±`±`·|­×§ï¬Y¨ÇÀɮסA¦ý¬O¦pªG¨C¦¸³£­n­«ÀY¶}©l²ÕĶ¡B³sµ²¡A±N·|¯Ó¥h³\¦h®É¶¡¡C¦³¤@­Ó¦Û°Ê²ÕĶªº¦n¥Îµ{¦¡¡A¦W¥s NMAKE.EXE¡A¥L¥i¥H¦Û°Êªº¨Ì¾Ú¦UÀɮשҫإߪº®É¶¡§PÂ_¨º¨ÇÀɮפw³Q§ó·s¡A¦Ó»Ý­n­««Ø¡A¨º¨ÇÀɮ׫h¤£»Ý­n­««Ø¡A¥i¥H¸`¬Ù¤£¤Ö®É¶¡¡A±z¥i¥H¦b http://spiff.tripnet.se/~iczelion/download.html §K¶O¤U¸ü NMAKE 1.5 ª©¡A°õ¦æ NMAKE15.EXE ¤§«á¡A·|±o¨ì NMAKE.ERR¡BNMAKE.EXE¡BREADME.TXT ¤T­ÓÀɮסA¥iª½±µ§â³o¤T­ÓÀɮײ¾¨ì±z¦w¸Ëªº MASM32\BIN ¤l¥Ø¿ýùØ¡A¤è«K¨Ï¥Î¡C

¨ä¹ê NMAKE.EXE ¬O¤£¨ü¨º¤@ºØ¹q¸£»y¨¥ªº­­¨î¡A¥¦¤£¶È¥i¥H¦Û°Ê¦a²ÕĶ²Õ¦X»y¨¥¡A§Y¨Ï C/C++¡BPASCAL ³£¥i¥H¨Ï¥Î¡CNMAKE.EXE ªº»yªk¬°¡J

NMAKE [options] [/f makefile] [/x stderrfile] [macrodefs] [targets]

NMAKE ªº¥Îªk«Ü½ÆÂø¡A¦¹³B¤p¤ì°¸¶È¤¶²Ð´X­Ó±`¥Îªº¡C­º¥ý»¡©ú /f °Ñ¼Æ¡A³o­Ó°Ñ¼Æ«á­±±µµÛ¤@­ÓºÙ¬° makefile Àɪº¤å¦rÀÉ¡A¦¹¤å¦rÀɤº¬O°O¿ýµÛ¥i°õ¦æÀɬO¦p¦ó²£¥Íªº¡A°²¦p /f °Ñ¼Æ¬Ù²¤ªº¸Ü¡ANMAKE ´N·|´M§ä¤º©wªº makefile ÀÉ¡A¦¹¤º©wªº makefile ÀÉ´N¬O²{¦b©Ò¦b¥Ø¿ýÀɦW¬° makefile ªºÀɮסC

Makefile Àɪº¤º®e¤@¯ë¦³¤@­Ó ALL ±Ô­z¡A¦¹±Ô­z¤§«á¬O±µµÛ³Ì«á­n»s³y¥X¨ÓªºÀɮסA¦¹Àɮ׬°³Ì«á¥Ø¼Ð¡A¦Ó«á«h¬O¤À¦¨´X­Ó¬q¸¨¡A²Ä¤@­Ó¬q¸¨¬O³Ì«á¥Ø¼Ð²£¥Íªº¤è¦¡¡A¦Ó³o­Ó³Ì«á¥Ø¼Ð¥i¯à·|¥Ñ¥t¥~´X­ÓÀɮ׸g¤@©wªº¨BÆJ²£¥Í¡A¦Ó³o´X­ÓÀɮתº²£¥Í¤è¦¡«h¤À§O°O¿ý¦b¨ä«áªº´X­Ó¬q¸¨ùØ¡A¦p¦¹Ãþ±À¡C¦Ó¨C­Ó¬q¸¨ªº®æ¦¡¬O

¼ÐªºÀɮצW : Àɮפ@ ÀɮפG ÀɮפT ¡K¡K
        µ{¦¡ °Ñ¼Æ

Àɮפ@¡BÀɮפG¡BÀɮפT¡K¡K¬O¥Î¨Ó²£¥Í¡y¼ÐªºÀɮסz¡A¤]´N¬O»¡¡A¼ÐªºÀɮשMÀɮפ@¡BÀɮפG¡BÀɮפT¡K¡K¦³Ãö¡A¥u­n³o¨ÇÀɮר䤤ªº¤@­Ó³Q­×§ï¤F¡A´N·|­«·s²£¥Í¡y¼ÐªºÀɮסz¡C¦Ó¼ÐªºÀɮײ£¥Í«h¬O¥Ñ¤U¤@¦æªºµ{¦¡©Ò²£¥Íªº¡Aµ{¦¡«á­±©Ò±µªº°Ñ¼Æ¡A©M¦b DOS ¼Ò¦¡¤¤©Ò¥Îªº§¹¥þ¬Û¦P¡A´N¬O¸Óµ{¦¡ªº°Ñ¼Æ¡C¦¹¥~­nª`·Nªº¬O¡A²Ä¤G¦æªºµ{¦¡¤§«e¤@©w­nªÅ¤@®æ¥H¤W¡A§_«h·|¥X²{

 fatal error U1034: syntax error : separator missing stop

ªº¿ù»~¡C¦¹¥~±z¤]¥i¥H¥[¤Wµù¸Ñ¡A¡y#¡z¦r¤¸¥H«áªº¤å¦r¥þ·|³Q·í¦¨µù¸Ñ¡A¦Ó³Q NMAKE ©¿²¤¡Aµù¸Ñ¥i¥H¦û¾Ú¤@¦æ¡A¤]¥i¥H¦b¤@¦æªº³Ì«á­±¡C

¨Ò¦p¥»³¹ùØ¡A³Ì«á±o¨ìªº¬O DRAW.EXE ÀÉ¡A¥¦¬O¥Ñ DRAW.OBJ »P DRAW.RES ¸g³sµ²¾¹ ( LINK.EXE ) ³sµ²²£¥Íªº¡A¦Ó DRAW.OBJ «h¬O¥Ñ²ÕĶ¾¹ ( ML.EXE ) ²ÕĶ²£¥Íªº¡ADRAW.RES «h¬O¥Ñ¸ê·½½sĶ¾¹ ( RC.EXE ) ½sĶ²£¥Íªº¡C©Ò¥H makefile ÀÉ®×¼g¦¨¤U­±ªº¼Ë¤l¡J

# ²£¥Í DRAW.EXE
ALL:DRAW.EXE

#³sµ²¾¹
DRAW.EXE:DRAW.OBJ DRAW.RES
    link /SUBSYSTEM:WINDOWS DRAW.OBJ DRAW.RES

#²ÕĶ¾¹
DRAW.OBJ:DRAW.ASM
    ml /c /coff DRAW.ASM    # ¶È²ÕĶ¤£©I¥s³sµ²¾¹¡A¬G¥[¤W /c °Ñ¼Æ

#¸ê·½½sĶ¾¹
DRAW.RES:DRAW.RC
    rc DRAW.RC

¥H¤å®Ñ³B²z³nÅé¡A¦pµ§°Oï©Î UltraEdit32 µ¥½s¿è¦s¬° DRAW.MAK¡AµM«á¦b DOS ¼Ò¦¡¤U¿é¤J

E:\HomePage\SOURCE>nmake /f draw.mak [Enter]

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

        ml /c /coff DRAW.ASM
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: DRAW.ASM
        rc DRAW.RC
        link /SUBSYSTEM:WINDOWS DRAW.OBJ DRAW.RES
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

±z´N¥i¥H¬Ý¨£ NMAKE ¬°±z¦Û°Ê²£¥Í DRAW.EXE¡A¦b±z¼¶¼gµ{¦¡¹Lµ{¤¤¡A§Y¨Ï­×§ï¬Y­Óµ{¦¡¡A¦Ó¨ä¥Lµ{¦¡¨ÃµL­×§ï¡ANMAKE ¤]·|¬°±z¦Û°ÊºûÅ@¡C©³¤U¬OÂǧU ML.EXE ·|©I¥s³sµ²¾¹ªº¯S©Ê©Ò»s°µªº makefile ÀÉ¡J

# ²£¥Í DRAW.EXE
ALL:DRAW.EXE

# ²ÕĶ¾¹¤Î³sµ²¾¹
DRAW.EXE:DRAW.ASM DRAW.RES
# ²ÕĶ¾¹·|¦Û°Ê¶Ç DRAW.OBJ µ¹³sµ²¾¹¡A¬G /link ¤§«á¤£¥Î¦A¥[¤W DRAW.OBJ
    ml /coff DRAW.ASM /link /SUBSYSTEM:WINDOWS DRAW.RES 

# ¸ê·½½sĶ¾¹
DRAW.RES:DRAW.RC
    rc DRAW.RC

©³¤U¤¶²Ð´X­Ó NMAKE ±`¥Îªº options¡C³o¨Ç options ³£¥H¡y/¡z©Î¡y-¡z¤Þ¾É¡A¤£ºÞ¤j¼g©Î¤p¼g¡Aµ²ªG¬Û¦P¡C²Ä¤@­Ó¡A¤j·§¤]¬O³Ì±`¥Îªº¬O¡y/a¡z¡A¥¦ªí¥Ü¤£ºÞÀɮ׬O§_§ó·s¡A¥þ³¡­«·s«Ø¥ß¡C°Ñ¼Æ¡y/d¡zªí¥ÜÅã¥Ü¦UÀÉ®×¥H¤Î¬ÛÃöÀɮשҫإ߮ɶ¡¡C°Ñ¼Æ¡y/help¡z©Î¡y/?¡zÅã¥Ü²µuªº»yªk¡C¦Ü©ó¨ä¥Lªº¥Îªk¥i°Ñ¦Ò¤â¥U¡C


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