Redraw problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Redraw problem

02 Oct 2020, 13:09

I'm using a PictureBox in my GUI. When other windows covers the GUI, something will happen as the pictures showing below.
I remember I saw some threads in the forum long time ago, but I cannot find them. It looks related with "Redraw". Can someone help? Please!

Snap1.jpg
Snap1.jpg (172.97 KiB) Viewed 669 times
Snap2.jpg
Snap2.jpg (93.88 KiB) Viewed 669 times
User avatar
mikeyww
Posts: 26891
Joined: 09 Sep 2014, 18:38

Re: Redraw problem

03 Oct 2020, 12:17

GuiControl might help. I have not tried it.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Redraw problem

04 Oct 2020, 10:08

seems like a shoddily implemented windowproc for the picture control
without seeing the code, no further statements can be made
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Redraw problem

04 Oct 2020, 12:30

The problem is related with GDI. same as PhiLho described here: https://autohotkey.com/board/topic/11620-tips-drawing-on-autohotkey-gui-with-gdi32/

My code was written long time ago. I used GDI drawing code modified form a code similar to PhiLho's.

Code: Select all

WinGet,hGuiWnd,id, A 
 hGuiWnd := WinExist()
hGuiDC := DllCall("GetDC", "UInt",  hGuiWnd)

Code: Select all

writeText(textString,textLen,x,y)
{
	global hGuiDC
	DPIScale(x,y)
	 DllCall("TextOut","uint",hGuiDC,"int",x,"int",y,"str",textString,"int",textLen) 
}

Line(x1,y1,x2,y2,myColor,lineWidth)
{
   	global hGuiDC
   	DPIScale(x1,y1,x2,y2,lineWidth)
   hCurrPen := DllCall("CreatePen", "UInt", PS_SOLID, "UInt", lineWidth, "UInt", myColor)
   hOldPen := DllCall("SelectObject", "UInt", hGuiDC, "UInt", hPen)
   DllCall("SelectObject" ,"UInt",hGuiDC,"UInt",hCurrPen) 
   DllCall("MoveToEx" ,"UInt",hGuiDC, "UInt",x1,"UInt",y1,"UInt",0) 
   DllCall("LineTo" ,"UInt",hGuiDC,"UInt",x2,"UInt",y2)
   DllCall("SelectObject", "UInt", hGuiDC, "UInt", hOldPen)
   DllCall("DeleteObject", "UInt", hCurrPen) 
}

rect(x1,y1,x2,y2,framColor,FillColor,BorderWidth)
{
	global hGuiDC
	DPIScale(x1,y1,x2,y2,BorderWidth)
	
    hPen := DllCall("CreatePen", "UInt", PS_SOLID, "UInt", BorderWidth, "UInt", framColor)
    hBrush := DllCall("CreateSolidBrush", "UInt", FillColor) 
    hOldPen := DllCall("SelectObject", "UInt", hGuiDC, "UInt", hPen) 
    hOldBrush := DllCall("SelectObject", "UInt", hGuiDC, "UInt", hBrush) 
    ; x, y for top-left, x, y for bottom-right 
    DllCall("Rectangle", "UInt", hGuiDC, "UInt", x1, "UInt", y1, "UInt", x2, "UInt", y2) 
    DllCall("SelectObject", "UInt", hGuiDC, "UInt", hOldPen) 
    DllCall("SelectObject", "UInt", hGuiDC, "UInt", hOldBrush) 
    DllCall("DeleteObject", "UInt", hPen) 
    DllCall("DeleteObject", "UInt", hBrush)	
}
Last edited by oldbrother on 04 Oct 2020, 21:50, edited 2 times in total.
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: Redraw problem

04 Oct 2020, 17:59

very cool, looks like the cross section of a four flute endmill, grinder toolpaths maybe? As someone who only uses endmills and doesn't create them that looks very intriguing

anyway, instead of manually handling the redrawing with gdi directly to the window each needed, I would recommend creating a gui, picture control and draw to a bitmap, then sendmessage the gdi picture data to the control... i've only used gdi+ but i think its the same with pure gdi

Code: Select all

SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hPicture%
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Redraw problem

05 Oct 2020, 20:41

Thank you!
gwarble wrote:
04 Oct 2020, 17:59
very cool, looks like the cross section of a four flute endmill, grinder toolpaths maybe? As someone who only uses endmills and doesn't create them that looks very intriguing
You are right. The script is for end mill fluting simulation. It works fine. But my coding is a mess :cry:
Snap1.png
Snap1.png (46.95 KiB) Viewed 515 times
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Redraw problem

08 Oct 2020, 18:22

there isnt a problem with GDI. the problem stems from the fact that for whatever reason u have opted to circumvent window's standard mechanism for painting win32 apps and have decided to externally draw onto the gui's(why??) DC
there is a proper way of achieving what u need to achieve and none of the techniques in this thread uve linked are it
what u need to do is subclass the picture control, replacing its windowproc with a custom one of ur own :arrow: https://docs.microsoft.com/en-us/windows/win32/controls/subclassing-overview
of course this may be a total overkill for what u need to do, so if all that is required is to display simply display a non-interactive image without exhibiting said "bug", id stick to @gwarble's advice

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Assquatch23 and 341 guests