Jump to content

Check RightClick on a Button


Recommended Posts

Is there any better solution to check right Click on a button rather than that one? Since could be there 100`s keys to process.

Topic is about to find out what is missing in AutoIT to handle contol ID`s of right Clicked Buttons amongst bunch of buttonkeys.

#include <GUIConstantsEx.au3> 

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "bye")
    GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp")
    global $cButton[9]
        for $x=1 to 3
            $cButton[$x] = GUICtrlCreateButton("Check"&$x, 10, 10*($X*5), 80, 30)
            GUICtrlSetOnEvent(-1, "_Button")
        next 
        $x+=1
            $cButton[$x] = GUICtrlCreateButton("NoCheck", 10, 10*($X*5), 80, 30)
    GUISetState()
While Sleep(10)
WEnd 

Func _Button()
    $nTempId=GUICtrlRead(@GUI_CtrlId) ; can get ID from Left Clicked Button//
    $aCInfo = GUIGetCursorInfo($hGUI)
    MsgBox(0, "Pressed",  "LEFT "&$nTempId&":"&GUICtrlRead($aCInfo[4]),.5)
EndFunc 

Func _SecondaryUp()
    $aCInfo = GUIGetCursorInfo($hGUI)
    for $x=1 to 3                               ; my solutionprocess slower....
        If $aCInfo[4] = $cButton[$x] Then
            $nTempId=GUICtrlRead(@GUI_CtrlId) ;cannot get  real ID, but last one.
            $nTempId2=GUICtrlRead($cButton[$x]) ;can get  ID            
            MsgBox(0, "Pressed", "RIGHT   "&$nTempId&":<=?  True= "&$nTempId2,1)
        EndIf
    next 
EndFunc 

Func bye()
    Exit
EndFunc

 

Edited by guiltyking
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>

