²Ä¤G¤Q¤K³¹¡@¥Î GDI¡Ï Æ[¬Ý¹Ï¤ùÀÉ

³o¤@³¹±N²³æ¤¶²Ð GDI¡Ï¡A¨Ã¥H¥»³¹¤¶²Ðªº´X­Ó API ¼¶¼g¤@­Ó¥i¥HÆ[¬Ý¼ÆºØ®æ¦¡ªºÀ³¥Îµ{¦¡¡C


GDI¡Ï ¬O¤°»ò¡H

¦b²Ä¤K³¹®É´¿¤¶²Ð¹L GDI¡]graphics device interface¡A¹Ï§Î¸Ë¸m¤¶­±¡^¡A´£¨Ñ¤F»P©PÃä¸Ë¸mµLÃöªºµ{¦¡³]­p¤è¦¡¡A¬Æ¦Ü³s Windows §@·~¨t²Î¥»¨­¦bø»s¦UÃþ¤¸¥ó¤]³£¾a GDI¡C¦Ó¥»³¹­n¤¶²Ðªº GDI¡Ï ¬O¦b¨ä«á¥[¤W¤@­Ó¡u¡Ï¡v¡AÅãµM¥i¥H²³æ¦a»{¬°¬O GDI ªº¤É¯Å§ï¨}ª©¥»¡C

ªº½T¦p¦¹¡C¦Û Windows XP ¤Î Windows Server 2003 ¶}©l¥[¤J GDI¡Ï¤§«á¡A¥¦¥i¥H»¡¬O§@·~¨t²Î¤ºªº¤@³¡¤À¤F¡C¥¦´£¨Ñ¤Gºû¦V¶q¹Ï§Î¡B¼v¹³³B²z©M¦L¨ê¼Ë¦¡¤T³¡¤À¡F¨C³¡¤À¦U¦Û¹ï­ì¨Óªº GDI ¶i¦æ¤F§ï¨}¡A¤]·s²K¤F¤@¨Ç¥\¯à¡C¹ï©ó¼v¹³¦Ó¨¥¡A¤ä´©§ó¦h®æ¦¡ªº¹Ï¤ùÀÉ¡A¥]¬A¤F PNG¡BJPG¡BGIF¡BExif¡BTIFF¡BWMF¡BEMF µ¥¡C

²Ä¤K³¹´£¹L¡AGDI ¶È¤ä´©¦ì¤¸¹Ï¡A¤]´N¬O Bitmap ®æ¦¡ªº¹Ï¤ù¡A¦Ó GDI¡Ï ¤ä´©ªº¹Ï¤ù¸û¦h¡A³o¤]¬O¥»³¹ªº­«ÂI¡C¨º»ò¦b¨Ï¥Î GDI¡Ï ªº®É­Ô¡A¦³¤°»ò­nª`·Nªº¶Ü¡H

¨Ï¥Î GDI¡Ï

¦b¨Ï¥Î GDI¡Ï «e¡A¶·ª`·N©³¤U¤T¥ó¨Æ¡G

