Ch 14 Åã¥Ü BMP ÀÉ (2)

¤W¤@³¹¡A¤p¤ì°¸¤¶²Ð¤F§â BMP ÀÉ®×»s§@¦¨ BITMAP ¸ê·½¦A±N¥LÅã¥Ü©óµøµ¡ªº¤èªk¡A¦ý¬OÃø¹D¨C¦¸Åã¥ÜÀɮ׳£­n§â BMP »s§@¦¨¸ê·½¤~¯àÅã¥Ü¶Ü¡H·íµM¤£¬O¡A±z¥u­n¥Î¹L ACDSee µ¥¨q¹Ï³nÅé´Nª¾¹D¤F¡C©Ò¥H¡A³o¤@³¹±N§ó¶i¤@¨B¡Aª½±µÅª¨ú BMP ÀɮרÃÅã¥Ü©ó¤u§@°Ï ( client area ) ¤º¡C

­n¹F¨ì¤W­z¥Øªº¡A©Ò¨Ï¥Îªº¤èªk»P«e¤@³¹¹p¦P¡C³£¦b³B²z WM_PAINT °T®§®É¡A¥ý¥H CreateCompatibleDC API «Ø¥ß¤@­Ó»Pµøµ¡¬Û¦Pªº³]³Æ¤º®e¡AºÙ¬°°O¾ÐÅé³]³Æ¤º®e¡A¦A§â³o­Ó°O¾ÐÅé³]³Æ¤º®e¤º¤§¸ê®Æ¡A¥H BitBlt API ¶Çµ¹µøµ¡³]³Æ¤º®e§Y¥i¡C¦ý°ÝÃD¨Ó¤F¡A¦b°O¾ÐÅé³]³Æ¤º®eªº¸ê®Æ¬O¤£¬O´N¬O BMP Àɤºªº¸ê®Æ¡A¥¦­Ì¬O¤£¬O¤@¼Ò¤@¼Ë©O¡H

«Ü©êºp¡Aµª®×¬O¥¦­Ì¨Ã¤£¤@¼Ë¡C¨Æ¹ê¤W¡A¦s¦bºÏºÐ¤W­±ªº BMP Àɮ׬O¤@ºØ»P¸Ë¸mµLÃöªº¹Ï¤ùÀÉ ( device-independent bitmap¡A²ºÙ DIB )¡A©Ò¿×»P¸Ë¸mµLÃöªº·N«ä¬O»¡¡A³oºØÀɮפ£ºÞ¦b¨º¤@ºØ¾÷¾¹¤W©ÒÅã¥Ü¥XªºÃC¦â³£¬O¤@¼Ëªº¡A³o¬O¦]¬° DIB ¤º§t¦³½Õ¦â½L¡C¦Ó¦s¦b¸ê·½ùتºÂI°}¹Ï ( ¦p«e¤@³¹ªº VBMP BITMAP game13.bmp ) ¬O¤@ºØ»P¸Ë¸m¬ÛÃöªºÂI°}¹Ï ( device-dependent bitmap¡A²ºÙ DDB )¡A³oºØ¹Ï¤ù¨S¦³°O¿ýÃC¦âªº½Õ¦â½L¡A©Ò¥H¦b¤£¦P¾÷¾¹¡B¦Lªí¾÷¤W¬Æ¦Ü¤£¦P³]³Æ¤º®e¤W©ÒÅã¥Üªº¹Ï®×ÃC¦â·|¤£¦P¡C¨º»ò±z¥i¯à·|°Ý¡A³o¼Ëªº¸Ü¡ADDB ÁÙ¦³¤°»ò¥Î³~©O¡H·íµM¦³Åo¡A¦]¬°¥¦­Ì¨S¦³½Õ¦â½L¡A©Ò¥H¦û¥Î¸û¤pªºªÅ¶¡³B²z°_¨Ó¤]¸û§Ö¡A¨Ò¦p¿Ã¹õ¤Wªº·Æ¹««ü¼Ð¡A´N¬O¦s©ñ¦b°O¾ÐÅ餤ªº DDB¡C

¨º»ò§Ú­Ì«ç»ò§â»P¸Ë¸mµLÃöªº BMP ÀÉ®×Åܦ¨¥i¥H³Q¨t²Î©Ò§Ö³t³B²zªº DDB ©O¡HWin32 ¨t²Î´£¨Ñ¤@­Ó API¡ACreateDIBitmap¡A¥¦¥i¥H§â DIB Âà´«¦¨ DDB¡Aµy«á¤p¤ì°¸¦A²Ó»¡³o­Ó API¡A²{¦b¡A¤p¤ì°¸¾ã²z¤W­±¤º®eÅܦ¨¤U­±ªº¨BÆJ¡G

  1. §Q¥Î GetOpenFileName ³q¥Î¹ï¸Ü²°¡A¿ï¾Ü¤@­Ó BMP ÀɮסAµM«á¥Î CreateFile API ¶}±Ò³o­ÓÀɮסA±µ¤U¨Ó¥Î GetFileSize API ¨ú±oÀɮפj¤p¡C
  2. ¨Ì¾ÚÀɮפj¤p¡A°t¸m¾A·í°O¾ÐÅé°Ï¶ô¡C
  3. ¥Î ReadFile API §â¾ã­Ó BMP ÀÉŪ¤J©Ò°t¸mªº°O¾ÐÅé°Ï¶ô¡C
  4. ¨Ì¾Ú BMP Àɪº¸ê®Æ¡A³]©wµøµ¡¤j¤p¡A¥HÅã¥Ü¾ã±i¹Ï¤ù¡C
  5. ¨ú±oµøµ¡ªº³]³Æ¤º®e ( hdc )¡A¨Ã¦A«Ø¥ß¤@­Ó¬Û¦Pªº°O¾ÐÅé³]³Æ¤º®e ( hdcMem )¡CµM«á¥Î CreateDIBitmap API §âŪ¤J°O¾ÐÅ餺ªº BMP ¸ê®ÆÂà´«¦¨»P¸Ë¸m¬Û¨Ìªº DDB ÂI°}¹Ï¡C
  6. §Q¥Î SelectObject API §â³o­Ó DDB ¹Ï¸ü¤J hdcMem ¤¤¡C¦A¥Î BitBlt API §â hdcMem ªº¦ì¤¸¹Ï¶Ç°e¨ì hdc ¤W¡C
  7. ³Ì«áÄÀ©ñ hdc¡BhdcMem¡BDDB¡C

