Sign in to follow this  
Followers 0
fmen

Right Click Menu

9 posts in this topic

OK, I've been working on a desktop popup menu and learning along the way.

When you click the right side of the desktop a menu with buttons pops up. I also want to add context menus to the buttons but am having problems. They will not not respond.

I added a simple right click context menu ("Exit") to the button "More". It won'trespond. I believe I am having problems with the loop as well as the Opt("GuiOnEventMode", 1). Any help will be appreciated.

(Sorry about the poor formatting)

;_________________________________________Initial Set Up_____________________________

AutoItSetOption ( "SendKeyDelay", '.01' )

AutoItSetOption ( "WinTitleMatchMode", 2 )

;#NoTrayIcon

#include <GUIConstants.au3>

#include <_IsPressed.au3>

Opt("GuiOnEventMode", 1)

;_________________________________________MAIN GUI And Buttons_______________________

$GuiWidth = 100

$GuiHeight = 500

$xPos = (@DesktopWidth-105)

$yPos = (@DesktopHeight - $GuiHeight) / 2

$Gui = GUICreate("GuiRight", 100, 500,$xpos, $yPos, $WS_POPUP,$WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)

;GUISetBkColor (0)

GUISetState(@SW_HIDE)

;ButtonA

$ButtonA = GUICtrlCreateButton ( "ButtonA", 15, 20 ,75 ,15)

GUICtrlSetOnEvent($ButtonA, "ButtonA_Pressed")

GUISetState(@SW_HIDE)

;ButtonB

$ButtonB = GUICtrlCreateButton ( "ButtonB", 15, 40 ,75 ,15)

GUICtrlSetOnEvent($ButtonB, "ButtonB_Pressed")

GUISetState(@SW_HIDE)

;ButtonC

$ButtonC = GUICtrlCreateButton ( "Terminate", 15, 460 ,75 ,15)

GUICtrlSetOnEvent($ButtonC, "Terminate")

GUISetState(@SW_HIDE)

;________________________________"More" Button & Right Click MoreButton___________________________

;MoreButton

$MoreButton = GUICtrlCreateButton ( "More", 15, 480 ,75 ,15)

$bcontext = GUICtrlCreateContextMenu($MoreButton)

$bexit = GUICtrlCreateMenuitem("Exit",$bcontext)

;_________________________________________Hotkeys_____________________________________

;_____________________________________________________________________________________

;______________________________LOOP Mouse click trapper(01=rt 02=rt 04=mid)__________

While 1

$msg = GUIGetMsg()

If $msg = $MoreButton Then Call ("Terminate")

If $msg = $bexit Then MsgBox(4096,"control", "Button_Go pressed")

$i = MouseGetPos()

If _IsPressed('04') = 1 Then Call ("Calig")

If _IsPressed('02') = 1 AND $i[0] = @DesktopWidth -1 Then Call ("Show_Gui")

If _IsPressed('01') = 1 AND $i[0] = @DesktopWidth -1 Then Call ("Bang")

If _IsPressed('01') = 1 AND $i[0] < @DesktopWidth -100 Then GUISetState(@SW_HIDE, "GuiRight")

Sleep(10)

Wend

;__________________________________________________________________________________________

;______________________________Button Functions____________________________________________

Func ButtonA_Pressed()

MsgBox(4096,"control", "Button_Go pressed")

GUISetState(@SW_HIDE, "GuiRight")

EndFunc

Func ButtonB_Pressed()

GUISetState(@SW_HIDE, "GuiRight")

GUISetState(@SW_HIDE, "More")

EndFunc

Func Terminate ()

Exit 0

EndFunc

Func More ()

MsgBox(4096,"control", "Button_Go pressed")

EndFunc

Func Show_Gui ()

Sleep (200)

Send ("{ESC}")

GUISetState(@SW_SHOW, "GuiRight")

EndFunc

;________________________________Next Left Click Functions________________________________

Func Bang()

MsgBox(4096,"control", "Bang! Bang! Bang!")

EndFunc

;_______________________________________Hotkey Functions___________________________________

;_______________________________________________The End______________________________________

GUIDelete()

Share this post


Link to post
Share on other sites



;MoreButton

$MoreButton = GUICtrlCreateButton ( "More", 15, 480 ,75 ,15)

needs to be

;MoreButton

$MoreButton = GUICtrlCreateButton ( "More", 15, 480 ,75 ,15)

GUICtrlSetOnEvent($MoreButton, "More")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Did you get this code to run at all? No warnings?

Modifying

;#include <_IsPressed.au3>
#include <misc.au3>

And adding missing functions did it on my system. (Version 3.1.1.75)

Regards

Uten

Share this post


Link to post
Share on other sites

just realized... with this

Opt("GuiOnEventMode", 1)

you cant use this

$msg = GUIGetMsg()

If $msg = $MoreButton Then Call ("Terminate")

from help

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

use one or the other

8)

this wont work because $moreButton is a button