²Ä¤@¡A¦pªG¨Ï¥Î WinInc §t¤JÀÉ·f°t UASM ²ÕĶ¡A¨º»ò¦b²Õ¦X»y¨¥­ì©lµ{¦¡ªº«e­±¡A»Ý§â¡uGDIPLUS.INC¡v¥]§t¶i¨Ó¡C¦P®É¤]­n¥[¤J¡uGDIPLUS.LIB¡v¶×¤Jµ{¦¡®w¡A¥H«K¨Ï³sµ²¾¹ª¾¹D¦p¦ó¦b¡uGDIPLUS.DLL¡v§ä¨ì©Ò¨Ï¥Îªº GDI¡Ï ¨ç¦¡¡Cµ{¦¡½X¦p¤U¡G

INCLUDE         GDIPLUS.INC
INCLUDELIB      GDIPLUS.LIB

²Ä¤G¡A¦b©I¥s GDI¡Ï ¨ç¦¡¤§«e¡A¥²¶·¥ý©I¥s GdiplusStartup¡A¥Hªì©l¤Æ GDI¡Ï¡AµM«á¤~¯à©I¥s¨ä¥L GDI¡Ï ¨ç¦¡¡F·í¤£¦A¨Ï¥Î GDI¡Ï ®É¡A¥²¶·©I¥s GdiplusShutdown §iª¾¨t²Îµ²§ô GDI¡Ï¡A¥HÄÀ©ñ GDI¡Ï ©Ò¨Ï¥Îªº¸ê·½¡C

²Ä¤T¡AGDI¡Ï ¨ç¦¡ªº¦^¶Ç­È»P¨ä¥L Win64 API ¤£¤Ó¤@¼Ë¡C¹ï GDI¡Ï ¨ç¦¡¦Ó¨¥¡A¦^¶Ç­È¬° 0 ¥Nªí°õ¦æ¦¨¥\¡F¦^¶Ç­È¬°¨ä¥L¼Æ­È¡A¥Nªí°õ¦æ¥¢±Ñ¡A¦Ó¸Ó¼Æ­È¥Nªí¿ù»~¥N½X¡CWindows ¯S§O§â GDI¡Ï ªº¦^¶Ç­ÈºÙ¬° GpStatus¡C¹ï 64 ¦ì¤¸ªº Windows¡AGpStatus ªºªø«×³£¬O QWORD¡A¦s©ó RAX ¼È¦s¾¹¤º¡C¤Uªí¬O GDI¡Ï API ªº¦^¶Ç­È¤Î·N¸q¡G

ªí¤@¡GGDI¡Ï ¨ç¦¡¦^¶Ç­È
Status¼Æ­È»¡©ú
OK0°õ¦æ¦¨¥\
GenericError1¤@¯ë¿ù»~¡A«üªº¬O¥¼³QÂkÃþªº¿ù»~
InvalidParameter2°Ñ¼Æ¤£¥¿½T
OutOfMemory3°O¾ÐÅ餣¨¬
ObjectBusy4¹Á¸Õ¾Þ§@¥¿¦b³Q¨ä¥L°õ¦æºü©Îµ{¦¡Âê©wªºª«¥ó
InsufficientBuffer5´£¨Ñªº½w½Ä°Ï¤j¤p¤£¨¬¥H¦s©ñ¾Þ§@µ²ªG
NotImplemented6¸Ó¨ç¼Æ¥Ø«e©|¥¼³Q¹ê§@¡A¥i¯à¬Oª©¥»¤£²Å©Î³]³Æ¥¼¤ä´©
Win32Error7ªí¥Ü¨Ó¦Û Win32 API ªº¿ù»~
WrongState8ªí¥Üª«¥óªºª¬ºA»P©Ò»Ý¾Þ§@¤£¤@­P¡A¨Ò¦p¦b¥¼¸gªì©l¤Æª¬ºA¤U°õ¦æø»s¾Þ§@
Aborted9ªí¥Ü¾Þ§@³Q¤¤¤î
FileNotFound0Ah¨S§ä¨ìÀÉ®×
ValueOverflow0Bh°õ¦æ²£¥Í¼Æ­È·¸¦ìªººâ³N¹Bºâ
AccessDenied0Ch¤£¤¹³\ÀÉ®×¼g¤J
UnknownImageFormat0Dh¥¼ª¾ªº¹Ï¤ùÀɮ׮榡
FontFamilyNotFound0Eh§ä¤£¨ì«ü©wªº¦r§Î¡A¨Ò¦p¦r§Î¦WºÙ¤£¥¿½T©Î¥¼¦w¸Ë¦r§Î
FontStyleNotFound0Fh§ä¤£¨ì«ü©wªº¦r§Î­·®æ
NotTrueTypeFont10h±q HDC ©Î LOGFONT ©ÒÂ^¨úªº¦r§Î¤£¬O TrueType ¦r§Î¡AµLªk»P GDI¡Ï ·f°t¨Ï¥Î
UnsupportedGdiplusVersion11h¦w¸Ë¦b¨t²Îªº GDI¡Ï ª©¥»»PÀ³¥Îµ{¦¡¤£¬Û²Å
GdiplusNotInitialized12hGDI¡Ï API ¤£¬O³B©óªì©l¤Æª¬ºA¡A ©I¥s GdiplusStartup ¥H¸Ñ¨M¦¹¿ù»~
PropertyNotFound13h¼v¹³¤¤¨S¦³«ü©wªºÄÝ©Ê
PropertyNotSupported14h¼v¹³®æ¦¡¤£¤ä´©«ü©wªºÄÝ©Ê¡A¦]¦¹µLªk³]©w
ProfileNotFound15h§ä¤£¨ì¥H CMYK ®æ¦¡Àx¦s¼v¹³©Ò»Ýªº¦â±m³]©wÀÉ

©³¤U¨Ó¤¶²Ð¥»³¹·|¥Î±o¨ìªº GDI¡Ï API¡A¥H¤Î¤@¨Ç·§©À¡C

GdiplusStartup API

¨C·í­n¨Ï¥Î GDI¡Ï «e¡A³£­n©I¥s GdiplusStartup¡A¹ï GDI¡Ï ¶i¦æªì©l¤u§@¡CGdiplusStartup ªº­ì«¬¦p¤U¡G

invoke  GdiplusStartup,\
        pToken,\          ; receives the GDI+ session handle
        pGdipStartInput,\ ; provides GDI+ initialization settings
        pGdipStartOutput  ; returns additional initialization details

pToken ¬O«ü¦V token ªº¦ì§}¡A¹ï 64 ¦ì¤¸ªº Windows ¦Ó¨¥¡Atoken ªºªø«×¬O QWORD¡CToken ¬O GDI¡Ï ®Ö¤ß°õ¦æÀô¹Òªº¼Ð»x¡A¨t²Î¥Î¥¦ºÞ²z¨ä¥Í©R©P´Á¡A³z¹L token¡AGDI¡Ï ¯à°÷°lÂÜ©M²M²z¨ä¤º³¡¸ê·½¡A½T«OÀ³¥Îµ{¦¡ªºÃ­©w©Ê©M¸ê·½ªº¥¿½T¦^¦¬¡C·í¤£¦A¨Ï¥Î GDI¡Ï ®É¡A¥²¶·©I¥s¥H¦^¦¬¸ê·½¡A³o®É­Ô¤]·|¥Î¨ì token¡C§Ú­Ì¥i¥H²³æ¦a§â token ·Q¹³¬°¥N½X¡]handle¡^¡C

pGdipStartInput ¬°µ²ºcÅé GdiplusStartupInput ªº¦ì§}¡A¸Óµ²ºcÅ骺Äæ¦ì¬O¡G

GdiplusStartupInput             STRUCT          8
  GdiplusVersion                UINT32          ?   ;GDI¡Ïª©¥»
  DebugEventCallback            DebugEventProc  ?   ;°£¿ù¨ç¦¡¦ì§}
  SuppressBackgroundThread      BOOL            ?   ;¬O§_±Ò¥Î«á¥x°õ¦æºü
  SuppressExternalCodecs        BOOL            ?   ;¬O§_¤¹³\¨Ï¥Î¥~³¡½s¸Ñ½X¾¹
