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 

Context Menu not showing

 
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: Tue Mar 09, 2010 9:50 pm    Post subject: Context Menu not showing Reply with quote

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%
}
; ------------------------------------------------------------------------------
Back to top
View user's profile Send private message Visit poster's website
Michael@Oz



Joined: 08 Nov 2009
Posts: 233
Location: Canberra Oz

PostPosted: Wed Mar 10, 2010 7:19 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
The Unknown Jobber



Joined: 19 Nov 2009
Posts: 161
Location: Florida

PostPosted: Wed Mar 10, 2010 1:29 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Michael@Oz



Joined: 08 Nov 2009
Posts: 233
Location: Canberra Oz

PostPosted: Wed Mar 10, 2010 10:46 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
The Unknown Jobber



Joined: 19 Nov 2009
Posts: 161
Location: Florida

PostPosted: Thu Mar 11, 2010 1:29 pm    Post subject: SOLVED Reply with quote

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
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