Jump to content
Sign in to follow this  
statik

Button default & timeout

Recommended Posts

statik

is there a way to set a form button to be default and to have a timeout like if it was just a msg box button? thnx

this is one of my buttons:

$Button1 = GUICtrlCreateButton("NIPR", 140, 424, 80, 40, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP))

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

Share this post


Link to post
Share on other sites
enaiman

Not so difficult - just delete and re-create the button after the timeout expires.

See a small example:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 327, 221, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("Button1", 16, 128, 291, 73, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "Button1Click")
$Label1 = GUICtrlCreateLabel("Default Button", 56, 32, 220, 17, $SS_CENTER)
GUISetState(@SW_SHOW)

$i = 0

While 1
    Sleep(200)
    If $i < 20 Then $i += 1
    If $i = 20 Then
        $i += 1
        GUICtrlDelete($Button1)
        $Button1 = GUICtrlCreateButton("Button1", 16, 128, 291, 73)
        GUICtrlSetData($Label1, "Not Default anymore")
    EndIf
WEnd

Func Button1Click()
    
EndFunc
Func Form1Close()
    Exit
EndFunc
Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
statik

Ok thanks. I have the default button with the timeout set. But now I need it so that when the default (which is NIPR) button is timed out and when a user clicks the default button, the script/program exits.

This is what I have so far:

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\admin\Desktop\SCRIPTING\Form1.kxf

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 501, 501, 192, 124)

GUISetBkColor(0xFFFFFF)

$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\admin\Desktop\SCRIPTING\1SOCS Emblem.GIF", 56, 16, 385, 350, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

$Label1 = GUICtrlCreateLabel("Is this workstation for NIPR or SIPR?", 104, 384, 302, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

$Button1 = GUICtrlCreateButton("NIPR", 140, 424, 80, 40, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP,$WS_BORDER))

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

GUICtrlSetOnEvent(-1, "Button1Click")

$Button2 = GUICtrlCreateButton("SIPR", 288, 424, 80, 40, BitOR($WS_GROUP,$WS_BORDER))

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

$i = 0

While 1

Sleep(3000)

If $i < 20 Then $i += 1

If $i = 20 Then

$i += 1

GUICtrlDelete($Button1)

$Button1 = GUICtrlCreateButton("NIPR", 140, 424, 80, 40, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP,$WS_BORDER))

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

EndIf

WEnd

Func Button1Click()

EndFunc

Func Form1Close()

Exit

EndFunc

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Edited by statik

Share this post


Link to post
Share on other sites
GEOSoft

You will be at this for weeks. You are attempting to use a Message loop with Opt("GUIEventMode") set to 1. With that setting the messages will be ignored.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
statik

hmm... if its that much of a pain, I will just remove the default with timer.

Share this post


Link to post
Share on other sites
GEOSoft

hmm... if its that much of a pain, I will just remove the default with timer.

Or dump that age old OnEvent mode and fun everything from a message loop. You can't use both.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
statik

Ok, well this is what I have now. can someone help me with the message loop?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\admin\Desktop\SCRIPTING\Form1.kxf
$Form1 = GUICreate("Form1", 501, 501, 192, 124)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\admin\Desktop\SCRIPTING\1SOCS Emblem.GIF", 56, 16, 385, 350, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("Is this workstation for NIPR or SIPR?", 104, 384, 302, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("NIPR", 140, 424, 80, 40, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP,$WS_BORDER))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("SIPR", 288, 424, 80, 40, BitOR($WS_GROUP,$WS_BORDER))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

EndSwitch
WEnd

Share this post


Link to post
Share on other sites
enaiman

Or dump that age old OnEvent mode

:idea:


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
statik

This is what I have now. What do I add to make the $Button1 default, and to have a timer of 30 seconds and when the time runs out it will automatically select $Button1??

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\admin\Desktop\SCRIPTING\Form1.kxf
$Form1 = GUICreate("Form1", 501, 501, 192, 124)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\admin\Desktop\SCRIPTING\1SOCS Emblem.GIF", 56, 16, 385, 350, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("Is this workstation for NIPR or SIPR?", 104, 384, 302, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("NIPR", 140, 424, 80, 40, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP,$WS_BORDER))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("SIPR", 288, 424, 80, 40, BitOR($WS_GROUP,$WS_BORDER))
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $Button1
    exit
Case $nMsg = $Button2
Endselect
Wend

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  

×