GdiplusStartupInput             ENDS

µ²ºcÅé GdiplusStartupInput ªº¥Î³~¦b©óªì©l¤Æ GDI¡Ï¡A¦]¦¹¦b©I¥s GdiplusStartup «e¡A¥²¶·§â³o­Óµ²ºcÅ餺ªº¦UÄæ¦ì³£¶ñ¤W¾A·íªº¸ê®Æ¡C©I¥s GdiplusStartup ®É¡AWindows Âǥѳo­Óµ²ºcÅ餺ªº¸ê®Æ¡A¹ï GDI¡Ï ¶i¦æªì©l¤Æ¤u§@¡C©³¤U¤¶²Ð¦UÄæ¦ì¡G

①¡BGdiplusVersion¡GGDI¡Ï ªºª©¥»¡C¥Ø«e¡]¥Á°ê 114 ¦~¡^GDI¡Ï ªºª©¥»¬O 1.0 ª©¡A¦]¦¹³o­ÓÄæ¦ì¥u¯à¶ñ¤J 1¡C¸ê®ÆÃþ«¬ UINT32 ¥Nªí 32 ¦ì¤¸µL¸¹¾ã¼Æ¡C
②¡BDebugEventCallback¡G¦¹¬°°£¿ù¨ç¦¡¦ì§}¡A¥Î©ó²`¤J´ú¸Õ GDI¡Ï ©Î°lÂÜ¿ù»~®É¡A¥i«ü©w¦Û©w¸q¨ç¼Æ¨Ó°O¿ý°£¿ù¨Æ¥ó¡C¦pªG¤£»Ý­n¡A¥i¥H§â³o­ÓÄæ¦ì³]¬° 0¡C¦¹Äæ¦ìªø«×¬O 64 ¦ì¤¸¡C
③¡BSuppressBackgroundThread¡G¦¹¬° 32 ¦ì¤¸ªº¾ã¼Æ¡A¬°¤@¥¬ªL­È¡Aªí¥Ü¬O§_±Ò¥Î«á¥x°õ¦æºü¡C¹w³]­È¬° FALSE¡Aªí¥Ü±Ò¥Î«á¥x°õ¦æºü¡F³]¬° TRUE¡A¤£±Ò¥Î«á¥x°õ¦æºü¡C«á¥x°õ¦æºü­t³dºÞ²z¤º³¡¸ê·½¡A³B²z¤@¨Ç§CÀu¥ý¯Åªº¤º³¡¾Þ§@¡C¤@¯ë±¡§Î¤U¡A±N¦¹Äæ¦ì³]¬° FALSE¡AÅý GDI¡Ï ¦Û¦æºÞ²z§Y¥i¡C
④¡BSuppressExternalCodecs¡G¦¹¬° 32 ¦ì¤¸ªº¾ã¼Æ¡A¬°¤@¥¬ªL­È¡Aªí¥Ü¬O§_¤¹³\¨Ï¥Î¥~³¡½s¸Ñ½X¾¹¡C¹w³]­È¬° FALSE¡Aªí¥Ü¤¹³\¸ü¤J¥~³¡½s¸Ñ½X¾¹¡C

pGdipStartOutput ¬°µ²ºcÅé GdiplusStartupOutput ªº¦ì§}¡A¦¹µ²ºc¥i¥Î©ó´£¨Ñ¤@¨Ç±Ò°Ê GDI¡Ï «áªºªþ¥[¸ê°T¡A¯S§O¬O±±¨î«á¥x°õ¦æºüªººÞ²z¡C¦pªG²Ä¤G­Ó°Ñ¼Æ©Ò«üµ²ºcÅ餤ªº²Ä¤T­ÓÄæ¦ì¡ASuppressBackgroundThread¡A¬° FALSE¡A«h pGdipStartOutput ¥i¥H¬O 0¡CGdiplusStartupOutput µ²ºcÅ骺­ÓÄæ¦ì¦p¤U¡G

GdiplusStartupOutput    STRUCT
  NotificationHook      NotificationHookProc    ?   ;ÄdºI¨ç¦¡¦ì§}¡A¥Î©ó³qª¾À³¥Îµ{¦¡ GDI¡Ï ªº«á¥x°õ¦æºü¥¿¦b±Ò°Ê
  NotificationUnhook    NotificationUnhookProc  ?   ;ÄdºI¨ç¦¡¦ì§}¡A¥Î©ó³qª¾À³¥Îµ{¦¡ GDI¡Ï ªº«á¥x°õ¦æºü¥¿¦b°±¤î
GdiplusStartupOutput    ENDS

¦b¤j¦h¼Æ±¡ªp¤U¡AGdiplusStartupOutput µ²ºcÅ餺ªº¨âÄæ¦ì§¡¥i³]¬° 0¡Aªí¥Ü¤£»Ý­n¥ÎÄdºI¨ç¦¡³B²z«á¥x°õ¦æºü¡CµM¦Ó¡A·íÀ³¥Îµ{¦¡»Ý­n²Ó½o¦aºÞ²z GDI¡Ï ªº«á¥x°õ¦æºü®É¡A¥i¥H¾A·í³]©w³o¨â­ÓÄæ¦ì¡C

¦pªG GdiplusStartup °õ¦æ¦¨¥\¡AGdiplusStartup ªº¦^¶Ç­È¬° 0¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C

GdiplusShutdown API

GdiplusShutdown ·|²M°£ GDI¡Ï ©Ò¨Ï¥Îªº¸ê·½¡C¨C©I¥s¤@¦¸ GdiplusStartup¡A³£À³¸Ó¤]©I¥s¤@¦¸ GdiplusShutdown¡CGdiplusShutdown ªº­ì«¬¦p¤U¡G

invoke  GdiplusShutdown,\
        token           ; the GDI+ session handle

GdiplusShutdown ¥u¦³¤@­Ó°Ñ¼Æ¡A´N¬O±q©I¥s GdiplusStartup ±o¨ìªº token¡C¦b«Ø¥ß¥ô¦ó GDI¡Ï ª«¥ó¤§«e±o¥ý©I¥s GdiplusStartup ªì©l¤Æ¡A¦Ó¥B¤]¥²¶·¥ý§R°£©Ò¦³ GDI¡Ï ª«¥ó¡A¤~¯à©I¥s GdiplusShutdown¡CGdiplusShutdown ¨S¦³¦^¶Ç­È¡C

¹ï²³æ¥\¯àªº GDI¡Ï À³¥Îµ{¦¡¦Ó¨¥¡AGDI¡Ï ªºªì©l¤Æ»P²M°£¡A¥i·Ó¥H¤U»¡©ú¶i¦æ¡C³q±`¨Ï GdiplusStartupInput ³]¬° <1,0,0,0>¡A¦Ó pGdipStartOutput ¤]³]¬° 0¡Cªì©l¤Æ¤u§@¡A¥i¥H¦bÀ³¥Îµ{¦¡¤@¶}©l¡A©Î¬O«Ø¥ßµøµ¡¤§«á¶i¤J°T®§°j°é¤§«e¡F¦Ó¦bµ²§ô°T®§°j°é¤§«áµ²§ô GDI¡Ï¡C¦p¤U­±µ{¦¡½X¡G

.DATA
hwnd    HWND    ?
token   DQ      ?
status  DQ      ?
gsi     GdiplusStartupInput <1,0,0,0>
          ⁝
main    PROC
          ⁝        
        mov     hwnd,RV(CreateWindowEx,¡K¡K)
        mov     status,RV(GdiplusStartup,OFFSET token,OFFSET gsi,0)
.while TRUE
        invoke  GetMessage,ADDR msg,0,0,0
.break .if rax==0
        invoke  TranslateMessage,ADDR msg
        invoke  DispatchMessage,ADDR msg
.endw
        invoke  GdiplusShutdown,token
          ⁝

°²¦p¨Ï¥Î WinInc ¥]§tÀÉ¡A¨º»ò¦b GdiPlusInit.INC ¤º«Å§i GdiplusShutdown ªº­ì«¬¦³»~¡AÀ³±N¨ä§ï¦¨¡G

