AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Context Menu not showing
PostPosted: March 9th, 2010, 10:50 pm 
Offline

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2010, 8:19 am 
Offline

Joined: November 8th, 2009, 2:46 am
Posts: 234
Location: Canberra Oz
I presume you mean this loop?
Code:
Loop
{
   GoSub, TXT1   
   Sleep, 5000
}
You could use a SetTimer instead
Code:
SetTimer TXT1, 5000
Also try
Code:
#MaxThreads 10
Although the help says defaults to ten, I have had issues when it was not implicitly set.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2010, 2:29 pm 
Offline

Joined: November 19th, 2009, 6:23 pm
Posts: 163
Location: Florida
Ok so I found out what the problem is....
All of the Control_Colors commands is whats causing it...
Code:
Control_Colors(Lime, Black, "Set", TXID%A_Index%)


the above command blocks the background....I'm trying to find a way around that


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2010, 11:46 pm 
Offline

Joined: November 8th, 2009, 2:46 am
Posts: 234
Location: Canberra Oz
From OnMessage() Help
Quote:
If this is undesirable, a message greater than or equal to 0x312 can be buffered until its function completes by specifying Critical as the first line of the function. Alternatively, Thread Interrupt can achieve the same thing as long as it lasts long enough for the function to finish. By contrast, a message less than 0x312 cannot be buffered by Critical or Thread Interrupt (however, in v1.0.46+, Critical may help because it checks messages less often, which gives the function more time to finish). The only way to guarantee that no such messages are missed is to ensure the function finishes in under 6 milliseconds (though this limit can be raised via Critical 30). One way to do this is to have it queue up a future thread by posting to its own script a monitored message number higher than 0x312. That message's function should use Critical as its first line to ensure that its messages are buffered.
First try
Code:
      Else
         ValLst .= H "|" W "|" L "`r`n"
      SetFormat, Integer, %Format_I%
      Critical,Off
      Return
If that is no good, try setting the Critical in the function to 30 and move it to be the first line


Report this post
Top
 Profile  
Reply with quote  
 Post subject: SOLVED
PostPosted: March 11th, 2010, 2:29 pm 
Offline

Joined: November 19th, 2009, 6:23 pm
Posts: 163
Location: Florida
that critical off did the trick
You are the man, thank you very much for your assistance sir.

This is actually the best version of custom colors I've found, when my program updates its quick, but other version like _CTLCOLORS_ have given me problems... ctlcolors would give me numerous errors, and on the same thread a different version wasn't as quick to update..

this works out for me...really well, again thank you


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

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:
cron
Powered by phpBB® Forum Software © phpBB Group