Sign in to follow this  
Followers 0
Nologic

Exit Contextmenu on loss of focus

1 post in this topic

I'm running into problems as I'm hoping to close this context menu on loss of focus or clicking something else.

I've attached full source and assets...it's setup in demo mode so it wont actually do anything, other than display messageboxes.

Any help in getting this working in such a fashion would be most welcome. :)

#include <Array.au3>

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>

#include <ModernMenuRaw.au3>

; Command Line Augments
;------------------------------
; .\VCSmenu.exe "<VCS_File.ini>" "<Active_File.Ext>"

; Final Uncomment
;------------------------------
;If $CmdLine[0] <> 2 Then Exit
;If NOT FileExists( $CmdLine[1] ) Then Exit
;If NOT FileExists( $CmdLine[2] ) Then Exit

; Final Delete
;------------------------------
$CmdLine1 = @ScriptDir & '\TortoiseGitMenu.ini'
$CmdLine2 = @ScriptDir & '\TortoiseGitMenu.ini'

; Final Code String Replace
;------------------------------
; $CmdLine1 = $CmdLine[1]
; $CmdLine2 = $CmdLine[2]

; String Reference
;------------------------------
; %f       = Full Path to File
; %p       = Directory Path to File
; %n       = File Name Minus Extension
; %e       = File Extension
; %modify% = Prompt for User Input

_createMenu( $CmdLine1 )