@DefProto WINGDIPAPI, GdiplusShutdown, stdcall, , <:QWORD>, 4

GdipLoadImageFromFile API

GdipLoadImageFromFile ·|®Ú¾Ú¹Ï¤ùÀÉ®×«Ø¥ß GpImage ª«¥ó¡C¦b GDI¡Ï ¤¤¦³³\¦hÃö©ó¹Ï§Îªºª«¥ó¡AGDI¡Ï ¨ç¦¡¥H³o¨Çª«¥ó¶i¦æø»s¡B¶î¦â¡B±ÛÂ൥¾Þ§@¡CGpImage ¥u¬O¨ä¤¤¤§¤@¡A¥i¥H§â GpImage ª«¥ó·Q¹³¦¨¬O¤@ºØ¥N½X¡AGDI¡Ï ¥i¥H¹ï³o GpImage ª«¥ó¶i¦æ¾Þ§@¡F´N¹³µøµ¡¥N½X¤@¼Ë¡A¨t²Î¥i¥H¹ïµøµ¡¥N½X¶i¦æ¾Þ§@¡A¨Ò¦p©ñ¤j¡BÁY¤p¡BÃö³¬µ¥¡CGdipLoadImageFromFile ªº­ì«¬¦p¤U¡G

invoke  GdipLoadImageFromFile,\
        lpFileName,\    ; pointer to name of the file
        pGpImage        ; pointer to a GpImage object

lpFileName ¬OÀɮצWºÙªº¦ì§}¡A¦¹ÀÉ®×¥i¥H¬O PNG¡BJPG¡BGIF¡BExif¡BTIFF¡BWMF¡BEMF µ¥®æ¦¡ªº¹Ï¤ùÀÉ¡A¦Ó¥BÀɦW¥²¶·¬O¸U°ê½XÀɦW¡CpGpImage ¬O GpImage ª«¥ó¦ì§}¡AGpImage ª«¥ó«ü¦V GDI¡Ï ¤º³¡ªº¸ê®Æ¡A¡uGp¡v¥Nªí GDI plus ªº·N«ä¡C

¦pªG GdipLoadImageFromFile °õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C·í¤£¦A¨Ï¥Î GpImage ª«¥ó®É¡A»Ý©I¥s GdipDisposeImage ¨ç¦¡¨ÓÄÀ©ñ¸Óª«¥ó¡A¥HÁקKµo¥Í¿ù»~¡C

GdipGetImageWidth API

¨ú±o GpImage ª«¥óªº¼e«×¡A­ì«¬¦p¤U¡G

invoke  GdipGetImageWidth,\
        gdipImage,\     ; GpImage object
        pWidth          ; pointer to width of a GpImage

gdipImage ¬O GpImage ª«¥ó¡CpWidth ¬OÅܼƦì§}¡A¦¹Åܼƪø 32 ¦ì¤¸¡C·í GdipGetImageWidth °õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡A¥B¨t²Î·|§â GpImage ª«¥ó¤¤ªº¹Ï¤ù¼e«×¼g¤J¦¹ÅܼƤ¤¡A³æ¦ì¬O¹³¯À¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C