³Ì«á³o¤T­Ó¨BÆJ¬OÅã¥Ü BMP ÀɪºÃöÁä¡A±z·|µo²{´X¥G»P«e¤@³¹ªº¨BÆJÃþ¦ü¡A©Ò®t§Oªº¥u¬O¦b©ó¥²¶·¦h¤@¹D¤âÄò¨Ó«Ø¥ß»PÂI°}¹Ï¸ê·½¤@¼Ëªº DDB ¹Ï¡A¨ä¾l¬Ò¤£ÅÜ¡C©³¤U¤p¤ì°¸´N§â«e­±¥¼´¿´£¹Lªº¥DÃD¡G°t¸m°O¾ÐÅé¡BBMP ¹ÏÀɵ²ºc¡B³]©wµøµ¡¤j¤p¡B«Ø¥ß DDB ¹Ï¤ùµy§@¸ÑÄÀ¡A¨º»ò´N±q°t¸m°O¾ÐÅé°Ï¶ô¶}©l§a¡I


°t¸m°O¾ÐÅé

¤HºÉ¬Òª¾¡ABMP Àɮ׫ܤj¡A¨º»ò¼¶¼gÅã¥Ü BMP ¹Ï¤ùªºµ{¦¡®É¡A¬O§_­n¦bµ{¦¡½X¤¤¹w¯d¤@¶ô°O¾ÐÅé¨Ó®e¯Ç±N­nŪ¤Jªº¹Ï¤ù¸ê®Æ©O¡H³o¼Ë°µ¤]¬O¤@ºØ¤èªk¡A¦ý¤£¬O³Ì¦nªº¤èªk¡C¤@¨Ó¡A¦¹®É©|¤£ª¾¨Ï¥ÎªÌ·|¿ï¾ÜªºÀɮר쩳¦³¦h¤j¡A­YªÅ¶¡¤£¨¬´N«Ü³Â·Ð¡C¤G¨Ó¹w¯dªºªÅ¶¡¥²µM­n«Ü¤j¡A·|¨Ïµ{¦¡Åܱo«Ü¤j¡C

©Ò¥H¸û¦nªº¤èªk¬Oµ¥¨ì¨Ï¥ÎªÌ¿ï©w¦nÀɮ׫á¡A¦A¨Ì»Ý­n¨M©w­n¥Î¦h¤Ö°O¾ÐÅé¨Ó®e¯Ç¦ì¤¸¹Ï¡C³o¼Ë´N¬O©Ò¿×ªº°ÊºA°t¸m°O¾ÐÅé¡C

GlobalAlloc API¡G°t¸m°O¾ÐÅé°Ï¶ô

¦b Win32 ¨t²ÎùØ¡A¥i¥Î GlobalAlloc °t¸m°O¾ÐÅé¡A¨ä­ì«¬¦p¤U¡G

HGLOBAL GlobalAlloc(
    UINT    uFlags  // object allocation attributes 
    DWORD   dwBytes // number of bytes to allocate  
   );

dwBytes ¬O­n°t¸mªº°O¾ÐÅé¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡CuFlags ¬O«ü©w°t¸m°O¾ÐÅ骺¤è¦¡¡A¥i¥H¦³¤U­±´XºØ¿ï¾Ü¡G

  1. GMEM_FIXED¡G°t¸m©T©wªº°O¾ÐÅé¡C¤£¥i©M GMEM_MOVEABLE ©Î GMEM_DISCARDABLE ²V¦X¨Ï¥Î¡C¥H GMEM_FIXED ¤è¦¡¡A©I¥s GlobalAlloc «á¡AGlobalAlloc ·|¦b EAX ¶Ç¦^©Ò°t¸mªº°O¾ÐÅé¦ì§}¡C

  2. GMEM_MOVEABLE¡G°t¸m¥i²¾°Êªº°O¾ÐÅé¡C¦b¥H«e Win3.1 ªº®É¥N¡A¹q¸£©Ò¸Ë°tªº°O¾ÐÅé ( DRAM ) «Ü¤Ö¡A¤j¬ù¥u¦³ 8¡B16MB ¥ª¥k¡A©Ò¥H°O¾ÐÅ骺¨Ï¥Î»Ý­n¤ç¤ç­p¸û¡C¦Ó¹q¸£¶}¾÷«á¸g¹L¦h¦¸ªº°õ¦æµ{¦¡¡BÃö³¬µ{¦¡¡A·|¯d¤U³\¦h¹s¸Hªº°O¾ÐÅéªÅ¶¡¡A³o¼Ë·|³y¦¨®ö¶O¡C­Y¥Î GMEM_MOVEABLE ¤è¦¡©Ò°t¸mªº°O¾ÐÅé¡A¨t²Î·|¦Û°Ê·h²¾°O¾ÐÅé°Ï¶ô¡A¨Ï³\¦h¹s¸H¥¼¥Îªº°O¾ÐÅ鶰¤¤°_¨Ó¡A§Î¦¨¤j¶ô¥¼¨Ï¥Îªº°O¾ÐÅé¨Ñµ{¦¡¨Ï¥Î¡C
    ³z¹L³oºØ¤è¦¡©Ò°t¸mªº°O¾ÐÅé«K·|ÀH®É¶¡¦Ó²¾°Ê°O¾ÐÅé¦ì§}¡A¨º§Ú­Ì«ç»ò¨Ï¥Î©O¡H·L³n©Ò´£¨Ñªº¤èªk¬O¡A³z¹L GMEM_MOVEABLE ©I¥s GlobalAlloc «á¡A©Ò¶Ç¦^ªº­È¬O¤@­Ó°O¾ÐÅ骫¥ó ( memory object ) ªº¥N½X ( ©Î°O¾ÐÅé°Ï¶ô¥N½X )¡A¨Ã«D¦ì§}¡A·í­n¦s¨ú³o¶ô°O¾ÐÅ骫¥óªº¸ê®Æ®É¡A¥²¶·¥ý©I¥s GlobalLock API Âê©w¦¹°O¾ÐÅ骫¥ó¡A­Y¦¨¥\¦¹ API ·|¶Ç¦^¸Ó°O¾ÐÅéªÅ¶¡ªº¦ì§}¡A­Y¥¢±Ñ«h¶Ç¦^ NULL¡C¦Óµ{¦¡´N¨Ì¾Ú¶Ç¦^ªº¦ì§}¦s¨ú°O¾ÐÅé¡C

  3. GMEM_DISCARDABLE¡G°t¸m¥i¼o±óªº°O¾ÐÅéªÅ¶¡¡C¨t²Î·|¨Ì¾Ú»Ý­n¡A¨Ò¦p°O¾ÐÅ餣°÷¥Î®É¡A¨t²Î·|§â³oºØ°O¾ÐÅé¼g¤JµwºÐ¨Ã¼È®É§R°£¡Aµ¥¨ì­n¥Î¨ì®É¦A¥ÑµwºÐŪ¦^¨Ó¡C°t¸m³oºØ°O¾ÐÅ鶷©M GMEM_MOVEABLE °t¦X¨Ï¥Î¡C

  4. GMEM_ZEROINIT¡G©Ò°t¸mªº°O¾ÐÅ駡¥ýÂk¹s¡C

  5. GPTR¡G¬Û·í©ó GMEM_FIXED ©M GMEM_ZEROINIT ¦X¥Î¡CGPTR ªº PTR ¬O«ü¡y«ü¼Ð¡z¦Ó¨¥¡A¥ç§Yªð¦^­È¬O©Ò°t¸m°O¾ÐÅ骺¦ì§}¡C

  6. GHND¡G¬Û·í©ó GMEM_MOVEABLE ©M GMEM_ZEROINIT ¦X¥Î¡CGHND ªº HND ¬O«ü¡yHANDLE¡z¦Ó¨¥¡A¥ç§Yªð¦^­È¬°°O¾ÐÅ骫¥ó¥N½X¡C
  7. GMEM_DDESHARE¡G»P GMEM_SHARE ¬Û¦P¡A

