MichaelB Posted July 27, 2007 Share Posted July 27, 2007 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 Link to comment Share on other sites More sharing options...
smashly Posted July 27, 2007 Share Posted July 27, 2007 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 Link to comment Share on other sites More sharing options...
cmichaelb Posted August 5, 2007 Share Posted August 5, 2007 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 Link to comment Share on other sites More sharing options...
Generator Posted August 5, 2007 Share Posted August 5, 2007 Some good example in my launcher, feel free to use it. 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