GdipGetImageHeight API

¨ú±o GpImage ª«¥óªº°ª«×¡A­ì«¬¦p¤U¡G

invoke  GdipGetImageHeight,\
        gdipImage,\     ; GpImage object
        pHeight         ; pointer to height of a GpImage

gdipImage ¬O GpImage ª«¥ó¡CpHeight ¬OÅܼƦì§}¡A¦¹Åܼƪø 32 ¦ì¤¸¡C·í GdipGetImageHeight °õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡A¥B¨t²Î·|§â GpImage ª«¥ó¤¤ªº¹Ï¤ù°ª«×¼g¤J¦¹ÅܼƤ¤¡A³æ¦ì¬O¹³¯À¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C

GdipCreateFromHDC API

GdipCreateFromHDC ¥Î©ó«Ø¥ß»P«ü©w¸Ë¸m¤º®e¬ÛÃöÁpªº GpGraphics ª«¥ó¡A¤]´N¬O»¡±q«ü©wªº³]³Æ¤º®e«Ø¥ß¤@­Ó GpGraphics ª«¥ó¡CGpGraphics ¬O GDI¡Ï ªºª«¥ó¤§¤@¡A¥¦¤]¬O¤@­Ó«ü¼Ð¡Aªø«×¬O 64 ¦ì¤¸¡A«ü¦V GDI¡Ï ¤º³¡ªº¸ê®Æµ²ºc¡C¨C·í­nø»s¹Ï§Î®É¡AGDI¡Ï ³£¬O¾Þ§@ GpGraphics ª«¥ó¡AµM«á¦b¸Ë¸m¤º®eø¥X¹Ï§Î¡C¥i¥H GpGraphics ª«¥ó·Q¹³¦¨¬O GDI¡Ï ª©ªº¸Ë¸m¤º®e¡CGdipCreateFromHDC ªº­ì«¬¬O¡G

invoke  GdipCreateFromHDC,\
        hdc,\           ; handle to device context
        pGpGraphics     ; pointer to a GpGraphics object

hdc ¬O­n§â¹Ï§Îø©ó¨ä¤Wªº¸Ë¸m¤º®e¥N½X¡A¥i¥H¸g¥Ñ©I¥s BeginPaint¡BGetDC ©Î CreateCompatibleDC ±o¨ì¡CpGpGraphics ¬O GpGraphics ª«¥óªº¦ì§}¡C

¦pªG GdipCreateFromHDC °õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C·í¤£¦A¨Ï¥Î GpGraphics ª«¥ó®É¡A»Ý©I¥s GdipDeleteGraphics ¨ç¦¡¨ÓÄÀ©ñ¸Óª«¥ó¡A¥HÁקKµo¥Í¿ù»~¡C

GdipDrawImageRectI »P GdipDrawImageRect API

GdipDrawImageRectI ¥Î©ó±N¹Ï§Î¡]¦p¦ì¤¸¹Ï©Î¦V¶q¹Ï§Î¡^ø»s¨ì«ü©wªº GpGraphics ª«¥ó¤W¡C³o­Ó¨ç¦¡¨Ï¥Î¾ã¼Æ«¬ºAªº°Ñ¼Æ¨Ó«ü©w¼v¹³ªº¦ì¸m¡A¦Ó¤£¬O¯BÂI¼Æ«¬ºA¡CGdipDrawImageRectI ªº­ì«¬¦p¤U¡G

invoke  GdipDrawImageRectI,\
        gdipGraphics,\  ; GpGraphics object
        gdipImage,\     ; GpImage object
        x,\             ; the x-coordinate of the upper-left corner of the rendered image
        y,\             ; the y-coordinate of the upper-left corner of the rendered image
        width,\         ; width of the destination rectangle
        height          ; height of the destination rectangle

GdipDrawImageRectI «e¨â­Ó°Ñ¼Æ¬O«ü§â GpImage ª«¥óø»s©ó GpGraphics ¤W­±¡CGpImage ª«¥ó³q±`¬O©I¥s GdipLoadImageFromFile ©Î GdipCreateBitmapFromHBITMAP ²£¥Í¡C°²¦p GpGraphics ¬O¥Ñ¿Ã¹õ¸Ë¸m¤º®e²£¥Í¡A¨º»ò GpImage ª«¥ó´N·|Åã¥Ü©ó¿Ã¹õ¤W¡Cx¡By ¬Oµøµ¡¤u§@°Ï®y¼Ð¡A¨t²Î·|§â GpImage ªº¥ª¤W¨¤Ã¸»s©ó¦¹®y¼Ð¤W¡Cx¡By ¬O 32 ¦ì¤¸µL¸¹¾ã¼Æ¡A¥H¹³¯À¬°³æ¦ì¡Cwidth¡Bheight ¬O­nø»sªº¥Ø¼Ð¯x§Îªº¼e«×»P°ª«×¡A¥H¹³¯À¬°³æ¦ì¡C°²¦p width¡Bheight »P GpImage ª«¥ó¤¤ªº¼e«×»P°ª«×¤£¦Pªº¸Ü¡A¨º»ò´N·|©ñ¤j©ÎÁY¤p¡A¤]¥i¯à·|©Ô¦ù©ÎÀ£ÁY¡C

¦pªG°õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C

ÁÙ¦³¤@­Ó GdipDrawImageRect GDI¡Ï API¡A¥\¯à»P GdipDrawImageRectI Ãþ¦ü¡A¨ç¦¡¦WºÙ¶È¬Û®t¤@­Ó¡uI¡v¡CGdipDrawImageRect ªº­ì«¬¬O¡G

invoke  GdipDrawImageRect,\
        gdipGraphics,\  ; GpGraphics object
        gdipImage,\     ; GpImage object
        x,\             ; the x-coordinate of the upper-left corner of the rendered image
        y,\             ; the y-coordinate of the upper-left corner of the rendered image
        width,\         ; width of the destination rectangle
        height          ; height of the destination rectangle

GdipDrawImageRectI »P GdipDrawImageRect ªº®t§O¦b©ó¡A«eªÌªº x¡By¡Bwidth¡Bheight ³£¬O 32 ¦ì¤¸¾ã¼Æ¡A«áªÌ«h¬O 32 ¦ì¤¸¯BÂI¼Æ¡]¤£½×¬O 64 ¦ì¤¸©Î 32 ¦ì¤¸ªº Windows ¤¤¡A¦¹³Bªº¯BÂI¼Æ³£¬O 32 ¦ì¤¸ªø¡^¡C«áªÌ¾A¦X»Ý­n°ªºë«×ø»s¡A¨Ò¦p±ÛÂà®É¨Ï¥Î¡C

GdipDeleteGraphics API

GdipDeleteGraphics ¥Î©óÄÀ©ñ GpGraphics ª«¥ó¡A¥H¸`¬Ù¸ê·½¡C¨ä­ì«¬¬°¡G

