Code: Select all
Gui, Font, s10
Gui, Color, 854506
Transparency := 90
TextColor := "White"
HBITMAP := LoadPicture("pic.png")
Imagen("HBITMAP:" . HBITMAP, "?Normal:90 ", HBITMAP)
Gui, Add, Text, w156 h24 c%TextColor%, Imagen
Gui, Add, Text, xp yp wp hp hwndhText ,
T := New paintDC(hText, HBITMAP, Transparency)
T.SetRedraw(True)
; ------------------------------------------------------------
HBITMAP2 := LoadPicture("pic.png")
Imagen("HBITMAP:" . HBITMAP2, "?Normal:90 BackGroundTrans", HBITMAP2)
Gui, Add, Text, xm w156 h24 c%TextColor%, Imagen +BGTrans
Gui, Add, Text, xp yp wp hp hwndhText2 +BackgroundTrans,
T2 := New paintDC(hText2, HBITMAP2, Transparency)
T2.SetRedraw(True)
; ------------------------------------------------------------
HBITMAP3 := LoadPicture("pic.png")
SetTransparency(HBITMAP3, 90)
Gui, Add, Text, xm w156 h24 c%TextColor%, SetTransparency
Gui, Add, Text, xp yp wp hp hwndhText3 ,
T3 := New paintDC(hText3, HBITMAP3, Transparency)
T3.SetRedraw(True)
; ------------------------------------------------------------
; IMAGEN + BackgroundTrans
Imagen_hBitmap := LoadPicture("pic.png")
Imagen("HBITMAP:" . Imagen_hBitmap, "?Normal:90 BackGroundTrans", Imagen_hBitmap)
Gui, Add, Text, xm y+40 w156 h24 c%TextColor%, Imagen_hBitmap
Gui, Add, Picture, xp yp +BackGroundTrans,% "HBITMAP:" . Imagen_Hbitmap
; --------------------------------------------
; SET TRANSPARENCY
SetTrans_hBitmap := LoadPicture("pic.png")
SetTransparency(SetTrans_hBitmap, 90)
Gui, Add, Text, x+20 yp w156 h24 c%TextColor%, SetTrans_hBitmap
Gui, Add, Picture, xp yp +BackGroundTrans,% "HBITMAP:" . SetTrans_hBitmap
Gui, Show, w500 h300
return
Class paintDC {
__New(hWnd, hBitmap, Transparency) {
This.HLB := hWnd
This.hBitmap := hBitmap
This.Transparency := Transparency
This.HasBackground := False
This.Drawing := True
SCCB := RegisterCallback("paintDC.SubClassCallback")
DllCall("Comctl32.dll\SetWindowSubclass", "Ptr", hWnd, "Ptr", SCCB, "Ptr", hWnd, "Ptr", &This)
}
SubClassCallback(uMsg, wParam, lParam, IdSubclass, RefData) {
Critical 100
hWnd := This ; first parameter 'hWnd' is passed as 'This'
Return Object(RefData).SubClassProc(hWnd, uMsg, wParam, lParam)
}
SubClassProc(hWnd, uMsg, wParam, lParam) {
Static WM := { ERASEBKGND: 0x0014, PAINT: 0x000F }
If (uMsg = WM.ERASEBKGND) {
If (!This.HasBackground) {
;FileAppend, Erase! `n,*
SELDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr", , "UPtr")
pBitmap := Gdip_CreateBitmapFromHBITMAP(This.hBitmap)
Gdip_GetImageDimension(pBitmap, W, H)
This.Width := W
This.Height := H
Gdip_DisposeImage(pBitmap)
DllCall("Gdi32.dll\SelectObject", "Ptr", SELDC, "Ptr", This.hBitmap)
This.SELDC := SELDC
This.HasBackground := True
}
}
If (uMsg = WM.PAINT) {
VarSetCapacity(PAINTSTRUCT, A_PtrSize + (4 * 7) + 32 + (A_PtrSize - 4), 0)
LBDC := DllCall("USer32.dll\BeginPaint", "Ptr", hWnd, "Ptr", &PAINTSTRUCT, "UPtr")
WM_GETFONT := 0x0031
SendMessage, %WM_GETFONT%, 0, 0, , ahk_id %hWnd%
Font := ErrorLevel
HFONT := DllCall("Gdi32.dll\SelectObject", "Ptr", LBDC, "Ptr", Font, "UPtr")
DllCall("Gdi32.dll\SetBkMode", "Ptr", LBDC, "Int", 1) ; TRANSPARENT
VarSetCapacity(RECT, 16, 0)
DllCall("GetClientRect", "Ptr", hWnd, "Ptr", &RECT)
W := This.Width , H := This.Height
;DllCall("Gdi32.dll\BitBlt", "Ptr", LBDC, "Int", 0, "Int", 0, "Int", This.Width, "Int", This.Height, "Ptr", This.SELDC, "Int", 0, "Int", 0, "UInt", SRCCOPY := 0x00CC0020)
DllCall("Gdi32.dll\GdiAlphaBlend", "Ptr", LBDC, "Int", 0, "Int", 0, "Int", W, "Int", H , "Ptr", This.SELDC, "Int", 0, "Int", 0, "Int", W, "Int", H , "UInt", (This.Transparency << 16))
ControlGetText, Txt,, ahk_id %hWnd%
Len := StrLen(Txt)
DllCall("Gdi32.dll\SetTextColor", "Ptr", LBDC, "UInt", 0xFFFFFF)
DllCall("User32.dll\DrawText", "Ptr", LBDC, "Ptr", &Txt, "Int", Len, "Ptr", &RECT, "UInt", 0x0840)
DllCall("User32.dll\OffsetRect", "Ptr", &RECT, "Int", 0, "Int", This.Height)
}
Return DllCall("Comctl32.dll\DefSubclassProc", "Ptr", hWnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam)
}
SetRedraw(Mode) {
;FileAppend, Redraw! `n,*
Static WM_SETREDRAW := 0x000B
Mode := !!Mode
This.Drawing := Mode
SendMessage, %WM_SETREDRAW%, %Mode%, 0, , % "ahk_id " . This.HLB
If (Mode)
WinSet, Redraw, , % "ahk_id " . This.HLB
Return True
}
}
The hBitmap from Imagen() and the hBitmap from your previous function SetTransparency, look different, which one is correct?