AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

New problem - can't color multiple controls

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
The Unknown Jobber



Joined: 19 Nov 2009
Posts: 161
Location: Florida

PostPosted: Wed Mar 10, 2010 8:01 pm    Post subject: New problem - can't color multiple controls Reply with quote

alright, new problem...

this script is suppose to update each control's background color based on the number.

The below code is only updating the last control because of Gui 25:+LastFound
If I take that out then no controls gets any update...

Num > 0 = Green
Num = 0 = Yellow
Num < 0 = Red

No matter what I try i can't get multiple windows updated. I even tried taking them out of the loop...I feel its on the tip of my tongue but i can't place it...

Any help is much appreciated.

Code:

#NoEnv
#MaxMem 100
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

BlockCount:=1
ColCount := 2
RowCount := 1
TotalUpdate := ColCount * RowCount
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% hwndTXID1 Border vRandomCount%BlockCount%,
      XTestPos+=TestColWid
      BlockCount+=1
      Gui 25:+LastFound
      GuiHwnd%A_Index% := WinExist()
      TotalGui := GuiHwnd%A_Index%
   }
   YTestPos+=TestColHeight
   XTestPos:=0
   ;Gui 25:+LastFound
                GuiHwnd%A_Index% := WinExist()
   TotalGui := GuiHwnd%A_Index%
}

   WindowProcNew := RegisterCallback("WindowProc", ""  ; Specifies "" to avoid fast-mode for subclassing.
    , 4, TXID1)  ; Must specify exact ParamCount when EventInfo parameter is present.
   WindowProcOld := DllCall("SetWindowLong", UInt, TotalGui, Int, -4  ; -4 is GWL_WNDPROC
    , Int, WindowProcNew, UInt)  ; Return value must be set to UInt vs. Int.

Gui, 25:Show, w%WinWidth% h%WinHeight% x0 y0, PAC
WinSet, Redraw
Loop
   {
   Sleep 100
   Gosub, Status_Update
   Sleep 2000
   }
RETURN

Status_Update:
Loop, %TotalUpdate%
{
   Random, TheRandomCount%A_Index%, -32, 32
   GotTheNum := TheRandomCount%A_Index%
   GuiControl, 25:,RandomCount%A_Index%, %GotTheNum%
   If(GotTheNum > 0)
   {
      TextBackgroundColor := Lime
   }
   Else If(GotTheNum < 0)
   {
      TextBackgroundColor := Red
   }
   Else if(GotTheNum = 0)
   {
      TextBackgroundColor := Yellow
   }
   Else
   {
      TextBackgroundColor := Black
   }
   TextBackgroundBrush := DllCall("CreateSolidBrush", UInt, TextBackgroundColor)
   WinSet, Redraw
}
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


WindowProc(hwnd, uMsg, wParam, lParam)
{
    Critical
    global TextBackgroundColor, TextBackgroundBrush, WindowProcOld
    if (uMsg = 0x138 && lParam = A_EventInfo)  ; 0x138 is WM_CTLCOLORSTATIC.
    {
        DllCall("SetBkColor", UInt, wParam, UInt, TextBackgroundColor)
        return TextBackgroundBrush  ; Return the HBRUSH to notify the OS that we altered the HDC.
    }
    ; Otherwise (since above didn't return), pass all unhandled events to the original WindowProc.
    return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group