GlobalFree API

·í°t¸mªº°O¾ÐÅ餣¦A¥Î©Îµ{¦¡µ²§ô®É¡A¥i¥H©I¥s GlobalFree ÄÀ©ñ°t¸m¹Lªº°O¾ÐÅé¡CGlobalFree ­ì«¬¬°¡G

HGLOBAL GlobalFree(
    HGLOBAL hMem    // handle to the global memory object 
   );

hMem ¬O°O¾ÐÅ骫¥ó¥N½X ( ¥H GMEM_MOVEABLE °t¸m°O¾ÐÅé ) ©ÎªÌ¬O°O¾ÐÅé¦ì§} ( ¥H GMEM_FIXED °t¸m°O¾ÐÅé )¡C¦pªG¦¹ API °õ¦æ¦¨¥\¡A¶Ç¦^ NULL¡F¦pªG°õ¦æ¥¢±Ñ¡A¶Ç¦^­ì¨Óªº°O¾ÐÅ骫¥ó¥N½X©Î¦ì§}¡C


BMP ¹ÏÀɪºµ²ºc

BMP ¹Ï¤ùÀɬO¤@ºØ»P¸Ë¸mµLÃöªº¹ÏÀÉ (DIB¡Adevice-independent bitmap )¡A·N«ä¬O¦bÀɮפº¥]§t¤FÃC¦âªº¸ê°T¡A©Ò¥H¦b¤£¦PÅã¥Ü¾¹¤§¤U¡A©ÒÅã¥Üªºµ²ªG¤´µM¬Û¦P¡CBMP ¦ì¤¸¹Ï¦³¨âºØ®æ¦¡¡A¤@ºØ¬O OS/2 ®æ¦¡¡A¥t¤@ºØ¬O WINDOWS ®æ¦¡ ( µù¤@ )¡COS/2 ®æ¦¡²{¦b¤w¸g¤ñ¸û¤Ö¥Î¤F¡A©Ò¥H³o¤@³¹ùØ¥ý½Íªº¬O Windows ®æ¦¡¡AOS/2 ®æ¦¡ªº BMP ¹ÏÀɦbµù¤G¡C¤@­Ó BMP ÀÉ®×¥]§t¤F¥|³¡¥÷¡GBITMAPFILEHEADER¡BBITMAPINFOHEADER¡BRGBQUAD ¥H¤Î¦ì¤¸¸ê®Æ¡C¤]¦³¤H§â BITMAPINFOHEADER¡BRGBQUAD ³o¨â³¡¥÷¦XºÙ¬° BITMAPINFO¡C§Ú­Ì´N±q BITMAPFILEHEADER ¶}©l§a¡C

²Ä¤@³¡¥÷¬O BITMAPFILEHEADER¡A¥¦¬O¤@­Óªø 14 ¦ì¤¸²Õªºµ²ºcÅé¡A¨ä©w¸q¬O¡G

BITMAPFILEHEADER    STRUC
bfType      DW      4D42H
bfSize      DD      ?
bfReserved1 DW      0
bfReserved2 DW      0
bfOffBits   DD      ?
BITMAPFILEHEADER    ENDS

BITMAPFILEHEADER ªº²Ä¤@­ÓÄæ¦ì¬Oªø¨â­Ó¦ì¤¸²Õ¡A¨ä·N¸q¬° ASCII ½Xªº¡yBM¡z¡A¥¦¥Nªí BMP ÀɪºÃѧO¦r¡A°²¦p¬Y­ÓÀɮתº«e¨â­Ó¦ì¤¸²Õ¬O¡yBM¡zªº¸Ü¡A¨º´N¦³¥i¯à¬O BMP ¦ì¤¸¹Ï¡G¦pªG¤£¬O¡yBM¡z¡A¨º´N¤£¬O BMP ¦ì¤¸¹Ï¡CbfSize ¬O³o­Ó¦ì¤¸¹ÏªºÀɮתø«×¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C±µ¤U¨Óªº¨â­ÓÄæ¦ì¬O«O¯dÄæ¦ì¡A¥²©w¬° 0¡C³Ì«á¤@­ÓÄæ¦ì bfOffBits ¬O¦ì¤¸¸ê®Æ¬Û¹ï©óÀÉ®×ÀYªº°¾²¾¶q¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C

±µ¤U¨Ó²Ä¤G³¡¥÷¬O BITMAPINFOHEADER µ²ºcÅé¡A¨ä²Õ¦¨Äæ¦ì¬O¡G

BITMAPINFOHEADER    STRUC  
biSize              DD      ?
biWidth             DD      ?
biHeight            DD      ?
biPlanes            DW      1
biBitCount          DW      ?
biCompression       DD      ?
biSizeImage         DD      ?
biXPelsPerMeter     DD      ?
biYPelsPerMeter     DD      ?
biClrUsed           DD      ?
biClrImportant      DD      ?
BITMAPINFOHEADER    ENDS

biSize ¬O³o­Óµ²ºcÅ骺ªø«×¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡A¹ï Windows ®æ¦¡¦Ó¨¥¡A¨ä¤j¤p¬° 28h¡F¹ï OS/2 ®æ¦¡¦Ó¨¥¡A¨ä¤j¤p¬O 0Ch ( ½Ð°Ñ¾\µù¤G )¡CbiWidth¡BbiHeight ¤À§Oªí¥Ü¦ì¤¸¹Ïªº¼e«×©Mªø«×¡A¥HÂI¬°³æ¦ì¡CbiHeight ¦³¥²­n¥[¥H»¡©ú¡AbiHeight ¦pªG¬°¥¿­È¡Aªí¥Ü³o±i¦ì¤¸¹Ïªº¸ê®Æ¥Ñ¥ª¤U¤è¶}©l¦V¥k¡A¤@ÂI¤@ÂI±Æ¦C¡A¨ì³Ì¥kÃä®É¡A¦A©¹¤W¤@¦C±Æ¡FbiHeight ¦pªG­t­È¡Aªí¥Ü³o±i¦ì¤¸¹Ïªº¸ê®Æ¥Ñ¥ª¤W¤è¶}©l¦V¥k¡A¤@ÂI¤@ÂI±Æ¦C¡A¨ì³Ì¥kÃä®É¡A¦A©¹¤U¤@¦C±Æ¡CbiPlanes ¬OÃC¦â¥­­±¼Æ¡A³o¬O¦­´ÁÅã¥Ü¥dµwÅé©|¥¼µo¹F®É¿ò¯d¤U¨Óªº¡A¦p¤µ¤w¼o±ó¤£¥Î¡A¥²¶·³]¬° 1¡C