Func _createMenu( $sIniFile )
    Global $hMenuGUI = GUICreate( '' , 1 , 1 )
    Global $hMenu    = GUICtrlCreateContextMenu()

    $aMyINI = IniReadSectionNames( $sIniFile )
    If IsArray( $aMyINI ) <> 1 Then Exit

    Global $aMenuArray[$aMyINI[0] + 1][7] = [[$aMyINI[0]]]
    For $ii = 1 To $aMenuArray[0][0]
        $aSection = IniReadSection( $sIniFile , $aMyINI[$ii] )
        $aMenuArray[$ii][0] = $aMyINI[$ii]
        $aMenuArray[$ii][1] = _IniArrayCheck( $aSection , 'Icon' )
        $aMenuArray[$ii][2] = _IniArrayCheck( $aSection , 'DIR'  )
        $aMenuArray[$ii][3] = _IniArrayCheck( $aSection , 'CMD'  )
        $aMenuArray[$ii][4] = _IniArrayCheck( $aSection , 'Input')
        $aMenuArray[$ii][5] = '' ; Control ID
        $aMenuArray[$ii][6] = '' ; Menu ID
    Next

    For $ii = 1 To $aMenuArray[0][0]
        $aTitle = StringSplit( $aMenuArray[$ii][0] , '|' )
        If $aTitle[0] = 1 Then
            ; Add First Level Menu Items
            If StringInStr( $aMenuArray[$ii][1] , '.\' ) Then $aMenuArray[$ii][1] = StringReplace( $aMenuArray[$ii][1] , '.\' , @ScriptDir & '\' )
            $aMenuArray[$ii][5] = _GUICtrlCreateODMenuItem( $aTitle[1] , $hMenu , $aMenuArray[$ii][1] , -1 )
            $aMenuArray[$ii][6] = $hMenu
        Else
            For $jj = 1 To $aTitle[0]
                If $aTitle[0] <> $jj Then
                    ; Create Sub Menus
                    $sFindString = ''
                    For $kk = 1 To $jj
                        $sFindString &= $aTitle[$kk] & '|'
                    Next
                    If _ArraySearch( $aMenuArray , $sFindString , 1 , 0 , 0 , 1 , 1 , 0 ) = $ii Then
                        If $jj > 1 Then
                            ; Find Next Longest Sub Menu String
                            $sNewFindString = StringLeft( $sFindString , StringInStr( $sFindString , '|' , 0 , -2 ))
                            $iNewFindStringLocation = _ArraySearch( $aMenuArray , $sNewFindString , 1 , 0 , 0 , 1 , 1 , 0 )
                            $iMenuLocation = $aMenuArray[$iNewFindStringLocation][6]
                        Else
                            $iMenuLocation = $hMenu
                        EndIf
                        ; Populate All Matching Sub Menu Items With Current Menu Value
                        $MenuIcon = IniRead( @ScriptDir & '\MenuIcons.ini' , $aTitle[$jj] , 'Icon' , '' )
                        If StringInStr( $MenuIcon , '.\' ) Then $MenuIcon = StringReplace( $MenuIcon , '.\' , @ScriptDir & '\' )
                        $iSubMenuInstance  = _GUICtrlCreateODMenu( $aTitle[$jj] , $iMenuLocation , $MenuIcon , 0 )
                        $iSubMenuInstances = _ArrayFindAll( $aMenuArray , $sFindString , 1 , 0 , 0 , 1 , 0 )
                        For $ll = 0 To UBound( $iSubMenuInstances ) - 1
                            $aMenuArray[$iSubMenuInstances[$ll]][6] = $iSubMenuInstance
                        Next
                    EndIf
                Else
                    ; Add Items to Sub Menus
                    If StringInStr( $aMenuArray[$ii][1] , '.\' ) Then $aMenuArray[$ii][1] = StringReplace( $aMenuArray[$ii][1] , '.\' , @ScriptDir & '\' )
                    $aMenuArray[$ii][5] = _GUICtrlCreateODMenuItem( $aTitle[$jj] , $aMenuArray[$ii][6] , $aMenuArray[$ii][1] , -1)
                EndIf
            Next
        EndIf
    Next

    GUIRegisterMsg( $WM_COMMAND , "WM_COMMAND" )
    GUIRegisterMsg( $WM_CONTEXTMENU , "WM_CONTEXTMENU" )

    WM_CONTEXTMENU( $hMenuGUI , 0x007b , $hMenuGUI , 0 )
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $Code =_WinAPI_HiWord($wParam)
    If $Code = 0 Then ; Menu Command
        Local $MenuID = _WinAPI_LoWord($wParam)
        ConsoleWrite("MenuID " & $MenuID & @CRLF )
    EndIf
    For $ii = 1 To $aMenuArray[0][0]
        If $wParam = $aMenuArray[$ii][5] Then
            $sFileDir   = StringLeft    ( $CmdLine2 , StringInStr( $CmdLine2 , '\' , 0 , -1 ) )
            $sFileExt   = StringTrimLeft( $CmdLine2 , StringInStr( $CmdLine2 , '.' , 0 , -1 ) - 1 )
            $sFileName  = StringTrimLeft( $CmdLine2 , StringInStr( $CmdLine2 , '\' , 0 , -1 ) )
            $sShortName = StringLeft    ( $sFileName  , StringInStr( $sFileName , '.' , 0 , -1 ) - 1 )

            $aMenuArray[$ii][2] = StringStripWS( $aMenuArray[$ii][2] , 3 )
            $aMenuArray[$ii][2] = StringReplace( $aMenuArray[$ii][2] , '%p' , $sFileDir )

            $aMenuArray[$ii][3] = StringStripWS( $aMenuArray[$ii][3] , 3 )
            $aMenuArray[$ii][3] = StringReplace( $aMenuArray[$ii][3] , '%f' , $CmdLine2 )
            $aMenuArray[$ii][3] = StringReplace( $aMenuArray[$ii][3] , '%p' , $sFileDir   )
            $aMenuArray[$ii][3] = StringReplace( $aMenuArray[$ii][3] , '%n' , $sShortName )
            $aMenuArray[$ii][3] = StringReplace( $aMenuArray[$ii][3] , '%e' , $sFileExt   )

            If StringInStr( $aMenuArray[$ii][3] , '%modify%' ) <> 0 Then
                $aMenuArray[$ii][4] = StringReplace( $aMenuArray[$ii][4] , '\n' , @LF )
                $sAnswer = InputBox( 'User Input Needed' , $aMenuArray[$ii][4] )
                $aMenuArray[$ii][3] = StringReplace( $aMenuArray[$ii][3] , '%modify%' , $sAnswer )
            EndIf

;           Run( @ComSpec & ' /c ' & $aMenuArray[$ii][3] , $aMenuArray[$ii][2] , @SW_HIDE )
            MsgBox( 0 , $aMenuArray[$ii][2] , $aMenuArray[$ii][3] )
            Exit
        EndIf
    Next
EndFunc

Func WM_CONTEXTMENU( $hWnd, $iMsg, $iwParam, $ilParam )
    $hMenuHandle = GUICtrlGetHandle( $hMenu )
    $Pos = MouseGetPos()
    _GUICtrlMenu_SetItemHighlighted ($hMenuHandle , 0 )
    _GUICtrlMenu_TrackPopupMenu( $hMenuHandle , $hMenuGUI , $Pos[0]-40 , $Pos[1]-15 )
EndFunc

Func _IniArrayCheck( ByRef $Array , $String )
    $iFind = _ArraySearch( $Array , $String , 1 , 0 , 0 , 0 , 1 , 0 )
    If NOT @Error Then
        Return $Array[$iFind][1]
    Else
        Return ''
    EndIf
EndFunc

VCSmenu.rar

post-2388-0-23494800-1391829839_thumb.pn

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