Hi Stef,
Glad it was of help. I was looking at the code I posted when it hit me that I could remove some useless code.
I also wanted to test again the the reordering of the code in "GuiSize:" , this was to stop the leaving part of one buttons image on the other.
This would happen when resized repeatedly and rapidly. This would help some, but not as much as I first thought. When all else fails RTFM.
So looking at "GuiControl, Move" in the Docs. , I see right below it "GuiControl, MoveDraw". The part that stood out was this
"also repaints the region of the GUI window occupied by the control". Well that figures because putting the curser on the button got rid of
the artifacts, as displaying the curser will redraw the image. Changed "GuiControl, Move" to "GuiControl, MoveDraw". All fixed.
Here is my previous post with changes and comments
Code: Select all
Gui, +hwndGui1 +resize -DPIScale ;-DPIScale added, keeps borders off of buttons
Gui, font, s15 ;Change the font size
Gui, add, button, w75 h25 gkey1 hwndBut1, Ok ;Removed "section" as the y is relative to the bottomMargin.
Gui, add, button, w75 h25 gkey2 hwndBut2, Cancel ;Removed "ys" as the y is relative to the bottomMargin.
Gui, font, ;Restore the font to the system's default GUI typeface, size, and color.
Gui, show, w300 h100
return
GuiSize: ;Launched when the window is resized, minimized, maximized, or restored.
rightMargin := 20, bottomMargin := 50
WinGetPos, x,y,w,h, ahk_id %Gui1%
ControlGetPos,,,w1,h1,,ahk_id %But1%
ControlGetPos,,,w2,h2,,ahk_id %But2%
GuiControl, movedraw, %But1%, % "x" w-(w1+w2+rightMargin) " y" h-(h1+bottomMargin) ;"MoveDraw" solves painting artifacts
GuiControl, movedraw, %But2%, % "x" w-(w2+rightMargin) " y" h-(h2+bottomMargin) ;when resized repeatedly and rapidly.
return
GuiClose:
GuiEscape:
ExitApp
key1: ;Do some work
msgbox,,, You clicked the Ok button.
return
key2:
msgbox,,, You clicked the Cancel button.
return
Alguimist posted here how to anchor the buttons using his fine editor AutoGUI. You can find the link to it here:
https://autohotkey.com/docs/commands/Edit.htm#Editors
I had used it a few years ago never even noticing the "Anchor" group box, and this was an older version I have v.1.1.3.7.
So grabbed his latest version 2.2.5, which uses a newer Lib. "AutoXYWH.ahk". Thank You to tmplinshi and toralf for that.
I installed AutoGUI, it's just a matter of extracting the zip file to a folder of your choice. I have one called Util in my C drive. In a couple of minutes a visual copy
of the Gui that was typed by hand was on the screen. Only typing required here was the window size and name, text on one button. Everything else was just mouse clicks.
I hit the Execute button in AutoGUI and tried resizing repeatedly and rapidly, and got the artifacts as with the handmade Gui before using "GuiControl, MoveDraw".
When all fails-READ, so looking at the source code for Lib. "AutoXYWH.ahk", there was the answer almost right at the top. A big Thank You to tmplinshi and toralf for this.
Read the comments in the example below to see how simple it was to fix.
Code: Select all
;From the comment "Generated by" until the comment after "ExitApp" the code is all
;made by AutoGUI, except my added changes, removes, or comments which are marked h99.
;All changes, removes, or comments are done in an editor after saving the AutoGUI script there.
;I used Notepad ++, but any editor you normaly use is Ok.
;The comment "Do not edit above this line" means what it says, because if you
;then make any changes using AutoGUI's "Preview Window" those edits are lost.
; Generated by AutoGUI 2.2.5a
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
#Include %A_ScriptDir%\AutoXYWH.ahk
Gui +Resize ; No -DPIScale needed here as AutoXYWH.ahk takes care of the problem. (comment added h99)
Gui Font, s10, Tahoma
Gui Add, Button, hWndhButton1 gkey1 x219 y73 w80 h23, &Cancel
;Gui Font ;redundant, so removed h99
;Gui Font, s10, Tahoma ;redundant, so removed h99
Gui Add, Button, hWndhButton2 gkey2 x136 y74 w80 h23, &OK
Gui Font ;Restores the font to the system's default GUI typeface, size, and color. (comment added h99)
Gui Show, w300 h100, Gui Test 1
Return
GuiSize:
If (A_EventInfo == 1) {
Return
}
AutoXYWH("xy*", hButton1) ;Added a * to xy to use MoveDraw instead of Move, h99
AutoXYWH("xy*", hButton2) ;solves painting artifacts when resized repeatedly and rapidly. h99
Return
GuiEscape:
GuiClose:
ExitApp
; Do not edit above this line
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx h99
;This is all added by me in Notepad++ just to show the keys doing something. h99 x
; x
key1: ;x
msgbox,,, You clicked the Cancel button. ;x
return ;x
;x
key2: ;Do some work ;x
msgbox,,, You clicked the Ok button. ;x
return ;x
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx h99
Everyone should have a copy of AutoGUI on hand. It is a real time saver. There are some real gems in the Tools folder, one of which is MagicBox.
That one I have been using for quite a while, it saves me from looking up alot of code. Alguimist, WELL DONE and a BIG THANK YOU
hunter99