Global Enum $idSettings = 1000
Global $hMain = GUICreate("", 120, 50)
Global $btnMenu = GUICtrlCreateButton("Menu", 10, 10, 100, 30)
Global $hBtnMenu = GUICtrlGetHandle($btnMenu)
Global $pButtonProc = DllCallbackGetPtr(DllCallbackRegister("ButtonProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))

GUISetState(@SW_SHOW, $hMain)

_WinAPI_SetWindowSubclass($hBtnMenu, $pButtonProc, 1000)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            GUIDelete($hMain)
            Exit 0
    EndSwitch
WEnd

Func ButtonProc($hWndFrom, $iMsg, $wParam, $lParam, $iSubclassId, $pData)
    Switch ($hWndFrom)
        Case $hBtnMenu
            Switch ($iMsg)
                Case $WM_RBUTTONUP
                    Local $hMenuButton = _GUICtrlMenu_CreatePopup($MNS_NOCHECK)
                    _GUICtrlMenu_AddMenuItem($hMenuButton, "Settings", $idSettings)
                    _GUICtrlMenu_TrackPopupMenu($hMenuButton, $hWndFrom)
                    _GUICtrlMenu_DestroyMenu($hMenuButton)
            EndSwitch
    EndSwitch
    Return _WinAPI_DefSubclassProc($hWndFrom, $iMsg, $wParam, $lParam)
EndFunc   ;==>EditProc

 

Edited by InunoTaishou
Link to comment
Share on other sites

Here's a short method I've used now and then:

#include <GUIConstantsEx.au3>

$hGui = GUICreate("Test GUI", 300, 200)
$send = GUICtrlCreateLabel("Test Label", 20, 40, 100, 40)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $send
            MsgBox(0, "Label", "Clicked", 1)
        Case $GUI_EVENT_SECONDARYUP
            $aCur = GUIGetCursorInfo($hGui)
            If IsArray($aCur) Then
                If $aCur[4] = $send Then
                    MsgBox(0, "Label", "Right Clicked", 1)
                EndIf
            EndIf
    EndSwitch
WEnd

Sometimes the method just depends on what other processing you need to include.

Link to comment
Share on other sites

I'm curious: what's the advantage of restricting over ignoring?

But, like I said, it depends on what other processing you need.

Regardless, I can imagine that your topic title will result in a lot of people looking for a minimal method ... and maybe the complicated ones, too.

Link to comment
Share on other sites

  • 4 years later...
On 4/12/2016 at 7:59 PM, qwert said:

Here's a short method I've used now and then:

#include <GUIConstantsEx.au3>

$hGui = GUICreate("Test GUI", 300, 200)
$send = GUICtrlCreateLabel("Test Label", 20, 40, 100, 40)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $send
            MsgBox(0, "Label", "Clicked", 1)
        Case $GUI_EVENT_SECONDARYUP
            $aCur = GUIGetCursorInfo($hGui)
            If IsArray($aCur) Then
                If $aCur[4] = $send Then
                    MsgBox(0, "Label", "Right Clicked", 1)
                EndIf
            EndIf
    EndSwitch
WEnd

Sometimes the method just depends on what other processing you need to include.

Wow! That is almost what I am need. Can you describe me what that array is doing, how to understand its behaviour?

UPD: is it possible to use multiple (included) switches/cases for better understanding?

Edited by krasnoshtan
Link to comment
Share on other sites

24 minutes ago, krasnoshtan said:

...Can you describe me what that array is doing, how to understand its behaviour?..

Okay, just got it. Every time right mouse button is released above the GUI, the check is performed - is there are any defined elements was right clicked.

Edited by krasnoshtan
Link to comment
Share on other sites

Maybe this :

#include <GUIConstants.au3>

$hGui = GUICreate("Test GUI", 300, 200)
$lab1 = GUICtrlCreateLabel("Test Label", 20, 40, 100, 25, $SS_SUNKEN)
$but1 = GUICtrlCreateButton("Button1", 20, 70, 100, 25)
$lab2 = GUICtrlCreateLabel("Test Label 2", 20, 100, 100, 25, $SS_SUNKEN)
$but2 = GUICtrlCreateButton("Button2", 20, 130, 100, 25)

GUISetState()

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
    Case $lab1
      MsgBox(0, "Label", "Clicked", 2)
    Case $GUI_EVENT_SECONDARYUP
      $aCur = GUIGetCursorInfo($hGui)
      If Not IsArray($aCur) Then ContinueLoop
      Switch $aCur[4]
        Case $lab1
          MsgBox(0, "Label 1", "Right Clicked", 2)
        Case $but1
          MsgBox(0, "Button 1", "Right Clicked", 2)
        Case $lab2
          MsgBox(0, "Label 2", "Right Clicked", 2)
        Case $but2
          MsgBox(0, "Button 2", "Right Clicked", 2)
      EndSwitch
  EndSwitch
WEnd

 

Link to comment
Share on other sites

3 minutes ago, Nine said:

Maybe this :

#include <GUIConstants.au3>

$hGui = GUICreate("Test GUI", 300, 200)
$lab1 = GUICtrlCreateLabel("Test Label", 20, 40, 100, 25, $SS_SUNKEN)
$but1 = GUICtrlCreateButton("Button1", 20, 70, 100, 25)
$lab2 = GUICtrlCreateLabel("Test Label 2", 20, 100, 100, 25, $SS_SUNKEN)
$but2 = GUICtrlCreateButton("Button2", 20, 130, 100, 25)

GUISetState()

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
    Case $lab1
      MsgBox(0, "Label", "Clicked", 2)
    Case $GUI_EVENT_SECONDARYUP
      $aCur = GUIGetCursorInfo($hGui)
      If Not IsArray($aCur) Then ContinueLoop
      Switch $aCur[4]
        Case $lab1
          MsgBox(0, "Label 1", "Right Clicked", 2)
        Case $but1
          MsgBox(0, "Button 1", "Right Clicked", 2)
        Case $lab2
          MsgBox(0, "Label 2", "Right Clicked", 2)
        Case $but2
          MsgBox(0, "Button 2", "Right Clicked", 2)
      EndSwitch
  EndSwitch
WEnd

 

yeah, that's clearer, thanks!

Link to comment
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
 Share

×
×
  • Create New...