Jump to content

Recommended Posts

Posted

I have finally progressed past little AUTOIT scripts that do just what the name implies. My latest endeavor is a desktop app launcher,strictly as a learning experience. My problem rears its ugly head when I attempt to write a right-click routine to open a

FILE SELECT GUI. Up to here, I have a nice little interface with a bunch of buttons and obviously the ability to close the app.

I want to right click on a button and have a FILE SELECT box come up. I need to return the selected executable (along with an icon ) to the button that I right clicked on, and have a link there to start the program. I realize that just about ANYBODY could write what I have so far, but now I'm ready to progress. I have gotten as far as GUICtrlCreateContextMenu and come to a screeching halt. I know this sounds like I want someone to write the code for me, but that is not the case. I just need some pointers as to how to get AUTOIT to do my bidding. Any and all help will be greatly appreciated as I struggle forward making great advances in software. michaelb

Posted

Hi,

Hope this crude example helps

#include <GuiConstants.au3>

Global $PathToFile

$Gui = GUICreate("Context Buttons", 220, 60)
$Icon = GUICtrlCreateIcon("shell32.dll",1 ,16,16,16,16)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button = GUICtrlCreateButton("Right Click To Set..", 10, 10, 200, 30, $WS_CLIPSIBLINGS)
$Context = GUICtrlCreateContextMenu($Button)
$ContextMenu = GUICtrlCreateMenuitem("Browse for file", $Context)
GuiSetState(@SW_SHOW, $Gui)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $ContextMenu
            $FileOpen = FileOpenDialog("Browse...", @ProgramFilesDir, "Executable (*.exe)",3)
            If @error <> 1 Then
                $PathToFile = $FileOpen
                $Sp = StringSplit($FileOpen, "\")
                GUICtrlSetImage($Icon, $FileOpen, 0, 0)
                GuiCtrlSetData($Button, StringTrimRight($Sp[$Sp[0]], 4))
                
            EndIf
        Case $msg = $Button
            If FileExists($PathToFile) Then
                ShellExecute($PathToFile)
            Else
                MsgBox(0,"Assign file to button..", "You need to assign a file to the button first", 3)
            EndIf   
    EndSelect
WEnd

Cheers

  • 2 weeks later...
Posted

Hi,

Hope this crude example helps

#include <GuiConstants.au3>

Global $PathToFile

$Gui = GUICreate("Context Buttons", 220, 60)
$Icon = GUICtrlCreateIcon("shell32.dll",1 ,16,16,16,16)
GUICtrlSetState(-1, $GUI_DISABLE)
$Button = GUICtrlCreateButton("Right Click To Set..", 10, 10, 200, 30, $WS_CLIPSIBLINGS)
$Context = GUICtrlCreateContextMenu($Button)
$ContextMenu = GUICtrlCreateMenuitem("Browse for file", $Context)
GuiSetState(@SW_SHOW, $Gui)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $ContextMenu
            $FileOpen = FileOpenDialog("Browse...", @ProgramFilesDir, "Executable (*.exe)",3)
            If @error <> 1 Then
                $PathToFile = $FileOpen
                $Sp = StringSplit($FileOpen, "\")
                GUICtrlSetImage($Icon, $FileOpen, 0, 0)
                GuiCtrlSetData($Button, StringTrimRight($Sp[$Sp[0]], 4))
                
            EndIf
        Case $msg = $Button
            If FileExists($PathToFile) Then
                ShellExecute($PathToFile)
            Else
                MsgBox(0,"Assign file to button..", "You need to assign a file to the button first", 3)
            EndIf   
    EndSelect
WEnd

Cheers

To SMASHLY -

I am forever in your debt. Your code is right on the money. I haven't learned as much as I wanted to, but the frustration factor has all but vanished.

Thanks So Much,

MichaelB

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...