biBitCount ªí¥Ü¨C¤@ÂI»Ý­n¥Î¦h¤Ö¦ì¤¸¡A¥u¥i¥H¬O 1¡B4¡B8¡B16¡B24 ©Î 32 ³o¨Ç¼Æ­È¡C¥¦¤ñ­ì¨Óªº OS/2 ®æ¦¡¦h¤F 16 ©M 32 ¨âºØ¡A¸Ô²Ó±¡§Î½Ð°Ñ¾\µù¤G¡C

biCompression ¬OÀ£ÁY¤è¦¡¡A³oºØÀ£ÁY¤è¦¡¬O¤£¥¢¯uªº¡A©M JPEG ¥¢¯uÀ£ÁY¤£¦P¡CbiCompression ¥i¥H¬O BI_RGB¡BBI_RLE8¡BBI_RLE4¡BBI_BITFIELDS ­È¡A¨ä¤¤ BI_RGB ¬O§¹¥þµLÀ£ÁYªº¡A¤]¬O³Ì±`¥Îªº¡CbiSizeImage ¬O BMP Àɪºªø«×¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C

biXPelsPerMeter¡BbiYPelsPerMeter ¬Oªí¥Ü³o±i¹Ïªº¸ÑªR«×¡A¥H¨C¤½¤Ø¦³¦h¤ÖÂI¡A«eªÌ¬O¼eªº¸ÑªR«×¡A«áªÌ¬O«ü°ªªº¸ÑªR«× ( ³oùتº¸ÑªR«×©M¤@¯ë¿Ã¹õªº¸ÑªR«×·N¸qµy·L¤£¦P )¡C

³Ì«á¨â­ÓÄæ¦ì biClrUsed¡BbiClrImportant ¬O·í biBitCount ¤£¬O 1¡B4¡B8¡B16¡B24 ©Î 32 ³o¨Ç¼Ð·Çªº¼Æ®É¨Ï¥Îªº¡C

²Ä¤T³¡¥÷¬O¦â±m¹ï·Óªí¡A¥¦¬O¥Ñ³\¦h¼Æ¥Ø¤£©wªº RGBQUAD µ²ºcÅé²Õ¦¨ªº¡ARGBQUAD µ²ºcÅé¦UÄæ¦ì¦p¤U¡G

RGBQUAD         STRUC
rgbBlue         db      ?
rgbGreen        db      ?
rgbRed          db      ?
rgbReserved     db      0
RGBQUAD         ENDS

RGBQUAD ªº¥\¥Î»P OS/2 ®æ¦¡ªº RGBTRIPLE ¬Û¦P¡A½Ð°Ñ¦Òµù¤G¡A¦ý¬O¦h¤F¤@­Ó«O¯d¦ì¤¸²Õ¡ArgbReserved¡A³o­Ó¦ì¤¸²Õ§¡³]¬°¹s¡A¦³¤F³o­Ó¦ì¤¸²Õ¡A¨Ï±o¦â±m¹ï·Óªí¤Wªº¨C­Ó RGBQUAD µ²ºcÅéªø«×§¡¬° 32 ¦ì¤¸¡A¥i¥H¨Ï 32 ¦ì¤¸ªº CPU ¦s¨ú®É±o¨ì¸û¦nªº®Ä²v¡C

²Ä¥|³¡¥÷¬O¦ì¤¸¸ê®Æ¡A¤]¬O¦s¦³¾ã±i¹Ï¤ùªº¹Ï®×¸ê®Æ¦s©ñ³B¡C


³]©wµøµ¡¤j¤p

³]©wµøµ¡¤j¤p¡A¥i¥H¥Î MoveWindow API¡A¥Îªk½Ð°Ñ¦Ò²Ä 11 ³¹¦³Ãö MoveWindow API ªº¥Îªk¡C¦ý­nª`·Nªº¬O MoveWindow °Ñ¼Æµøµ¡ªº°ª«×¡AnHeight¡A¬O¥]§t¤W¤U¨âÃ䪺Ãä®Ø«p«×¡B¼ÐÃDÄæ°ª«×¡B¿ï³æ°ª«×¡B¤u§@°Ï°ª«×¡Cµøµ¡ªº¼e«×¡AnWidth¡A«h¥]§t¥ª¥k¨âÃ䪺Ãä®Ø«p«×¤Î¤u§@°Ï¼e«×¡C¦Ó BMP ¹Ï¤ùªº¼e«×»P°ª«×À³«ê¦n¶ñº¡¾ã­Ó¤u§@°Ï¡A©Ò¥H©I¥s MoveWindow ®É¡A¥²¶·¥ý¨ú±o¼ÐÃDÄæ°ª«×¡B¿ï³æ°ª«×¡BÃä®Ø«p«×³o¨Ç¼Æ­È¡C³o¨Ç¸ê®Æ¥i¥Î GetSystemMetrics API Àò±o¡C

GetSystemMetrics API

GetSystemMetrics API ªº­ì«¬¬O¡G

int GetSystemMetrics(
    int   nIndex    // system metric or configuration setting to retrieve
   );

nIndex ¬O·Q­n¨ú±oªº¸ê®Æ¡A·í©I¥s GetSystemMetrics «á¡A¨t²Î·|§â³o¨Ç¸ê®Æ¦s©ó EAX ¶Ç¦^¨Ó¡CnIndex ¥i¥H¬O¤U­±³o¨Ç¼Æ­È¡G( ¤p¤ì°¸¶È¦C¥X³¡¥÷¡A¨ä¾l½Ð°Ñ¦Ò MSDN )

¦ì¤¸­È »¡¡@¡@¡@©ú
SM_CXSCREEN
SM_CYSCREEN
¿Ã¹õªº¼e«×»P°ª«×¡A¥HÂI¬°³æ¦ì¡C
SM_CXFULLSCREEN
SM_CYFULLSCREEN
µøµ¡©ñ¤j¬°¥þ¿Ã¹õ®É¡A¤u§@°Ïªº³Ì¤j¼e«×»P°ª«×¡A¥HÂI¬°³æ¦ì¡C³o®É°ª«×¤£·|¬O¿Ã¹õ¸ÑªR«×ªº°ª«×¡A¥²¶·¦A¦©°£¤u§@¦C¡B¼ÐÃDÄ檺°ª«×¡C
SM_CXSIZEFRAME
SM_CYSIZEFRAME
³ò¶¦bµøµ¡©P³òªºÃä®Ø«p«×¡CSM_CXSIZEFRAME ¬O«ü¥ª¥k¨âÃä®Øªº«p«×¡ASM_CYSIZEFRAME ¬O«ü¤W¤U¨âÃä®Øªº°ª«×¡C
SM_CYCAPTION ¼ÐÃDÄæ°ª«×¡A¥HÂI¬°³æ¦ì
SM_CYMENU ¿ï³æ°ª«×¡A¥HÂI¬°³æ¦ì
SM_CMOUSEBUTTONS ·Æ¹««öÁä¼Æ¥Ø¡A­Y¬° 0¡Aªí¥Ü¨S¸Ë·Æ¹«
SM_MOUSEPRESENT ¬O§_¦w¸Ë·Æ¹«¡ATRUE ªí¥Ü¤w¦w¸Ë¡AFALSE ªí¥Ü¥¼¦w¸Ë

