moveable picture in gui? Topic is solved
moveable picture in gui?
how can i make a moveable picture in gui without mousegetpos loop?
Re: moveable picture in gui?
I mean that the picture is a control that could be moved with this command.
Re: moveable picture in gui?
I see. Others may know. I can only think of doing it by identifying a click on the image, and then following the mouse-- apparently not what you want here. Another idea is to create two GUIs, with the picture representing a single GUI.
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: moveable picture in gui? Topic is solved
An example:
Code: Select all
imageUrl := "https://i.imgur.com/26lSSUi.png"
Gui, New, +hwndhParent +LabelParent
Gui, New, +hwndhChild +Parent%hParent% -Caption
Gui, Margin, 0, 0
Gui, Add, Pic,, % "HBITMAP:" . GetHBitmapFromImageURL(imageUrl)
Gui, Show, NA x100 y100
Gui, %hParent%: Show, w460 h460
OnMessage( 0x201, Func("WM_LBUTTONDOWN").Bind(hChild) )
Return
ParentClose() {
ExitApp
}
WM_LBUTTONDOWN(hChild, wp, lp, msg, hwnd) {
if (hwnd = hChild)
PostMessage, WM_NCLBUTTONDOWN := 0xA1, HTCAPTION := 2,,, ahk_id %hChild%
}
GetHBitmapFromImageURL(url) {
Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Whr.Open("GET", url, true)
Whr.Send()
Whr.WaitForResponse()
if (Whr.Status != 200) {
MsgBox, Failed to load the image!
ExitApp
}
Return (new GDIplus).HBitmapFromStream(Whr.ResponseStream)
}
class GDIplus {
__New() {
if !DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr")
DllCall("LoadLibrary", "Str", "gdiplus")
VarSetCapacity(si, 8 + A_PtrSize*2, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "PtrP", pToken, "Ptr", &si, "Ptr", 0)
this.token := pToken
}
__Delete() {
DllCall("gdiplus\GdiplusShutdown", "Ptr", this.token)
if hModule := DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr")
DllCall("FreeLibrary", "Ptr", hModule)
}
HBitmapFromStream(Stream) {
DllCall("gdiplus\GdipCreateBitmapFromStream", "Ptr", ComObjValue(Stream), "PtrP", pBitmap)
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "PtrP", hBitmap, "UInt", 0xFFFFFFFF)
DllCall("gdiplus\GdipDisposeImage", "Ptr", pBitmap)
Return hBitmap
}
}
Re: moveable picture in gui?
Thank you, this is workingteadrinker wrote: ↑25 Oct 2021, 18:07An example:Code: Select all
imageUrl := "https://i.imgur.com/26lSSUi.png" Gui, New, +hwndhParent +LabelParent Gui, New, +hwndhChild +Parent%hParent% -Caption Gui, Margin, 0, 0 Gui, Add, Pic,, % "HBITMAP:" . GetHBitmapFromImageURL(imageUrl) Gui, Show, NA x100 y100 Gui, %hParent%: Show, w460 h460 OnMessage( 0x201, Func("WM_LBUTTONDOWN").Bind(hChild) ) Return ParentClose() { ExitApp } WM_LBUTTONDOWN(hChild, wp, lp, msg, hwnd) { if (hwnd = hChild) PostMessage, WM_NCLBUTTONDOWN := 0xA1, HTCAPTION := 2,,, ahk_id %hChild% } GetHBitmapFromImageURL(url) { Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") Whr.Open("GET", url, true) Whr.Send() Whr.WaitForResponse() if (Whr.Status != 200) { MsgBox, Failed to load the image! ExitApp } Return (new GDIplus).HBitmapFromStream(Whr.ResponseStream) } class GDIplus { __New() { if !DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr") DllCall("LoadLibrary", "Str", "gdiplus") VarSetCapacity(si, 8 + A_PtrSize*2, 0), si := Chr(1) DllCall("gdiplus\GdiplusStartup", "PtrP", pToken, "Ptr", &si, "Ptr", 0) this.token := pToken } __Delete() { DllCall("gdiplus\GdiplusShutdown", "Ptr", this.token) if hModule := DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr") DllCall("FreeLibrary", "Ptr", hModule) } HBitmapFromStream(Stream) { DllCall("gdiplus\GdipCreateBitmapFromStream", "Ptr", ComObjValue(Stream), "PtrP", pBitmap) DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Ptr", pBitmap, "PtrP", hBitmap, "UInt", 0xFFFFFFFF) DllCall("gdiplus\GdipDisposeImage", "Ptr", pBitmap) Return hBitmap } }
Re: moveable picture in gui?
@teadrinker thank you
How modify script if want use a picture from computer ? ( like c:\test.png )
How modify script if want use a picture from computer ? ( like c:\test.png )
Re: moveable picture in gui?
@teadrinker:
IMO, this will free the Gdiplus.dll even if the class did not load it. That might have unwanted side-effects.
Code: Select all
class GDIplus {
__New() {
if !DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr")
DllCall("LoadLibrary", "Str", "gdiplus")
VarSetCapacity(si, 8 + A_PtrSize*2, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "PtrP", pToken, "Ptr", &si, "Ptr", 0)
this.token := pToken
}
__Delete() {
DllCall("gdiplus\GdiplusShutdown", "Ptr", this.token)
if hModule := DllCall("GetModuleHandle", "Str", "gdiplus", "Ptr")
DllCall("FreeLibrary", "Ptr", hModule)
}
...
}
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: moveable picture in gui?
Yeah, you are right, I just copied this code from GDIp.ahk. This is better:
Code: Select all
class GDIplus {
__New() {
this.hLib := DllCall("LoadLibrary", "Str", "gdiplus", "Ptr")
VarSetCapacity(si, 8 + A_PtrSize*2, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "PtrP", pToken, "Ptr", &si, "Ptr", 0)
this.token := pToken
}
__Delete() {
DllCall("gdiplus\GdiplusShutdown", "Ptr", this.token)
DllCall("FreeLibrary", "Ptr", this.hLib)
}
...
}
Code: Select all
class GDIplus {
__New() {
static Instance := ""
if Instance.references++
Return Instance
this.hLib := DllCall("LoadLibrary", "Str", "gdiplus", "Ptr")
VarSetCapacity(si, 8 + A_PtrSize*2, 0), si := Chr(1)
DllCall("gdiplus\GdiplusStartup", "UPtrP", pToken, "Ptr", &si, "Ptr", 0)
this.token := pToken, this.references := 1
Return Instance := this
}
Release() {
if --this.references
Return
DllCall("gdiplus\GdiplusShutdown", "Ptr", this.token)
DllCall("FreeLibrary", "Ptr", this.hLib)
}
...
}
Code: Select all
imagePath := "D:\Downloads\Icons\github-logo-icon.png"
Gui, New, +hwndhParent +LabelParent
Gui, New, +hwndhChild +Parent%hParent% -Caption
Gui, Margin, 0, 0
Gui, Add, Pic,, % imagePath
Gui, Show, NA x100 y100
Gui, %hParent%: Show, w460 h460
OnMessage( 0x201, Func("WM_LBUTTONDOWN").Bind(hChild) )
Return
ParentClose() {
ExitApp
}
WM_LBUTTONDOWN(hChild, wp, lp, msg, hwnd) {
if (hwnd = hChild)
PostMessage, WM_NCLBUTTONDOWN := 0xA1, HTCAPTION := 2,,, ahk_id %hChild%
}
Re: moveable picture in gui?
@teadrinker , thank you , works fine