Rawox Posted June 6, 2010 Share Posted June 6, 2010 (edited) Hi there, I am currently working on a total rewrite of a script I started a few months ago. I need to view the It sets the hotkey (CTRL+ALT+V) but it doesn't show the contextmenu while this line worked in the older version... Func _showMenu() WM_CONTEXTMENU($hGUI, 0x007b, 0, 0) EndFunc ;==>_showMenu Rewrite: expandcollapse popup#include <GuiMenu.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Misc.au3> _Singleton(@ScriptName) HotKeySet("^!v", "_showMenu") Global $Title = "RightClip" Global $Version = "2.1" Global $IniDir = @ScriptDir & "\Configuration.ini" Global $DefaultDelim = "[\|/]", $TABDelim = "[\TAB/]", $CRLFDelim = "[\CRLF/]", $CRDelim = "[\CR/]", $LFDelim = "[\LF/]" Global $itArray = StringSplit ( IniRead ( $IniDir, "Array", "itArray", "" ), $DefaultDelim, 3 ) Global $idConfig $hGUI = GUICreate ( $Title & " " & $Version, 200, 100 ) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") GUISetState ( @SW_SHOW, $hGUI ) While 1 Sleep ( 10 ) WEnd Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) Local $hMenu $hMenu = _GUICtrlMenu_CreatePopup () $itArray = StringSplit ( IniRead ( $IniDir, "Array", "itArray", "" ), $DefaultDelim, 3 ) $i = 0 Do $i += 1 _GUICtrlMenu_AddMenuItem($hMenu, $itArray[$i-1], $i) Until $i == UBound ( $itArray ) _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "", 0) $idConfig = UBound($itArray) + 1 _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Configuration", $idConfig) _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam) _GUICtrlMenu_DestroyMenu ($hMenu) Return True EndFunc ;==>WM_CONTEXTMENU Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case 0 ;No Operation Case $idConfig _WinAPI_ShowMsg ("Configuration") Case Else _WinAPI_ShowMsg ("Test") EndSwitch EndFunc ;==>WM_COMMAND Func _showMenu() WM_CONTEXTMENU($hGUI, 0x007b, 0, 0) EndFunc ;==>_showMenu Old version: expandcollapse popup;#NoTrayIcon #include <GuiMenu.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Misc.au3> Opt("MustDeclareVars", 1) HotKeySet("^!v", "_showMenu") AdlibRegister("_ClipToArray",250) _Singleton(@ScriptName) Global $Title = "RightClip" Global $Version = "0.7" Global $Author = "Rawox" Global $IniDir = @ScriptDir & "\Config.ini" Global $ClipHist = "", $MenuLen = IniRead ( $IniDir, "General", "MaxChar", "30" ), $MenuHeight = IniRead ( $IniDir, "General", "MaxItem", "10" ) Global $sDelim = "[||]", $TabDelim = "[|TAB|]", $CRLFDelim = "[|CRLF|]", $CRDelim = "[|CR|]", $LFDelim = "[|LF|]" Global $hGUI, $idConfig, $Result, $i, $MenuResult, $Test, $Replacer, $MenuItem, $ResetClip Global $ConfigGui, $Width = 270, $Height = 256, $FocusGroup, $StartWithWin, $MaxChar, $MaxCharUD, $MaxItem, $MaxItemUD, $Save, $TABInput, $CRLFInput, $CRInput, $LFInput, $Quit Dim $itArray[1] = [""] $hGUI = GUICreate($Title, 400, 300) GUISetState(@SW_HIDE) $ConfigGui = GUICreate ( $Title & " " & $Version & " Configuration", $Width, $Height, -1, -1, $WS_SYSMENU ) $FocusGroup = GUICtrlCreateGroup ( "General", 15, 15, $Width - 30, 75 ) GUICtrlCreateLabel ( "Maximum Number of items:", 30, 38 ) GUICtrlCreateLabel ( "Maximum Characters per item:", 30, 61 ) $MaxItem = GUICtrlCreateInput ( IniRead ( $IniDir, "General", "MaxItem", "10" ), 190, 35, 50, 20 ) $MaxItemUD = GUICtrlCreateUpdown ( $MaxItem ) $MaxChar = GUICtrlCreateInput ( IniRead ( $IniDir, "General", "MaxChar", "30" ), 190, 58, 50, 20 ) $MaxCharUD = GUICtrlCreateUpdown ( $MaxChar ) $StartWithWin = GUICtrlCreateCheckbox ( "Start with Windows", 25, $Height - 67 ) $Save = GUICtrlCreateButton ( "Save", $Width - 75, $Height - 71, 60, 28 ) $Quit = GUICtrlCreateButton ( "Quit", $Width - 135, $Height - 71, 60, 28 ) GUICtrlSetState ( $StartWithWin, IniRead ( $IniDir, "General", "StartWithWin", 1 ) ) GUICtrlSetState ( $FocusGroup, $GUI_FOCUS ) GUISetState ( @SW_SHOW, $ConfigGui ) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") While 1 Switch GUIGetMsg() Case $Quit Exit Case $Save If GUICtrlRead ( $StartWithWin ) = 1 Then FileCreateShortcut ( @ScriptFullPath, @StartupDir & "\" & $Title ) Else FileDelete ( @StartupDir & "\" & $Title & ".lnk" ) EndIf _saveINI() Case $GUI_EVENT_CLOSE GUISetState ( @SW_HIDE, $ConfigGui ) EndSwitch WEnd Func _showMenu() WM_CONTEXTMENU($hGUI, 0x007b, 0, 0) EndFunc ;==>_showMenu Func _paste($vText) $ResetClip = ClipGet() $vText = StringReplace($vText, $TabDelim, @TAB) $vText = StringReplace($vText, $CRLFDelim, @CRLF) $vText = StringReplace($vText, $CRDelim, @CR) $vText = StringReplace($vText, $LFDelim, @LF) ClipPut($vText) Send("^v") ClipPut($ResetClip) EndFunc ;==>_paste Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ;ConsoleWrite("WM_COMMAND: " & @CRLF & _ ; @TAB & "hWnd = " & $hWnd & @CRLF & _ ; @TAB & "iMsg = " & $iMsg & @CRLF & _ ; @TAB & "iwParam = " & $iwParam & @CRLF & _ ; @TAB & "ilParam = " & $ilParam & @CRLF) Switch $iwParam Case 0 ; NOOP Case $idConfig GUISetState ( @SW_SHOW, $ConfigGui ) Case Else $itArray = StringSplit(IniRead($IniDir, "Array", "Array", ""), $sDelim, 1) If $iwParam < UBound($itArray) Then _paste($itArray[$iwParam]) EndIf EndSwitch EndFunc ;==>WM_COMMAND Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) ;ConsoleWrite("WM_CONTEXTMENU: " & @CRLF & _ ; @TAB & "hWnd = " & $hWnd & @CRLF & _ ; @TAB & "iMsg = " & $iMsg & @CRLF & _ ; @TAB & "iwParam = " & $iwParam & @CRLF & _ ; @TAB & "ilParam = " & $ilParam & @CRLF) Local $hMenu, $MenuItem, $idConfig $hMenu = _GUICtrlMenu_CreatePopup() For $n = 0 To UBound($itArray)-1 ;use Ubound for size and start at 0 If $itArray[$n] Then $MenuItem = $itArray[$n] $MenuItem = StringReplace($MenuItem, $TabDelim, "") $MenuItem = StringReplace($MenuItem, $CRLFDelim, " ") $MenuItem = StringReplace($MenuItem, $CRDelim, " ") $MenuItem = StringReplace($MenuItem, $LFDelim, " ") Do If StringLeft($MenuItem, 1) == " " Then $MenuItem = StringTrimLeft($MenuItem, 1) EndIf Until StringLeft($MenuItem, 1) <> " " If StringLen($MenuItem) > $MenuLen Then $MenuItem = StringLeft($MenuItem, $MenuLen) & "..." EndIf _GUICtrlMenu_AddMenuItem($hMenu, $MenuItem, $n) EndIf Next _GUICtrlMenu_AddMenuItem($hMenu, "") $idConfig = $itArray[0] + 1 _GUICtrlMenu_AddMenuItem($hMenu, "Configuration", $idConfig) _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) _GUICtrlMenu_DestroyMenu($hMenu) Return True EndFunc ;==>WM_CONTEXTMENU #cs Func _checkClip() If ClipGet() <> $ClipHist Then $ClipHist = ClipGet() $itArray = StringSplit(IniRead($IniDir, "Array", "Array", ""), $sDelim, 1) $Replacer = StringReplace(ClipGet(), @TAB, $TabDelim) $Replacer = StringReplace($Replacer, @CRLF, $CRLFDelim) $Replacer = StringReplace($Replacer, @CR, $CRDelim) $Replacer = StringReplace($Replacer, @LF, $LFDelim) If $itArray[0] = "" Then $itArray[0] = $Replacer Else _ArrayInsert($itArray, 0, $Replacer) EndIf EndIf _popArray() IniWrite($IniDir, "Array", "Array", _ArrayToString($itArray, $sDelim)) EndFunc ;==>_checkClip Func _popArray() $MenuHeight = IniRead ( $IniDir, "General", "MaxItem", "10" ) While UBound ( $itArray ) > $MenuHeight _ArrayDelete ( $itArray, UBound ( $itArray ) ) WEnd EndFunc ;==>_popArray #ce Func _ReplaceDelim($oldDelim, $newDelim) For $i = 0 To $MenuHeight-1 StringReplace($itArray[$i],$oldDelim,$newDelim) Next EndFunc Func _ClipToArray() Local $Clip = ClipGet() If $Clip <> $ClipHist Then $ClipHist = $Clip $Clip = StringReplace($Clip, @TAB, $TabDelim) $Clip = StringReplace($Clip, @CRLF, $CRLFDelim) $Clip = StringReplace($Clip, @CR, $CRDelim) $Clip = StringReplace($Clip, @LF, $LFDelim) _ArrayPush($itArray,$Clip,1) _saveINI() ;You will have to save this together with the curently used delimiters. Calling it seperate can cause incompatability EndIf EndFunc Func _saveINI() IniWrite ( $IniDir, "General", "StartWithWin", GUICtrlRead ( $StartWithWin ) ) IniWrite ( $IniDir, "General", "MaxItem", GUICtrlRead ( $MaxItem ) ) IniWrite ( $IniDir, "General", "MaxChar", GUICtrlRead ( $MaxChar ) ) IniWrite ( $IniDir, "Delimiters", "TAB", GUICtrlRead ( $TABInput ) ) IniWrite ( $IniDir, "Delimiters", "CRLF", GUICtrlRead ( $CRLFInput ) ) IniWrite ( $IniDir, "Delimiters", "CR", GUICtrlRead ( $CRInput ) ) IniWrite ( $IniDir, "Delimiters", "LF", GUICtrlRead ( $LFInput ) ) IniWrite($IniDir, "Array", "Array", _ArrayToString($itArray, $sDelim)) EndFunc ;===>_saveINI Anyone can help me? Thanks in advance, Rawox Edited June 6, 2010 by Rawox Link to comment Share on other sites More sharing options...
VAN0 Posted June 6, 2010 Share Posted June 6, 2010 (edited) This worked in my test: Func _showMenu() WM_CONTEXTMENU($hGUI, 0x007b, $hGUI, 0) EndFunc ;==>_showMenu [EDIT] comparing your new version with the old one, I see these two lines are different: old: _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) new: _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam) Edited June 6, 2010 by VAN0 Link to comment Share on other sites More sharing options...
Rawox Posted June 6, 2010 Author Share Posted June 6, 2010 Thanks for the help! I used the first line and it's now working again =] Are you new to AutoIt and programming and was it just bad luck or what? xD Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now