Jump to content
Sign in to follow this  
VAN0

Run shortcut Maximized/Minimized

Recommended Posts

VAN0

Why doesn't the following work?

1. Compile a GUI program to exe

2. Create a shortcut to the compiled GUI program

3. Right-click shortcut and do (Run: Minimized)

4. Run the shortcut and the program should run initially minimized

Here is an example GUI program (using AutoIt3 beta v3.1.1.124):

 

 

#include <GUIConstants.au3>
$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Button1 = GUICtrlCreateButton("AButton1", 152, 80, 209, 41)
GUISetState(@SW_SHOW)
While 1
$msg = GuiGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   ExitLoop
  Case Else
   ;;;;;;;
EndSelect
WEnd
Is this possible in AutoIt?

Livewire

 

Just add a GUISetState(@SW_MINIMIZE) after the GUISetState(@SW_SHOW)

You need to show first unless the minmize will be rejected.

 

How do I make the code recognize that the "user" selected Run minimize from Windows (Right-click: Run Minimized)?

 

Any ideas?

 

Thank you.

Edited by VAN0

Share this post


Link to post
Share on other sites
BrewManNH

You could use a combination of ProcessExists to see if the program is running, and then use WinGetState to see if it's minimized.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
VAN0

You could use a combination of ProcessExists to see if the program is running, and then use WinGetState to see if it's minimized.

I think you misunderstood the question. I'm trying start the compiled script itself minimized if it was started via shortcut with "run minimized" option selected:

post-58062-0-97332200-1394212175_thumb.p

Share this post


Link to post
Share on other sites
BrewManNH

I understood what you posted, maybe you should have asked what you wanted to do. Your post quoted someone asking how to detect that it was started minimized, that's the answer I gave you.

The question you asked in your second post was answered in your first post, use GUISetState(@SW_MINIMIZED).


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
VAN0

GUISetState(@SW_MINIMIZE) will minimize the window regardless of how it was started with or without "run minimized" option

Share this post


Link to post
Share on other sites
VAN0

create your exe with command line switch support. You can then specify the shortcut to run the EXE the way you want.

Yes, that's a one way to go. Or store settings in registry or .ini file. But all this is a work arou

So there is no way within AU3 catch with what options the script was started?

Share this post


Link to post
Share on other sites
BrewManNH

So, what exactly is it that you need? Do you need to detect that it was started minimized, do you need to start it minimized, do you need to create a shortcut that starts it minimized? I have no clue what it is you're looking for because you've given 3 different answers so far.

if you need to detect if it was started minimized, use my answer, if you need to start it minimized use the answer in your first post and my second reply, if you need to create a shortcut to start it minimized use FileCreateShortCut, if you need to find out if the shortcut is set to start it minimized use FileGetShortCut. If none of these solutions fit what you think you're asking, then obviously you need to be a LOT clearer in asking the right question.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
VAN0

The original post has perfectly explained the question.

So, let me chew it to a fine paste for you from the very beginning:

  • having a simple script with GUI compiled into example.exe:

    #include <GUIConstants.au3>
        $Form1 = GUICreate("AForm1", 622, 441, 192, 125)
        $Button1 = GUICtrlCreateButton("AButton1", 152, 80, 209, 41)
        GUISetState(@SW_SHOW)
        While 1
        $msg = GuiGetMsg()
        Select
          Case $msg = $GUI_EVENT_CLOSE
           ExitLoop
          Case Else
           ;;;;;;;
        EndSelect
        WEnd
  • When example.exe executed directly, a window showed on screen = GOOD, just as expected.
  • Right click on example.exe and select "Create shortcut". You should see a new file created "example.exe - Shortcut", if you don't see that file you might need do folder refresh
  • Right click on the new file example.exe - Shortcut and go to properties
  • On top of the properties window are several tabs, click on the one with name "Shortcut" in it
  • Find a row with "Run:" and a dropdown menu next to it, select "Minimized" in the dropdown menu
  • Click "Ok" button
  • Double click on example.exe - Shortcut file, a normal, not minimized, window showed on screen = NOT GOOD, because from user's point of view it was expected to be started minimized
What do I need to add to the code to make window show on screen (start normal) when example.exe executed directly and start minimized when it's started via shortcut with "run minimized" option?

So if you still believe that both of your "solutions" are valid solutions for this question, would you mind, please, make a working example?

 

Thank you.

Edited by VAN0

Share this post


