http://www.autohotkey.com/forum/topic10957.html
http://www.autohotkey.com/forum/topic29199.html
별도의 외부 이미지 파일 없이 스크립트 안에 이미지를 포함시키는 방법입니다.
1. 이미지파일 변환
오직 BMP 포맷만 지원합니다.
다음 스크립트를 실행시키고 가장 위의 Edit창에 변환할 bmp파일의 이름을 적고 Open File 버튼을 눌러줍니다.
밑의 Edit 창에 16진수로 변환된 이미지 파일의 내용이 나타납니다.
전체를 복사해서 텍스트 파일로 저장해 두세요.
gui, add, edit, w400 vFile,
gui, add, button, w100 gOpen x+10,Open File
gui, add, edit, r40 w510 vOutput xm
gui, show
Open:
gui, submit, nohide
BinRead(file,data)
Bin2Hex(h,data,res)
guicontrol,,output,%h%
return
Bin2Hex(ByRef h, ByRef b, n=0) ; n bytes binary data -> stream of 2-digit hex
{ ; n = 0: all (SetCapacity can be larger than used!)
format = %A_FormatInteger% ; save original integer format
SetFormat Integer, Hex ; for converting bytes to hex
m := VarSetCapacity(b)
If (n < 1 or n > m)
n := m
Address := &b
h =
Loop %n%
{
x := *Address ; get byte in hex
StringTrimLeft x, x, 2 ; remove 0x
x = 0%x% ; pad left
StringRight x, x, 2 ; 2 hex digits
h = %h%%x%
Address++
}
SetFormat Integer, %format% ; restore original format
}
BinRead(file, ByRef data, n=0, offset=0)
{
h := DllCall("CreateFile","Str",file,"Uint",0x80000000,"Uint",3,"UInt",0,"UInt",3,"Uint",0,"UInt",0)
IfEqual h,-1, SetEnv, ErrorLevel, -1
IfNotEqual ErrorLevel,0,Return,0 ; couldn't open the file
m = 0 ; seek to offset
IfLess offset,0, SetEnv,m,2
r := DllCall("SetFilePointerEx","Uint",h,"Int64",offset,"UInt *",p,"Int",m)
IfEqual r,0, SetEnv, ErrorLevel, -3
IfNotEqual ErrorLevel,0, {
t = %ErrorLevel% ; save ErrorLevel to be returned
DllCall("CloseHandle", "Uint", h)
ErrorLevel = %t% ; return seek error
Return 0
}
m := DllCall("GetFileSize","UInt",h,"Int64 *",r)
If (n < 1 or n > m)
n := m
Granted := VarSetCapacity(data, n, 0)
IfLess Granted,%n%, {
ErrorLevel = Mem=%Granted%
Return 0
}
result := DllCall("ReadFile","UInt",h,"Str",data,"UInt",n,"UInt *",Read,"UInt",0)
if (!result or Read < n)
t = -3
IfNotEqual ErrorLevel,0, SetEnv,t,%ErrorLevel%
h := DllCall("CloseHandle", "Uint", h)
IfEqual h,-1, SetEnv, ErrorLevel, -2
IfNotEqual t,,SetEnv, ErrorLevel, %t%-%ErrorLevel%
Return Read
}
2. 다음 스크립트의 ~~~부분에 위에서 구한 16진수 데이터를 적당한 크기로 나눠서 넣어주시면 끝~
LoadBitmap1:
BMPH =
(
;~~~~~~~~~~~~~~~~~
)
BMPH =%BMPH%
(
;~~~~~~~~~~~~~~~~~
)
다음은 제가 직접 만들어서 확인한 예제입니다.
Gui 1:+LastFound
GUI1:=WinExist() , hDC:=DllCall("GetDC",UInt,Gui1)
Gui, Add, Text, w32 h32 0xE hwndhPic ; SS_BITMAP = 0xE
GoSub, LoadBitmap1
hBMP := DllCall( "CreateDIBitmap", UInt,hDC, UInt,(bmiHAddr:=&BMP+14)
,UInt,(CBM_INIT:=4), UInt,&BMP+NumGet(BMP,10), UInt,&BMP+14, UInt,(DIB_PAL_COLORS:=1) )
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBMP,, ahk_id %hPic%
Gui, Show, w160 h120, sample
Return
GuiClose:
GuiEscape:
ExitApp
Return
LoadBitmap1:
BMPH =
(
424d360c000000000000360000002800000020000000200000000100180000000000000c000012170000121700000000000000000000ffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffffffffff000000ffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff000000ffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000ffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff33ccff000000ffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffffffffffffffffffffff00000000000033ccff33ccff33ccff33ccff33ccff000000ffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffffffffff00000000000033ccff33ccff33ccff33ccff000000000000000000000000000000ffff
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff33ccff33ccff33ccff0000006699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff0000006699cc000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffff
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff0000006699cc0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000033ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff00000033ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff0000006699cc6699cc6699cc6699cc6699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000000000000000033ccff33ccff33ccff33ccff33ccff33ccff0000000000000000006699cc6699cc6699cc6699cc000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000000000033ccff33ccff
)
BMPH =%BMPH%
(
33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000033ccff33ccff00000033ccff33ccff33ccff00000000000000000000000033ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff00000000000033ccff33ccff33ccff000000ffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff00000033ccff33ccff33ccff000000ffffffffffff000000ffffffffffffffffff000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffff000000ffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffff000000ffffff0000
)
BMPH =%BMPH%
(
00ffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffff000000ffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000000000000000000000000000ffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffff00000033ccff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000033ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff33ccff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff00000000000000000033ccff33ccff33ccff33ccff33ccff33ccff000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000ffffffffffff000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000ffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000
)
BMPH =%BMPH%
(
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
)
; Laszlo's MCode() ; http://www.autohotkey.com/forum/viewtopic.php?p=135302#135302
nSize := StrLen(BMPH)//2
VarSetCapacity( BMP,nSize )
Loop % nSize
NumPut( "0x" . SubStr(BMPH,2*A_Index-1,2), BMP, A_Index-1, "Char" )
BMPH= ; empty it
Return
출처 http://www.autohotkey.pe.kr/bbs/board.php?bo_table=tip&wr_id=172&page=3