invoke  GdipDeleteGraphics,\
        gdipGraphics    ; GpGraphics object

GdipDeleteGraphics ¥u¦³¤@­Ó°Ñ¼Æ¡A´N¬O­nÄÀ©ñªº GpGraphics ª«¥ó¡C¦pªG°õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C

GdipDisposeImage API

GdipDisposeImage ¥Î©óÄÀ©ñ GpImage ª«¥ó¡A¨ä­ì«¬¬°¡G

invoke  GdipDisposeImage,\
        gdipImage       ; GpImage object

GdipDisposeImage ¥u¦³¤@­Ó°Ñ¼Æ¡A´N¬O­nÄÀ©ñªº GpImage ª«¥ó¡C¦pªG°õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡F¦pªG¥¢±Ñ¡A¦^¶Ç­È¬°¨ä¿ù»~½X¡A¨£¤Wªí¤@¡C

¥Î GDI¡Ï Åã¥Ü¹Ï¤ùÀÉ

°²¦p­n¥Î GDI¡Ï ©óµøµ¡¤u§@°Ï¤WÅã¥Ü¹Ï¤ùÀÉ¡A¬O¤£¿ùªº¿ï¾Ü¡A¦]¬° GDI¡Ï ¤ä´©³\¦hºØ®æ¦¡ªº¹Ï¤ùÀÉ¡C©³¤U²­z³o¬q¹Lµ{¡G

  1. ©I¥s GdipLoadImageFromFile §â¹Ï¤ùÀÉÅܦ¨ GpImage ª«¥ó¡C
  2. ©I¥s GdipCreateFromHDC «Ø¥ß»P¸Ë¸m¤º®e¬ÛÃöÁpªº GpGraphics ª«¥ó¡C
  3. ©I¥s GdipDrawImageRectI ±N GpImage ª«¥óø»s©ó GpGraphics ª«¥ó¤W¡A¦]¬° GpGraphics ª«¥ó»P¸Ë¸m¤º®e¬ÛÃöÁp¡A´N¯à§â¹Ï¤ùÀÉÅã¥Ü¨ä¤W¡C

¤W­±ªº¹Lµ{¬O³Ì®Ö¤ßªº³¡¤À¡A¨Ã¤£¥]§t¨Ï¥Î GDI¡Ï «eªºªì©l¤Æ¤Î¨Ï¥Î«áªºÄÀ©ñ GDI¡Ï ¸ê·½¡A¤]¤£¥]§tÄÀ©ñ GpGraphics »P GpImage ª«¥ó¡C°²¦p­nÅýÅã¥Ü¦bµøµ¡¤u§@°Ï¹Ï¤ùÀɼe«×»P°ª«×¡A«ê¦n®e¯Ç©ó¤u§@°Ï¤º¡A¨º»ò´N±o½Õ¾ãµøµ¡¤u§@°Ï¤j¤p¡A³s±a¤]·|½Õ¾ãµøµ¡¤j¤p¡C

AdjustWindowRectEx API

