Jump to content
Sign in to follow this  
OliverA

Create a Func for this?

Recommended Posts

OliverA

Hi, i have this script

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
 
Global $GUI = GUICreate("MyGUI", 200, 200, -1, -1, BitOR($WS_POPUPWINDOW, $WS_SYSMENU, $WS_MINIMIZEBOX))
GUISetBkColor(0x00000)
$dTitleBarColor = 0x00000
$hTitleBar = GUICtrlCreateLabel("My Test", 0, 4, 140, 25, $SS_NOTIFY, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 11, 500, "Arial")
GUICtrlSetColor($hTitleBar, 0xFFFFFF)
GUICtrlSetBkColor($hTitleBar, $dTitleBarColor)
 
Local $hClose = GUICtrlCreateLabel(" X", 170, 4, 22, 21)
GUICtrlSetFont(-1, 12, 600, -1)
GUICtrlSetColor($hClose, 0xFFFFFF)
GUICtrlSetBkColor($hClose, $dTitleBarColor)
GUICtrlSetTip($hClose, "Close")
GUICtrlSetBkColor(-1, $dTitleBarColor)
 
Local $hMinimize = GUICtrlCreateLabel("__", 140, 4, 21, 21)
GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS")
GUICtrlSetColor($hMinimize, 0xFFFFFF)
GUICtrlSetBkColor($hMinimize, $dTitleBarColor)
GUICtrlSetTip($hMinimize, "Minimize")
GUISetState(@SW_SHOW)
 
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE, $hClose
   Exit
  Case $hMinimize
   GUISetState(@SW_MINIMIZE, $GUI)
 EndSwitch
WEnd

