Make progress bar's background transparent Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Make progress bar's background transparent

11 Nov 2018, 16:32

Hello

I know this is probably not possible as +BackgroundTrans only supports a few controls, but I'm still hanging on the possibility of applying it to a Gui Progress control (not to be confused with the Progress command which creates its own separate window/splashscreen type thingy).

Is there some EXStyle that can make its background transparent? Just for aesthetic reasons :)

btw, if you do know of such a style that might work, try applying it with WinSet , [Ex]Style , as I've found that Gui, +/- Option isn't reliable, for example optioning in -E0x20000 to fix the Windows bug where it applies the border style after moving/resizing the progress bar only works on my system if I apply it by WinSet.

Thanks! (not getting my hopes up :lol: )
Last edited by pneumatic on 11 Nov 2018, 18:45, edited 1 time in total.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Make progress bar's background transparent  Topic is solved

11 Nov 2018, 18:01

Hi pneumatic,


On approach could be to use the WinSet, TransColor command, which make all pixels of the chosen color invisible inside the target window, as demonstrated in the following example:

Code: Select all

#NoEnv
#SingleInstance force
SetWorkingDir % A_ScriptDir
#Warn
; Windows 8.1 64 bit - Autohotkey v1.1.29.01 32-bit Unicode

myColor := "ddff99"

GUI, +HWNDmyGUI
GUI, Add, Progress, w500 h140 background%myColor% hwndmyProgress
DetectHiddenWindows, On
WinSet, TransColor, % myColor, % "ahk_id " . myGUI
DetectHiddenWindows, Off
GUI, Show, AutoSize
Loop 10 {
	GuiControl,, % myProgress, +10
sleep, 400
}
ExitApp

#If MouseIsOver(myGUI, myProgress)
	LButton::return ;  otherwise, if the user clicks on an invisible pixel, the click will "fall through" to the window behind it
#If

MouseIsOver(_window, _control) {
	if not (WinActive("ahk_id " . _window))
		return false
	_coordMode := A_CoordModeMouse
	CoordMode, Mouse, Window
	MouseGetPos, _mx, _my
	CoordMode, Mouse, % _coordMode
    ControlGetPos, _x1, _y1, _cw, _ch,, % "ahk_id " . _control
	_x2 := _x1 + _cw
	if _mx not between %_x1% and %_x2%
		return false
	_y2 := _y1 + _ch
	if _my not between %_y1% and %_y2%
		return false
return true
}

Hope this helps.
my scripts
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Make progress bar's background transparent

11 Nov 2018, 18:44

Thanks, that would work, but then my progress bar has to live in its own separate window, and so I need to write some convoluted stuff to have it follow around my other GUI window if the user happens to drag it.

edit: maybe it could be made as a child window and with no title bar so the user can't move it.

edit: It works, but +Parent causes the child window (which contains the progress bar) to display underneath all the controls of its parent window. I need it to display on top.

edit: seems this style should do it
WS_CLIPCHILDREN
0x02000000L
Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window.

Except I can't get it to work (I presume the style is +0x2000000)? The child window just remains underneath all the parent window's controls.

Ok I got it to partially work by adding the child window immediately after the parent is created, but there are graphical artefacts and it only seems to draw on top after I drag the child window around for a bit.

edit: it seems it needs to be done exactly like this:

1. create parent window with +0x2000000 style, but dont add any controls to it yet
3. create child window and its controls
4. add controls to parent window
5. show parent window
6. show child window

^ anything other than that exact order results in either the child window appearing beneath all the parent window controls, or painting artefacts (which could be partially fixed with WinSet, Redraw , but not reliably enough imo)

At least I know the 0x200000 style is working as removing it causes it to draw behind again.

edit: bah, still getting some weird painting artefacts whenever I make changes to the parent GUI. Probably still need to do some repaints somewhere. Might put this one in the too hard basket :lol:
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Make progress bar's background transparent

13 Nov 2018, 11:20

Hi pneumatic,

Ah, I'm sorry... it is so obvious; for some reason, arguably by enthousiasm, by 'progress bar's background transparent', I understood: 'progress bar's background transparent, itself transparent'...
It's actually a good idea to experiment with the +Parent trick, continuing in the direction indicated by WinSet, TransColor.
I let a sample code which follows the milestones that you laid out so far:

Code: Select all

/*
according to the indications given by pneumatic:
1. create parent window with +0x2000000 style, but dont add any controls to it yet
3. create child window and its controls
4. add controls to parent window
5. show parent window
6. show child window
*/
#NoEnv
#SingleInstance force
SetWorkingDir % A_ScriptDir
#Warn
; Windows 8.1 64 bit - Autohotkey v1.1.29.01 32-bit Unicode



GUI, 1:+HWNDGUIID +0x2000000 +Resize
GUI, 2:+HWNDGUIID2 +ToolWindow -Caption +Owner%GUIID% +Parent%GUIID%
GUI 2:Add, Progress, w100 h100 +HWNDhProgress +Background777777, 10
GUI, 1:Add, Edit, w150 h150 hwndhEdit,
GUI, 1:Show, w300 h300
GUI, 2:Show, x15 y15 AutoSize
WinSet, TransColor, 7777777, % "ahk_id " . GUIID2
return

!i::GuiControl, Hide, % hEdit
!j::GuiControl, Hide, % hProgress
!k::GuiControl, Show, % hEdit
!l::GuiControl, Show, % hProgress

!m::
	GuiControl,, % hProgress, 0
	Loop, 10 {
		GuiControl,, % hProgress, +10
	sleep, 400
	}
return

!n::GUI, 1:Add, Edit, x100 y100 w100 h100
Btw, for your part, what kind of changes made to the parent window lead to unexpected painting artefacts?

Otherwise, I guess you've just got to wait for some ahk superstar to pull out a solution from its magician hat...
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mapcarter, peter_ahk, Rohwedder and 295 guests