Working with GDIP2 windows. Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Xeilous
Posts: 12
Joined: 04 Feb 2018, 04:06

Working with GDIP2 windows.

04 Feb 2018, 07:50

I haven't been able to find many examples on this. Hopefully I can get some help here. I'm using GDI+
https://github.com/tariqporter/Gdip2

1. Is there a way to draw the new text in a GDIP2 window without redrawing everything else, or is the way that I've done it correct?

2. How do I make it so that when the user presses F1, the window is redrawn at the new position(if it was moved), instead of it snapping back into the original position? OnMessage(0x03, "WM_MOVE") doesn't seem to work, which is what I presume I could use to store the window X & Y positions.

Code: Select all

#Persistent
#SingleInstance Force

#Include ..\dist\Gdip2.ahk

; Start Gdip
gdip1 := new Gdip()

; Create a window w = 300, h = 200 using a Size Object
size1 := new gdip1.Size(300, 200)
win1 := new gdip1.Window(size1)

; Create a solid brush using A, R, G, B
brush1 := new gdip1.Brush(170, 0, 0, 0)

; We can call any draw/fill function with x, y, w, h, or we can use a point object, size object
win1.FillRoundedRectangle(brush1, new gdip1.Point(0, 0), size1, 20)

options1 := {}
options1.brush := new gdip1.Brush(187, 255, 255, 255)
options1.style := ["underline", "italic"]
options1.horizontalAlign := "center"
options1.width := win1.width
options1.height := win1.height
options1.size := 20
win1.WriteText("Original Text", options1)

; Update the window with its current position
win1.Update({ x: (A_ScreenWidth-size1.width)//2, y: (A_ScreenHeight-size1.height)//2 })

; By placing this OnMessage here. The function WM_LBUTTONDOWN will be called every time the user left clicks on the gui
OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x03, "WM_MOVE")
return

;#######################################################################

; This function is called every time the user clicks on the gui
; The PostMessage will act on the last found window (this being the gui that launched the subroutine, hence the last parameter not being needed)
WM_LBUTTONDOWN()
{
   PostMessage, 0xA1, 2
}

; WM_MOVE does not work
WM_MOVE(wParam, lParam)
{
    X := lParam & 0xFFFF
    Y := lParam >> 16
 /*   if A_GuiControl
        Control := "`n(in control " . A_GuiControl . ")"
*/
    ToolTip You are moving the Gui window #%A_Gui% at client coordinates %X%x%Y%.%Control%
}
;#####################################################################################

Esc::
ExitApp
return

; Press F1 to redraw the window with different text
; PROBLEM: Window resets position to center of screen
F1::
win1.Clear()
win1.FillRoundedRectangle(brush1, new gdip1.Point(0, 0), size1, 20)
win1.WriteText("New Text", options1)
; Update the window with its current position
win1.Update()
return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Working with GDIP2 windows.  Topic is solved

04 Feb 2018, 09:50

Try this: (added a line at the end)

Code: Select all

; Update the window with it's current position
WinGetPos, WinX, WinY,,, % "ahk_id " win1.hwnd
win1.Update({x: WinX, y: WinY})
I hope that helps.
Xeilous
Posts: 12
Joined: 04 Feb 2018, 04:06

Re: Working with GDIP2 windows.

04 Feb 2018, 10:25

Yes! Thanks. So in order to update the contents of the window, must I redraw everything, even if I only need to update the text? It's not a big deal, but it would be good to know.

For example:

Code: Select all

F1::
win1.Clear()
win1.FillRoundedRectangle(brush1, new gdip1.Point(0, 0), size1, 20)
win1.WriteText("New Text", options1)
; Update the window with it's current position
WinGetPos, WinX, WinY,,, % "ahk_id " win1.hwnd
win1.Update({x: WinX, y: WinY})
return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Working with GDIP2 windows.

04 Feb 2018, 10:32

I think yes, you need to draw everything, just as you do there. I'm not entirely sure though.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Working with GDIP2 windows.

04 Feb 2018, 11:21

you need to draw everything
You can make partial changes using Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0) in the old version gdip but i have no experience with classes and its syntax.
I tried it with the setclip in gdip2 but i failed and there is no resetclip available in gdip2.

I guess there is an error in gdip2 for the update function ,you should be able to use win1.update() like in the old version gdip but the if condition in the code does not work it - if (paramObj.x != "")- is true when the default is paramObj=0 ,if you remove the condition it works.( maybe for the wrong reason ....)

Code: Select all

	
		Update(paramObj=0)
		{
			if (paramObj.x != "")   
				this.point.x := paramObj.x

			if (paramObj.y != "")
				this.point.y := paramObj.y
				
				

			return this.UpdateLayeredWindow(this.hwnd, this.obj.hdc, this.x, this.y, this.width, this.height, this.alpha)
		}
soundcloud.com/user-32706894

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], Escamillo, Eureka, just me, PIGuySteve and 213 guests