How to background-fill around simple GUI buttons?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sashaatx
Posts: 339
Joined: 27 May 2021, 08:27
Contact:

How to background-fill around simple GUI buttons?

Post by sashaatx » 12 Jan 2023, 17:03

How to eliminate background white-remanence around the button?

Code: Select all

; Generated by Auto-GUI 3.0.1
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Menu Tray, Icon, shell32.dll, 28

LBVar := ListBoxItems()

Gui Main: New, +LabelMain +hWndhWndMain
Gui Font, s12 cWhite, Segoe UI
Gui Color, 0x494949
Gui Font
Gui Font, s12, Consolas
Gui Add, ListBox, hWndhLbxItems vItemsvalue gItems x24 y64 w180 h270, %LBVar%
Gui Font
Gui Font, s12 cWhite, Segoe UI
Gui Add, Button, hWndhBtnLaunch vBtnLaunch gLaunch x223 y303 w97 h28, Launch

Gui Show, w346 h408, Geo11 Launcher
Return
image.png
image.png (16.96 KiB) Viewed 672 times
Attachments
image.png
image.png (11.47 KiB) Viewed 672 times
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :


sashaatx
Posts: 339
Joined: 27 May 2021, 08:27
Contact:

Re: How to background-fill around simple GUI buttons?

Post by sashaatx » 12 Jan 2023, 17:17

mikeyww wrote:
12 Jan 2023, 17:09
Ideas: viewtopic.php?f=6&t=1103
GDIP
Ive spent many many hours messing with gdip, and it felt like a bottomless pit with no instruction manual. Png's sent to clipboard and code with no explanation of structure or where it goes.

I have multiple apps with Pywebview, and Nutreon ahk and have plenty of experience with spending too much time designing buttons. The gdip stuff has been a painful non starter.

Is this meaning to also infer there is no solution where the button has a white outline and black window background?

Thansk! helpful as always.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

User avatar
mikeyww
Posts: 27095
Joined: 09 Sep 2014, 18:38

Re: How to background-fill around simple GUI buttons?

Post by mikeyww » 12 Jan 2023, 17:28

I'm not an expert in it, but I believe that the options are very limited with the native Windows buttons. The AHK documentation shows some possible styles, but I do not know that you can actually round the corners-- hence, the link that I mentioned for button images. Others here may know more. A button image would be easy to implement if you know what the image should be.

just me
Posts: 9488
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to background-fill around simple GUI buttons?

Post by just me » 13 Jan 2023, 08:02

This is what you can do with simple message handling to restrict the 'white' background around buttons:

Code: Select all

; Generated by Auto-GUI 3.0.1
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Menu Tray, Icon, shell32.dll, 28

LBVar := ListBoxItems()

GuiColorBGR := 0x494949

Gui Main: New, +LabelMain +hWndhWndMain
Gui Font, s12 cWhite, Segoe UI
Gui Color, 0x494949
Gui Font
Gui Font, s12, Consolas
Gui Add, ListBox, hWndhLbxItems vItemsvalue gItems x24 y64 w180 h270, %LBVar%
Gui Font
Gui Font, s12 cWhite, Segoe UI
Gui Add, Button, hWndhBtnLaunch vBtnLaunch gLaunch x223 y303 w97 h28, Launch

OnMessage(0x0135, "WM_CTLCOLORBTN")

Gui Show, w346 h408, Geo11 Launcher
Return

GuiClose:
GuiEscape:
ExitApp

WM_CTLCOLORBTN(DC) {
   Static DCB := DllCall("Gdi32.dll\GetStockObject", "UInt", 18, "UPtr") ; DC_BRUSH = 18
   Global GuiColorBGR
   DllCall("SetDCBrushColor", "Ptr", DC, "UInt", GuiColorBGR)
   Return DCB
}

Items:
Launch:
Return

ListBoxItems() {
   Return "1|2|3|4|5|6"
}

m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: How to background-fill around simple GUI buttons?

Post by m3user » 14 Jan 2023, 17:23

Wow, great! Is there a similarly easy way to change the button color?

just me
Posts: 9488
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to background-fill around simple GUI buttons?

Post by just me » 15 Jan 2023, 04:13

@m3user: No! ;)

User avatar
boiler
Posts: 17073
Joined: 21 Dec 2014, 02:44

Re: How to background-fill around simple GUI buttons?

Post by boiler » 15 Jan 2023, 08:16

sashaatx wrote: GDIP
Ive spent many many hours messing with gdip, and it felt like a bottomless pit with no instruction manual. Png's sent to clipboard and code with no explanation of structure or where it goes.

I have multiple apps with Pywebview, and Nutreon ahk and have plenty of experience with spending too much time designing buttons. The gdip stuff has been a painful non starter.
There is no need for you to touch anything to do with GDIP to use just me’s ImageButton class. It’s all self-contained, and you never even have to see any GDIP content. Just instantiate the class and call its methods to implement your buttons.

sashaatx
Posts: 339
Joined: 27 May 2021, 08:27
Contact:

Re: How to background-fill around simple GUI buttons?

Post by sashaatx » 26 Jan 2023, 16:54

boiler wrote:
15 Jan 2023, 08:16
sashaatx wrote: GDIP
Ive spent many many hours messing with gdip, and it felt like a bottomless pit with no instruction manual. Png's sent to clipboard and code with no explanation of structure or where it goes.

I have multiple apps with Pywebview, and Nutreon ahk and have plenty of experience with spending too much time designing buttons. The gdip stuff has been a painful non starter.
There is no need for you to touch anything to do with GDIP to use just me’s ImageButton class. It’s all self-contained, and you never even have to see any GDIP content. Just instantiate the class and call its methods to implement your buttons.
"just init the class", when all or most gui docs are functional based guis, and my time spent with class based GUIs in ahk has taken years off my life.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

User avatar
boiler
Posts: 17073
Joined: 21 Dec 2014, 02:44

Re: How to background-fill around simple GUI buttons?

Post by boiler » 26 Jan 2023, 18:15

The GUI doesn't have to be class based. You just create buttons using the class. You wouldn't be creating a class or working within a class. It's almost like making function calls. There are examples at that thread.

Of course you don't have to do any of that, but if you want to have more advanced looking GUIs, then the code is a little more involved. It's a trade-off only you can make.

Post Reply

Return to “Ask for Help (v1)”