Code: Select all
colorWithTransparency := 0x70AABB00
width := 300
height := 100
hBitmap := CreateColoredBitmap(width, height, colorWithTransparency)
RC := DrawText(hBitmap, "Timer:", "x45 y18 cAAAA00FF s40", "calibri")
x := RegExReplace(RC, "([^|]+\|){2}([^|]+).+", "$2") + 45
drawWidth := 250 - x
drawHeight := RegExReplace(RC, "([^|]+\|){3}([^|]+).+", "$2")
DrawLine(hBitmap, 0x99FF0000, [50, 70], [250, 70], 4)
Gui, Margin, 0, 0
Gui, Color, White
Gui, Add, Text, x10 y5, test
Gui, Add, Pic, x0 y0 BackgroundTrans hwndhPic, HBITMAP:*%hBitmap%
Gui, Show
pToken := Gdip_Startup()
hPicDc := GetDC(hPic)
SRCCOPY := 0xCC0020
MDC := CreateCompatibleDC()
MBM := CreateDIBSection(drawWidth, drawHeight)
oBM := SelectObject(MDC, MBM)
BitBlt(MDC, 0, 0, drawWidth, drawHeight, hPicDc, x, 18, SRCCOPY)
DrawDC := CreateCompatibleDC()
DrawBM := CreateDIBSection(drawWidth, drawHeight)
oDrawBM := SelectObject(DrawDC, DrawBM)
G := Gdip_GraphicsFromHDC(DrawDC)
Loop 1000 {
BitBlt(DrawDC, 0, 0, drawWidth, drawHeight, MDC, 0, 0, SRCCOPY)
Gdip_TextToGraphics(G, A_Index, "w" . drawWidth . " c809900DD s40 Center", "calibri")
BitBlt(hPicDc, x, 18, drawWidth, drawHeight, DrawDC, 0, 0, SRCCOPY)
Sleep, 10
}
Gdip_DeleteGraphics(G)
SelectObject(DrawDC, oDrawBM)
DeleteDC(DrawDC)
DeleteObject(DrawBM)
SelectObject(MDC, oBM)
DeleteDC(MDC)
DeleteObject(MBM)
DeleteDC(hPicDc)
Gdip_Shutdown(pToken)
DrawText(hBitmap, "1000", "x" x - 8 " y18 cAAAA00FF s40", "calibri")
GuiControl,, %hPic%, HBITMAP:%hBitmap%
Return
GuiClose() {
ExitApp
}
CreateColoredBitmap(width, height, color) {
hBitmap := GDI.CreateDIBSection(width, -height,, pBits)
Loop % height {
i := A_Index - 1
Loop % width
NumPut(color, pBits + (width*i + A_Index - 1)*4, "UInt")
}
Return hBitmap
}
DrawLine(ByRef hBitmap, color, FromXY, ToXY, thickness) {
DC := new GDI(hBitmap)
pToken := Gdip_Startup()
G := Gdip_GraphicsFromHDC(DC.MDC)
(color >> 24 = 0 && color |= 0xFF000000)
pPen := Gdip_CreatePen(color, thickness)
Gdip_DrawLine(G, pPen, FromXY[1], FromXY[2], ToXY[1], ToXY[2])
Gdip_DeletePen(pPen)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
}
DrawText(ByRef hBitmap, text, options, font, width := "", height := "") {
DC := new GDI(hBitmap)
pToken := Gdip_Startup()
G := Gdip_GraphicsFromHDC(DC.MDC)
RC := Gdip_TextToGraphics(G, text, options, font, width, height)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
Return RC
}
class GDI {
__New(ByRef hBitmap) {
static szBITMAP := 4*4 + A_PtrSize*2
VarSetCapacity(BITMAP, szBITMAP, 0)
DllCall("GetObject", "Ptr", hBitmap, "UInt", szBITMAP, "Ptr", &BITMAP)
width := NumGet(BITMAP, 4, "UInt")
height := NumGet(BITMAP, 8, "UInt")
hTmpBitmap := this.CreateDIBSection(width, -height)
this.MDC := DllCall("CreateCompatibleDC", "Ptr", 0, "Ptr")
this.hTmpObj := DllCall("SelectObject", "Ptr", this.MDC, "Ptr", hTmpBitmap, "Ptr")
this.DrawBackground(hBitmap, width, height)
DllCall("DeleteObject", "Ptr", hBitmap)
hBitmap := hTmpBitmap
}
__Delete() {
DllCall("SelectObject", "Ptr", this.MDC, "Ptr", this.hTmpObj, "Ptr")
DllCall("DeleteDC", "Ptr", this.MDC)
}
DrawBackground(hBitmap, width, height) {
static SRCCOPY := 0xCC0020
hTmpDC := DllCall("CreateCompatibleDC", "Ptr", this.MDC, "Ptr")
hTmpObj := DllCall("SelectObject", "Ptr", hTmpDC, "Ptr", hBitmap, "Ptr")
DllCall("BitBlt", "Ptr", this.MDC, "Int", 0, "Int", 0, "Int", width, "Int", height, "Ptr", hTmpDC, "Int", 0, "Int", 0, "UInt", SRCCOPY)
DllCall("SelectObject", "Ptr", hTmpDC, "Ptr", hTmpObj, "Ptr")
DllCall("DeleteDC", "Ptr", hTmpDC)
}
CreateDIBSection(w, h, bpp := 32, ByRef ppvBits := 0) {
hdc := DllCall("GetDC", "Ptr", 0, "Ptr")
VarSetCapacity(bi, 40, 0)
NumPut( 40, bi, 0, "UInt")
NumPut( w, bi, 4, "UInt")
NumPut( h, bi, 8, "UInt")
NumPut( 1, bi, 12, "UShort")
NumPut( 0, bi, 16, "UInt")
NumPut(bpp, bi, 14, "UShort")
hbm := DllCall("CreateDIBSection", "Ptr", hdc, "Ptr", &bi, "UInt", 0, "PtrP", ppvBits, "Ptr", 0, "UInt", 0, "Ptr")
DllCall("ReleaseDC", "Ptr", 0, "Ptr", hdc)
return hbm
}
}