$bcontext = GUICtrlCreateContextMenu($MoreButton)

so remove that line...

and alos remove

If $msg = $bexit Then MsgBox(4096,"control", "Button_Go pressed")

you need to look at that context menu in help

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

I had a strong feeling that was the problem, but if I don't use Opt("GuiOnEventMode", 1) then the rest of the script doesn't work. I suppose that GuiSwitch etc needs to be used.

Share this post


Link to post
Share on other sites

ok... i am board... i will clean it up for you

i will post it in a few

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

ok here we go

;_________________________________________Initial Set Up_____________________________

AutoItSetOption ( "SendKeyDelay", '.01' )
AutoItSetOption ( "WinTitleMatchMode", 2 )

;#NoTrayIcon 
#include <GUIConstants.au3>
;#include <_IsPressed.au3>
#include <misc.au3>

Opt("GuiOnEventMode", 1)

;_________________________________________MAIN GUI And Buttons_______________________
$GuiWidth = 100
$GuiHeight = 500
$xPos = (@DesktopWidth-105)
$yPos = (@DesktopHeight - $GuiHeight) / 2

$Gui = GUICreate("GuiRight", 100, 500,$xpos, $yPos, $WS_POPUP,$WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)
;GUISetBkColor (0)

;ButtonA
$ButtonA = GUICtrlCreateButton ( "ButtonA", 15, 20 ,75 ,15)
GUICtrlSetOnEvent($ButtonA, "ButtonA_Pressed")

;ButtonB
$ButtonB = GUICtrlCreateButton ( "ButtonB", 15, 40 ,75 ,15)
GUICtrlSetOnEvent($ButtonB, "ButtonB_Pressed")


;ButtonC
$ButtonC = GUICtrlCreateButton ( "Terminate", 15, 460 ,75 ,15)
GUICtrlSetOnEvent($ButtonC, "Terminate")

;________________________________"More" Button & Right Click MoreButton___________________________

;MoreButton
$MoreButton = GUICtrlCreateButton ( "More", 15, 480 ,75 ,15)
GUICtrlSetOnEvent($MoreButton, "More")


$bcontext = GUICtrlCreateContextMenu($MoreButton)
$bexit = GUICtrlCreateMenuitem("Exit",$bcontext)
GUICtrlSetOnEvent(-1, "Terminate")

$b_new_to_me = GUICtrlCreateMenuitem("New to me",$bcontext)
GUICtrlSetOnEvent(-1, "New_to_me")

;set this to hide if you want
GUISetState()

;_________________________________________Hotkeys_____________________________________

;_____________________________________________________________________________________

;______________________________LOOP Mouse click trapper(01=rt 02=rt 04=mid)__________

While 1
;$msg = GUIGetMsg()

$i = MouseGetPos()
If _IsPressed('04') = 1 Then Call ("Calig")
If _IsPressed('02') = 1 AND $i[0] = @DesktopWidth -1 Then Call ("Show_Gui") 
If _IsPressed('01') = 1 AND $i[0] = @DesktopWidth -1 Then Call ("Bang")
If _IsPressed('01') = 1 AND $i[0] < @DesktopWidth -100 Then GUISetState(@SW_HIDE, "GuiRight") 

Wend
;__________________________________________________________________________________________

;______________________________Button Functions____________________________________________

Func ButtonA_Pressed()
MsgBox(4096,"control", "Button_A pressed") 
GUISetState(@SW_HIDE, "GuiRight")
EndFunc

Func ButtonB_Pressed()
MsgBox(4096,"control", "Button_B pressed") 
GUISetState(@SW_HIDE, "GuiRight")
GUISetState(@SW_HIDE, "More")
EndFunc

Func Terminate() 
Exit 0 
EndFunc

Func More() 
MsgBox(4096,"control", "Button_Go pressed")
GUISetState(@SW_HIDE, "GuiRight")
GUISetState(@SW_HIDE, "More")
EndFunc

Func Show_Gui() 
Sleep (200) 
Send ("{ESC}")
GUISetState(@SW_SHOW, "GuiRight") 
EndFunc

;________________________________Next Left Click Functions________________________________

Func Bang()
MsgBox(4096,"control", "Bang! Bang! Bang!") 
EndFunc

Func Calig()
; dont know what this one does ????
MsgBox(4096,"control", "Calig! Calig! Calig!") 
EndFunc

Func New_to_me()
MsgBox(4096,"control", "This right click menu inside of a button is new to me  "& @CRLF & @CRLF  & "Bang! Bang! Bang!") 
EndFunc

;_______________________________________Hotkey Functions___________________________________



;_______________________________________________The End______________________________________

GUIDelete()

it all works... but maybe you need the beta version

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Valuater, I can't thank you enough. It's exacly what I wanted. You are correct about the beta, but it works fine if _Ispressed.au3 is included. Thanks again.

Share this post


Link to post
Share on other sites

Glad i could help

...also i tried to demonstrate how to add more menu's to the more button

hope you understand what i did

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0