Multiple GUIs differing shade of color. Please Help. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Multiple GUIs differing shade of color. Please Help.

Post by PipeDreams » 02 Jan 2020, 21:03

Hello,
I found this great example by Lexikos and I wanted to integrate it into an existing script that I have already made. However, I am having trouble setting differing GUI colors properly for each window. Here is where I am stuck.

Code: Select all

MaxColorValue:=(255) ;MaxColorValue
R:=(16)	;Red
G:=(8)	;Green
B:=(0)	;Blue
SetPrimaryColor:=R
Value:=(50)
ValueSet:= ((MaxColorValue//Value)+1)
SetFormat, IntegerFast, HEX

 ;Example of multiple GUIs:
Loop, %ValueSet%
{	n := FreeGuiNumber()  ; or in simple cases:  n += 1
	Subtract:=(Value * %n%)
	One := (MaxColorValue-Subtract<<SetPrimaryColor)
	Gui, %n%: -Caption +AlwaysOnTop +ToolWindow
	;Gui, %n%:Color, Red
	Gui, %n%: Color, %One%
	Gui, %n%:Show, % NoActivate "X"(A_ScreenWidth//4)+A_Index*50 "Y"(A_ScreenHeight//4) "W"50 "H"525, `#%n%
} Return

;https://autohotkey.com/board/topic/54978-multiple-dynamic-gui-window-of-parents/
FreeGuiNumber()
{	SetFormat, IntegerFast, Dec
	Gui %A_Index%:+LastFoundExist
	IfWinNotExist
	Return A_Index
} Return
I keep getting Hex errors, but if I convert back to Dec I get no colors...
How can I set the colors in each of the Gui's, so that they all appear as the child GUI's from the example below?

Code: Select all

Gui, Main: -AlwaysOnTop -Caption +LastFound ;+E0x20 Makes GUI click through
Main_ID := WinExist()
Gui, Main: Color, Black
Gui, Main: Show, w710 h535, Parent

MaxColorValue:=(255) ;MaxColorValue
R:=(16)	;Red
G:=(8)	;Green
B:=(0)	;Blue
SetPrimaryColor:=R
Value:= 60
SetFormat, IntegerFast, HEX

Subtract:=(Value * 0)
One := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 1: Color, %One%
Gui, 1: -Caption +LastFound +E0x00010000 ;The ExStyle allows the parent to take focus if it's clicked.
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 1: Show, x5 y5 w50 h525, Child #1

Subtract:= (Value * 1)
Two := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 2: Color, %Two%
Gui, 2: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 2: Show, x55 y5 w50 h525, Child #2

Subtract:= (Value * 2)
Three := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 3: Color, %three%
Gui, 3: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 3: Show, x105 y5 w50 h525, Child #3

Subtract:= (Value * 3)
Four := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 4: Color, %Four%
Gui, 4: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 4: Show, x155 y5 w50 h525, Child #4

Subtract:= (Value * 4)
Five := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 5: Color, %Five%
Gui, 5: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 5: Show, x205 y5 w50 h525, Child #5

Subtract:= (Value * 5)
Six := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 6: Color, %Six%
Gui, 6: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 6: Show, x255 y5 w50 h525, Child #6

Subtract:= (Value * 6)
Seven := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 7: Color, %Seven%
Gui, 7: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 7: Show, x305 y5 w50 h525, Child #7

Subtract:= (Value * 7)
Eight := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 8: Color, %Eight%
Gui, 8: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 8: Show, x355 y5 w50 h525, Child #8

Subtract:= (Value * 8)
Nine := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 9: Color, %Nine%
Gui, 9: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 9: Show, x405 y5 w50 h525, Child #9

Subtract:= (Value * 9)
Ten := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 10: Color, %Ten%
Gui, 10: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 10: Show, x455 y5 w50 h525, Child #10

Subtract:= (Value * 10)
Eleven := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 11: Color, %Eleven%
Gui, 11: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 11: Show, x505 y5 w50 h525, Child #11

Subtract:= (Value * 11)
Twelve := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 12: Color, %Twelve%
Gui, 12: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 12: Show, x555 y5 w50 h525, Child #12

Subtract:= (Value * 12)
Thirteen := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 13: Color, %Thirteen%
Gui, 13: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 13: Show, x605 y5 w50 h525, Child #13

Subtract:= (Value * 13)
Fourteen := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 14: Color, %Fourteen%
Gui, 14: -Caption +LastFound +E0x00010000
DllCall("SetParent", "uint", WinExist(), "uint", Main_ID)
Gui, 14: Show, x655 y5 w50 h525, Child #14

Return
Last edited by PipeDreams on 03 Jan 2020, 16:14, edited 1 time in total.

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

Re: Multiple GUIs differing shade of color. Please Help.

Post by just me » 03 Jan 2020, 07:01

Code: Select all

Loop, %ValueSet%
{	n := FreeGuiNumber()  ; or in simple cases:  n += 1
	Subtract:=(Value * n) ; <<<<<<<<<< it's an expression, removed the %-signs
	...

Do you only want to show some colors?

User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Re: Multiple GUIs differing shade of color. Please Help.

Post by PipeDreams » 03 Jan 2020, 16:21

just me wrote:
03 Jan 2020, 07:01

Code: Select all

Loop, %ValueSet%
{	n := FreeGuiNumber()  ; or in simple cases:  n += 1
	Subtract:=(Value * n) ; <<<<<<<<<< it's an expression, removed the %-signs
	...

Do you only want to show some colors?
Thank you, but no. It needs to scale the selected color to look more like this:
R.png
R.png (784 Bytes) Viewed 1303 times
But what I'm getting ATM is this
ick.png
ick.png (909 Bytes) Viewed 1298 times

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Multiple GUIs differing shade of color. Please Help.

Post by flyingDman » 03 Jan 2020, 19:09

If the ultimate intent is to have a gui showing scales of color, you might try to do something like this:

Code: Select all

sections := 14
width := ceil(800/ sections), height := 500

gui, margin,0,0
gui, -dpiscale -caption
loop,% sections
	{
	R := substr("00" Format("{:X}", round(255 - (a_index - 1) * 255/sections)), -1) 
	G := "00"
	B := "00" 
	RGB := R . G . B, 	y := a_index = 1 ? 0 : width
	Gui, Add, Progress, xp+%y% w%width% h%height% c%RGB% Background%RGB%, 100
	}
Gui, show, center
return

esc::
exitapp
20200103_184708clip.jpg
20200103_184708clip.jpg (4.48 KiB) Viewed 1182 times
Playing around with section count and w/ values of R,G, and B can yield something like this:
20200103_163640clip.jpg
20200103_163640clip.jpg (4.73 KiB) Viewed 1182 times
14.3 & 1.3.7

User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Re: Multiple GUIs differing shade of color. Please Help.

Post by PipeDreams » 04 Jan 2020, 23:11

flyingDman wrote:
03 Jan 2020, 19:09
Spoiler


Your script is very nice, it is so darn close to what I’m looking for. However, because I am using this as a part of a kind of pixel calculator which I plan on using to make other scripts, the background color of each bar (i.e., section) needs to match the summation of the equation below.
For Example:
If the Hex value of Red is 0xFF0000, and the Dec translation of 0xFF0000 is (255<<16). Then if:
Bar#1
R := (255-(50*0)<<16) = 0xFF or 255
Then
Bar#2 should be
(255-(50*1)<<16)= 0xCD or 205
Then
Bar#3
(205-(50*2)<<16)= 0x9B or 155 … and so on

Which means only 6 bars are needed for FF through 0B
0xFF0000|0xCD0000|0x9B0000|0x690000|0x370000|0x0B0000
Each bar needs to multiply 50 by its corresponding BarNumber and then subtract that sum from 255 accordingly.

I was able to control this in my scripts by using:

Code: Select all

Subtract:=(Value * 0) To get 0xFF0000
One := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 1: Color, %One%

Subtract:= (Value * 1) To get 0xCD0000
Two := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 2: Color, %Two%

Subtract:= (Value * 2) To get 0x9B0000
Three := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, 3: Color, %three%
Or condensed

Code: Select all

Subtract:=(Value * n)
One := (MaxColorValue-Subtract<<SetPrimaryColor)
Gui, %n%: Color, %One%
But I am not sure where to place the control in your script because it is a bit advanced for me to be honest, I do not understand all of it. I'm not well versed with the ternary operator thing.

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Multiple GUIs differing shade of color. Please Help.  Topic is solved

Post by flyingDman » 05 Jan 2020, 14:34

6 sections with R value decrementing by 50 (i.e 255, 205, etc):

Code: Select all

sections := 6
width := ceil(800/ sections), height := 500

gui, margin,0,0
gui, -dpiscale -caption
loop,% sections
	{
	r := substr("00" Format("{:X}", 255 - (a_index - 1) * 50), -1) 
	b := "00" 
	g := "00" 
	RGB := R . G . B, 	y := a_index = 1 ? 0 : width
	Gui, Add, Progress, xp+%y% w%width% h%height% c%RGB% Background%RGB%, 100
	}
Gui, show, center
return

esc::
exitapp
y := a_index = 1 ? 0 : width means: if a_index is equal 1 (first loop) the value of y is 0. If it is not equal 1, the value of y is equal to the content of the variable width . You can write it down as an if ... else statement, but once you get the hang of it, ... you won't.

BTW i'am not familiar with bitwise notations like (255-(50*1)<<16) and can't duplicate it. Using Format("{:X}", Y) instead.
14.3 & 1.3.7

User avatar
PipeDreams
Posts: 165
Joined: 19 Dec 2015, 00:20

Re: Multiple GUIs differing shade of color. Please Help.

Post by PipeDreams » 06 Jan 2020, 15:52

Spoiler
:dance: Thank you my friend! This is exactly what I'm looking for.
flyingDman wrote:
05 Jan 2020, 14:34
y := a_index = 1 ? 0 : width means: if a_index is equal 1 (first loop) the value of y is 0. If it is not equal 1, the value of y is equal to the content of the variable width . You can write it down as an if ... else statement, but once you get the hang of it, ... you won't.
Thank you, I'll keep that in mind for future experimentation. I am in college ATM and do not have the time to study AHK like I use to, so thank you again for your help.
flyingDman wrote:
05 Jan 2020, 14:34
BTW i'am not familiar with bitwise notations like (255-(50*1)<<16) and can't duplicate it. Using Format("{:X}", Y) instead.
Apparently it doesn't matter, you've overcome the issue in a clever manner. There is still so much more I need to learn about this stuff.

Post Reply

Return to “Ask for Help (v1)”