AdjustWindowRectEx ¯à®Ú¾ÚÀ³¥Îµ{¦¡©Ò«ü©wªº¤u§@°Ï¼e«×»P°ª«×¡A­pºâµøµ¡¤j¤p¡CAdjustWindowRectEx ¶È­pºâµøµ¡ªº¤Ø¤o¡A¨Ã¤£·|¯u¥¿§ïÅܨä¤Ø¤o¡A¦]¦¹ÁÙ­n§â©Ò±oªºµøµ¡¤j¤p¡A¥H°Ñ¼Æ¶Çµ¹ CreateWindowEx ©Î SetWindowPos ¤~¯à¯u¥¿Åýµøµ¡¤ºªº¤u§@°Ï¡A²Å¦XÀ³¥Îµ{¦¡©Ò«ü©wªº¡CAdjustWindowRectEx ªº­ì«¬¦p¤U¡G

invoke  AdjustWindowRectEx,\
        lpRect,\        ; pointer to client-rectangle structure
        dwStyle,\       ; window styles
        bMenu,\         ; menu-present flag
        dwExStyle       ; extended style

©³¤U»¡©ú³o¨Ç°Ñ¼Æªº·N¸q¡G

  1. lpRect ¬O RECT µ²ºcÅé¦ì§}¡C¦b©I¥s AdjustWindowRectEx «e¡A¦¹µ²ºcÅ餺¥²¶·¤w¦s¦³«ü©wªº¤u§@°Ï¥ª¤W¨¤¤Î¥k¤U¨¤®y¼Ð¡F¦pªG AdjustWindowRectEx °õ¦æ¦¨¥\¡A¦¹µ²ºcÅé·|Åܬ°µøµ¡ªº¥ª¤W¨¤¤Î¥k¤U¨¤®y¼Ð¡A¦Ó¦¹µøµ¡ªº¤u§@°Ï«ê¦n¬O©I¥s«eÀ³¥Îµ{¦¡©Ò«ü©wªº¡C
  2. dwStyle ¬Oµøµ¡­·®æ¡A¦]¬°¦³¨Çµøµ¡­·®æ·|¼vÅTµøµ¡¤j¤p¡A¬G¦¹°Ñ¼Æªí¥Üµøµ¡­·®æ¹ïµøµ¡¤Ø¤oªº¼vÅT¡CdwStyle ¤£¯à¬O¶È¶È WS_OVERLAPPED ³æ¿W¦s¦b¡A¦]¬° WS_OVERLAPPED ¤§¼Æ­È¬O 0¡A¨Ã¤£´£¨Ñ¥ô¦óÃB¥~ªºµøµ¡­·®æ¡C
  3. bMenu ¥Î©óªí¥Üµøµ¡¬O§_¦³¥D¥\¯àªí¡A¥D¥\¯àªí¤]·|¼W¥[µøµ¡°ª«×¡C¦pªG¨ã¦³¥D¥\¯àªí¡AÀ³±N bMenu ³]¬° 1¡F§_«h³]¬° 0¡C
  4. dwExStyle ¬Oµøµ¡ªºÃB¥~­·®æ¡A¥¦¤]·|§ïÅܵøµ¡¤Ø¤o¡C