Link to post
Share on other sites
Melba23

VAN0,

Interesting - that shortcut selection does not appear to work for AutoIt exes (and Google tells me that they are not alone in this). :wacko:

There might be a way to detect from the registry that this setting has been made, but why go to all that trouble? MBALZESHARI had the right idea - the problem can be solved easily by using the commandline like this: ;)

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("AForm1", 622, 441, 192, 125)
$Button1 = GUICtrlCreateButton("AButton1", 152, 80, 209, 41)

; Check if there was a command line parameter passed to the exe
If $CMDLINE[0] And $CMDLINE[1] = "-min" Then
    GUISetState(@SW_SHOWMINIMIZED)
Else
    GUISetState(@SW_SHOW)
EndIf

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
Now adding -min after the calling path in the shortcut properties will start the app minimized. :)

And you can test it in SciTE by using the Shft-F8 shortcut or the <View - Parameters> menu item. ;)

M23

P.S.

 

The original post has perfectly explained the question

Evidently it did not - as shown by the responses. Remember that the message is what is understood by the recipient, not the sender. And we are all volunteers here, so getting ratty is just likely to drive people away. ;)

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
johnmcloud
Me = 1 vs MVPs/Mod = 0, this time and maybe only this time i have the ANSWER  :thumbsup:
Yeah is not a competition but it is a satisfaction
;~ ;johnmcloud - 2014
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

;~ Global Const $tagSTARTUPINFO = "int Size;ptr Reserved1;ptr Desktop;ptr Title;int X;int Y;int XSize;int YSize;int XCountChars;" & _
;~      "int YCountChars;int FillAttribute;int Flags;short ShowWindow;short Reserved2;ptr Reserved3;int StdInput;" & _
;~      "int StdOutput;int StdError"
Global $sState = @SW_SHOW
Global $sShortcut = _RunFromShortcut()

If IsArray($sShortcut) Then
    If $sShortcut[6] = 3 Then $sState = @SW_SHOWMAXIMIZED
    If $sShortcut[6] = 7 Then $sState = @SW_SHOWMINIMIZED
EndIf

$hGUI = GUICreate("Johnmcloud knows best", 265, 250, -1, -1, $WS_MAXIMIZEBOX)
_WinAPI_ShowWindow($hGUI, $sState) ;@SW_SHOWMAXIMIZED with GUISetState not work

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _RunFromShortcut()
    Local $tSI = DllStructCreate($tagSTARTUPINFO)
    DllCall('kernel32.dll', 'none', 'GetStartupInfoW', 'struct*', $tSI)
    If @error Then Return SetError(@error, @extended, 0)
    Local $vFlag = DllStructGetData($tSI, 'Flags')
    If BitAND($vFlag, 0x800) Then
        Local $sTitle = DllStructCreate('wchar ShortcutPath[261]', DllStructGetData($tSI, 'Title'))
        Local $sShortcutPath = DllStructGetData($sTitle, 'ShortcutPath')
        If $sShortcutPath Then
            Return FileGetShortcut($sShortcutPath)
        Else
            Return SetError(1, 0, 0)
        EndIf
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc   ;==>_Shortcut
Edited by johnmcloud
  • Like 1

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

Well done! :thumbsup:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
johnmcloud

Thanks Melba ;)

Since I'm here, do you know why this work:

_WinAPI_ShowWindow($hGUI, @SW_SHOWMAXIMIZED)

But this not?

GUISetState(@SW_SHOWMAXIMIZED, $hGUI)

With GuiSetState i don't see nothing...

The help say:

"When windows are created they are initially hidden so you must use this function to display them (@SW_SHOW)"

But @SW_SHOWMAXIMIZED isn't like @SW_SHOW + @SW_MAXIMIZED both in the same @MACRO?

The curious thing is this work:

GUISetState(@SW_SHOWMINIMIZED, $hGUI)

Minimize yes, maximize not  :huh:

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

I have come across this problem with GUISetState before. KaFu pointed out that the occasional failures of my GUIFrames UDF were caused by using GUISetState instead of _WinAPI_ShowWindow (or WinSetState). But I once had an exchange with trancexx when she was still a Dev and she was most insistent that AutoIt GUIs should use GUISetState - although as often the case she was not very forthcoming about exactly why so I cannot pass on any insight. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
johnmcloud

I think tomorrow i'll open a new thread about this matter in dev section, just for understand why internal function work with minimize but not with maximize. Thanks

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×