I have multiple GUI and i don't want to write everytime all this line. It's possible to create a func like _TitleBar($Title, $Color etc.?

The main problem is the return value for the Case $GUI_EVENT_CLOSE, $hClose and Case $hMinimize, how to do that?

Thanks


I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Share this post


Link to post
Share on other sites
FireFox

The main problem is the return value for the Case $GUI_EVENT_CLOSE, $hClose and Case $hMinimize, how to do that?

An example of events with multiple GUIs :

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
JohnOne

Something like this is one way.

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

Global $hClose, $GUI, $hMinimize

func _GUI() 
$GUI = GUICreate("MyGUI", 200, 200, -1, -1, BitOR($WS_POPUPWINDOW, $WS_SYSMENU, $WS_MINIMIZEBOX))
GUISetBkColor(0x00000)
$dTitleBarColor = 0x00000
$hTitleBar = GUICtrlCreateLabel("My Test", 0, 4, 140, 25, $SS_NOTIFY, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 11, 500, "Arial")
GUICtrlSetColor($hTitleBar, 0xFFFFFF)
GUICtrlSetBkColor($hTitleBar, $dTitleBarColor)

$hClose = GUICtrlCreateLabel(" X", 170, 4, 22, 21)
GUICtrlSetFont(-1, 12, 600, -1)
GUICtrlSetColor($hClose, 0xFFFFFF)
GUICtrlSetBkColor($hClose, $dTitleBarColor)
GUICtrlSetTip($hClose, "Close")
GUICtrlSetBkColor(-1, $dTitleBarColor)

$hMinimize = GUICtrlCreateLabel("__", 140, 4, 21, 21)
GUICtrlSetFont(-1, 8, 600, 4, "Comic Sans MS")
GUICtrlSetColor($hMinimize, 0xFFFFFF)
GUICtrlSetBkColor($hMinimize, $dTitleBarColor)
GUICtrlSetTip($hMinimize, "Minimize")
GUISetState(@SW_SHOW)
Endfunc

While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE, $hClose
   Exit
  Case $hMinimize
   GUISetState(@SW_MINIMIZE, $GUI)
 EndSwitch
WEnd

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
PhoenixXL

try with GUICtrlSetDefBkColor and GUICtrlSetDefColor

Edit u are using the font name in its attribute parameter

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
guinness

They want something like this I think...

#include <Constants.au3>

Local Enum $eGUI, $eInput ; Use Enum to access the array values instead of 0, 1 etc... more readable.
Local $aGUI1 = CreateGUI('myFirstGUI', Default, Default, Default, Default)
Local $aGUI2 = CreateGUI('mySecondGUI', Default, Default, Default, Default)

MsgBox($MB_SYSTEMMODAL, '', $aGUI1[$eGUI]) ; GUI handle from the first GUI
MsgBox($MB_SYSTEMMODAL, '', $aGUI2[$eInput]) ; Input from the second GUI

; Return an array with the controls and GUI.
Func CreateGUI($sTitle, $iLeft, $iTop, $iWidth, $iHeight)
    Local $aGUIControls[2] ; Depends on the number of controls.
    $aGUIControls[0] = GUICreate($sTitle, $iLeft, $iTop, $iWidth, $iHeight)
    $aGUIControls[1] = GUICtrlCreateInput('SomeInput', 50, 50)
    ; Continue with controls
    Return $aGUIControls
EndFunc   ;==>CreateGUI

Enum from the beta version of AutoIt:

#include <Constants.au3>

Example()

Func Example()
    ; Create variables in Local scope and enumerate through the variables. Default is to start from 0.
    Local Enum $eCat, $eDog, $eMouse, $eHamster ; $eHamster is equal to the value 3, not 4.

    ; Create an array in Local scope with 4 elements.
    Local $aAnimalNames[4]

    ; Assign each array element with the name of the respective animal. For example the name of the cat is Jasper.
    $aAnimalNames[$eCat] = 'Jasper' ; $eCat is equal to 0, similar to using $aAnimalNames[0]
    $aAnimalNames[$eDog] = 'Beethoven' ; $eDog is equal to 1, similar to using $aAnimalNames[1]
    $aAnimalNames[$eMouse] = 'Pinky' ; $eMouse is equal to 2, similar to using $aAnimalNames[2]
    $aAnimalNames[$eHamster] = 'Fidget' ; $eHamster is equal to 3, similar to using $aAnimalNames[3]

    ; Display the values of the array.
    MsgBox($MB_SYSTEMMODAL, '', '$aAnimalNames[$eCat] = ' & $aAnimalNames[$eCat] & @CRLF & _
            '$aAnimalNames[$eDog] = ' & $aAnimalNames[$eDog] & @CRLF & _
            '$aAnimalNames[$eMouse] = ' & $aAnimalNames[$eMouse] & @CRLF & _
            '$aAnimalNames[$eHamster] = ' & $aAnimalNames[$eHamster] & @CRLF)

    ; Sometimes using this approach for accessing an element is more practical than using a numerical value, due to the fact changing the index value of
    ; the enum constant has no affect on it's position in the array. Therefore changing the location of $eCat in the array is as simple as changing the order
    ; it appears in the initial declaration e.g.

    ; Local Enum $eDog, $eMouse, $eCat, $eHamster

    ; Now $eCat is the 2nd element in the array. If you were using numerical values, you would have to manually change all references of $aAnimalNames[0] to
    ; $aAnimalNames[2], as well as for the other elements which have now shifted.
EndFunc   ;==>Example
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
PhoenixXL

I you have multiple GUI use GUIGetMsg(1), [check the help file]

I code shortening is your main aim try something like this

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

Global $GUI = GUICreate("MyGUI", 200, 200, -1, -1, BitOR($WS_POPUPWINDOW, $WS_SYSMENU, $WS_MINIMIZEBOX))

GUISetBkColor(0x00000)
GUICtrlSetDefBkColor(0x00000)
GUICtrlSetDefColor(0xFFFFFF)

$hTitleBar = GUICtrlCreateLabel("My Test", 0, 4, 140, 25, $SS_NOTIFY, $GUI_WS_EX_PARENTDRAG)
SetOptions()

Local $hClose = GUICtrlCreateLabel(" X", 170, 4, 22, 21)
SetOptions("Close", 12, 600)

Local $hMinimize = GUICtrlCreateLabel("__", 140, 4, 21, 21)
SetOptions("Minimize", 8, 600, "Comic Sans MS" )

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $hClose
Exit
Case $hMinimize
GUISetState(@SW_MINIMIZE, $GUI)
EndSwitch
WEnd

Func SetOptions($tip = '', $size = 11, $weight = 500, $fontname = 'Arial')
GUICtrlSetFont(-1, $size, $weight, 0, $fontname)
If $tip <> '' Then GUICtrlSetTip(-1, $tip)
EndFunc ;==>SetOptions

i don't want to write everytime all this line

That is why we use functions ;) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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  

×