Jump to content

Recommended Posts

Posted (edited)

Ok, I asked so much different questions that and I can't get it to work.

So I'll just post what I'm trying to get in the hope that someone will fix it for me :idea:, I can't find the solution.

I'm trying to create a contextmenu when a user presses CTRL+ALT+V which shows the 10 latest items of text he pasted to the clipboard, then a seperator and at last the configuration item at the bottom.

When a user opens the menu (using CTRL+ALT+V) and clicks one of the items, the script needs to look in an INI file where the string that he has copied are stored in and paste it (using CTRL+V)

Anyone knows how I should do this? This was my try...

#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.3"
Global      $Author =       "Rawox"
Global      $IniDir =       @ScriptDir & "\Config.ini"
Global      $hGUI, $idConfig, $ClipHist = "", $sDelim = "[||]", $Result, $i, $MenuLen = 30, $MenuResult, $Test
Global      $itArray[1], $itemArray[1], $menuArray
            $itArray[0] = 0
            $itemArray[0] = 0

$hGUI =     GUICreate ( $Title, 400, 300 )
            GUISetState(@SW_HIDE)

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

            Do

            Until 1 = 2

Func _showMenu()
    WM_CONTEXTMENU ( )
EndFunc

Func _checkClip()
    If ClipGet ( ) <> $ClipHist AND ClipGet ( ) <> "" Then
        $ClipHist = ClipGet ( )
        $itArray[0] = $itArray[0] + 1
        $Result = StringReplace ( $ClipHist, @CRLF, "|[CRLF]|" )
        $Result = StringReplace ( $Result, @CR, "|[CR]|" )
        $Result = StringReplace ( $Result, @LF, "|[LF]|" )
        $Result = StringReplace ( $Result, @TAB, "|[TAB]|" )
        _ArrayAdd ( $itArray, $Result )
        IniWrite ( $IniDir, "Array", "itArray", _ArrayToString ( $itArray, $sDelim ) )
    EndIf
EndFunc

Func WM_COMMAND ( $hWnd, $iMsg, $iwParam, $ilParam )
    ConsoleWrite ( "iwParam = " & $iwParam & @CRLF )
    Switch $iwParam
        Case $idConfig
            _WinAPI_ShowMsg("Configuration")
    EndSwitch
EndFunc

Func WM_CONTEXTMENU ( )
    Local $hMenu

    $hMenu = _GUICtrlMenu_CreatePopup ( )
    $itArray = StringSplit ( IniRead ( $IniDir, "Array", "itArray", "" ), $sDelim, 3 )
    _GUICtrlMenu_InsertMenuItem ( $hMenu, 0, "Configuration", $idConfig )
    _GUICtrlMenu_InsertMenuItem ( $hMenu, 0, "", 0 )
    If $itArray[0] <> 0 Then
        $i = 0
        Do
            $i += 1
            $MenuResult = StringReplace ( $itArray[$i], "|[CRLF]|", " " )
            $MenuResult = StringReplace ( $MenuResult, "|[CR]|", " " )
            $MenuResult = StringReplace ( $MenuResult, "|[LF]|", " " )
            $MenuResult = StringReplace ( $MenuResult, "|[TAB]|", "" )
            If StringLen ( $MenuResult ) > $MenuLen Then $MenuResult = StringLeft ( $MenuResult, $MenuLen ) & "..."
            $itemArray[0] = $itemArray[0] + 1
            _ArrayAdd ( $itemArray, $MenuResult )
            _GUICtrlMenu_InsertMenuItem ( $hMenu, 0, $MenuResult, $MenuResult )
        Until $i == $itArray[0]
    EndIf
    _GUICtrlMenu_TrackPopupMenu ( $hMenu, WinGetHandle ( $Title ) )
    _GUICtrlMenu_DestroyMenu ( $hMenu )
    Return True
EndFunc
Edited by Rawox
Posted

When that function is called by an event, the usage of those parameters is defined by the message type:

$hWnd is typically the handle of the window that generated/received the message

$iMsg is typically and integer that identifies the message type (see Windows Messages chart in AutoIt help file appendix)

$wParam and $lParam usage varies greatly depending on the message type.

You would usually look up the particular message on MSDN to see how the parameters are used. For example: WM_CONTEXTMENU

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

[see first post]

Well, thanks for your answer PsaltyDS,

As you've seen I've posted quite a lot these days but I can't get my script to work...

Can you, or someone please give me an good and not hard to understand solution??

With this I mean a fix so my script works and not some example, or 'you should try this function'.

I just want this part of the script to work so I can develop it further. I understand you guys on the forums usually don't make scripts for other people, but please... :idea:

Thanks in advance,

Rawox

Posted

Don't get frustrated, you're almost there! :)

You've posted a nice demo script to work with, so the stuff about not writing your script for you isn't an issue.

I don't recall what's in your Config.ini; please post a sample that will work with this.

:idea:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted (edited)

It automatically generates the .ini in @ScriptDir if everything goes alright...

But I just can't get any notification from the contextmenu, that's the problem right now. I just need a unique number, id, class or whatever to be returned if I press an menu-item.

Edited by Rawox
Posted (edited)

OK, that just confused the heck out of me, so I dropped the AdlibRegister(), INI file, and Clipboard stuff completely to focus on the real issue.

You need to assign a Command ID to each menu item, and that will show up as $iwParam when WM_COMMAND happens. Then you can use that Command ID to determine what to do about it:

#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)
HotKeySet("^!v", "_showMenu")
HotKeySet("^!x", "_Quit")
_Singleton(@ScriptName)

Global $Title = "RightClip"
Global $Version = "0.3"
Global $Author = "Rawox"
Global $IniDir = @ScriptDir & "\Config.ini"
Global $hGUI, $idConfig, $ClipHist = "", $sDelim = "[||]", $Result, $i, $MenuLen = 30, $MenuResult, $Test
Global $itArray[1], $itemArray[1], $menuArray
$itArray[0] = 0
$itemArray[0] = 0

$hGUI = GUICreate($Title, 400, 300)
ConsoleWrite("$hGUI = " & $hGUI & @LF)
GUISetState(@SW_HIDE)

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

Do
    Sleep(10)
Until 1 = 2

Func _showMenu()
    WM_CONTEXTMENU($hGUI, 0x007b, 0, 0)
EndFunc   ;==>_showMenu

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
            _WinAPI_ShowMsg("Configuration")
        Case Else
            If $iwParam < UBound($itArray) Then
                _WinAPI_ShowMsg($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

    $hMenu = _GUICtrlMenu_CreatePopup()

    $itArray = StringSplit("Item One|Item Two|Item Three|Item Four", "|")
    If $itArray[0] <> 0 Then
        For $n = 1 To $itArray[0]
            _GUICtrlMenu_AddMenuItem($hMenu, $itArray[$n], $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 _Quit()
    MsgBox(64, "Exit", "Quitting...", 3)
    Exit
EndFunc   ;==>_Quit

Each time you hit "Item One" on the popup menu in this example it sends WM_COMMAND with the correct $iwParam for that item, and then sends an extra one with $iwParam = 0. The other items don't do that, and I haven't a clue why "Item One" does, hence the "NOOP" in the handler.

:idea:

PS: If you want to fire the menu for something other than the hot key, just call:

WM_CONTEXTMENU($hGUI, 0x7b, 0, 0)
Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
×
×
  • Create New...