Remove focus (blue border) from GUI buttons.

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 216
Joined: 10 Mar 2016, 21:19

Remove focus (blue border) from GUI buttons.

15 Mar 2019, 17:45

Hello
I have created a simple GUI with several buttons. I dont use the "default" setting in any of the buttons when I add them in the GUI. The GUI starts with all the buttons unfocused (no blue border) by using the command:

Code: Select all

GuiControl, -Default, %A_GuiControl%
Gui, Show, , Box
Image

So far so good.
The Config button opens a secondary GUI when clicked, while the main GUI gets minimized in the systray.
Here is the problem:
If I close the second GUI, the main GUI gets restored. But this time, the Config button is focused with the blue border.
This also happens if I dont open the second GUI at all and instead, I only minimize and restore the main GUI. This time the button 1 is focused with the blue border.

Image Image

I dont want any any button to have that blue border, after I close the second GUI or restore the main GUI.
I searched the forum and tried various methods but nothing works.
I think the closest to the solution, is this post by Lexikos but I cant make it work:
https://www.autohotkey.com/boards/viewtopic.php?t=23543#p111066

Any idea how I can fix this? :?:
teadrinker
Posts: 646
Joined: 29 Mar 2015, 09:41
Contact:

Re: Remove focus (blue border) from GUI buttons.

15 Mar 2019, 19:09

Hi

Try this:

Code: Select all

OnMessage(0x6, "WM_ACTIVATE")
Gui, Add, Text, x10 Hidden
for k, v in [1, 2, 3, "Exit", "Config"]
   Gui, Add, Button, % "xp y" (k = 1 ? 10 : "+5") " w80", % v
Gui, Show
Return

WM_ACTIVATE(wp, lp, msg, hwnd) {
   static WA_ACTIVE := 1
   if (wp = WA_ACTIVE)
      GuiControl, %hwnd%: Focus, Static1
}
swagfag
Posts: 2379
Joined: 11 Jan 2017, 17:59

Re: Remove focus (blue border) from GUI buttons.

15 Mar 2019, 19:47

how about this castrated button hack

Code: Select all

Gui New, +Hwndhwnd
Gui Show, w300 h300

x := y := 20
w := 50
h := 20

Gui New, -Caption +Parent%hwnd%
Gui Add, Button, % "x-4 y-4 h" h + 8 " w" w + 8, Button
Gui Show, w%w% h%h% x%x% y%y%

Esc::
GuiClose:
GuiEscape:
	ExitApp
the buttons will prolly be best manipulated through hwnds, which ive omitted in this example
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: Remove focus (blue border) from GUI buttons.

16 Mar 2019, 06:52

Code: Select all

WinSet, Region, 2-2 w96 h16, ahk_id %MyEdit%
2-2 This will remove 2 pixels of every direction.
w96 h16 This will tell the WinSet command that our control now has w96 and h16. It's the result of removing 2 pixels north and south from the height, and 2 pixels east and west from the width. That is 100-2-2= 96 and 20-2-2=16
ahk_id %MyEdit% This is the Window's Handle (hwnd) of my control.

Edit: and then you could add +Border to the button if you want a black contour

This code was found here : https://www.autohotkey.com/boards/viewtopic.php?f=7&p=267506#p267506
KilliK
Posts: 216
Joined: 10 Mar 2016, 21:19

Re: Remove focus (blue border) from GUI buttons.

16 Mar 2019, 08:28

I want to avoid messing with the default styles for now.
I tried teadrinker's solution. It does work for when I minimize and restore the GUI, the buttons remain unfocused.
But if I click a button, the focus is not removed, the blue border stays there.
So I am half there. I tried various methods with SendMessage, GuiControl and ControlFocus but unless I am doing something wrong, nothing works.
:cry:
DRocks
Posts: 441
Joined: 08 May 2018, 10:20

Re: Remove focus (blue border) from GUI buttons.

16 Mar 2019, 11:56

I understand.

What if you detect Left Button clicks and execute their individual gLabels / functions from the Left Click rather than the button itself ?

Code: Select all

OnMessage(0x201, "OnWM_LBUTTONDOWN")

OnWM_LBUTTONDOWN(wParam, lParam, msg, hWnd) {


; pseudo idea not actually coded:
; MouseGetPos, (retrieve the name/hwnd/ of the control under mouse cursor)
; if the control clicked is button 1 thene xecute button1 action and dont send the LeftButton (it wont focus the button)
; else if the control clicked is button 2 execute button 2's action and dont send the LButton down message.

}
KilliK
Posts: 216
Joined: 10 Mar 2016, 21:19

Re: Remove focus (blue border) from GUI buttons.

17 Mar 2019, 13:29

I finally found a solution. I created a hidden button which doesnt mess up the GUI layout. and I controlclick it, whenever I want to lose focus from the normal buttons. problem solved.
thanks for all your help. I ll keep in mind some of your suggestions, in case I need to fix similar problems in the future. cheers.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Gibbons, letacio, unconnu and 43 guests