ÂÇ¥Ñ GetSystemMetrics API ©ÒÀò±o¼ÐÃDÄæ°ª«×¥[¤W¤W¤U¨âÃä®Ø«p«×¤§«á¡A¦A¥[¤W¹Ï¤ù°ª«×´N¬O³Ì«áªºµøµ¡°ª«×¡F¦Ó¥ª¥k¨âÃä®Øªº«p«×¦A¥[¤W¹Ï¤ù¼e«×´N¬O¤u§@°Ïªº¼e«×¤F¡C


«Ø¥ß DDB ¹Ï¤ù

CreateDIBimap API ¬O¨Ì¾Ú DIB ¹Ï¤ºªº¸ê®Æ«Ø¥ß DDB¡A¨ä­ì«¬¦p¤U¡G

HBITMAP CreateDIBitmap(
    HDC     hdc,                        // handle to device context 
    CONST   BITMAPINFOHEADER *lpbmih,   // pointer to bitmap size and format data 
    DWORD   fdwInit,                    // initialization flag 
    CONST   VOID *lpbInit,              // pointer to initialization data 
    CONST   BITMAPINFO *lpbmi,          // pointer to bitmap color-format data 
    UINT    fuUsage                     // color-data usage 
);

hdc ¬O¸Ë¸m¤º®e¡Clpbmih ¬O¤@­Ó¦ì§}«ü¼Ð¡A«ü¦V BMP ¹ÏÀɪº BITMAPINFOHEADER¡CfdwInit ¬O¤@²ÕºX¼Ð¡A«ü¥Ü§@·~¨t²Î¦p¦ó§â¦ì¤¸¸ê®ÆÅܦ¨ DDB ¹Ï¤ù¡A¥¦¥i¥H¬O¤U­±¼Æ­È¡G

¼Æ­È»¡¡@¡@©ú
CBM_INIT ¨Ì¾Ú lpbInit ©M lpbmi ©Ò«ü¤§¦ì§}¤ºªº¸ê®Æ¡A³]©w¦ì¤¸¹Ï¤§¸ê®Æ¡C
0¨t²Î¤£³]©w¦ì¤¸¹Ï¤§¸ê®Æ¡C

lpbInit ©M lpbmi ¨â°Ñ¼Æ³£¬O«ü¼Ð¡A«eªÌ«ü¦V BMP ¹ÏÀɪº¦ì¤¸¸ê®Æ¡A³o­Ó¦ì¤¸¸ê®Æ©Ò¦b¥i¥H¥Ñ bfOffBits ¨D±o¡F«áªÌ«ü¦V BMP ¹ÏÀɪº BITMAPINFO µ²ºcÅé ( BITMAPINFOHEADER ©M RGBQUAD ¨â³¡¥÷¦X°_¨ÓºÙ¬° BITMAPINFO )¡C


­ì©l½X

©³¤U´N§Q¥Î¤W­±­ì²z¡A¼¶¼g¤@­Ó¯à°÷Åý¤H±qºÏºÐ¾÷¤¤¬D¿ï¤@­Ó BMP ÀɮסAµM«á§â¥¦Åã¥Ü¦b¿Ã¹õ¤Wªºµ{¦¡¡AViewBMP.EXE¡A¥¦°õ¦æ®Éµe­±¬°¡G

«ö¤U¡y¶}±Ò¡z«ö¶s«á¡Aµe­±Åܦ¨¡G
¦pªG¨Ï¥ÎªÌ«ö¤U¡y¨ú®ø¡z«ö¶s©Î¶}±Ò¹ï¸Ü²°¥k¤W¨¤ªºÃö³¬«ö¶s¡A¨º»ò´N·|¥X²{©³¤Uªºµe­±¡G

¦n¤F¡A©³¤U¨Ó¬O ViewBMP ªº­ì©l½X¡A­º¥ý¬O ViewBMP.RC¡G

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

#define IDM_EXIT        4001
#define IDM_OPEN        4000

VBMPMenu        MENU
BEGIN
        MENUITEM        "¶}±Ò",IDM_OPEN
        MENUITEM        "Â÷¶}",IDM_EXIT
END

VBMPIcon ICON   EYE.ICO

¦Ó ViewBMP.ASM ­ì©l½X¦p¤U¡G

        .586
        .model  flat,stdcall
        option  casemap:none

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

IDM_OPEN        equ     4000
IDM_EXIT        equ     4001
MAX_FullFN      equ     260     ;017 §tºÏºÐ¾÷¡B¸ô®|¡B¥D¡B°ÆÀɦWªø«×
MAX_OnlyFN      equ     100     ;018 ¶È§t¥DÀɦW¡B°ÆÀɦW¤§ªø«×
;*************************************************
        .data
wc              WNDCLASSEX      <30h,?,?,0,0,?,?,?,?,0,offset szClassName,?>
msg             MSG             <?>
ofn             OPENFILENAME    <?>
hInstance       HINSTANCE       ?
hwnd            HWND            ?
hMenu           HMENU           ?
hFile           HFILE           ?
hGlobalMem      HGLOBAL         ?
hBitmap         HBITMAP         ?
cyNonClient     dd              0       ;030 «D¤u§@°Ï°ª«×Á`©M
cxNonClient     dd              0       ;031 «D¤u§@°Ï¼e«×Á`©M
nBMPWidth       dd              ?       ;032 BMP ¹Ïªº¼e«×
nBMPHeight      dd              ?       ;033 BMP ¹Ïªº°ª«×
nFileSize       dd              ?       ;034 BMP Àɪº¤j¤p
nReadBytes      dd              ?       ;035 ¹ê»ÚŪ¨úªº¦ì¤¸²Õ
lpCaption       dd              -1      ;036 ¶}±ÒÂÂÀɮɡA¿ù»~¦r¦êªº¦ì§}
bIfGlobal       db              0       ;037 ¬O§_´¿°t¸m°O¾ÐÅé
szFullFN        db              MAX_FullFN dup (0)        ;038 §¹¾ãÀɦW¦s©ñ³B
szDefExt        db              'BMP',0
szFNFilter      db              'ÂI°}¹Ï (*.BMP, *.DIB)',0,'*.BMP;*.DIB',0,0
szNoFile        db              '±z¨S¦³¿ï©wÀɦW¡C',0
szOpenErr       db              'Ū¨úÀɮ׿ù»~¡C',0
szNotBMP        db              '¦¹Àɮ׫D BMP ®æ¦¡¡C',0
szClassName     db              'ViewBMP',0
szAppName       db              'Æ[¬ÝÂI°}¹Ï',0,'- ',MAX_OnlyFN dup (0)
szMenuName      db              'VBMPMenu',0
szIconName      db              'VBMPIcon',0
;***********************************************************
        .code
