Jump to content
Sign in to follow this  
Inpho

Minimize GUI after pressing button

Recommended Posts

Inpho

Hi all, I've progressed some since my last thread (or at least I think I have :P). But now I have another problem.

After some advice stealing >here and >here I got as far as making a GUI which suits my needs, but I'd like it to minimise automatically after I press any button.

You can see at line 34 the last command I tried

ok maybe you cant, no line markers :P

Case $Button1
            $vdata = $clip1
            _ClipBoard_SetData($vdata)
            $nMsg = $GUI_EVENT_MINIMIZE

 

 

Do I have to call a function while inside a loop just for the minimize? And can you see any beginner mistakes in the code, like do I really need to close the dll in something as simple as this? And is the Sleep timer adequate?

I have a feeling there should be an "AutoIt Bible", a definitive Do's and Don'ts of AutoIt xD

HotKeySet("{Ins}", "ShowGUI")
HotKeySet("{esc}", "_Exit")
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Clipboard.au3>

#region Contents ;; which data is contained in the button and assigned into the clipboard
$clip1 = "Label1"
$clip2 = "Label2"
$clip3 = "Label3"
#EndRegion

#region gui ;; creates gui
Global $Show = False
$Form1 = GUICreate("Form1", 322, 146, 238, 287)
$Button1 = GUICtrlCreateButton($clip1, 16, 16, 283, 25)
$Button2 = GUICtrlCreateButton($clip2, 16, 56, 283, 25)
$Button3 = GUICtrlCreateButton($clip3, 16, 96, 283, 25)
#EndRegion

#region loop ;; inputs data into clipboard according to button pressed
Local $hDLL = DllOpen("user32.dll")
sleep ( 1000 )
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $vdata = $clip1
            _ClipBoard_SetData($vdata)
            $nMsg = $GUI_EVENT_MINIMIZE
        Case $Button2
            $vdata = $clip2
            _ClipBoard_SetData($vdata)
        Case $Button3
            $vdata = $clip3
            _ClipBoard_SetData($vdata)
        Case $GUI_EVENT_MINIMIZE
            $Show = Not $Show
            GUISetState($Show, $Form1)
    EndSwitch
WEnd

#region Functions ;; Makes Insert key minimize to tray, while hiding from taskbar, and set Esc to close program
Func ShowGUI()
    $Show = Not $Show
    GUISetState($Show, $Form1)
EndFunc
Func _Exit()
    Exit
endfunc
#EndRegion

Thanks in advance

 

EDIT: Just spotted this is causing me a problem with gui_event_minimise so going toi have to find another way

        Case $GUI_EVENT_MINIMIZE
            $Show = Not $Show
            GUISetState($Show, $Form1)
Edited by Inpho

Share this post


Link to post
Share on other sites
Inpho

Fixed it, yes I feel stupid for posting before I tried more, but works now :P

HotKeySet("{Ins}", "ShowGUI")
HotKeySet("{esc}", "_Exit")
#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Clipboard.au3>

#Region Contents ;; which data is contained in the button and assigned into the clipboard
Global $clip1 = "Clip 1"
Global $clip2 = "Clip 2"
Global $clip3 = "Clip 3"
#EndRegion Contents

#Region gui ;; creates gui
Global $Show = False
Global $Form1 = GUICreate("Clipboard Copier", 322, 146, 238, 287)
Global $Button1 = GUICtrlCreateButton($clip1, 16, 16, 283, 25)
Global $Button2 = GUICtrlCreateButton($clip2, 16, 56, 283, 25)
Global $Button3 = GUICtrlCreateButton($clip3, 16, 96, 283, 25)
#EndRegion gui

#Region loop ;; inputs data into clipboard according to button pressed, minimises to tray after pressing button/minimise and hides from taskbar
Local $hDLL = DllOpen("user32.dll")
Sleep(1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $vdata = $clip1
            _ClipBoard_SetData($vdata)
            $Show = Not $Show
            GUISetState($Show, $Form1)
        Case $Button2
            $vdata = $clip2
            _ClipBoard_SetData($vdata)
            $Show = Not $Show
            GUISetState($Show, $Form1)
        Case $Button3
            $vdata = $clip3
            _ClipBoard_SetData($vdata)
            $Show = Not $Show
            GUISetState($Show, $Form1)
        Case $GUI_EVENT_MINIMIZE
            $Show = Not $Show
            GUISetState($Show, $Form1)
        DllClose($hDLL)
    EndSwitch
WEnd
#EndRegion loop
#Region Functions ;; Makes Insert key minimize to tray, while hiding from taskbar, and set Esc to close program
Func ShowGUI()
    $Show = Not $Show
    GUISetState($Show, $Form1)
EndFunc   ;==>ShowGUI
Func _Exit()
    Exit
EndFunc   ;==>_Exit
#EndRegion Functions

Share this post


Link to post
Share on other sites
MikahS

Glad you figured it out yourself :)

I know you made mention to an "AutoIt Bible", well here is some of the >Best Practices in AutoIt


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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  

×