¦b¹q¸£¤Wªº¹Ï¤ù¤jP¤À¦¨¨âºØ¡A¦V¶q¹Ï»PÂI°}¹Ï¡C¦V¶q¹Ï¬O«ü¹³ AutoCAD ©Ò¦sªº *.DWG ÀÉ¡A©Î¬O¹³ºô»Úºô¸ô³Ì¬y¦æªº Flash¡A¥¦Ìªº¹Ï¤ù¥Dn¬O¥H½u¡B¶ê¡K¡Kµ¥°ò¥»´X¦ó¹Ï§Îºc¦¨¡A¨Ò¦pµe¤@±i¤HÁy¡A¥u»Ý¤@Ó¾ò¶ê·í½ü¹ø¡B¨âÓ¤p¶ê·í²´·ú¡B¤@Ó¤T¨¤§Î·í»ó¤l¡B¤@Ó¾ò¶ê·í¼L¡AµM«á¦U¶î¤W¾A·íÃC¦â¡A¦Ó´yz¶ê©Î¾ò¶ê¥u»Ýn¤Ö¼Æªº´XÓÂI©Î¥b®|§Y¥i¡A©Ò¥Hµe¥X¤@´T¦V¶q¹Ï¥²¶·¸g¹L¤@¨Çpºâ¡AµÛ¦â¡A·í¹Ï§Î½ÆÂø®É´N·|¤ñ¸ûºC¡C¦V¶q¹ÏªºÀuÂI¬OÀɮתº¤j¤p¸û¤p¡A¦]¬°¥un¦s¤U¤Ö¶qªºÃöÁä¸ê®Æ´N¥i¥H¤F¡C
¦ý¬On¦s¤@±i¤Hª«·Ó©Î·´ºµ¥·Ó¤ù¡A´N¨S¦³¿ìªk¥Î²³æªº´X¦ó¹Ï§Îªí¥Ü¡A³o¨Ç´N¬OÂI°}¹Ï¡C¤@¯ë¥i¥H§âÂI°}¹Ï¬Ý¦¨¬O¥Ñ³\¦hÂI¥Ñ¥ª¦Ó¥k¡B¥Ñ¤W¦Ó¤U¤@ÓÂI¤@ÓÂI°ï¬ä¦Ó¦¨ ( ¦³¨ÇÂI°}¹Ï¤£¬O³o¼Ë±Æ¦C¡A¦ý¦¹³B¤p¤ì°¸¥u¬O´£¤@´£³oÓÆ[©À¦Ó¤w )¡C¦Ó¨C¤@ÂI¥Ñ¤£¦PªºÃC¦âªí²{¥X¨Ó¡A©Ò¥H´N¥i¥HÅã¥X¤@´T¹Ï¤ù¡A¨Ò¦p°ÆÀɦW¬° BMP ªº¹Ï¤ù ( Bitmap ªºÁY¼g¡A¤]ºÙ¬°¡y¦ì¤¸¹Ï¡z¡AÀÉ®×Åé¿n«Ü¤j )¡C¦ý¬O¦]¬°³o¼Ëªº¹Ï¤ùÀɮפӤj¤F¡A©Ò¥H²£¥Í¦U¦¡¦U¼ËªºÀ£ÁY¤è¦¡¡A¦Ó³y¦¨¦hºØ°ÆÀɦW¡A¦p GIF¡BJPG¡BPNG µ¥µ¥¡C
³o¤@³¹ªº¥D¨¤¦ì¤¸¹Ï¡A¤]´N¬O°ÆÀɦW¬° BMP ªº¹ÏÀÉ¡A¥¦¬O¨S¦³¸g¹LÀ£ÁYªºÂI°}¹Ï¡A¤]¬O Windows ª½±µ¤ä´©ªº¡C¦b³o¤@³¹ùØ¡A¤p¤ì°¸n§â¤@±i game13.bmp ÀÉÅã¥Ü¦b¿Ã¹õ¤W¡A¥¦¬O¤@±i 1024*768 ¤j¤pªº¹Ï®×¡A¦@ 2359350 ¦ì¤¸²Õ¤j¤p¡A¹Ï¤ùªº¼Ë¤l¦p¤U¡G
nÅã¥Ü BMP ¦ì¤¸¹Ïªº¨BÆJ¤jP¥i¤À¬°¥H¤U´XÓ¨BÆJ¡G
½ÐÄ~Äò¬Ý©³¤U¶i¤@¨Bªº»¡©ú¡C
BMP ¹ÏÀɤ]¬O¸ê·½ªº¤@ºØ¡A¦p«e©Òz¡A±ý¨Ï BMP ÀÉÅã¥Ü¦bµøµ¡ùØ¡A³Ì²³æªº¤èªk¬O¨Ï¥¦Åܦ¨¸ê·½ªº¤@³¡¥÷¡C¦b¸ê·½´yzÀɤ¤¡A¥i¥H¥Î¤U±ªº±Ôz©w¸q BMP Àɦ¨¬°¸ê·½¡G
¦ì¤¸¹ÏÃѧO½X BITMAP [DISCARDABLE] ¦ì¤¸¹ÏÀɮצW
´N¦p¦P«e±ªº¹Ï¥Ü¤@¼Ë¡A¡y¦ì¤¸¹ÏÃѧO½X¡z¬O¤@Ó¦r¦ê¡A±N¨Ó¦bµ{¦¡°õ¦æ®É¥H³oÓÃѧO½X¦r¦ê¨Ó¥Nªí«á±ªº¡y¦ì¤¸¹ÏÀɮצW¡z¡CBITMAP ¬Oªí¥Ü³o¬q¸¨¬O´yz¦ì¤¸¹Ï¥Îªº¡A¦]¬°¸ê·½´yzÀɤ¤¦³³\¦h¤£¦Pªº¬q¸¨¡A¦³©w¸q¿ï³æªº¡A¦³©w¸q¹Ï¥Üªº¡A¦³©w¸q¹ï¸Ü²°ªºµ¥µ¥¡CDISCARDABLE ¬Oªí¥Ü¦ì¤¸¹Ï¤£¦A¨Ï¥Îªº®ÉÔ¥i¥H¼È®É±q°O¾ÐÅ餤ÄÀ©ñ¥H¸`¬Ù°O¾ÐÅé¡A¥¦¬O¤@Ó¥i¦³¥iµLªº°Ñ¼Æ¡C
§â¦ì¤¸¹Ï©w¸q¦¨¸ê·½«á¡A·í¨t²Î°õ¦æ¨ã¦³¦ì¤¸¹Ï¸ê·½ªºµ{¦¡®É¡AÁÙ¥²¶·¥Î LoadBitmap §â¸ê·½¤¤ªº¦ì¤¸¹Ï¸ü¤J¨ì°O¾ÐÅéùØ¡CLoadBitmap ªºì«¬¬O¡G
HBITMAP LoadBitmap( HINSTANCE hInstance, // handle of application instance LPCTSTR lpBitmapName // address of bitmap resource name );
¨ä¤¤¡AhInstance ¬Oµ{¦¡ªº¼Ò²Õ¥N½X¡AlpBitmapName ¬O¤@Óªø«ü¼Ð¡A«ü¦V¦ì¤¸¹ÏÃѧO½X¦r¦êªº¦ì§}¡A¦¹¦r¦ê¶·¥H¹s¬°µ²§À¡A°õ¦æ§¹ LoadBitmap API «á¡AEAX ·|¶Ç¦^¦ì¤¸¹Ï¥N½X¡C±µ¤U¨Ó¡A´Nn·Ç³Æ¦b¿Ã¹õ¤Wµe¥X¹Ï¤ù¤F¡CÁÙ°O±o¤Z¬O¦b¿Ã¹õ¤Wµe¥X¹Ï§Î³£±o¥ý¨ú±o³]³Æ¤º®e ( device context )¡C¦b¦^À³ WM_PAINT ®É¡A¥Î BeginPaint ¨ú±o¡A¦Óµ²§ô WM_PAINT ®É¥Î EndPaint ÄÀ©ñ¸Ë¸m¤º®e¡C
·í¨ú±o¸Ë¸m¤º®e«á¡A¥»¨ÓÀ³¸Ó¹ï¿Ã¹õµe¹Ï¡A¦ý¤@¯ëªº°µªk¬O¥ý«Ø¥ß¤@Ó©M¦¹µøµ¡¬Û¦Pªº¸Ë¸m¤º®e¡AºÙ¬°°O¾ÐÅé¸Ë¸m¤º®e¡A§@¬°½w½Ä°Ï¡A¦A¥Ñ³oÓ½w½Ä°Ïª½±µ§â¦ì¤¸¹Ï¶Ç°e¨ìnÅã¥Üªº¸Ë¸m¤º®e¤W¡C³o¬O¦]¬°ÂI°}¹ÏÀɮ׳q±`«Ü¤j¡A¦b¸ûºC³tªº¹q¸£ª½±µ¹ïµøµ¡ªº¸Ë¸m¤º®e¿é¥X¡A®e©ö³y¦¨µe±¡y§Ý°Ê¡z¡A¦ý¦pªGª½±µ°µ¶Ç°eªº¸Ü¡A¥i¥HÁקK¡C
n«Ø¥ß¬Û¦Pªº¸Ë¸m¤º®e¡A¥i¥H¥Î CreateCompatibleDC API¡A¨ä쫬¬°
HDC CreateCompatibleDC( HDC hdc // handle to memory device context );
¥¦¥u¦³¤@ӰѼơA´N¬O©M¨º¤@Ó³]³Æ¤º®e¬Û¦P¡A¦pªG¦¨¥\¡Aªð¦^Ȧs©ó EAX¡A¬°·s«Øªº³]³Æ¤º®e¥N½X¡C
·í«Ø¥ß¦n·sªº°O¾ÐÅé³]³Æ¤º®e¤§«á¡A´N¥i¥H¹ï³oÓ½w½Ä°Ïµe¹Ï¤F¡A©Ò¥Îªº API ¬O SelectObject¡A¥¦¥i¥H§â¸ê·½Àɤº©w¸qªº¦ì¤¸¹Ïª«¥óµe¦b¸Ë¸m¤º®e¤W¡CSelectObject ªºì«¬¡B¥Îªk½Ð°Ñ¦Ò²Ä¤³¹¡C
·í°O¾ÐÅé¸Ë¸m¤º®eªº¹Ï§Î¤w¸gµe¦n¤§«á¡A´N¥i¥H§â½w½Ä°Ïªº¸ê®Æ¶Ç°e¨ììµøµ¡ªº¸Ë¸m¤º®e¤F¡A¥i¥H¥Î BitBlt API §¹¦¨¡C
BitBlt ¬O¶Ç°e¤@Ӱ϶ôªº¦ì¤¸¸ê®Æ ( bit-block transfer )¡A·N§Y¨Ï¦b°O¾ÐÅ餺ªº¦ì¤¸¹Ï¡A¶Ç°e¨ì³]³Æ¤º®e¡CBitBlt 쫬¬°¡G
BOOL BitBlt( HDC hdcDest, // handle to destination device context int nXDest, // x-coordinate of destination rectangle's upper-left corner int nYDest, // y-coordinate of destination rectangle's upper-left corner int nWidth, // width of destination rectangle int nHeight, // height of destination rectangle HDC hdcSrc, // handle to source device context int nXSrc, // x-coordinate of source rectangle's upper-left corner int nYSrc, // y-coordinate of source rectangle's upper-left corner DWORD dwRop // raster operation code );
hdcDest ¬O¥Øªº¦aªº³]³Æ¤º®e¥N½X¡AnXDest¡BnYDest ¬O¥Øªº¦a³]³Æ¤º®eªº®y¼Ð¡AnWidth¡BnHeight ¬O¶Ç°e¹Ï¤ùªº¼e«×»Pªø«×¡ChdcSrc ¬O¨Ó·½³]³Æ¤º®e¡AnXSrc¡BnYSrc ¬O¨Ó·½ªº®y¼Ð¡AdwRop ¬O¶Ç°e«áªº¾Þ§@¤è¦¡¡C·ínÅã¥Ü¦ì¤¸¹Ï®É¡AÅãµMn§âµøµ¡ªº¤u§@°Ï©Ò¥Nªíªº³]³Æ¤º®e³]¬°¥Øªº³]³Æ¤º®e¡A°²¦pn±q¥ª¤W¨¤¶}©lÅã¥ÜÂI°}¹Ïªº¸Ü¡AnXDest¡BnYDest §¡³]¬°¹s¡A¦Ó©ÒnÅã¥Üªº¦ì¤¸¹Ï¦h¼e¡A¦h°ª«h¥Ñ nWidth¡BnHeight «ü©w¡A¦Ó¨Ó·½³]³Æ¤º®e¥²¶·«ü¦V¦ì¤¸¹Ï©Ò¦bªº°O¾ÐÅé³]³Æ¤º®e¡C
³Ì«á¤@ӰѼơAdwRop¡A¬O¥Î¨Ó¦b¶Ç°e®É¥i©M¯S©wÃC¦â¹Bºâ¡C¤UªíÅã¥Ü¥i¯àªº¼ÆÈ¡G
¼ÆÈ | »¡©ú |
BLACKNESS | ¥þ³¡Åܶ¦â¡C§Y¥Øªº¸ê®Æ¶ñ¤J 0 |
DSTINVERT | NOT ¥Øªº¸ê®Æ |
MERGECOPY | ¨Ó·½¸ê®Æ AND µe¨êÃC¦â |
MERGEPAINT | ( NOT ¨Ó·½¸ê®Æ ) OR µe¨êÃC¦â |
NOTSCRCOPY | NOT ¨Ó·½¸ê®Æ |
NOTSRCERASE | NOT ( ¨Ó·½¸ê®Æ OR ¥Ø¼Ð¸ê®Æ ) |
PATCOPY | µe¨êÃC¦â |
PATINVERT | µe¨êÃC¦â XOR ¥Ø¼Ð¸ê®Æ |
PATPAINT | µe¨êÃC¦â OR ( NOT ¨Ó·½¸ê®Æ ) OR ¥Ø¼Ð¸ê®Æ |
SRCAND | ¨Ó·½¸ê®Æ and ¥Ø¼Ð¸ê®Æ |
SRCCOPY | ¨Ó·½¸ê®Æ |
SRCERASE | ¨Ó·½¸ê®Æ AND ( NOT ¥Ø¼Ð¸ê®Æ ) |
SRCINVERT | ¨Ó·½¸ê®Æ XOR ¥Ø¼Ð¸ê®Æ |
SRCPAINT | ¨Ó·½¸ê®Æ OR ¥Ø¼Ð¸ê®Æ |
WHITENESS | ¶ñ¤J¥Õ¦â¡C |
¸g¹L³o»ò¦h¨BÆJ¡A²×©ó¤j¥\§i¦¨¤F¡C¤p¤ì°¸§â³o¨Ç¨BÆJ¿@ÁY¦¨¤U¹Ï¡G
¦b³o¤@³¹ùØ¡A§ÚÌ¥u³æ¯ÂÅã¥Ü¦ì¤¸¹Ï§Y¥i¡A¤£§@¹Bºâ¡A©Ò¥H¦b©I¥s BitBlt ®É¡AdwRop °Ñ¼Æ¥Î SCRCOPY §Y¥i¡C³Ì«á¦A¥Ñ DeleteDC ÄÀ©ñ¥Ñ CreateCompatibleDC ©Ò«Ø¥ßªº°O¾ÐÅé¸Ë¸m¤º®e¡C
DeleteDC ¬O¥Î¨ÓÄÀ©ñ«ü©wªº¸Ë¸m¤º®e¡C쫬¬°¡G
BOOL DeleteDC( HDC hdc // handle to device context );
hdc ¬On³QÄÀ©ñªº¸Ë¸m¤º®e¡CY¦¨¥\¡A«h EAX ¶Ç¦^«D¹s¼Æ¡AY¥¢±Ñ¡A«h EAX ¬°¹s¡C
n¦bµøµ¡¤W¥[¤W±²¶b¡A¥²¶·¦b©I¥s CreateWindow «Ø¥ßµøµ¡®É¡A¦b dwStyle °Ñ¼Æ¤¤«ü©w WS_HSCROLL ©Î WS_VSCROLL ³o¨âÓ·®æ¡A«eªÌªí¥Ü¤ô¥±²¶b¡A«áªÌªí¥Ü««ª½±²¶b¡Cª`·N¡A¦¹³B©Ò¥[¤Jªº±²¶b¤£¬O±±¨î¤¸¥ó¡A¦Ó¬Oµøµ¡±²¶b¡A¨âªÌÁöµM¬Û¹³¡A¦ý·N¸q¤W¤£¦P ( ±²¶b±±¨î¤¸¥ó¨£²Ä¤Q³¹ )¡C¦pªG¥u«ü©w¤F³o¨âÓ·®æ¡A¦Ó¤£°µ¨ä¥¦¨Æ¡A¨º»ò¥u¬OÅã¥Ü¥X±²¶b¦Ó¤w¡A¦ý¬OµLªk¥¿±`§@¥Î¡C¬°¤FÅý±²¶b¯à°÷µo´§§@¥Î¡AÁÙ¶·°µ¨â¥ó¨Æ¡G²Ä¤@¡An¥ý¥Î SetScrollRange ³]¦n±²¶b½d³ò¡F²Ä¤G¡A³B²z WM_HSCROLL¡BWM_VSCROLL °T®§¡C
³]©w±²¶b½d³ò¤@¯ë¬O¥Î SetScrollRange API¡A¨ä쫬¬O¡G
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µøµ¡¥N½X¡A¦¹µøµ¡¥N½X¬O«ü¾Ö¦³±²¶bªºµøµ¡¡CnBar ¬O¥un³]©w½d³òªº±²¶b¡A¥i¥H¬O¤U±¤TºØªº¨ä¤¤¤@ºØ¡GSB_CTL¡BSB_HORZ¡BSB_VERT¡A¤@Óµøµ¡³Ì¦h¥u¦³¤@Ó¤ô¥±²¶b©M¤@Ó««ª½±²¶b¡An³]©w¤ô¥±²¶b®É¡A¥Î SB_HORZ¡Fn³]©w««ª½±²¶b®É¡A¥Î SB_VERT¡F¦pªGn³]©w¹ï¸Ü²°ªº±²¶b½d³ò¡A¥Î SB_CTL¡CnMinPos¡BnMaxPos ¤À§O¬O¾ÞÁa±ìªº³Ì¤p©M³Ì¤j½d³ò¡CbRedraw ¬O¬O§_«·sø»s¡ATRUE ªí«Ã¸¡FFALSE ªí¥Ü¤£«Ã¸¡C
¤@¯ë±²¶b¥~Æ[¦p¤U¡G
¾Þ§@±²¶b³oºØ¬Ý¦ü²³æ¡A¦ý¹ï Win32 ¨t²Î¦Ó¨¥¡A«o²£¥Í¤F½ÆÂøªº°T®§¡C·Æ¹«¹ï¤ô¥±²¶b¾Þ§@®É¡A¨Ò¦p·Æ¹«¦b¥ª½bÀY©Î¥k½bÀY«ö¤@¤U¡A©Î¥H·Æ¹«©ìµÛ¾ÞÁa±ì²¾°Ê¡A©Î¦b¥ª·Æ°Ê±ì©Î¦b¥k·Æ°Ê±ì¤W«ö¤@¤Uµ¥µ¥ªº°Ê§@¡A³£·|²£¥Í WM_HSCROLL °T®§¡A³oÓ WM_HSCROLL °T®§±N©ñ¨ìµ{¦¡ªº°T®§¦î¦C¤¤µ¥«Ý³B²z¡C¦P¼Ëªº¡A¥H·Æ¹«¹ï««ª½±²¶b¾Þ§@®É¡A·|²£¥Í WM_VSCROLL °T®§¡C
WM_HSCROLL ¬O¨Ï¥ÎªÌ¹ï¤ô¥±²¶b¾Þ§@®É¡A¹ï©Ò¾Ö¦³ªºµøµ¡µo¥Xªº°T®§¡CWM_HSCROLL ªº wParam ¸û§Cªº¤Q¤»¦ì¤¸¬O¨Ï¥ÎªÌ¹ï±²¶b°µ¤F¤°»ò°Ê§@¡A¦¹°Ê§@ºÙ¬°³qª¾½X¡A¤Uªí»¡©ú¨ä·N¸q¡G
³q¡@ª¾¡@½X wParam ¸û§Cªº¤Q¤»¦ì¤¸ |
¼ÆÈ | »¡¡@¡@¡@©ú |
SB_LINELEFT | 0 | ·í¨Ï¥ÎªÌ«ö¤@¤U±²¶bªº¥ª½bÀY®É¡A¾ÞÁa±ì³Q¦V¥ª²¾°Ê¤@®æ |
SB_LINERIGHT | 1 | ·í¨Ï¥ÎªÌ«ö¤@¤U±²¶bªº¥k½bÀY®É¡A¾ÞÁa±ì³Q¦V¥k²¾°Ê¤@®æ |
SB_LEFT | 6 | ·í¨Ï¥ÎªÌ§â¾ÞÁa±ì©ì²¾°Ê¨ì·Æ°Ê±ìªº³Ì¥ªÃä¡A¤]´N¬O SetScrollRange ªº³Ì¤pȰѼƳB |
SB_RIGHT | 7 | ·í¨Ï¥ÎªÌ§â¾ÞÁa±ì©ì²¾°Ê¨ì·Æ°Ê±ìªº³Ì¥kÃä¡A¤]´N¬O¾ÞÁa±ì¦b SetScrollRange ªº³Ì¤jȰѼƳB |
SB_PAGELEFT | 2 | ·í¨Ï¥ÎªÌ¦b¾ÞÁa±ì¥ªÃ䪺·Æ°Ê±ì¤W«ö¤@¤U®É¡Aµøµ¡¤ºªº¸ê®Æ±NÅã¥Ü¦V¥ªÃ䪺¤@ӿùõµe± |
SB_PAGERIGHT | 3 | ·í¨Ï¥ÎªÌ¦b¾ÞÁa±ì¥kÃ䪺·Æ°Ê±ì¤W«ö¤@¤U®É¡Aµøµ¡¤ºªº¸ê®Æ±NÅã¥Ü¦V¥kÃ䪺¤@ӿùõµe± |
SB_THUMBPOSITION | 4 | ·í¨Ï¥ÎªÌ©ì¾ÞÁa±ì²¾°Ê¦Ó«á°±¤î®É¡Aµo¥X¨ã¦³ SB_THUMBPOSITION ªº WM_HSCROLL °T®§ |
SB_THUMBTRACK | 5 | ·í¨Ï¥ÎªÌ©ì¾ÞÁa±ì²¾°Ê®É¡Aµo¥X¨ã¦³ SB_THUMBTRACK ªº WM_HSCROLL °T®§ |
¤p¤ì°¸µyµy»¡©ú¤Wªí¡C·í¨Ï¥ÎªÌ¥H SetScrollRange ³]©w±²¶b½d³ò®É¡A¥Î°Ñ¼Æ nMinPos ©M nMaxPos ³]©w³Ì¤jÈ©M³Ì¤pÈ¡A¨Ò¦p
invoke SetScrollRange,hWnd,SB_HORZ,0,3,TRUE
¨º»ò±²¶bªº¾ÞÁa±ì¥Ñ¥ª¦Ó¥k¦@¦³ 0¡B1¡B2¡B3 ¥|Ó¦ì¸m¡A°²¦p²{¦b¾ÞÁa±ì¦b 0 ªº¦ì¸m¡A·í¨Ï¥ÎªÌ«ö¤@¤U¦V¥k½bÀY¡A«h±²¶bµo¥X¨ã¦³ SB_LINERIGHT ªº WM_HSCROLL °T®§¡A¥B¾ÞÁa±ì¦ì¸m²¾¨ì 1 ªº¦ì¸m¡C·Æ°Ê±ì³Q¾ÞÁa±ì¤À¦¨¨â³¡¤À¡A·í¨Ï¥ÎªÌ«ö¤@¤U¾ÞÁa±ì¥kÃ䪺·Æ°Ê±ì¡A«h±²¶bµo¥X¨ã¦³ SB_PAGERIGHT ªº WM_HSCROLL °T®§¡FY«ö¤@¤U¥ªÃ䪺·Æ°Ê±ì¡A«h²£¥Í¨ã¦³ SB_PAGELEFT ªº WM_HSCROLL¡A³o¨Ç°Ê§@¨t²Î·|¦Û°Ê§ó·s±²¶b¤W¾ÞÁa±ìªº¦ì¸m¡A¦ý¬Oµøµ¡¤¤¤u§@°Ïªº¤º®e¥²¶·µ{¦¡¦Û¦æ§ó·s¡C
©³¤U¬Oì©lµ{¦¡¡AViewYUNA.ASM¡Aªº¤º®e¡G
.386
.model flat,stdcall
option casemap:none
IDM_EXIT equ 4000
include windows.inc
include user32.inc
include gdi32.inc
include kernel32.inc
includelib user32.lib
includelib gdi32.lib
includelib kernel32.lib
WndProc proto :HWND,:UINT,:WPARAM,:LPARAM
;***********************************************************
.DATA
hMenu HMENU ?
hInstance HINSTANCE ?
hwnd HWND ?
hBitmap dd ? ;022 ¦ì¤¸¹Ïª«¥ó¥N½X
nxClient dd ? ;023 ¤u§@°Ï¼e«×
nyClient dd ? ;024 ¤u§@°Ï°ª«×
ncx dd ? ;025 BMP ¹ÏÀɪº¼e«×
ncy dd ? ;026 BMP ¹ÏÀɪº°ª«×
iVPos dd ? ;027 ««ª½±²¶b¾ÞÁa±ì¦ì¸m
iHPos dd ? ;028 ¤ô¥±²¶b¾ÞÁa±ì¦ì¸m
iVMax dd ? ;029 ««ª½±²¶b³Ì¤j½d³ò
iHMax dd ? ;030 ¤ô¥±²¶b³Ì¤j½d³ò
ClassName db 'ViewBMPWinClass',0
AppName db 'Æ[¬Ý¦ì¤¸¹Ï game13.bmp',0
MenuName db 'VBMPMenu',0
IconName db 'BMPIcon',0
BMPName db 'VBMP',0
wc WNDCLASSEX <?>
msg MSG <?>
;***********************************************************
.CODE
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 eax,hInstance
mov wc.hInstance,eax
invoke LoadIcon,hInstance,offset IconName
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
mov wc.hbrBackground,COLOR_WINDOW+1
invoke LoadMenu,hInstance,offset MenuName
mov hMenu,eax
mov wc.lpszClassName,offset ClassName
invoke RegisterClassEx,offset wc
invoke CreateWindowEx,NULL,offset ClassName,offset \
AppName,WS_VSCROLL or WS_HSCROLL or \ ;058 ᨾ
WS_OVERLAPPEDWINDOW,0,0,400,400,0,hMenu,hInstance,NULL
mov hwnd,eax
invoke ShowWindow,hwnd,SW_MAXIMIZE ;061 ³Ì¤j¤Æ
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
;-----------------------------------------------------------
WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
local bitmap:BITMAP ;073 ¦s©ñ¦ì¤¸¹ÏÄÝ©Ê
local ps:PAINTSTRUCT
local hdc,hdcMem:HDC
.if uMsg==WM_CREATE
invoke LoadBitmap,hInstance,offset BMPName ;078 ¸ü¤J¦ì¤¸¹Ï
mov hBitmap,eax
invoke GetObject,hBitmap,sizeof BITMAP,addr bitmap ;080 ¦ì¤¸¹ÏÄÝ©Ê
mov ecx,bitmap.bmWidth ;081 ¦ì¤¸¹Ï¼e«×¦s©ó ncx
mov ncx,ecx
mov ecx,bitmap.bmHeight ;083 ¦ì¤¸¹Ï°ª«×¦s©ó ncy
mov ncy,ecx
.elseif uMsg==WM_SIZE
mov eax,lParam ;087 ¨ú±o¤u§@°Ï¤j¤p¡AECX=°ª«×¡AEAX=¼e«×
mov ecx,eax
and eax,0ffffh
shr ecx,16
mov nxClient,eax
mov nyClient,ecx
mov ecx,ncx ;093 pºâ¤ô¥±²¶b³Ì¤j½d³ò
sub ecx,eax
shr ecx,3
mov iHMax,ecx
invoke SetScrollRange,hWnd,SB_HORZ,0,ecx,TRUE
mov eax,ncy ;098 pºâ««ª½±²¶b³Ì¤j½d³ò
sub eax,nyClient
shr eax,3
mov iVMax,eax
invoke SetScrollRange,hWnd,SB_VERT,0,eax,TRUE
sub edx,edx
mov iVPos,edx
mov iHPos,edx
.elseif uMsg==WM_PAINT
invoke BeginPaint,hWnd,addr ps ;108 ¨ú±oµøµ¡ªº³]³Æ¤º®e
mov hdc,eax
invoke CreateCompatibleDC,eax ;110 «Ø¥ß¬Û¦Pªº³]³Æ¤º®e§@¬°¨Ó·½
mov hdcMem,eax
invoke SelectObject,hdcMem,hBitmap ;112 ¿ï©w¨Ó·½³]³Æ¤º®eªº¦ì¤¸¹Ï
mov eax,iVPos ;113 ¦¹¥|¦æpºâÅã¥ÜÂI°}¹Ïªº°_ÂI
shl eax,3
mov ecx,iHPos
shl ecx,3
invoke BitBlt,hdc,0,0,nxClient,nyClient,hdcMem,\
ecx,eax,SRCCOPY ;118 ¶Ç°e¦ì¤¸¹Ï¨ìµøµ¡ªº³]³Æ¤º®e
invoke DeleteDC,hdcMem ;119 ÄÀ©ñ¨Ó·½³]³Æ¤º®e
invoke EndPaint,hWnd,addr ps ;120 ÄÀ©ñµøµ¡³]³Æ¤º®e
.elseif uMsg==WM_HSCROLL
mov eax,wParam
and eax,0ffffh
.if ax==SB_LEFT
go_lft: mov iHPos,0
.elseif ax==SB_RIGHT
go_rgt: mov eax,iHMax
mov iHPos,eax
.elseif (ax==SB_LINERIGHT)||(ax==SB_PAGERIGHT)
inc iHPos ;130 ³B²z SB_LINERIGHT¡BSB_PAGERIGHT
mov eax,iHPos
cmp eax,iHMax
jg go_rgt
.elseif (ax==SB_LINELEFT)||(ax==SB_PAGELEFT)
dec iHPos
jl go_lft
.elseif ax==SB_THUMBTRACK
mov eax,wParam
shr eax,16
mov iHPos,eax
.endif
invoke SetScrollPos,hWnd,SB_HORZ,iHPos,TRUE
invoke InvalidateRect,hWnd,NULL,FALSE
.elseif uMsg==WM_VSCROLL ;145 ³B²z WM_VSCROLL
mov eax,wParam
and eax,0ffffh
.if ax==SB_TOP
go_top: mov iVPos,0
.elseif ax==SB_BOTTOM
go_btm: mov eax,iVMax
mov iVPos,eax
.elseif (ax==SB_LINEDOWN)||(ax==SB_PAGEDOWN)
inc iVPos
mov eax,iVPos
cmp eax,iVMax
jg go_btm
.elseif (ax==SB_LINEUP)||(ax==SB_PAGEUP)
dec iVPos
jl go_top
.elseif ax==SB_THUMBTRACK
mov eax,wParam
shr eax,16
mov iVPos,eax
.endif
invoke SetScrollPos,hWnd,SB_VERT,iVPos,TRUE
invoke InvalidateRect,hWnd,NULL,FALSE
.elseif uMsg==WM_COMMAND
mov eax,wParam
;¥H¤U¬O¨Ï¥ÎªÌÂI¿ï¿ï³æ
.if lParam==0
.if ax==IDM_EXIT
jmp exit
.endif
.endif
.elseif uMsg==WM_CLOSE
exit: invoke DestroyWindow,hWnd
.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
©³¤U¬O¸ê·½´yzÀÉ¡AViewYUNA.RC¡AÀɪº¤º®e¡G
#include "c:\masm32\include\resource.h" #define IDM_EXIT 4000 VBMPMenu MENU BEGIN MENUITEM "Â÷¶}(&X)",IDM_EXIT END BMPIcon ICON EYE.ICO VBMP BITMAP game13.bmp
©³¤U¬O makefile ÀÉ¡AViewYUNA.MAK¡Aªº¤º®e¡G
ALL:ViewYUNA.EXE ViewYUNA.EXE : ViewYUNA.ASM ViewYUNA.RES ML /coff ViewYUNA.ASM /link ViewYUNA.RES ViewYUNA.RES : ViewYUNA.RC EYE.ICO game13.bmp RC ViewYUNA.RC
nÅã¥Ü¦ì¤¸¹Ï¡A·íµM¥²¶·¥ýª¾¹D³o±i¹Ï¦³¦h¤j¡A©Ò¥H¤p¤ì°¸¦b³B²z WM_CREATE °T®§®É¡A´N¨ú±o¦ì¤¸¹Ï¤j¤p¡CWin32 API¡AGetObject ¥i¥H°µ³o¥ó¨Æ¡C
GetObject ¥i¥H¨ú±o¹Ï§Îª«¥óªºÄݩʸê®Æ¡A³o¨Ç¹Ï§Îª«¥ó¥]¬A¦ì¤¸¹Ï ( Bitmap )¡Bµ§¨ê ( Brush )¡B¦r«¬ ( Font )¡Bµeµ§ ( Pen ) µ¥µ¥¡Cº¥ý¨Ó¬Ý¬Ý GetObject ªºì«¬¡G
int GetObject( HGDIOBJ hgdiobj, // handle to graphics object of interest int cbBuffer, // size of buffer for object information LPVOID lpvObject // pointer to buffer for object information );
hgdiobj ¬On¨ú±oÄݩʸê®Æªº¹Ï§Îª«¥ó¥N½X¡CcbBuffer ¬O³o¨ÇÄݩʸê®Æªº¤j¤p¡A¥¦·|¨Ì¹Ï§Îª«¥ó¡Bª©¥»¤£¦P¦Ó§ïÅÜ¡ClpvObject °Ñ¼Æ«ü¦V¤@Óµ²ºcÅé¦ì§}¡A¸Óµ²ºcÅé«K¬O¦s©ñ©ÒÀò±oªºÄݩʸê®Æ¡C¦P¼Ëªº¡A¨Ì¹Ï§Îª«¥ó¤£¦P¡AlpvObject ©Ò«ü¦Vªºµ²ºcÅé¦WºÙ¤]·|¤£¦P¡A½Ð°Ñ¦Ò¤Uªí¡G
hgdiobj Ãþ«¬ | lpvObject |
HBITMAP | BITMAP |
HPEN | LOGPEN |
HBRUSH | LOGBRUSH |
HFONT | LOGFONT |
¦¹³B¡A¤p¤ì°¸¥u¤¶²Ð BITMAP µ²ºcÅé¡C¨äÄæ¦ì¬O¡G
BITMAP STRUCT bmType DWORD ? bmWidth DWORD ? bmHeight DWORD ? bmWidthBytes DWORD ? bmPlanes DWORD ? bmBitsPixel DWORD ? bmBits DWORD ? BITMAP ENDS
bmType ¬O¦ì¤¸¹ÏÃþ«¬¡AÀ³¸Ó¬° 0¡CbmWidth¡BbmHeight ¤À§O¬O¦ì¤¸¹Ï¼e«×¡Bªø«×¡A¥HÂI¬°³æ¦ì¡CbmWidthBytes ¬O¨C¤@¦C§t¦h¤Ö¦ì¤¸²Õ¡CbmPlanes ¬OÃC¦â¥± ( color planes )¡CbmBitsPixel¬O¨C¤@ÂI¥H¦h¤Ö¦ì¤¸ªí¥Ü¡CbmBits ¬O¤@Ó«ü¼Ð¡C¦]¦¹¦bµ{¦¡²Ä 80 ¦æ¡A¤]´N¬O³B²z WM_CREATE °T®§®É¡A©I¥s GetObject¡A¨Ã¦b²Ä¤TӰѼÆùØ«ü©wµ²ºcÅéÅÜ¼Æ bitmap ¦ì§}¡C³o¼Ë¤@¨Ó¡A©I¥s§¹¦¨«á¡A¦b³oÓµ²ºcÅéùØ´N·|¦³¦ì¤¸¹Ïªº¼e«×¡B°ª«×¤F¡C¤À§O¦s¦bÅÜ¼Æ ncx¡Bncy ùØ¡C
°£¤F¨ú±o¦ì¤¸¹Ï¤j¤p¥~¡AÁÙ±oª¾¹Dµøµ¡¤u§@°Ï ( client area ) ¤j¤p¡A¤~¯à¨M©wnÅã¥Ü¨º¤@³¡¥÷ªº¦ì¤¸¹Ï¡C·í¨t²Î·s«Ø¥ßµøµ¡®É¡A©Î¨Ï¥ÎªÌ¥H·Æ¹«©ì¦íµøµ¡Ãä®Ø²¾°Ê¡A©ÎªÌ«ö¼ÐÃDÄæ¥kÃ䪺³Ì¤j¤Æ«ö¶s©Î³Ì¤p¤Æ«ö¶s®É¡A³£·|²£¥Í WM_SIZE¡Aªí¬Oµøµ¡¤j¤p§ïÅܤF¡A¦¹®É wParam ¤º¬Oµøµ¡¦]¦ó§ïÅܤj¤p¡A¥i¥H¬O
wParam | »¡¡@¡@©ú |
SIZE_MAXIMIZED | ¨Ï¥ÎªÌ«ö¤U³Ì¤j¤Æ«ö¶s |
SIZE_MINIMIZED | ¨Ï¥ÎªÌ«ö¤U³Ì¤p¤Æ«ö¶s |
SIZE_RESTORED | ¨Ï¥ÎªÌ«ö¤U«ì´_ìµøµ¡¤j¤pªº«ö¶s |
lParam ¤¤¸û§Cªº¤Q¤»¦ì¤¸¬O¤u§@°Ïªº¼e«×¡A¸û°ªªº¤Q¤»¦ì¤¸¬O¤u§@°Ïªº°ª«×¡Cµ{¦¡²Ä 91¡B92 ¦æ¡A¤À§O§â¤u§@°Ïªº¼e«×¡B°ª«×¦s¤J nxClient¡BnyClient ÅܼÆùØ¡C
µ{¦¡²Ä 93 ¦æ¶}©lpºâ¤ô¥±²¶b¦³´XÓ¦ì¸m¡C¤p¤ì°¸¬O¥H¨C«ö¤@¦¸±²¶bªº·Æ°Ê±ì©Î½bÀY¡A«K²¾°Ê 8 ÓÂI¡A¦Ó game13.bmp ¦ì¤¸¹Ï¤ñ¤u§@°Ï¤j ( ¤p¤ì°¸ªº¹q¸£¿Ã¹õ³]¦¨ 1024*768¡A¦©¥h¼ÐÃDÄæ¡BÃä®Øµ¥µ¥¡A¹Ï¤ù¤ñ¤u§@°Ï¤j¡C©Ò¥H ¦pªG§A¿Ã¹õ¤ñ 1024*768 ¤jªº¸Ü¡A¥i¯à·|¥X¿ù¡A³oÂI¤p¤ì°¸¼g³oÓµ{¦¡®É¡A˨S¦³¦Ò¼{¨ì¡C )¡A¦]¦¹¦ì¤¸¹Ï¦©¥h¤u§@°Ïªº¤j¤p¡A¦A¤À¦¨¨Cµ¥¤À 8 ÂI¡A©Ò±o¨ìªº°Ó´N¬O±²¶b¾ÞÁa±ì¥i²¾°Êªº¦ì¸m¡C
Á|¨Ò¨Ó»¡¡Agame13.bmp °ª 768 ÂI¡A¦Ó¤u§@°Ï°ª 680 ÂI¡A©Ò¥Hµøµ¡¤W¥u¯àÅã¥Ü 680 ÂI°ªªº¦ì¤¸¹Ï¡A¦b¤u§@°Ï¥~ªº 88 ÂI´NµLªkÅã¥Ü¤F¡C½Ð°Ñ¦Ò¤U¹Ï¡A¥Õ¦â¯x§Î©Ò³ò°_¨Óªº°Ï°ì°²³]¬O¤u§@°Ïªº½d³ò¡A¹Ï¤ù°ª«×¦©¥h¤u§@°Ï°ª«×¦A°£¥H 8¡A´N¥i±o¨ì±²¶bÀ³¤À¦¨´Xµ¥¤À¡C
¤p¤ì°¸¥H¨C¦¸¦V¤W±²©Î¦V¤U±²°Ê 8 ÂI¡A¦]¦¹¾ÞÁa±ì¦³ 11 Ó¦ì¸m¡A¦A¥[¤W¤@¶}©l³Ì¤W¤èªº¦ì¸m¡A¦@¦³ 12 Ó¦ì¸m¡A¤À§O¥H 0¡B1¡B2¡B3¡B4¡K¡K11 ªí¥Ü³o 12 Ó¦ì¸m¡C³o¬Oµ{¦¡²Ä 98 ¨ì 101 ¦æ©Ò§@ªº¨Æ±¡¡C
¤p¤ì°¸§â°ª«×ªº³Ì¤j¦ì¸m¦s¦b iVMax ÅܼƤ¤¡A¦Ó§â¾ÞÁa±ì²{¦b¦ì¸m¦s¦bÅÜ¼Æ iVPos ÅܼÆùØ¡A·í¨Ï¥ÎªÌ¨C¦V¤U²¾°Ê±²¶b¾ÞÁa±ì¤@¦¸®É¡AiVPos «K¼W¥[¤@¡AµM«á¦AÀˬd iVPos ¬O§_¤j©ó iVMax¡AY¤j©ó«h¨Ï iVPos µ¥©ó iVMax¡C¦P¼Ë¦a¡AY¨Ï¥ÎªÌ¨C¦V¤W²¾°Ê±²¶b¾ÞÁa±ì¤@¦¸®É¡AiVPos «K´î¤@¡AµM«á¦AÀˬd iVPos ¬O§_¤p©ó 0¡AY¤p©ó«h¨Ï iVPos «ì´_¬° 0¡C³o¼Ë´N¯à¨Ï¾ÞÁa±ì¦b 0¡ã11 ªº¦ì¸m¤W¤F¡C§A¥i¥H°Ñ¦Òµ{¦¡²Ä 145 ¦æ¡A³B²z¾ãÓ WM_HSCROLL °T®§ªº¤è¦¡¡C
¦Ó³B²z WM_VSCROLL ¤]¬OÃþ¦ü¡A´N¤£¦h»¡¤F¡C¤U¦¸±N¤¶²Ðª½±µ¥Ñ BMP ÀÉ®×Åã¥Ü¹Ï¤ù¡A¤£¦A§â BMP »s§@¦¨¸ê·½¡A§AÀ³¸Ó·|µo²{³o¼Ë°µ¦¨ªºÀɮ׫ܤj¡A¤£²Å¦X²Õ¦X»y¨¥ªºÀuÂI¡C