;-----------------------------------------------------------
;¿ï¾Ü BMP ÀÉ¡A¨ÃŪ¨ú BMP ÀÉ
;¶Ç¦^­È¡GlpCaption=0¡Aªí¥¿½Tªº BMP ÀÉ
;        lpCaption ¤£¬°¹s¡A«h lpCaption ¬°¦r¦ê¦ì§}¡A¦¹¦r¦êªí¥Ü¿ù»~­ì¦]
OpenBMPFile     proc    hwin:HWND
        mov     eax,hwin
        mov     ofn.lStructSize,sizeof ofn      ;056 OPENFILENAME ªø«×
        mov     ofn.hwndOwner,eax
        mov     ofn.lpstrFilter,offset szFNFilter
        mov     ofn.lpstrCustomFilter,NULL
        mov     ofn.nFilterIndex,1              ;060 ¹w³]°ÆÀɦW *.BMP ©Î DIB
        mov     ofn.lpstrFile,offset szFullFN   ;061 §¹¾ãÀɦW¦s©ñ³B
        mov     ofn.nMaxFile,MAX_FullFN
        mov     ofn.lpstrFileTitle,offset szAppName+13
        mov     ofn.nMaxFileTitle,MAX_OnlyFN
        mov     ofn.lpstrInitialDir,NULL        ;065 ¥Îµ{¦¡©Ò¦b¤l¥Ø¿ý
        mov     ofn.lpstrTitle,NULL             ;066 ¥Î¹w³]¼ÐÃD
        mov     ofn.Flags,OFN_READONLY          ;067 °ßŪ
        mov     ofn.lpstrDefExt,offset szDefExt
        mov     ofn.lCustData,NULL
        mov     ofn.lpTemplateName,NULL
        invoke  GetOpenFileName,addr ofn
.if eax
        invoke  CreateFile,offset szFullFN,\    ;073 «ö¤U¶}±ÒÂÂÀɪº½T©w«ö¶s
                GENERIC_READ,FILE_SHARE_READ,\
                NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
  .if eax!=INVALID_HANDLE_VALUE
        mov     hFile,eax                       ;077 ¥¿½T¦a¶}±ÒÀÉ®×
        invoke  GetFileSize,eax,NULL            ;078 ¨ú±o BMP Àɤj¤p
        mov     nFileSize,eax
    .if bIfGlobal                               ;080 Àˬd¬O§_´¿°t¸m°O¾ÐÅé
        invoke  GlobalFree,hGlobalMem           ;081 ¦pªG´¿¡A«h¥ýÄÀ©ñ°O¾ÐÅé
    .endif
        invoke  GlobalAlloc,GMEM_FIXED,nFileSize;083 ¨Ì¾Ú BMP Àɤj¤p°t¸m°O¾ÐÅé
        mov     bIfGlobal,1
        mov     hGlobalMem,eax
        invoke  ReadFile,hFile,eax,nFileSize,offset nReadBytes,NULL
        mov     eax,hGlobalMem  ;087 Àˬd©ÒŪ¨úªº«e¨â¦r¤¸¬O§_¬° 'BM'
    .if word ptr [eax]==4d42h   ;088 ­Y¬O¡A«h¬°¥¿½Tªº BMP ÀÉ
        mov     ecx,[eax+12h]   ;089 ¨ú±o BMP ¹Ïªº¼e«×
        mov     edx,[eax+16h]   ;090 ¨ú±o BMP ¹Ïªºªø«×
        mov     nBMPWidth,ecx
        mov     nBMPHeight,edx
        add     ecx,cxNonClient
        add     edx,cyNonClient
        invoke  MoveWindow,hwin,0,0,ecx,edx,TRUE        ;095 ­«³]µøµ¡¤j¤p
        mov     lpCaption,0
    .elseif
        mov     lpCaption,offset szNotBMP       ;098 ­Y§_¡A«h«D BMP ®æ¦¡
    .endif
        invoke  CloseHandle,hFile
  .else
        mov     lpCaption,offset szOpenErr      ;102 ¶}±ÒÀɮ׿ù»~
  .endif
.else
        mov     lpCaption,offset szNoFile       ;105 «ö¤U¶}±ÒÂÂÀɪº¨ú®ø«ö¶s
.endif

        mov     ecx,offset szAppName+10         ;108 ¨M©wµøµ¡¼ÐÃDªº¤å¦r
.if lpCaption==0
        mov     byte ptr [ecx],' '              ;110 ¥¿½TªºÅª¥X BMP ÀÉ
.else
        mov     byte ptr [ecx],0                ;112 ¶}±Ò¤£¥¿½T©Î«ö¤U¨ú®ø«ö¶s
.endif
        invoke  InvalidateRect,hwin,NULL,TRUE   ;113 ±j­¢­«·sø»s¤u§@°Ï
        ret
OpenBMPFile     endp
;-----------------------------------------------------------
WndProc proc    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
        local   ps:PAINTSTRUCT,hDC:HDC,hdcMem:HDC,rect:RECT
.if uMsg==WM_CREATE
        invoke  GetSystemMetrics,SM_CYCAPTION   ;121 ¨ú±o¼ÐÃDÄæ°ª«×
        mov     cyNonClient,eax
        invoke  GetSystemMetrics,SM_CYMENU      ;123 ¨ú±o¿ï³æ°ª«×
        add     cyNonClient,eax
        invoke  GetSystemMetrics,SM_CYSIZEFRAME ;125 ¨ú±oÃä®Ø°ª«×
        shl     eax,1
        add     cyNonClient,eax
        invoke  GetSystemMetrics,SM_CXSIZEFRAME ;128 ¨ú±oÃä®Ø¼e«×
        shl     eax,1
        mov     cxNonClient,eax

.elseif uMsg==WM_COMMAND
        mov     eax,wParam
  .if ax==IDM_EXIT
        jmp     exit
  .elseif ax==IDM_OPEN
        invoke  OpenBMPFile,hWnd
  .endif
        invoke  SetWindowText,hWnd,offset szAppName

