I'm using GDI+ to draw to an empty picture control within my Gui.
It successfully updates the background color of the image to GREEN, however if I resize the Gui, move it off & on the screen, minimize/restore, etc it will go back to BLACK.
Any suggestions on how to keep the update from disappearing?
I'm thinking I need SendMessage or something like that...
Code: Select all
#SingleInstance Force
Persistent
If (!DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "UPtr")) { ; Load GDI+ module
Throw Error("Failed to load Gdiplus library")
}
GdiplusStartupInput := Buffer(A_PtrSize = 8 ? 24 : 16, 0) ; GdiplusStartupInput structure
NumPut("UInt", 1, GdiplusStartupInput) ; GdiplusVersion
DllCall("Gdiplus.dll\GdiplusStartup", "UPtr*", &pToken := 0, "UPtr", GdiplusStartupInput.Ptr, "UPtr", 0) ; Initialize GDI+
If (!pToken) {
Throw Error("Failed to start Gdiplus")
}
; Create a Bitmap object
DllCall("Gdiplus.dll\GdipCreateBitmapFromScan0", "Int", 640, "Int", 480, "Int", 0, "Int", 0x26200A, "UPtr", 0, "UPtr*", &pBackgroundImage := 0)
; Create a Graphics object associated with pBackgroundImage
DllCall("Gdiplus.dll\GdipGetImageGraphicsContext", "UPtr", pBackgroundImage, "UPtr*", &pBackgroundGraphics := 0)
MyGui := Gui()
MyGui.MarginX := 0
MyGui.MarginY := 0
MyGui.Opt("+LastFound +DPIScale +Resize")
MyGui.Title := "Example"
MyGui.Name := "Example"
MyGui.BackColor := "000000"
hBackground := MyGui.Add("Picture", "x0 y0 w640 h480 +0xE")
; Get pointer to control graphics image
DllCall("Gdiplus.dll\GdipCreateFromHWND", "UPtr", hBackground.Hwnd, "UPtr*", &pControlGraphics := 0)
MyGui.Show("w640 h480")
DllCall("Gdiplus.dll\GdipGraphicsClear", "UPtr", pBackgroundGraphics, "Int", 0xFF00FF00)
DllCall("Gdiplus.dll\GdipDrawImage", "UPtr", pControlGraphics, "UPtr", pBackgroundImage, "Float", 0, "Float", 0)
return ; End automatic execution
F5::Reload