lpRect ©Ò«üªº RECT µ²ºcÅé¦b©I¥s«e¡A¥ª¤W¨¤®y¼Ð¤£¤@©w¥²¶·¬O ( 0,0 )¡A¥i¥H¬O¨ä¥L®y¼Ð¡C§Ú­Ì¥i¥H§â RECT µ²ºcÅ骺¥ª¤W¨¤»P¥k¤U¨¤®y¼Ð¡A·Q¹³¦¨¬O¿Ã¹õ®y¼Ð¡A¦Ó¨ä®t­È´N¬O¤u§@°Ïªº¼e«×»P°ª«×¡CAdjustWindowRectEx ­pºâ®É¡A·|±NÃä®Ø¡B¼ÐÃDÄæµ¥¦]¯À¦Ò¼{¶i¥h¡A¦Ó¨Ï¥ª¤W¨¤®y¼Ð©¹¥ª¤W¤èÂX¥R¡A¥k¤U¨¤®y¼Ð©¹¥k¤U¤èÂX¥R¡A¥H¦Ü©ó¨Ï RECT µ²ºcÅéÅܦ¨µøµ¡ªº¥ª¤W¨¤»P¥k¤U¨¤®y¼Ð¡A¦ý¨ä¤u§@°Ïªº¥ª¤W¨¤»P¥k¤U¨¤®y¼Ð¤´¤£ÅÜ¡A¥u¬O¨Sªí¥Ü¥X¨Ó¡C

AdjustWindowRectEx ¤£·|±N WS_VSCROLL ©Î WS_HSCROLL ¯Ç¤J¦Ò¼{¡C­Y­n¦Ò¼{±²°Ê¶b¡A½Ð¨Ï¥Î SM_CXVSCROLL ©Î SM_CYHSCROLL ©I¥s GetSystemMetrics¡C¦pªG¥D¥\¯àªí¦³¨â¦C¡A¨º»ò AdjustWindowRectEx µLªk³B²z¡A¥²¶·¥Î SM_CYMENU ¬°°Ñ¼Æ©I¥s GetSystemMetrics¡A±o¨ì¥D¥\¯àªí¨C¦C°ª«×¡C¦pªG AdjustWindowRectEx °õ¦æ¦¨¥\¦^¶Ç­È¬° 1¡A§_«h¬°¹s¡C


½d¨Ò VIEWIMG

±µ¤U¨Ó´N±N¤W­±©Ò´£¹Lªº­ì²z¤Î GDI¡Ï API À³¥Î¦b²Õ¦X»y¨¥ùØ¡A¼¶¼g¤@­Ó¯àÆ[¬Ý¸û¦h®æ¦¡¹Ï¤ùÀɪº VIEWIMG À³¥Îµ{¦¡¡C©³¤U¬O VIEWIMG.EXE.MANIFEST ªº¤º®e¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    type="win32"
    name="AtHome.Wanker.ViewImg"
    version="1.0.0.0"
    processorArchitecture="amd64"
  />
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="amd64"
        publicKeyToken="6595b64144ccf1df"
        language="*"
      />
    </dependentAssembly>
  </dependency>
</assembly>

©³¤U¬O VIEWIMG.RC ªº¤º®e¡G

1
2
3
4
5
6
#include "RESOURCE.H"

#define RT_MANIFEST 24
1       RT_MANIFEST MOVEABLE PURE "VIEWIMG.EXE.MANIFEST"

2000    ICON    EYE.IC

©³¤U¬O VIEWIMG.ASM ªº¤º®e¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
OPTION  CASEMAP:NONE
OPTION  WIN64:3
OPTION  LITERALS:ON

UNICODE  EQU    1      ;¨Ï¥ÎUNICODE½s½X¦r¤¸

INCLUDE         WINDOWS.INC ;¥]§tGDIPLUS.INC¡A«Å§iGDI¡Ï¨ç¦¡
INCLUDE         GDIPLUS.INC ;¥]§tGDIPLUS.LIB¡A¨ÏGDI¡Ï¨ç¦¡¯à¶¶§Q³sµ²
INCLUDELIB      GDIPLUS.LIB
INCLUDELIB      GDI32.LIB
INCLUDELIB      KERNEL32.LIB
INCLUDELIB      USER32.LIB
;*******************************************************************************
.DATA
hInst           DQ      ?
gdipToken       DQ      ?   ;Token
gdipImage       DQ      ?   ;GpImageª«¥ó
gdipGraphics    DQ      ?   ;GpGraphicsª«¥ó
gdipStart       GdiplusStartupInput <1,0,0,0>   ;ªì©l¤ÆGDI¡Ï©Ò»Ý¸ê®Æ
szClassName     DW  "VIEWIMG",0
szTitle         DW  770bh,5716h,7a0bh,5f0fh,0   ;¬Ý¹Ïµ{¦¡
szFileName      DW  "re2r.jpg",0                ;¹Ï¤ùÀɪºÀɦW
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
WndProc PROC    hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL   hDC:HDC,ps:PAINTSTRUCT,cxImg:DWORD,cyImg:DWORD,rcWnd:RECT
.if uMsg==WM_PAINT
        mov     hDC,RV(BeginPaint,hWnd,ADDR ps)
    ;§â¹Ï¤ùÀÉÅܦ¨GpImageª«¥ó¡B«Ø¥ß»PhDC¬ÛÃöÁpªºGpGraphicsª«¥ó¡A±o¨ìGpImageªº¤Ø¤o
        invoke  GdipLoadImageFromFile,OFFSET szFileName,OFFSET gdipImage
        invoke  GdipCreateFromHDC,hDC,OFFSET gdipGraphics
        invoke  GdipGetImageWidth,gdipImage,ADDR cxImg
        invoke  GdipGetImageHeight,gdipImage,ADDR cyImg
    ;­pºâµøµ¡¤Ø¤o¡A¥H²Å¦X¹Ï¤ù¤Ø¤o
        mov     rcWnd.left,0
        mov     rcWnd.top,0
        mov     eax,cxImg
        mov     ecx,cyImg
        mov     rcWnd.right,eax
        mov     rcWnd.bottom,ecx
        invoke  AdjustWindowRectEx,ADDR rcWnd,WS_OVERLAPPEDWINDOW,0,0
    ;³]©wµøµ¡¦ì¸m¤Î¤Ø¤o
        mov     r10d,rcWnd.right
        mov     r11d,rcWnd.bottom
        sub     r10d,rcWnd.left
        sub     r11d,rcWnd.top
        invoke  SetWindowPos,hWnd,0,50,50,r10d,r11d,SWP_NOZORDER
    ;§âGpImageª«¥óø»s©óGpGraphics¤W
        invoke  GdipDrawImageRectI,gdipGraphics,gdipImage,0,0,cxImg,cyImg
    ;ÄÀ©ñGpImage»PGpGraphicsª«¥ó
        invoke  GdipDisposeImage,gdipImage
        invoke  GdipDeleteGraphics,gdipGraphics
        invoke  EndPaint,hWnd,ADDR ps

.elseif uMsg==WM_DESTROY
        invoke  PostQuitMessage,0

.else
def:    invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
        ret

.endif
rtn:    xor     rax,rax
        ret
WndProc ENDP
;-------------------------------------------------------------------------------
main    PROC
        LOCAL   hwnd:HWND,msg:MSG,wc:WNDCLASSEX
        mov     hInst,RV(GetModuleHandle,0)
        mov     wc.cbSize,SIZEOF WNDCLASSEX
        lea     rdx,WndProc
        mov     wc.style,CS_HREDRAW or CS_VREDRAW
        mov     wc.lpfnWndProc,rdx
        mov     wc.cbClsExtra,0
        mov     wc.cbWndExtra,0
        mov     wc.hInstance,rax
        mov     wc.hIcon,RV(LoadIcon,hInst,2004)
        mov     wc.hIconSm,rax
        mov     wc.hCursor,RV(LoadCursor,0,IDC_ARROW)
        mov     wc.hbrBackground,COLOR_WINDOW+1
        mov     wc.lpszMenuName,0
        lea     rdx,szClassName
        mov     wc.lpszClassName,rdx
        invoke  RegisterClassEx,ADDR wc
        mov     hwnd,RV(CreateWindowEx,0,ADDR szClassName,OFFSET szTitle,\
                WS_OVERLAPPEDWINDOW,50,50,400,200,0,0,hInst,0)
        invoke  GdiplusStartup,OFFSET gdipToken,OFFSET gdipStart,0
        invoke  ShowWindow,hwnd,SW_SHOWNORMAL
        invoke  UpdateWindow,hwnd
.while TRUE
        invoke  GetMessage,ADDR msg,0,0,0
.break .if rax==0
        invoke  TranslateMessage,ADDR msg
        invoke  DispatchMessage,ADDR msg
.endw
        invoke  GdiplusShutdown,gdipToken
        invoke  ExitProcess,0
main    ENDP
;*******************************************************************************
END      main

³o­Óµ{¦¡ªº­ì²z³£¤w¸g´£¹L¡A¤£¦h»¡¤F¡C