.elseif uMsg==WM_PAINT
        invoke  BeginPaint,hWnd,addr ps ;142 ¨ú±o³]³Æ¤º®e
        mov     hDC,eax
  .if lpCaption==0
        mov     edx,hGlobalMem          ;145 ¶}±Ò¥¿½Tªº BMP ÀÉ
        mov     ecx,edx
        add     ecx,[edx+10]            ;147 ecx «ü¦V¦ì¤¸¹Ï¸ê®Æ
        add     edx,14                  ;148 edx «ü¦V BITMAPINFO µ²ºcÅé
        invoke  CreateDIBitmap,eax,edx,CBM_INIT,ecx,edx,DIB_RGB_COLORS
        mov     hBitmap,eax
        invoke  CreateCompatibleDC,hDC
        mov     hdcMem,eax
        invoke  SelectObject,hdcMem,hBitmap 
        invoke  BitBlt,hDC,0,0,nBMPWidth,nBMPHeight,hdcMem,0,0,SRCCOPY
        invoke  DeleteObject,hBitmap
  .elseif lpCaption==0ffffffffh                 ;156 µ{¦¡­è°õ¦æ¡A©|¥¼¿ï¾ÜÀÉ®×
  .else
        invoke  GetClientRect,hWnd,addr rect    ;158 ¨S¦³¶}±Ò BMP ÀÉ
        invoke  DrawText,hDC,lpCaption,-1,addr rect,DT_CENTER or \
                DT_VCENTER or DT_SINGLELINE
  .endif
        invoke  EndPaint,hDC,addr ps

.elseif uMsg==WM_DESTROY
exit:   invoke  PostQuitMessage,NULL

.else
def:    invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
.endif
        xor     eax,eax
        ret
WndProc endp
;-----------------------------------------------------------
start:  invoke  GetModuleHandle,NULL
        mov     hInstance,eax
        invoke  GetCommandLine
        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,eax,offset szIconName
        mov     wc.hIcon,eax
        mov     wc.hIconSm,eax
        invoke  LoadCursor,NULL,IDC_ARROW
        mov     wc.hCursor,eax
        invoke  LoadMenu,hInstance,offset szMenuName
        mov     hMenu,eax
        invoke  RegisterClassEx,offset wc
        invoke  CreateWindowEx,NULL,offset szClassName,offset szAppName,\ 
                WS_SYSMENU or WS_CAPTION,0,10,400,100,0,hMenu,hInstance,NULL 
        mov     hwnd,eax
        invoke  ShowWindow,hwnd,SW_SHOWDEFAULT
        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
;***********************************************************
        end     start

³Ì«á¬O ViewBMP.MAK Àɪº¤º®e¡G

ALL:ViewBMP.EXE

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

ViewBMP.RES : ViewBMP.RC EYE.ICO
        RC ViewBMP.RC

¸Ñ»¡

³o­Óµ{¦¡¥D­n³¡¥÷³£¤w¸g»¡©ú¹L¤F¡A©³¤U¥u»¡©ú¤@¨Ç©|¥¼»¡©úªº³¡¥÷¡C

lpCaption ÅܼÆ

³o­ÓÅܼƬO¥Î¨Ó°O¿ý¦r¦ê¦ì§}¡A³o­Ó¦r¦ê¬O·í¿ù»~µo¥Í®É ( ¨Ò¦p«ö¤U¨ú®ø«ö¶s¡B©Ò¿ï©wªºÀɮפ£¬O BMP Àɵ¥µ¥¡K)¡A¦b¤u§@°Ï©ÒÅã¥Üªº¿ù»~°T®§¡C¦pªG¤@¤Á¥¿±`¡AlpCaption ´N³Q³]¬°¹s ( ²Ä 96 ¦æ )¡C

°£¦¹¤§¥~¡AlpCaption ÁÙ¦³¥t¤@­Ó¥Î³~¡C¥Ñ©óµ{¦¡¥²¶·³B²z WM_PAINT °T®§¥HÅã¥Ü BMP ¹Ï®×ÀÉ¡A¦ý¬O·íµ{¦¡¤@¶}©l°õ¦æ®É¡A¨Ï¥ÎªÌÁÙ¨S¦³¿ï©wÀɮסA³o®É­n³B²zªº WM_PAINT °T®§©M­nÅã¥Ü¹Ï®×®Éªºµ{¦¡½X¨Ã¤£¤@¼Ë¡C¨ä¹ê³o®É­Ô®Ú¥»´N¤£¶·³B²z WM_PAINT °T®§¡AÀ³¸Óª½±µ¥æµ¹ DefWindowProc API ³B²z WM_PAINT¡C¬°¤F°Ï§O¬O¤£¬O ViewBMP ¬O¤£¬O¤@¶}©l°õ¦æ¡A©Ò¥H¤p¤ì°¸§â lpCaption ·í§@¤@­ÓºX¼Ð¡A¨äªì©l­È¬° ¡Ð1¡A·íµ{¦¡¤@¶}©l°õ¦æ®É¡AlpCaption µ¥©ó ¡Ð1¡A³o®É´N¤£³B²z WM_PAINT °T®§¡A·í¿ï©w BMP ÀÉ¥B¥¿½T¶}±Ò®É¡A lpCaption ´N³]©w¬°¹s¡C¦pªG¨Ï¥ÎªÌ«ö¨ú®ø«ö¶s¡A«h lpCaption «ü¦V¿ù»~¦r¦ê©Ò¦b¡C


µù¤@¡GOS/2 ¬O IBM ¥X«~ªº¤@ºØ§@·~¨t²Î¡A¦­´Á»P·L³n¦@¦P¶}µo¡A¥H´Á¯à¨ú¥N DOS¡A¦¨¬°²Ä¤G¥N§@·~¨t²Î¡A³o¥i¥H¥Ñ¨ä¦WºÙ¡AOperating System/2 ¬Ý¥X¡C«á¨Ó¥Ñ©ó Windows 3.0 ªº¦¨¥\¡A·L³n¨M©w¶}µo¤U¤@¥N Windows 95 ¦Ó°h¥X OS/2 ªº¶}µo¡A³Ì«á OS/2 ¥Ñ IBM ¿W¦Û¶}µo¨Ã¾P°â¡C¦³Ãö©ó§ó¦h OS/2 ªº¤¶²Ð¡A½Ð°Ñ¦Ò AKIMASA ªººô¯¸¡C

¤p¤ì°¸¤]´¿¸g¹ï OS/2 «ÜµÛ°g¡A¦ý¦]¸ê·½¡B³nÅé¤Ó¤Ö¡A²×¨s©è¤£¦í²{¹êªºÀ£¤O¦Ó³vº¥Âà¦V¥Î Windows 9x/Me¡C¤£¹L¤p¤ì°¸¤´µM«ÜÁÙ©À 1994¡ã1999 ¦~¨º¬q¥Î OS/2 ªº®É¥ú¡A§Ú±`¦b·Q¡A°²¦p¤£¬O OS/2 Àu²§©Ê¯à«Â¯Ù¨ì·L³nªº Windows 3.1¡A»¡¤£©w·L³n¤´µM°±¯d¦b 16 ¦ì¤¸ªº§@·~¨t²Î¡C¦]¬° OS/2 ªºÄvª§¡A¤~·|«P¨Ï·L³n¶i¨B¡C³Ìªñ ( 2005 ¦~ 8 ¤ë¥ª¥k ) ¤@­Ó¨Ò¤l¤]¬O¡A·L³nªº IE6 ¤w¸g¦n´X¦~³£¤£§ó·s¡Aª½¨ì¥\¯à±j«lªº¤õª° ( Firefox ) µoªí«á¡A¤~¨£·L³n¥[ºò¶}µo IE7¡C

