Hello,
I'm testing a script here that changes colors based on the number that is displayed. What I want to do is at any time the user right clicks, the menu pops up so the user can take action...however, the problem is, the menu won't pop up unless there is no loop.
Can anyone assist please?
Code:
#NoEnv
#Include \\cfbisfs1\Users\Home\ntkirby\Canvas\PAC\Support_Files\BackgroundColors.ahk
BlockCount:=1
ColCount := 2
RowCount := 2
WinWidth:=128*ColCount
WinHeight:=96*RowCount
TestColWid:=(WinWidth/ColCount)
TestColHeight:=(WinHeight/RowCount)
XTestPos:=0
YTestPos:=0
Gui, 25:Color, dddddd, dddddd
Gui, 25:-Caption +Border
Gui, 25:Font,, Arial
Gui, 25:Font, s25 bold
Loop, %RowCount%
{
Loop, %ColCount%
{
Gui, 25:Font, s48 bold
Gui, 25:Add, Text, Center x%XTestPos% y%YTestPos% w%TestColWid% h%TestColHeight% vTX%BlockCount% hwndTXID%BlockCount% Border vRandomCount%BlockCount%,
XTestPos+=TestColWid
BlockCount+=1
}
YTestPos+=TestColHeight
XTestPos:=0
}
Gui, 25:Show, w%WinWidth% h%WinHeight% x0 y20, PAC
Gui, 25:+LastFound
WinSet, Redraw
Loop
{
GoSub, TXT1
Sleep, 5000
}
Return
25GuiContextMenu:
Menu, ContextMenu, Add, Reload, AHKReload2
Menu, ContextMenu, Add, Exit, AHKExit2
Menu, ContextMenu, Add, Minimize, AHKMinimize2
Menu, ContextMenu, Show
RETURN
AHKExit2:
ExitApp
RETURN
AHKReload2:
RELOAD
RETURN
AHKMinimize2:
WinMinimize, A
RETURN
TXT1:
;Loop, %RowCount%
;{
Loop, %BlockCount%
{
Random, TheRandomCount%A_Index%, -32, 32
GotTheNum := TheRandomCount%A_Index%
GuiControl, 25:, RandomCount%A_Index%, %GotTheNum%
If(GotTheNum > 0)
{
Control_Colors(Lime, Black, "Set", TXID%A_Index%)
}
Else If(GotTheNum < 0)
{
Control_Colors(Red, White, "Set", TXID%A_Index%)
}
Else if(GotTheNum = 0)
{
Control_Colors(Yellow, Black, "Set", TXID%A_Index%)
}
Else
{
Control_Colors(Black, White, "Set", TXID%A_Index%)
}
TColor := TXID%A_Index%
WinSet, Redraw, , ahk_id %TColor%
}
;}
Return
Below is the accompanying script....
Code:
; ------------------------------------------------------------------------------
; Defined Colors - these are setup backwards as Color = 0xBBGGRR instead of
; Color = 0xRRGGBB (all in hexidecimal format)
; EX: Quartz = 0xDBE0F3 would be defined below as Quartz = 0xF3E0DB
; When searching for colors use site: http://www.colblindor.com/color-name-hue/
; Its a little buggy to use the site but it is extremely accurate with colors.
; Another very good site is http://chir.ag/projects/name-that-color/
; There is a drop down with pre-selected colors you can choose from then you
; Can modify as needed. Once you modify it go back to the first site to get
; the actual name.
; ------------------------------------------------------------------------------
Black = 0x000000
Green = 0x008000
Silver = 0xC0C0C0
Lime = 0x00FF00
Gray = 0x808080
Olive = 0x800080
White = 0xFFFFFF
Yellow = 0x00FFFF
Maroon = 0x000080
Navy = 0x800000
Red = 0x0000FF
Blue = 0xFF0000
Purple = 0x800080
Teal = 0x808000
Fuchsia = 0xFF00FF
Aqua = 0xFFFF00
LavenderBlue = 0xFBD4CB
Quartz = 0xF3E0DB
Atlantis = 0x4ADB79
; ------------------------------------------------------------------------------
; Function Control_Colors ()
; ------------------------------------------------------------------------------
Control_Colors(wParam, lParam, Msg, Hwnd) {
Static Init := True ; Initialize (OnMessage)
Static SetVal := "Set" ; values receive
Static ValLst := "" ; value list
Static RX := "\|(?P<B>0x[[:xdigit:]]{6})\|(?P<T>[*0]x[[:xdigit:]]{6})$"
Static Default := "*x000000"
Static WM_CTLCOLOREDIT := 0x0133
Static WM_CTLCOLORLISTBOX := 0x134
Static WM_CTLCOLORSTATIC := 0x0138
Static BRUSH := 0
; ---------------------------------------------------------------------------
Critical
Format_I := A_FormatInteger
SetFormat, Integer, H
; ---------------------------------------------------------------------------
; in the first proclamation OnMessage () set treat
; ---------------------------------------------------------------------------
If (Init) {
OnMessage(WM_CTLCOLOREDIT, "Control_Colors")
OnMessage(WM_CTLCOLORLISTBOX, "Control_Colors")
OnMessage(WM_CTLCOLORSTATIC, "Control_Colors")
OnMessage(WM_CTLCOLORMSGBOX, "Control_Colors")
Init := False
}
; ---------------------------------------------------------------------------
; proclamation with "Set"
; ---------------------------------------------------------------------------
If (Msg = SetVal) {
If !(Hwnd + 0) {
GuiControlGet, nHwnd, Hwnd, %Hwnd%
Hwnd := nHwnd
}
W := (SubStr(wParam, 1, 1) = "*") ? Default
: "0x" SubStr("000000" SubStr(wParam + 0, 3), -5)
L := (W = Default) ? Default
: (SubStr(lParam, 1, 1) = "*") ? Default
: "0x" SubStr("000000" SubStr(lParam + 0, 3), -5)
H := Hwnd + 0
If (RegExMatch(ValLst, "Sm)^" H "\|"))
ValLst := RegExReplace(ValLst, "Sm)^" H "\|.*$", H "|" W "|" L)
Else
ValLst .= H "|" W "|" L "`r`n"
SetFormat, Integer, %Format_I%
Return
}
; ---------------------------------------------------------------------------
; normal event treatment
; ---------------------------------------------------------------------------
If (RegExMatch(ValLst, "Sim)^" (lParam + 0) RX, C)) {
If (BRUSH) {
DllCall("DeleteObject", UInt, BRUSH)
BRUSH := 0
}
If (CT != Default)
DllCall("SetTextColor", UInt, wParam, UInt, CT)
DllCall("SetBkColor", UInt, wParam, UInt, CB)
SetFormat, Integer, %Format_I%
Return (BRUSH := DllCall("CreateSolidBrush", UInt, CB))
}
SetFormat, Integer, %Format_I%
}
; ------------------------------------------------------------------------------