I have a fix, I'll be posting shortly, the script needs to handle WM_ERASEBKGND.
Code: Select all
;WM_ERASEBKGND := 0x14
OnMessage(0x14, "WM_ERASEBKGND")
q:: ;draw bitmap/icon onto GUI
vToggle := !vToggle
vMgnX := 5, vMgnY := 5
;vImgW := 32, vImgH := 32
vImgW := 256, vImgH := 256
vImgX := vMgnX, vImgY := vMgnY
vWinW := vImgW + 2*vMgnX
vWinH := vImgH + 2*vMgnY
if vToggle
hBitmap := LoadPicture(A_AhkPath, Format("W{} H{}", vImgW, vImgH)), vImgType := 0
else
hIcon := LoadPicture(A_AhkPath, Format("W{} H{}", vImgW, vImgH), vImgType)
;WinGet, hWnd, ID, ahk_class Notepad
Gui, New, +HwndhGui
Gui, Show, % Format("W{} H{}", vWinW, vWinH)
hWnd := hGui
;===============
;test code to redraw the image
w::
if InStr(A_ThisHotkey, "w")
{
WinGet, hWnd, ID, A
WinGetClass, vWinClass, % "ahk_id " hWnd
if !(vWinClass = "AutoHotkeyGUI")
return
}
;===============
hDC1 := DllCall("user32\GetDC", Ptr,hWnd, Ptr)
if (vImgType = 0) ;IMAGE_BITMAP := 0
{
hDC := DllCall("gdi32\CreateCompatibleDC", Ptr,hDC1, Ptr)
hBitmapOld := DllCall("gdi32\SelectObject", Ptr,hDC, Ptr,hBitmap, Ptr)
DllCall("gdi32\BitBlt", Ptr,hDC1, Int,vImgX, Int,vImgY, Int,vImgW, Int,vImgH, Ptr,hDC, Int,0, Int,0, UInt,0x00CC0020) ;SRCCOPY := 0x00CC0020
DllCall("gdi32\SelectObject", Ptr,hDC, Ptr,hBitmapOld, Ptr)
DllCall("gdi32\DeleteDC", Ptr,hDC)
}
else if (vImgType = 1) ;IMAGE_ICON := 1
DllCall("user32\DrawIconEx", Ptr,hDC1, Int,vMgnX, Int,vMgnX, Ptr,hIcon, Int,vImgW, Int,vImgH, UInt,0, Ptr,0, UInt,0x3) ;DI_NORMAL := 0x3
return
WM_ERASEBKGND(wParam, lParam, uMsg, hWnd2)
{
global
vDoDrawImg := 1 ;set this to 0 and the image won't be redrawn
vDoDrawBgd := 1 ;set this to 0 and the background won't be redrawn
;return ;uncomment this line and the window will be blank
hWnd := hWnd2
if !(hWnd = hGui)
return
hDC1 := DllCall("user32\GetDC", Ptr,hWnd, Ptr)
if !vDoDrawImg
Sleep, 0
else if (vImgType = 0) ;IMAGE_BITMAP := 0
{
hDC := DllCall("gdi32\CreateCompatibleDC", Ptr,hDC1, Ptr)
hBitmapOld := DllCall("gdi32\SelectObject", Ptr,hDC, Ptr,hBitmap, Ptr)
DllCall("gdi32\BitBlt", Ptr,hDC1, Int,vImgX, Int,vImgY, Int,vImgW, Int,vImgH, Ptr,hDC, Int,0, Int,0, UInt,0x00CC0020) ;SRCCOPY := 0x00CC0020
DllCall("gdi32\SelectObject", Ptr,hDC, Ptr,hBitmapOld, Ptr)
DllCall("gdi32\DeleteDC", Ptr,hDC)
}
else if (vImgType = 1) ;IMAGE_ICON := 1
DllCall("user32\DrawIconEx", Ptr,hDC1, Int,vMgnX, Int,vMgnX, Ptr,hIcon, Int,vImgW, Int,vImgH, UInt,0, Ptr,0, UInt,0x3) ;DI_NORMAL := 0x3
if vDoDrawBgd
{
hDC2 := wParam
DllCall("gdi32\ExcludeClipRect", Ptr,hDC2, Int,vImgX, Int,vImgY, Int,vImgX+vImgW, Int,vImgY+vImgH)
hRgn := DllCall("gdi32\CreateRectRgn", Int,0, Int,0, Int,1, Int,1, Ptr)
DllCall("gdi32\GetClipRgn", Ptr,hDC2, Ptr,hRgn)
hBrush := DllCall("user32\GetSysColorBrush", Int,15, Ptr) ;COLOR_BTNFACE := 15
DllCall("gdi32\FillRgn", Ptr,hDC2, Ptr,hRgn, Ptr,hBrush)
DllCall("gdi32\DeleteObject", Ptr,hRgn)
}
return 1
}