AutoHotkey Community

It is currently May 27th, 2012, 4:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: March 10th, 2010, 9:01 pm 
Offline

Joined: November 19th, 2009, 6:23 pm
Posts: 163
Location: Florida
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)
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group