µù¤G¡GOS/2 ªº BMP ÀÉ®×µ²ºc»P Windows ªº BMP ÀÉ®×µ²ºcÃþ¦ü¡A³á¡IÀ³¸Ó»¡ Windows ªº BMP Àɵ²ºc¬O¥Ñ OS/2 ÂX¥R¦Ó¨Óªº¡COS/2 ªº BMP ÀÉ®×µ²ºcªº²Ä¤@³¡¥÷¬O¥Ñ 14 ­Ó¦ì¤¸²Õ²Õ¦¨ªº BITMAPFILEHEADER µ²ºcÅé¡A¨ä·N¸q»P Windows ®æ¦¡ªº¬Û¦P¡C¦b BITMAPFILEHEADER µ²ºcÅ餧«áªº²Ä¤G³¡¥÷¬O¥Ñ 12 ­Ó¦ì¤¸²Õ²Õ¦¨ªº BITMAPCOREHEADER µ²ºcÅé¡G

BITMAPCOREHEADER    STRUC
bcSize      dd      ?
bcWidth     dw      ?
bcHeight    dw      ?
bcPlanes    dw      ?
bcBitCount  dw      ?
BITMAPCOREHEADER    ENDS

²Ä¤@­ÓÄæ¦ì¡AbcSize¡A«üªº¬O³o­Óµ²ºcÅ骺¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡A¦]¦¹¨ä¼Æ­È¬O 0ch¡A¥¦¥i¥H¥Î¨Ó¤À¿ë¬O OS/2 ®æ¦¡©Î¬O Windwos ®æ¦¡ªº BMP ÀÉ¡C²Ä¤G¡B¤T­ÓÄæ¦ì¡AbcWidth¡BbcHeight ¬O³o­Ó¦ì¤¸¹Ïªº¼e«×©Mªø«×¡A¥HÂI¬°³æ¦ì¡CbcPlanes ¬OÃC¦â¥­­±¼Æ¡A¤]©M Windows ®æ¦¡¤@¼Ë¡AÀ³¸Ó³]¬°¤@¡C

³Ì«á¤@­ÓÄæ¦ì¡AbcBitCount¡A¬O¨C­ÓÂI©Ò¦û¥Îªº¦ì¤¸¼Æ¡A¥i¥H¬O 1¡B4¡B8¡B24¡C¦pªG¬O 1¡Aªí¥Ü¨CÂI¶È¦û¥Î¤@­Ó¦ì¤¸¡A¤@­Ó¦ì¤¸¥i¥H¬O 0 ©Î 1¡A¦]¦¹¥i¥Hªí¥Ü¨âºØÃC¦â¡F¦pªG¬O 4¡A¨º»ò·|¦³¤U­± 16 ºØ±¡§Î¡G

0000    0001    0010    0011    0100    0101    0110    0111
1000    1001    1010    1011    1100    1101    1110    1111

¥i¥H¥Î 24¡×16 ­pºâ¡A¦pªG¨C¤@ºØ¼Æ­È¥Nªí¤@ºØÃC¦â¡A¨º´N¯àªí¥Ü 16 ºØÃC¦â¡C¨ä¾lÃC¦â¦p¤Uªí¡G

bcBitCount ­pºâ ÃC¦â¼Æ RGBTRIPLE
µ²ºcÅé¼Æ¥Ø
1 2122
4 241616
8 28256256
24 ( True-Color ) 224167772160

²Ä¤T³¡¥÷¬O¤@­Ó¥Ñ³\¦h RGBTRIPLE µ²ºcÅé©Ò²Õ¦¨ªº¦â±m¹ï·Óªí¡AÅU¦W«ä¸q¡A¥¦¬O°O¿ý¦â±m¥Îªº¡A¥¦ªºªø«×¤£©T©w¡A»PÃC¦â¼Æ¦³Ãö¡C¥ý¬Ý¥¦ªº²Õ¦¨³æ¦ì¡ARGBTRIPLE µ²ºcÅé¡A¥Ñ¨ä¦W¦r´N¥i²q·Q±o¨ì¡ARGBTRIPLE ¬O¤@­Ó¥Ñ¬õºñÂŤT­ì¦â¥ú©Ò²Õ¦¨¥Nªí¦UºØÃC¦â±j®zªºµ²ºcÅé¡G

RGBTRIPLE   STRUC
rgbBlue     db      ?       ;ÂŦâ¥ú±j«×
rgbGreen    db      ?       ;ºñ¦â¥ú±j«×
rgbRed      db      ?       ;¬õ¦â¥ú±j«×
RGBTRIPLE   ENDS

¥i¥H°Ñ¦Ò¤Wªí¡A¦pªG bcBitCount ¬° 1 ®É¡A¦â±m¹ï·Óªí¦³¨â­Ó RGBTRIPLE µ²ºcÅé¡F¦pªG bcBitCount ¬° 4 ®É¡A¦â±m¹ï·Óªí¦³ 16 ­Ó RGBTRIPLE µ²ºcÅé¡K¡K¡A³oÀ³¤£Ãø²z¸Ñ¡CÁ|¨Ò¨Ó»¡¡A bcBitCount ¬° 4 ®É¡A¥i¥Hªí¥Ü 16 ºØÃC¦â¡A¦ý¬O¬O¨º 16 ºØÃC¦â©O¡H´N¥Ñ¦â±m¹ï·Óªí°O¿ý¡A¨C­Ó RGBTRIPLE µ²ºcÅéªí¥Ü¤@ºØÃC¦â¡A³oºØÃC¦â¬O¥Ñ¤T­ì¦â¥ú±j®z¤£¦P¦Ó²£¥Í¡A¦]¦¹ 16 ºØÃC¦â´N±o¦³ 16 ­Ó RGBTRIPLE µ²ºcÅé°O¿ý¡C¨º»ò¬°¤°»ò True-Color ¤£¥Î¦â±m¹ï·Óªí©O¡H³o­Óµª®×«Ü©úÅã¡A½ÐŪªÌ¦Û¦æ«ä¦ÒÅo¡C

²Ä¥|³¡¥÷¤]¬O³Ì«á¤@³¡¥÷´N¬O¦ì¤¸¸ê®Æ¡A¦s¦³¾ã±i¹Ï¤ùªº¹Ï®×¡C


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