Rawox Posted May 27, 2010 Share Posted May 27, 2010 (edited) Hi there, Can anyone tell me why the contextmenu returns the number of items in the array as soon as you change the max item to a lower number in the configuration and press CTRL+ALT+V again... Background info: This script adds copied items to a contextmenu that can be showed using CTRL+ALT+V. In the configuration it is possible to set the maximum number of items in the contextmenu. Some way it adds a number when this maxitem variable is lowered... 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("_checkClip") _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 = IniRead ( $IniDir, "Delimiters", "TAB", "[|TAB|]" ), $CRLFDelim = IniRead ( $IniDir, "Delimiters", "CRLF", "[|CRLF|]" ), $CRDelim = IniRead ( $IniDir, "Delimiters", "CR", "[|CR|]" ), $LFDelim = IniRead ( $IniDir, "Delimiters", "LF", "[|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 ) GUICtrlCreateGroup ( "INI Configuration Delimiters", 15, 100, $Width - 30, 78 ) GUICtrlCreateLabel ( "TAB:", 30, 123 ) GUICtrlCreateLabel ( "CRLF:", 30, 147 ) GUICtrlCreateLabel ( "CR:", 150, 123 ) GUICtrlCreateLabel ( "LF:", 150, 147 ) $TABInput = GUICtrlCreateInput ( IniRead ( $IniDir, "Delimiters", "TAB", "[|TAB|]" ), 70, 120, 60, 20 ) $CRLFInput = GUICtrlCreateInput ( IniRead ( $IniDir, "Delimiters", "CRLF", "[|CRLF|]" ), 70, 144, 60, 20 ) $CRInput = GUICtrlCreateInput ( IniRead ( $IniDir, "Delimiters", "CR", "[|CR|]" ), 180, 120, 60, 20 ) $LFInput = GUICtrlCreateInput ( IniRead ( $IniDir, "Delimiters", "LF", "[|LF|]" ), 180, 144, 60, 20 ) $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() _popArray() IniWrite($IniDir, "Array", "Array", _ArrayToString($itArray, $sDelim)) 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 Local $MenuLen = IniRead ( $IniDir, "General", "MaxChar", "30" ) $hMenu = _GUICtrlMenu_CreatePopup() $itArray = StringSplit(IniRead($IniDir, "Array", "Array", ""), $sDelim, 1) If $itArray[0] <> 0 Then For $n = 1 To $itArray[0] $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) Next EndIf _GUICtrlMenu_AddMenuItem($hMenu, "") $idConfig = $itArray[0] + 1 _GUICtrlMenu_AddMenuItem($hMenu, "Configuration", $idConfig) _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) _GUICtrlMenu_DestroyMenu($hMenu) Return True EndFunc ;==>WM_CONTEXTMENU Func _checkClip() If ClipGet() <> $ClipHist Then $ClipHist = ClipGet() $itArray = StringSplit(IniRead($IniDir, "Array", "Array", ""), $sDelim, 3) $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 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 ) ) EndFunc ;===>_saveINI Edited June 4, 2010 by Rawox Link to comment Share on other sites More sharing options...
jaberwacky Posted May 27, 2010 Share Posted May 27, 2010 Give us a lil more background info please. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Rawox Posted May 27, 2010 Author Share Posted May 27, 2010 Give us a lil more background info please.Good enough? Link to comment Share on other sites More sharing options...
Tvern Posted May 27, 2010 Share Posted May 27, 2010 (edited) It's not _ArrayDelete that adds the count. Like you said in the title. _ArrayDelete returns the count, while only modifying the array. StringSplit, however returns the array size in $returnedarray[0] Also you might want to take a look at your AdlibRegister as it's writing to your ini file non-stop. Edit: You might also want to comment out the line that copies the script to @StartupDir Edited May 27, 2010 by Tvern Link to comment Share on other sites More sharing options...
Rawox Posted May 27, 2010 Author Share Posted May 27, 2010 It's not _ArrayDelete that adds the count. Like you said in the title. _ArrayDelete returns the count, while only modifying the array. StringSplit, however returns the array size in $returnedarray[0] Also you might want to take a look at your AdlibRegister as it's writing to your ini file non-stop. Edit: You might also want to comment out the line that copies the script to @StartupDir It copies to @StartupDir if you enable that option... I don't know how to modify the script to not return the count? I'm trying for 2 days already and I can't get it. Could you please show me how to do this or at least point me in the right direction with a little more info. Link to comment Share on other sites More sharing options...
Tvern Posted May 27, 2010 Share Posted May 27, 2010 It copies to @StartupDir if you enable that option... Yes, but the option is enabled by default.I don't know how to modify the script to not return the count? I'm trying for 2 days already and I can't get it.Could you please show me how to do this or at least point me in the right direction with a little more info.At line 150 you set the stringsplit flag to 3, meaning: flag = 1, entire delimiter string is needed to mark the split+flag = 2, disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case).but at lines 100 and 119 you use flag 1. Change those to 3 as you did on line 150. Link to comment Share on other sites More sharing options...
Rawox Posted May 27, 2010 Author Share Posted May 27, 2010 (edited) The options is enabled by default because it should be And, when I change all three to 3 the script doesn't work. Changing it to 1 will still cause the script to return those numbers... Edited May 27, 2010 by Rawox Link to comment Share on other sites More sharing options...
Tvern Posted May 27, 2010 Share Posted May 27, 2010 I'm still trying to figure out exactly what your code does. The problem you have is being caused, because half your script uses a 1 based array, with the cound in $itArray[0], while the other half uses a 0 based array. You'll need make the entire script use the same type of array. If you choose to use a 0 based array you need to replace the references to $itArray[0] with Ubound($itArray)-1. If you choose to use a 1 based array you need stop saving $itArray[0] for instance by changing IniWrite($IniDir, "Array", "Array", _ArrayToString($itArray, $sDelim)) to IniWrite($IniDir, "Array", "Array", _ArrayToString($itArray, $sDelim,1)) Link to comment Share on other sites More sharing options...
Rawox Posted May 27, 2010 Author Share Posted May 27, 2010 I want to create a null-based array but can't get the right way to convert it. Could you, or someone else, please convert it? Link to comment Share on other sites More sharing options...
Tvern Posted May 27, 2010 Share Posted May 27, 2010 I tried to tweak your code to work, but every change to fix one thing broke another, so I rewrote part of it. I hope you can make sense out of it. I've only rewritten the troublesome functions, but most of the stuff missing should be easily added onto this. expandcollapse popup#include <GuiMenu.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Misc.au3> Opt("MustDeclareVars", 1) _Singleton(@ScriptName) HotKeySet("^!v", "_showMenu") Global $Title = "RightClip" Global $Version = "0.7" Global $Author = "Rawox" Global $hGUI ;hgui Variables Global $ConfigGui, $Width = 270, $Height = 256 ;config gui variables Global $FocusGroup, $MaxItem, $MaxItemUD, $MaxChar, $MaxCharUD ;group 1 cotrols Global $TABInput, $CRLFInput, $CRInput, $LFInput, $StartWithWin, $Save, $Quit ;group 2 controls Global $sDelim = "[||]", $ClipHist, $newDelim Global $IniDir = @ScriptDir & "\Config.ini" Global $TabDelim = IniRead ( $IniDir, "Delimiters", "TAB", "[|TAB|]" ) Global $CRLFDelim = IniRead ( $IniDir, "Delimiters", "CRLF", "[|CRLF|]" ) Global $CRDelim = IniRead ( $IniDir, "Delimiters", "CR", "[|CR|]" ) Global $LFDelim = IniRead ( $IniDir, "Delimiters", "LF", "[|LF|]" ) Global $MenuLen = IniRead ( $IniDir, "General", "MaxChar", "30" ) Global $MenuHeight = IniRead ( $IniDir, "General", "MaxItem", "10" ) Global $itArray = StringSplit(IniRead($IniDir, "Array", "Array", ""), $sDelim, 3) ReDim $itArray[$MenuHeight] AdlibRegister("_ClipToArray",250) $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 ( $MenuHeight, 190, 35, 50, 20 ) $MaxItemUD = GUICtrlCreateUpdown ( $MaxItem ) $MaxChar = GUICtrlCreateInput ( $MenuLen, 190, 58, 50, 20 ) $MaxCharUD = GUICtrlCreateUpdown ( $MaxChar ) GUICtrlCreateGroup ( "INI Configuration Delimiters", 15, 100, $Width - 30, 78 ) GUICtrlCreateLabel ( "TAB:", 30, 123 ) GUICtrlCreateLabel ( "CRLF:", 30, 147 ) GUICtrlCreateLabel ( "CR:", 150, 123 ) GUICtrlCreateLabel ( "LF:", 150, 147 ) $TABInput = GUICtrlCreateInput ($TabDelim, 70, 120, 60, 20 ) $CRLFInput = GUICtrlCreateInput ($CRLFDelim, 70, 144, 60, 20 ) $CRInput = GUICtrlCreateInput ($CRDelim, 180, 120, 60, 20 ) $LFInput = GUICtrlCreateInput ($LFDelim, 180, 144, 60, 20 ) $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 ) While 1 Local $msg = GUIGetMsg(1) Switch $msg[1] Case $hGUI ;Messages from controls in the main GUI go here Switch $msg[0] Case $GUI_EVENT_CLOSE AdlibUnRegister("_ClipToArray") Exit EndSwitch Case $ConfigGui ;Messages from controls in the Config GUI go here Switch $msg[0] Case $MaxItem, $MaxItemUD If $MenuHeight <> GUICtrlRead($MaxItem) Then $MenuHeight = GUICtrlRead($MaxItem) ReDim $itArray[$MenuHeight] ;resize the array. You can also save the new array here. EndIf Case $MaxChar, $MaxCharUD If $MenuLen <> GUICtrlRead($MaxChar) Then $MenuLen = GUICtrlRead($MaxChar) EndIf Case $TABInput $newDelim = GUICtrlRead($TABInput) If $TabDelim <> $newDelim Then _ReplaceDelim($TabDelim, $newDelim) ;adjust the array $TabDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $CRLFInput $newDelim = GUICtrlRead($CRLFInput) If $CRLFDelim <> $newDelim Then _ReplaceDelim($CRLFDelim, $newDelim) ;adjust the array $CRLFDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $CRInput $newDelim = GUICtrlRead($CRInput) If $CRDelim <> $newDelim Then _ReplaceDelim($CRDelim, $newDelim) ;adjust the array $CRDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $LFInput $newDelim = GUICtrlRead($LFInput) If $LFDelim <> $newDelim Then _ReplaceDelim($LFDelim, $newDelim) ;adjust the array $LFDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $ConfigGui) GUISetState(@SW_SHOW, $hGUI) Case $Quit AdlibUnRegister("_ClipToArray") Exit Case $Save _saveINI() EndSwitch EndSwitch WEnd Func _showMenu() WM_CONTEXTMENU($hGUI, 0x007b, 0, 0) EndFunc ;==>_showMenu 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 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 Link to comment Share on other sites More sharing options...
Rawox Posted May 27, 2010 Author Share Posted May 27, 2010 (edited) Thanks for the help, but how do I get the messages returned by the contextmenu now? I need to paste the value from the array that was clicked. Like in this WM_COMMAND: 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 Edited May 27, 2010 by Rawox Link to comment Share on other sites More sharing options...
Tvern Posted May 27, 2010 Share Posted May 27, 2010 You should be able to just put the corresponding functions and function calls into the new code The created menuitems are the same as in the original script. Link to comment Share on other sites More sharing options...
Rawox Posted May 27, 2010 Author Share Posted May 27, 2010 When I add the function it doesn't work. Tried lots of things... Link to comment Share on other sites More sharing options...
Tvern Posted May 27, 2010 Share Posted May 27, 2010 this mostly works, but needs some tweaking expandcollapse popup#include <GuiMenu.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <Misc.au3> Opt("MustDeclareVars", 1) _Singleton(@ScriptName) HotKeySet("^!v", "_showMenu") Global $Title = "RightClip" Global $Version = "0.7" Global $Author = "Rawox" Global $hGUI ;hgui Variables Global $ConfigGui, $Width = 270, $Height = 256 ;config gui variables Global $FocusGroup, $MaxItem, $MaxItemUD, $MaxChar, $MaxCharUD ;group 1 cotrols Global $TABInput, $CRLFInput, $CRInput, $LFInput, $StartWithWin, $Save, $Quit ;group 2 controls Global $sDelim = "[||]", $ClipHist, $newDelim, $idConfig Global $IniDir = @ScriptDir & "\Config.ini" Global $TabDelim = IniRead ( $IniDir, "Delimiters", "TAB", "[|TAB|]" ) Global $CRLFDelim = IniRead ( $IniDir, "Delimiters", "CRLF", "[|CRLF|]" ) Global $CRDelim = IniRead ( $IniDir, "Delimiters", "CR", "[|CR|]" ) Global $LFDelim = IniRead ( $IniDir, "Delimiters", "LF", "[|LF|]" ) Global $MenuLen = IniRead ( $IniDir, "General", "MaxChar", "30" ) Global $MenuHeight = IniRead ( $IniDir, "General", "MaxItem", "10" ) Global $itArray = StringSplit(IniRead($IniDir, "Array", "Array", ""), $sDelim, 3) ReDim $itArray[$MenuHeight] AdlibRegister("_ClipToArray",250) $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 ( $MenuHeight, 190, 35, 50, 20 ) $MaxItemUD = GUICtrlCreateUpdown ( $MaxItem ) $MaxChar = GUICtrlCreateInput ( $MenuLen, 190, 58, 50, 20 ) $MaxCharUD = GUICtrlCreateUpdown ( $MaxChar ) GUICtrlCreateGroup ( "INI Configuration Delimiters", 15, 100, $Width - 30, 78 ) GUICtrlCreateLabel ( "TAB:", 30, 123 ) GUICtrlCreateLabel ( "CRLF:", 30, 147 ) GUICtrlCreateLabel ( "CR:", 150, 123 ) GUICtrlCreateLabel ( "LF:", 150, 147 ) $TABInput = GUICtrlCreateInput ($TabDelim, 70, 120, 60, 20 ) $CRLFInput = GUICtrlCreateInput ($CRLFDelim, 70, 144, 60, 20 ) $CRInput = GUICtrlCreateInput ($CRDelim, 180, 120, 60, 20 ) $LFInput = GUICtrlCreateInput ($LFDelim, 180, 144, 60, 20 ) $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 Local $msg = GUIGetMsg(1) If $msg Then ConsoleWrite($msg[0] & @CRLF) Switch $msg[1] Case $hGUI ;Messages from controls in the main GUI go here Switch $msg[0] Case $GUI_EVENT_CLOSE AdlibUnRegister("_ClipToArray") Exit EndSwitch Case $ConfigGui ;Messages from controls in the Config GUI go here Switch $msg[0] Case $MaxItem, $MaxItemUD If $MenuHeight <> GUICtrlRead($MaxItem) Then $MenuHeight = GUICtrlRead($MaxItem) ReDim $itArray[$MenuHeight] ;resize the array. You can also save the new array here. EndIf Case $MaxChar, $MaxCharUD If $MenuLen <> GUICtrlRead($MaxChar) Then $MenuLen = GUICtrlRead($MaxChar) EndIf Case $TABInput $newDelim = GUICtrlRead($TABInput) If $TabDelim <> $newDelim Then _ReplaceDelim($TabDelim, $newDelim) ;adjust the array $TabDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $CRLFInput $newDelim = GUICtrlRead($CRLFInput) If $CRLFDelim <> $newDelim Then _ReplaceDelim($CRLFDelim, $newDelim) ;adjust the array $CRLFDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $CRInput $newDelim = GUICtrlRead($CRInput) If $CRDelim <> $newDelim Then _ReplaceDelim($CRDelim, $newDelim) ;adjust the array $CRDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $LFInput $newDelim = GUICtrlRead($LFInput) If $LFDelim <> $newDelim Then _ReplaceDelim($LFDelim, $newDelim) ;adjust the array $LFDelim = $newDelim _saveINI() ;You will have to save this together with the curently used array. Calling it seperate can cause incompatability EndIf Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $ConfigGui) GUISetState(@SW_SHOW, $hGUI) Case $Quit AdlibUnRegister("_ClipToArray") Exit Case $Save _saveINI() EndSwitch EndSwitch WEnd Func _showMenu() WM_CONTEXTMENU($hGUI, 0x007b, 0, 0) EndFunc ;==>_showMenu Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) Local $hMenu, $MenuItem $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 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 Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case "0x" & Hex($idConfig,16) GUISetState ( @SW_SHOW, $ConfigGui ) Case Else If $iwParam < UBound($itArray) Then _paste($itArray[$iwParam]) EndIf EndSwitch EndFunc ;==>WM_COMMAND Func _paste($vText) Local $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 Link to comment Share on other sites More sharing options...
Rawox Posted June 4, 2010 Author Share Posted June 4, 2010 Tvern (or someone else), I almost literally pulled my hairs out of my head and now I just want to create it the way it was it. (Not so complicated any more). Can someone please recreate it so it just adds the copied text to the listview (using _paste) and when I click a listviewitem it pastes the text... That would be so awesome because I just want it to use for myself right now so no GUI is needed! Respect for the one that fixes it, Rawox 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