Leaderboard
Popular Content
Showing content with the highest reputation on 03/06/2019 in all areas
-
Just my luck I only tested with 9 subfolders , you just need to turn the second value into a number, you could also use something like the following (probably could be written better) but works: Local $aFolderPath, $x = 0 Local $aFolderPaths = _FileListToArrayRec(@ScriptDir, "*", 2, 1, 1, 2) _ArrayColInsert($aFolderPaths, 1) For $i = 1 To $aFolderPaths[0][0] $aFolderPath = StringSplit($aFolderPaths[$i][0], "\") If _ArraySearch($aFolderPaths, Number($aFolderPath[0] & "." & $x), 1, 0, 0, 0, 1, 1) > -1 Then $x += 1 $aFolderPaths[$i][1] = Number($aFolderPath[0] & "." & $x) Else $x = 0 While _ArraySearch($aFolderPaths, Number($aFolderPath[0] & "." & $x), 1, 0, 0, 0, 1, 1) > -1 $x += 1 WEnd $aFolderPaths[$i][1] = Number($aFolderPath[0] & "." & $x) EndIf Next _ArraySort($aFolderPaths, 1, 1, 0, 1) _ArrayDisplay($aFolderPaths)3 points
-
A simple regexp can't do that this way. Not only patterns (named or not) only live while the regex engine scans the subject. PCRE (at least PCRE1 which is implemented in current AutoIt versions) has no support for substitution. The Replace part is an AutoIt construct which can only recognize $1, $2, $3, ... (or equivalently \1, \2, \3, ...) as a sugar for successive capturing groups. Due to the way regex works (try to match the pattern by scanning the subject left to right), you can't exchange the role of $1 and $2 depending on their content or order of matching. Yet there is a simple possibility: give up duplicate pattern numbering! Local $aDate = ["2014/04", "2014-04", "04-2014", "04\2014", "04/2014", "2014\04"] Local $DATE_PATTERN = "(\d{4})[-\/\\](\d{2})|(\d{2})[-\/\\](\d{4})" For $d In $aDate ConsoleWrite($d & " --> " & StringRegExpReplace($d, $DATE_PATTERN, "$1$4-$2$3") & @LF) Next Forcing capture of distinct fix-length subpatterns works, since what isn't matched yields an empty string, which we may concatenate transparently.2 points
-
Explain what you mean by it's wrong, what's wrong? What are you expecting to happen if the variables are those values, and what you're seeing happen?2 points
-
Pixelsearch error handling
jchd and one other reacted to FrancescoDiMuro for a topic
@Wllwllwll Enjoy the permaban2 points -
Version 1.7.0.1
10,054 downloads
Extensive library to control and manipulate Microsoft Outlook. This UDF holds the functions to automate items (folders, mails, contacts ...) in the background. Can be seen like an API. There are other UDFs available to automate Outlook: OutlookEX_GUI: This UDF holds the functions to automate the Outlook GUI. OutlookTools: Allows to import/export contacts and events to VCF/ICS files and much more. Threads: Development - General Help & Support - Example Scripts - Wiki BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort KNOWN BUGS (last changed: 2020-02-09) None1 point -
OutlookTools
falcontechnics reacted to water for a file
Version 0.6.0.0
1,294 downloads
Built on top of the OutlookEX UDF it offers some often needed extended functionality (import/export ics/vcf/csv files etc.) (former name: iCal UDF). Note: This is a beta version - script breaking changes may occur at any time! Prerequisite: OutlookEX UDF. Details about all functions can be found in the Wiki. ICS (iCalendar) import - Import iCal events from an ICS file to an Outlook calendar VCF (vCard) import - Import vCard contacts to an Outlook contacts folder CSV import - Import data from a CSV file and create Outlook items in a specified folder Export - Export Outlook items (contacts, appointments) in VCF, ICS, CSV or Excel format Links: https://tools.ietf.org/html/rfc5545 (ICS - iCalendar) https://tools.ietf.org/html/rfc6350 (VCF - vCard) Threads: General Help & Support Known Bugs: (last changed: 2019-01-22) None Things to come: (last changed: 2022-01-25) Support for EML mails (email contents as plain text in MIME format) will be added BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort1 point -
I just noticed that Outlook does not allow to import iCal events programmatically. I might implement some of the iCalendar data format (RFC 5545) if someone is interested Please post here or click the "Like" button if you think this is a good idea Edit: For download please see my signature1 point
-
You might find it useful to keep Unicode letters and digits as well. Prepend (*UCP) at the pattern to make \w match any Unicode letter or digit or _, and \d any Unicode digit. Fictuous example: Local $title = "영국여사 조쉬엄마의 첫 치맥 먹방 도전!?! ◓ ♬♫\ghuo .*. ỸἇἮὤ ∑ [ທຊکڄຮ] (+조쉬 사춘기 썰)" Local $titley = StringRegExpReplace($title, "(*UCP)[^\w\h-\.!\()]", "") MsgBox(0, "", $titley) If ever you need to filter in or out specific languages or types of Unicode codepoint, you may find the \p<something> construct pretty handy. See help under StringRegexp() for basics or the full official PCRE1 doc https://www.pcre.org/original/doc/html/pcrepattern.html1 point
-
Remove symbols/emoticons and other junk from a string with StringRegExpReplace
FrancescoDiMuro reacted to Melba23 for a topic
SirAlonne, Welcome to the AutoIt forums. As always with RegEx questions a sample string with the required result is always a helpful addition to your post. M231 point -
Ahhh, I understand now, thank everyone1 point
-
Hello ThePoro, wellcome to AutoIt Forum. Your problem is about comparing wrong data types. GUICtrlCreateInput elements may includes characters, numbers etc. So "GUICtrlRead" function returns you result as a string even if you put just numbers into it. You have to convert result of "GUICtrlRead" function to integer if you expect compare it as integer. Otherwise if you check "50" is less than "100" you get false as result. Because that means compare 50 and 100 as string and OS handle these strings by their characters. According to ASCII List "50" is bigger than "100"; Converting string to integer; Local $px = Int(GUICtrlRead($input1)) Local $py = Int(GUICtrlRead($input2)) Here is a full example; #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> $gui = GUICreate("gui for testing", 300, 90, -1, -1) $input1 = GUICtrlCreateInput("50", 0, 0, 300, 30) $input2 = GUICtrlCreateInput("150", 0, 30, 300, 30) $button1 = GUICtrlCreateButton("clone", 0, 60, 300, 30) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $button1 clone() EndSwitch WEnd Func clone() Local $px = Int(GUICtrlRead($input1)) Local $py = Int(GUICtrlRead($input2)) Local $temp = @DesktopDir & "\temp.csv" FileDelete($temp) While $px <= $py Local $name = "P"&$px FileWrite($temp, "" & $name & ""& @CRLF) $px+= 1 WEnd $a=FileRead($temp) ClipPut($a) MsgBox($MB_ICONINFORMATION,"","Copied to Clipboard") EndFunc1 point
-
Is it fixed if you add the missing double quote-mark? FileWrite($temp, "" & $name & ""& @CRLF)1 point
-
Values read from a control are strings. Convert to numbers using Int() or Number() to compare to numeric values.1 point
-
Yeah always remember if your search isn't pulling results take a word off, it usually helps a TON.1 point
-
you are missing this portion : Opt("SendCapslockMode", 0)1 point
-
https://www.autoitscript.com/forum/topic/10198-check-for-capslock-and-turn-off-so-lowercase/1 point
-
I needed a program that could count down to xx days. I found lots of count downer's, but common for them all was that I needed to know the end date, but what I needed was one where I could just add the amount of days. So I ended up creating my own count down, that could do just that. Now I would like to share what I ended up with. I did borrow some of the count down code from this nice count down Stylish Countdown GUI by @billthecreator So what can this countdown do? 1. Countdown to a specific day, that can be chosen either by the amount of days to count down to, or by choosing a date. 2. Edit an existing event. 3. Delete an existing event. 4. On mouse over the Event, the event description is shown as a tip. 5. Play a sound when time is up (if enabled for the event). 6. Show a popup when time is up (if enabled for the event), the popup text is the event description. 7. Save an event as default, so it can be reused. 8. Can be pinned in place, so the gui is unmovable. 9. Can remember the last GUI position (If chosen in the settings) 10. Uses colors on days / time, Black, Green, Yellow and Red. When Less than 5 days to event, the days will turn Red, 6 to 10 days Yellow, 11+ Green The time will change to Green when 0 days and 23 to 13 hours left, Yellow when 12 to 7 hours and Red from 5 to 0, else it's Black When the time is up, the Event name label background will change to Yellow and the text to Red When adding/Editing/Deleting an event the GUI is updated, not by restarting the program, but by deleting and recreating the events. When an event time is up, the event is set as disabled - but will still exist in the event ini file, but it won't be loaded into the GUI when the countdown'er is started. The event can be edited, and restarted or deleted permanently. Some screenshots: #include <Date.au3> #include <ColorConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <String.au3> #include <GuiComboBox.au3> #include <MsgBoxConstants.au3> #include <WinAPIDlg.au3> #include <Sound.au3> #include <GuiListBox.au3> #include <WinAPISysWin.au3> Opt("GUIOnEventMode", 1) Opt('MustDeclareVars', 1) Opt('GUIResizeMode', $GUI_DOCKALL) ; To prevent ctrls to move when we add a new event OnAutoItExitRegister('MenuItem_ExitClick') ; To save pos at closedown, if savepos is enabled Global $g_iSecs, $g_iMins, $g_iHours, $g_iDays ; Get settings Global $g_sSetFile = @ScriptDir & '\Settings.ini' Global $g_sEventFile = @ScriptDir & '\Events.ini' Global $g_iMaxEvents = IniRead($g_sSetFile, 'Settings', 'MaxEvents', 6) ; Max Number of events Global $g_bPin = StringToType(IniRead($g_sSetFile, 'Settings', 'Pin', False)) ; Pin in place, GUI Can't be moved Global $g_bRemember = StringToType(IniRead($g_sSetFile, 'Settings', 'Remember', False)) ; Remember last position and start at that pos Global $g_iGuiLeft = IniRead($g_sSetFile, 'settings', 'posx', -1) ; Gui Left pos (x) Global $g_iGuiRight = IniRead($g_sSetFile, 'settings', 'posy', -1) ; Gui right pos (y) Global $g_sSoundFile = IniRead($g_sSetFile, 'Settings', 'SoundFile', @WindowsDir & '\media\tada.wav') Global $g_bSoundPlay = StringToType(IniRead($g_sSetFile, 'Settings', 'SoundPlay', True)) Global $g_bPopup = StringToType(IniRead($g_sSetFile, 'Settings', 'popup', True)) ; Do a popup window with event description Global $g_bStartWithWin = StringToType(IniRead($g_sSetFile, 'Settings', 'StartWithWin', True)) ; If the prog should start with windows ; Check if the gui should start at last saved position If $g_bRemember = False Then $g_iGuiRight = -1 ; Default Screen center $g_iGuiLeft = -1 ; Default Screen center EndIf ; Creates an array to hold the end dates of the event(s), it's State (Enabled) and the SectionName of the event. ; this array we uses to calc the countdown, and to prevent the need to keep reopen the event ini file, to get the ; enddate of a given event. Global $g_aEventData[1][3] = [['EndDate', 'Enabled', 'SectionName']] ; Get events Global $g_aEvents = IniReadSectionNames($g_sEventFile) ; Check if we have any Events If Not IsArray($g_aEvents) Then ; If we don't have any events, we creates the array with 1 and Null, 1 to be used to create an empty gui ; Null so we know that there isn't any events Global $g_aEvents[2] = [1, Null] EndIf ; call the EventOnLoad function EventOnLoad() Global $g_idLbl_Days[$g_iMaxEvents + 1], _ $g_idLbl_Hrs[$g_iMaxEvents + 1], _ $g_idLbl_Min[$g_iMaxEvents + 1], _ $g_idLbl_Sec[$g_iMaxEvents + 1], _ $g_idLbl_Event[$g_iMaxEvents + 1] Global $g_iSpace = 80 Global $g_iGuiHeight = ($g_iSpace * $g_aEvents[0]) + 8 #Region ### START Koda GUI section ### Form=D:\Profil\Rex\ISN AutoIt Studio\Projects\Countdown Days\GUI\hCountdownDays.kxf Global $hCountdownDays = GUICreate("CountDown Days", 136, $g_iGuiHeight, $g_iGuiLeft, $g_iGuiRight, $WS_POPUP, $WS_EX_TOOLWINDOW) ; Gui menu Global $hCountdownDayscontext = GUICtrlCreateContextMenu() Global $MenuItem_EventHandling = GUICtrlCreateMenu("Event(s)", $hCountdownDayscontext) Global $MenuItem_AddEvent = GUICtrlCreateMenuItem("Add", $MenuItem_EventHandling) GUICtrlSetOnEvent(-1, "MenuItem_AddEventClick") Global $MenuItem_EditEvent = GUICtrlCreateMenuItem("Edit", $MenuItem_EventHandling) GUICtrlSetOnEvent(-1, "MenuItem_EditEventClick") Global $MenuItem_DeleteEvent = GUICtrlCreateMenuItem("Delete", $MenuItem_EventHandling) GUICtrlSetOnEvent(-1, "MenuItem_DeleteEventClick") Global $MenuItem_Settings = GUICtrlCreateMenuItem("Settings", $hCountdownDayscontext) GUICtrlSetOnEvent(-1, "MenuItem_SettingsClick") Global $MenuItem_Pin = GUICtrlCreateMenuItem("Pin in Place", $hCountdownDayscontext) GUICtrlSetOnEvent(-1, "MenuItem_PinClick") Global $MenuItem_Exit = GUICtrlCreateMenuItem("Exit", $hCountdownDayscontext) GUICtrlSetOnEvent(-1, "MenuItem_ExitClick") GUISetBkColor(0x4E4E4E) Global $idLbl_Move = GUICtrlCreateLabel("", 1, 1, 134, 12, $SS_CENTER, $GUI_WS_EX_PARENTDRAG) GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0x808080) ; Create a label to frame the gui, so it don't look to flat Global $idFrame = GUICtrlCreateLabel('', 0, 0, 136, $g_iGuiHeight, BitOR($SS_SUNKEN, $WS_DISABLED, $SS_SIMPLE)) If $g_aEvents[1] = Null Then UpdateGui(False) ; Update Countdown GUI Else UpdateGui(True) ; Update Countdown GUI EndIf ; check if we needs to tick the pin, and disable the Move label If $g_bPin = True Then GUICtrlSetState($MenuItem_Pin, $GUI_CHECKED) GUICtrlSetState($idLbl_Move, $GUI_DISABLE) EndIf ; Check if we should disable the add event MenuItem If $g_aEvents[0] >= $g_iMaxEvents Then GUICtrlSetState($MenuItem_AddEvent, $GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form=D:\Profil\Rex\ISN AutoIt Studio\Projects\Countdown Days\GUI\hAddEvent.kxf Global $hAddEvent = GUICreate("Add Event", 206, 407, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_CAPTION)) GUISetOnEvent($GUI_EVENT_CLOSE, "hWnd_Close") Global $idAddEvent = GUICtrlCreateDummy() ; Create a dumme, we use this to calculate the CtrlID of the Controls created after the dummy GUICtrlCreateLabel("Default Events:", 8, 8, 77, 17) ; This would be dummy + 1 in ID GUICtrlCreateCombo("", 8, 24, 185, 25, $CBS_DROPDOWNLIST) GUICtrlSetTip(-1, "Saved default events") GUICtrlSetOnEvent(-1, "idCombo_EventsChange") GUICtrlCreateLabel("Event Name:", 8, 56, 66, 17) GUICtrlCreateInput("", 8, 72, 185, 21) GUICtrlSetLimit(-1, 24) GUICtrlSetTip(-1, "Name of event." & @CRLF & "This is the text that will be shown at the gui." & @CRLF _ & "Max length is 24 chars") GUICtrlCreateLabel("Event description:", 8, 104, 89, 17) GUICtrlCreateEdit("", 8, 120, 185, 89, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetTip(-1, "Event description." & @CRLF _ & "This wil be shown as a tip upon hovering, and also in the popup (if popup is enabled)") GUICtrlCreateCheckbox("Choose Event date by calendar", 8, 216, 170, 17) GUICtrlSetOnEvent(-1, "idCb_ChoseDateClick") GUICtrlCreateLabel("Days to event:", 8, 240, 73, 17) GUICtrlCreateInput("", 8, 256, 73, 21, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetLimit(-1, 3) GUICtrlSetTip(-1, "Days to the event") GUICtrlCreateLabel("Time of event", 112, 240, 69, 17) GUICtrlCreateDate('', 112, 256, 82, 21, BitOR($DTS_UPDOWN, $DTS_TIMEFORMAT)) GUICtrlSendMsg(-1, $DTM_SETFORMATW, 0, 'HH:mm:ss') ; Set time style GUICtrlCreateLabel("Event date:", 8, 240, 59, 17) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlCreateDate('', 8, 256, 186, 21, 0) GUICtrlSendMsg(-1, $DTM_SETFORMATW, 0, 'yyyy/MM/dd HH:mm:ss') ; Set Date and Time style GUICtrlSetTip(-1, "The end date of the event") GUICtrlSetState(-1, BitOR($GUI_DISABLE, $GUI_HIDE)) ; Diasbled and hidden yy default GUICtrlCreateLabel("Sound to play:", 8, 280, 72, 17) GUICtrlCreateInput('', 8, 296, 160, 21, $ES_READONLY) ; Default sound to play at event end GUICtrlCreateButton("...", 174, 296, 21, 21) GUICtrlSetOnEvent(-1, "idBtn_SoundBrowseClick") GUICtrlCreateCheckbox("Play sound", 8, 328, 73, 17) GUICtrlCreateCheckbox("Popup", 88, 328, 49, 17) GUICtrlCreateCheckbox("Save as default event", 8, 352, 124, 17) GUICtrlSetTip(-1, "Saves the event as a default event, that later can be choosen from the dropdown") GUICtrlCreateButton("&Add event", 8, 376, 75, 21) GUICtrlSetTip(-1, "Adds the events and closes the add event gui") GUICtrlSetOnEvent(-1, "idBtn_AddEventClick") GUICtrlCreateButton("&Close", 120, 376, 75, 21) GUICtrlSetOnEvent(-1, "hWnd_Close") GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form=D:\Profil\Rex\ISN AutoIt Studio\Projects\Countdown Days\GUI\hEditEvent.kxf Global $hEditEvent = GUICreate("Edit Event", 206, 407, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP, $WS_CAPTION)) GUISetOnEvent($GUI_EVENT_CLOSE, "hWnd_Close") Global $idEditEvent = GUICtrlCreateDummy() GUICtrlCreateLabel("Choose events to edit:", 8, 8, 110, 17) GUICtrlCreateCombo("", 8, 24, 185, 25, $CBS_DROPDOWNLIST) GUICtrlSetOnEvent(-1, "idCombo_EventsChange") GUICtrlCreateLabel("Event Name:", 8, 56, 66, 17) GUICtrlCreateInput("", 8, 72, 185, 21) GUICtrlSetLimit(-1, 24) GUICtrlSetTip(-1, "Name of event. This is the text that will be shown at the gui. Max length is 24 chars") GUICtrlCreateLabel("Event description:", 8, 104, 89, 17) GUICtrlCreateEdit("", 8, 120, 185, 89, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetTip(-1, "Event description. This will be shown as a tip upon hovering, and also in the popup (if popup is enabled)") GUICtrlCreateCheckbox("Choose event date by calender", 8, 216, 170, 17) GUICtrlSetOnEvent(-1, "idCb_ChoseDateClick") GUICtrlCreateLabel("Days to event:", 8, 240, 73, 17) GUICtrlCreateInput("", 8, 256, 73, 21, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetLimit(-1, 3) GUICtrlSetTip(-1, "Days to the event, time will be from the time the event is added") GUICtrlCreateLabel("Time of event", 112, 240, 69, 17) GUICtrlCreateDate('', 112, 256, 82, 21, BitOR($DTS_UPDOWN, $DTS_TIMEFORMAT)) GUICtrlSendMsg(-1, $DTM_SETFORMATW, 0, 'HH:mm:ss') GUICtrlSetTip(-1, "Time of the event") GUICtrlCreateLabel("Event date:", 8, 240, 59, 17) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlCreateDate('', 8, 256, 186, 21, 0) GUICtrlSendMsg(-1, $DTM_SETFORMATW, 0, 'yyyy/MM/dd HH:mm:ss') GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetState(-1, $GUI_HIDE) GUICtrlSetTip(-1, "Choose the end date of the event") GUICtrlCreateLabel("Sound to play:", 8, 280, 72, 17) GUICtrlCreateInput("", 8, 296, 160, 21, $ES_READONLY) GUICtrlCreateButton("...", 174, 296, 21, 21) GUICtrlSetOnEvent(-1, "idBtn_SoundBrowseClick") GUICtrlCreateCheckbox("Play sound", 8, 328, 73, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateCheckbox("Popup", 88, 328, 49, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateCheckbox("Enabled", 8, 352, 60, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetTip(-1, "Enables or disables the event, if disabled it don't show in the countdown gui") GUICtrlCreateButton("&Update", 8, 376, 75, 21) GUICtrlSetTip(-1, "Updates the selected event") GUICtrlSetOnEvent(-1, "idBtn_UpdateEventClick") GUICtrlCreateButton("&Close", 120, 376, 75, 21) GUICtrlSetOnEvent(-1, "hWnd_Close") GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form=D:\Profil\Rex\ISN AutoIt Studio\Projects\Countdown Days\GUI\hEditEvent.kxf Global $hDeleteEvent = GUICreate("Delete Event", 206, 318, Default, Default, BitOR($WS_SYSMENU, $WS_POPUP, $WS_CAPTION)) GUISetOnEvent($GUI_EVENT_CLOSE, "hWnd_Close") Global $idDelEvent = GUICtrlCreateDummy() GUICtrlCreateLabel("Choose event to delete:", 8, 8, 122, 16) GUICtrlCreateCombo("", 8, 24, 185, 25, $CBS_DROPDOWNLIST) GUICtrlSetTip(-1, "Event to delete") GUICtrlSetOnEvent(-1, "idCombo_EventsChange") GUICtrlCreateLabel("Event Name:", 8, 56, 66, 16) GUICtrlCreateInput("", 8, 72, 185, 21, $ES_READONLY) GUICtrlCreateLabel("Event description:", 8, 104, 89, 16) GUICtrlCreateEdit("", 8, 120, 185, 89, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL, $ES_READONLY)) GUICtrlCreateLabel("Event date:", 8, 216, 59, 17) GUICtrlCreateInput("", 8, 232, 186, 21, $ES_READONLY) GUICtrlCreateCheckbox("Enabled", 8, 264, 60, 17) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateButton("&Delete", 8, 288, 75, 21) GUICtrlSetTip(-1, "Deletes selected event") GUICtrlSetOnEvent(-1, "idBtn_EventDeleteClick") GUICtrlCreateButton("&Close", 120, 288, 75, 21) GUICtrlSetTip(-1, "Closes the add event, without saving the event.") GUICtrlSetOnEvent(-1, "hWnd_Close") GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form=D:\Profil\Rex\ISN AutoIt Studio\Projects\Countdown Days\GUI\hSettings.kxf Global $hSettings = GUICreate("Settings", 203, 327, Default, Default, BitOR($WS_SYSMENU, $WS_POPUP, $WS_CAPTION)) GUISetOnEvent($GUI_EVENT_CLOSE, "hWnd_Close") GUICtrlCreateLabel("Max Number of events:", 8, 12, 114, 17) GUICtrlSetTip(-1, "Max number of events." & @CRLF & "On a 1920x1080 Screen the max would be aprox 13 events.") Global $idInp_Sett_MaxEvents = GUICtrlCreateInput("", 122, 8, 21, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER)) GUICtrlSetLimit(-1, 2) Global $idCb_Sett_Remember = GUICtrlCreateCheckbox("Remember last position.", 8, 32, 130, 17) GUICtrlSetTip(-1, "When countdown is closed, it saves the position it was placed, and starts at that position.") Global $idCb_Sett_PlaySound = GUICtrlCreateCheckbox("Play Sound", 8, 56, 74, 17) GUICtrlSetTip(-1, "Plays a sound when the event time is up.") Global $idCb_Sett_Pop = GUICtrlCreateCheckbox("Show popup", 88, 56, 80, 17) GUICtrlSetTip(-1, "Shows a popup windows, when the event time is up." & @CRLF & "The content of the popup windows will be the event description.") Global $idInp_Sett_Sound = GUICtrlCreateInput("", 8, 104, 153, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY)) GUICtrlSetTip(-1, "Default sound to play when the event time is up.") Global $idCb_Sett_StartWithWin = GUICtrlCreateCheckbox("Start with windows", 8, 80, 110, 17) GUICtrlSetTip(-1, "Start the program with windows") Global $idBtn_Sett_SoundBrowse = GUICtrlCreateButton("...", 168, 104, 21, 21) GUICtrlSetOnEvent(-1, "idBtn_SoundBrowseClick") GUICtrlCreateLabel("Default events:", 8, 136, 76, 17) Global $idList_Sett_DefEvents = GUICtrlCreateList("", 8, 152, 185, 97) GUICtrlSetTip(-1, "Default events that, can be picked from add event.") GUICtrlCreateButton("&Remove", 8, 256, 75, 21) GUICtrlSetTip(-1, "Deletes the selected Default event") GUICtrlSetOnEvent(-1, "idBtn_Sett_RemEventClick") GUICtrlCreateButton("&OK", 8, 296, 75, 21) GUICtrlSetOnEvent(-1, "idBtn_Sett_OKClick") GUICtrlCreateButton("&Close", 120, 296, 75, 21) GUICtrlSetOnEvent(-1, "hWnd_Close") GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### ;~ If $cmdline[0] = 1 Then RelHandle($cmdline[1]) Countdown() AdlibRegister("Countdown", 1000) While 1 Sleep(100) WEnd Func EventOnLoad($bMsg = True) ; This function is used to prevent array subscript dimension range exceeded, and to remove events that is currently disabled. ; Also it checks if there is more events enabled that max events allows, and throws a msg about it - and trims the max events ; to match the MaxEvents allowed ; First we removes the events that is currently disabled Local $sDelRange ; To save the array index where the disabled event is stored For $i = 1 To $g_aEvents[0] ; Check if the event is disabled, using StringToType to convert string to Bool If StringToType(IniRead($g_sEventFile, $g_aEvents[$i], 'Enabled', True)) = False Then ; If the event is disabled we add the index to our save index var and adds a ";" in case that more than one is disabled $sDelRange &= $i & ';' EndIf Next If $sDelRange <> '' Then ; If we had some Disabled events, we remove them from the array _ArrayDelete($g_aEvents, StringTrimRight($sDelRange, 1)) ; And then we update the value of $g_aEvents[0] $g_aEvents[0] = UBound($g_aEvents) - 1 If $g_aEvents[0] = 0 Then ; If there is no enabled events Dim $g_aEvents[2] = [1, Null] ; We updates the array, so we know that there is't any enabled events EndIf EndIf ; Then we check if there is more events that allowed If $g_aEvents[0] > $g_iMaxEvents And $bMsg = True Then ; If there is more events that allowed, we throw a warn - and trims the array to max MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Error', _ 'The amount of events exceeds the max nr of events' & @CRLF & _ 'Only the first ' & $g_iMaxEvents & ' events will be loaded!') $g_aEvents[0] = $g_iMaxEvents EndIf ; Updates the EventData array ReDim $g_aEventData[UBound($g_aEvents)][3] ; Add enddate to the array For $i = 1 To $g_aEvents[0] $g_aEventData[$i][0] = IniRead($g_sEventFile, $g_aEvents[$i], 'EndDate', _NowCalc()) $g_aEventData[$i][1] = StringToType(IniRead($g_sEventFile, $g_aEvents[$i], 'Enabled', True)) $g_aEventData[$i][2] = $g_aEvents[$i] Next EndFunc ;==>EventOnLoad Func MenuItem_AddEventClick() ; Add default evnets to dropdown Local $aDefEvents = IniReadSectionNames($g_sSetFile) If IsArray($aDefEvents) Then For $i = 1 To $aDefEvents[0] If $aDefEvents[$i] <> 'Settings' Then ; If the name is settings we ignore it ; Add the defaults to the combo and revert the name from hex to string. GUICtrlSetData($idAddEvent + 2, _HexToString($aDefEvents[$i])) EndIf Next EndIf ; Set default sound to play GUICtrlSetData($idAddEvent + 15, $g_sSoundFile) GUICtrlSetTip($idAddEvent + 15, $g_sSoundFile) ; Check if the playsound and popup is enabled in settings CbSetState($idAddEvent + 17, $g_bSoundPlay) CbSetState($idAddEvent + 18, $g_bPopup) ; Set focus to the Event Name input GUICtrlSetState($idAddEvent + 4, $GUI_FOCUS) ; Show the gui GUISetState(@SW_SHOW, $hAddEvent) EndFunc ;==>MenuItem_AddEventClick Func MenuItem_DeleteEventClick() Local $aEvents = IniReadSectionNames($g_sEventFile) If IsArray($aEvents) Then For $i = 1 To $aEvents[0] GUICtrlSetData($idDelEvent + 2, IniRead($g_sEventFile, $aEvents[$i], 'Name', 'Error Reading Name')) Next EndIf GUISetState(@SW_SHOW, $hDeleteEvent) EndFunc ;==>MenuItem_DeleteEventClick Func MenuItem_EditEventClick() ; First we get events from the inifile Local $aEvents = IniReadSectionNames($g_sEventFile) If IsArray($aEvents) Then For $i = 1 To $aEvents[0] GUICtrlSetData($idEditEvent + 2, IniRead($g_sEventFile, $aEvents[$i], 'Name', 'Error Reading Name')) Next EndIf ; Then we ticks of the date checkbox so it shows date picker GUICtrlSetState($idEditEvent + 7, $GUI_CHECKED) ; And hides/disables the Days to evnet / event time input and labels GUICtrlSetState($idEditEvent + 8, $GUI_HIDE) ; Hide the label Days to event GUICtrlSetState($idEditEvent + 9, BitOR($GUI_DISABLE, $GUI_HIDE)) ; Hide the input Days to event GUICtrlSetData($idEditEvent + 9, '') ; Clear the input Days to event GUICtrlSetState($idEditEvent + 10, $GUI_HIDE) ; Hides the label Time to event GUICtrlSetState($idEditEvent + 11, BitOR($GUI_DISABLE, $GUI_HIDE)) ; Hide the TimePicker Time to event ; Show date picker and lable GUICtrlSetState($idEditEvent + 12, $GUI_SHOW) ; Show the label Event date GUICtrlSetState($idEditEvent + 13, BitOR($GUI_ENABLE, $GUI_SHOW)) ; Show the Date time picker ; Then we show the GUI GUISetState(@SW_SHOW, $hEditEvent) EndFunc ;==>MenuItem_EditEventClick Func MenuItem_SettingsClick() ; Update the gui with info's from the settings file, or if no settings file exists, with defaults ; Add default evnets to Listbox (The events that is saved, and can be loaded in add event) Local $aDefEvents = IniReadSectionNames($g_sSetFile) If IsArray($aDefEvents) Then ; If it's an array we continue For $i = 1 To $aDefEvents[0] If $aDefEvents[$i] <> 'Settings' Then ; If the name is settings we ignore it ; Add the defaults to the listbox and convert the name from hex to string. _GUICtrlListBox_AddString($idList_Sett_DefEvents, _HexToString($aDefEvents[$i])) EndIf Next EndIf ; Check if the Remember, playsound, popup and Start with windows is enabled in settings CbSetState($idCb_Sett_Remember, $g_bRemember) CbSetState($idCb_Sett_PlaySound, $g_bSoundPlay) CbSetState($idCb_Sett_Pop, $g_bPopup) CbSetState($idCb_Sett_StartWithWin, $g_bStartWithWin) ; Set default sound GUICtrlSetData($idInp_Sett_Sound, IniRead($g_sSetFile, 'Settings', 'SoundFile', @WindowsDir & '\media\Tada.wav')) ; Set max events GUICtrlSetData($idInp_Sett_MaxEvents, IniRead($g_sSetFile, 'Settings', 'MaxEvents', 6)) ; Show the gui GUISetState(@SW_SHOW, $hSettings) EndFunc ;==>MenuItem_SettingsClick Func MenuItem_ExitClick() ; Check if the program should save it's poition If $g_bRemember = True Then PosSave() Exit EndFunc ;==>MenuItem_ExitClick Func MenuItem_PinClick() ; Get state of MenuItem Pin in place ; If the pin is enabled, the gui can't be moved If BitAND(GUICtrlRead($MenuItem_Pin), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($MenuItem_Pin, $GUI_UNCHECKED) $g_bPin = False ; Update the var IniWrite($g_sSetFile, 'Settings', 'Pin', False) ; Update the ini file GUICtrlSetState($idLbl_Move, $GUI_ENABLE) ; Enable the label, this allows the gui to be moved Else GUICtrlSetState($MenuItem_Pin, $GUI_CHECKED) $g_bPin = True ; Update the var IniWrite($g_sSetFile, 'Settings', 'Pin', True) ; Update the ini file GUICtrlSetState($idLbl_Move, $GUI_DISABLE) ; Disable the label, preventing the gui to be moved EndIf EndFunc ;==>MenuItem_PinClick Func hWnd_Close() ; First we check if it's Add, Edit or Delete event gui that send the msg Switch WinGetHandle('[ACTIVE]') ; The handle of the current gui Case WinGetHandle($hAddEvent) ; If its Add event Local $iCtrlID = $idAddEvent ; hide the addevent gui GUISetState(@SW_HIDE, $hAddEvent) Case WinGetHandle($hEditEvent) ; If its Edit event Local $iCtrlID = $idEditEvent ; hide the editevent gui GUISetState(@SW_HIDE, $hEditEvent) Case WinGetHandle($hDeleteEvent) ; If its Delete event Local $iCtrlID = $idDelEvent ; hide the Delete event gui GUISetState(@SW_HIDE, $hDeleteEvent) Case WinGetHandle($hSettings) ; If its Settings ; Hide the gui GUISetState(@SW_HIDE, $hSettings) Return EndSwitch ; Clear all ; The first 3 ctrls is the same for all 3 gui's _GUICtrlComboBox_ResetContent($iCtrlID + 2) ; Clear the combo GUICtrlSetData($iCtrlID + 4, '') ; Clear the input Event name GUICtrlSetData($iCtrlID + 6, '') ; Clear the edit event Description ; Now we need to check if we have the edit or update gui If WinGetHandle($hAddEvent) Or WinGetHandle($hEditEvent) = WinGetHandle('[ACTIVE]') Then GUICtrlSetState($iCtrlID + 7, $GUI_UNCHECKED) ; Unchecks the Choose event date by calender checkbox GUICtrlSetData($iCtrlID + 9, '') ; Clear the input Days to event GUICtrlSetState($iCtrlID + 19, $GUI_UNCHECKED) ; Uncheck Save as default / Enabled checkbox Else ; Uncheck the Enabled checkbox at the delete gui GUICtrlSetState($iCtrlID + 19, $GUI_UNCHECKED) ; Uncheck Enabled checkbox EndIf EndFunc ;==>hWnd_Close Func idBtn_Sett_OKClick() ; Read infos and update the settings. ; Get maxEvents Local $iMaxEvents = GUICtrlRead($idInp_Sett_MaxEvents) If $iMaxEvents = '' Then MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Max number of events', _ "The input Max number of events is empty, but it shouldn't be" & @CRLF & 'Please type number of max allowed events!!') GUICtrlSetState($idInp_Sett_MaxEvents, $GUI_FOCUS) Else IniWrite($g_sSetFile, 'Settings', 'MaxEvents', $iMaxEvents) EndIf ; Write the settings to ini file IniWrite($g_sSetFile, 'Settings', 'Remember', (GUICtrlRead($idCb_Sett_Remember) = $GUI_CHECKED) ? True : False) IniWrite($g_sSetFile, 'Settings', 'SoundPlay', (GUICtrlRead($idCb_Sett_PlaySound) = $GUI_CHECKED) ? True : False) IniWrite($g_sSetFile, 'Settings', 'Popup', (GUICtrlRead($idCb_Sett_Pop) = $GUI_CHECKED) ? True : False) IniWrite($g_sSetFile, 'Settings', 'StartWithWin', (GUICtrlRead($idCb_Sett_StartWithWin) = $GUI_CHECKED) ? True : False) IniWrite($g_sSetFile, 'Settings', 'SoundFile', GUICtrlRead($idInp_Sett_Sound)) ; Check if the program should rember it's last position If GUICtrlRead($idCb_Sett_Remember) = $GUI_CHECKED Then PosSave() ; Check if the program should start with windows If GUICtrlRead($idCb_Sett_StartWithWin) = $GUI_CHECKED Then RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Run', 'CCD', 'REG_SZ', '"' & @ScriptFullPath & '"') Else RegDelete('HKCU\Software\Microsoft\Windows\CurrentVersion\Run', 'CCD') EndIf ; Update the global vars $g_bRemember = (GUICtrlRead($idCb_Sett_Remember) = $GUI_CHECKED) ? True : False $g_bSoundPlay = (GUICtrlRead($idCb_Sett_PlaySound) = $GUI_CHECKED) ? True : False $g_bPopup = (GUICtrlRead($idCb_Sett_Pop) = $GUI_CHECKED) ? True : False $g_bStartWithWin = (GUICtrlRead($idCb_Sett_StartWithWin) = $GUI_CHECKED) ? True : False $g_sSoundFile = GUICtrlRead($idInp_Sett_Sound) GUISetState(@SW_HIDE, $hSettings) EndFunc ;==>idBtn_Sett_OKClick Func idBtn_Sett_RemEventClick() ; First we warn about the removal Local $iStyle = BitOR($MB_YESNO, $MB_SETFOREGROUND, $MB_TOPMOST, $MB_ICONWARNING) Local $sEvent = GUICtrlRead($idList_Sett_DefEvents) Local $iMsgBoxAnswer = MsgBox($iStyle, 'Delete event', 'The event "' & $sEvent & '" will be deletede!' & @CRLF & "Do you want to continue?") Switch $iMsgBoxAnswer Case $IDYES ; Remove the evetn from ini file IniDelete($g_sSetFile, _StringToHex($sEvent)) ; Remove selected from the list box _GUICtrlListBox_DeleteString($idList_Sett_DefEvents, _GUICtrlListBox_FindString($idList_Sett_DefEvents, $sEvent)) Case $IDNO Return EndSwitch EndFunc ;==>idBtn_Sett_RemEventClick Func idCb_ChoseDateClick() ; Handel the Choose by date checkbox for either Add or Edit event gui ; First we check if it's Add or Edit event gui that is asking Switch WinGetHandle('[ACTIVE]') ; The handle of the current gui Case WinGetHandle($hAddEvent) ; If its Add event Local $iCtrlID = $idAddEvent Case WinGetHandle($hEditEvent) ; If its Edit event Local $iCtrlID = $idEditEvent EndSwitch ; Get state of checkbox Local $bChoseDate = (GUICtrlRead($iCtrlID + 7) = $GUI_CHECKED) ? True : False ; Handel state of checkbox Switch $bChoseDate Case True ; Hide, disable and clear days and time input / label GUICtrlSetState($iCtrlID + 8, $GUI_HIDE) ; Hide the label Days to event GUICtrlSetState($iCtrlID + 9, BitOR($GUI_DISABLE, $GUI_HIDE)) ; Hide the input Days to event GUICtrlSetData($iCtrlID + 9, '') ; Clear the input Days to event GUICtrlSetState($iCtrlID + 10, $GUI_HIDE) ; Hides the label Time to event GUICtrlSetState($iCtrlID + 11, BitOR($GUI_DISABLE, $GUI_HIDE)) ; Hide the TimePicker Time to event ; Show date picker and lable GUICtrlSetState($iCtrlID + 12, $GUI_SHOW) ; Show the label Event date GUICtrlSetState($iCtrlID + 13, BitOR($GUI_ENABLE, $GUI_SHOW)) ; Show the Date time picker Case False ; Hide, disable and clear date picker and label GUICtrlSetState($iCtrlID + 12, $GUI_HIDE) ; Hide the label Event date GUICtrlSetState($iCtrlID + 13, BitOR($GUI_DISABLE, $GUI_HIDE)) ; Hide the Date time picker ; Enable, show and set time input / labels GUICtrlSetState($iCtrlID + 8, $GUI_SHOW) ; Show the label Days to event GUICtrlSetState($iCtrlID + 9, BitOR($GUI_ENABLE, $GUI_SHOW)) ; Shows the Input Days to event GUICtrlSetState($iCtrlID + 10, $GUI_SHOW) ; Shows the label Time to event GUICtrlSetState($iCtrlID + 11, BitOR($GUI_ENABLE, $GUI_SHOW)) ; Show time picker EndSwitch EndFunc ;==>idCb_ChoseDateClick Func idBtn_AddEventClick() ; First we handle the inputs etc. ; Read data from gui, and add it to an array Local $sReadName = GUICtrlRead($idAddEvent + 4) ; Read name from Event name input If $sReadName = '' Then MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Event Name Error', 'The input "Event name" was empty!' & _ @CRLF & 'Please enter type an Event name!!') GUICtrlSetState($idAddEvent + 4, $GUI_FOCUS) Return EndIf ; Get state of checkbox Local $bChoseDate = (GUICtrlRead($idAddEvent + 7) = $GUI_CHECKED) ? True : False ; Handel state of checkbox Switch $bChoseDate Case True ; Get DTS from date picker Local $sDTS = GUICtrlRead($idAddEvent + 13) Case False ; Check that days is not empty Local $sReadDays = GUICtrlRead($idAddEvent + 9) If $sReadDays <> '' Then Local $sDTS = CalcEndDate($sReadDays, GUICtrlRead($idAddEvent + 11)) Else MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Days Error', 'The input "Days to event" was empty!' & _ @CRLF & 'Please enter number of days!!') GUICtrlSetState($idAddEvent + 9, $GUI_FOCUS) Return EndIf EndSwitch Local $sEvent = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC ; We use this to prevent events with same SectionNames in the ini file. ; Create an array to hold the Event values Local $aValues[8][2] $aValues[0][0] = 7 ; Number of elements in the array $aValues[0][1] = '' $aValues[1][0] = 'Name' $aValues[1][1] = $sReadName ; Event Name $aValues[2][0] = 'Description' $aValues[2][1] = StringReplace(GUICtrlRead($idAddEvent + 6), @CRLF, ' ') ; Get data from edit $aValues[3][0] = 'EndDate' $aValues[3][1] = $sDTS ; Event end date $aValues[4][0] = 'Sound' $aValues[4][1] = GUICtrlRead($idAddEvent + 15) ; Get sound to play from input sound to play $aValues[5][0] = 'PlaySound' $aValues[5][1] = (GUICtrlRead($idAddEvent + 17) = $GUI_CHECKED) ? True : False ; To play or not play sound at event end $aValues[6][0] = 'Popup' $aValues[6][1] = (GUICtrlRead($idAddEvent + 18) = $GUI_CHECKED) ? True : False ; To show or not to show popup at event end $aValues[7][0] = 'Enabled' $aValues[7][1] = 'True' ; The Event is Enabled by default IniWriteSection($g_sEventFile, $sEvent, $aValues) ; Write data to ini file ; Get state of save as default checkbox If GUICtrlRead($idAddEvent + 19) = $GUI_CHECKED Then ; We dont save all the info, only Days to Event, Sound to play, To play o not play the sound and to show or not to show the popup ; Trim the array from unneeded data _ArrayDelete($aValues, '1;7') ; Remove Name and Enabled $aValues[0][0] = 5 ; Update the number of values left in the array $aValues[2][0] = 'Days' ; Change EndDate to Days ; Get the amount of days to event +1 course the cal is only returing whole days and the event will be in x days and 23:59:xx sec ; There for we needs to ad +1, so it will correspond to the amount of days th euser might have entered in Days to Event $aValues[2][1] = _DateDiff('D', _NowCalc(), $sDTS) + 1 IniWriteSection($g_sSetFile, _StringToHex(GUICtrlRead($idAddEvent + 4)), $aValues) ; Write the info to Settings file EndIf hWnd_Close() ; Close the gui If $g_aEvents[1] = Null Then UpdateGui(True) ; Update Countdown GUI with Msg Else UpdateGui(False) ; Update Countdown GUI without msg EndIf EndFunc ;==>idBtn_AddEventClick Func idBtn_UpdateEventClick() ; First we read the combo to get the index of the selected event Local $iIndex = _GUICtrlComboBox_GetCurSel($idEditEvent + 2) + 1 ; Now we get the data from the inifile Local $aEvents = IniReadSectionNames($g_sEventFile) ; First we handle the inputs etc. ; Read data from gui, and add it to an array Local $sReadName = GUICtrlRead($idEditEvent + 4) ; Read name from Event name input If $sReadName = '' Then MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Event Name Error', 'The input "Event name" was empty!' & _ @CRLF & 'Please enter type an Event name!!') GUICtrlSetState($idEditEvent + 4, $GUI_FOCUS) Return EndIf ; Get state of checkbox Local $bChoseDate = (GUICtrlRead($idEditEvent + 7) = $GUI_CHECKED) ? True : False ; Handel state of checkbox Switch $bChoseDate Case True ; Get DTS from date picker Local $sDTS = GUICtrlRead($idEditEvent + 13) Case False ; Check that days is not empty Local $sReadDays = GUICtrlRead($idEditEvent + 9) If $sReadDays <> '' Then Local $sDTS = CalcEndDate($sReadDays, GUICtrlRead($idEditEvent + 11)) Else MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Days Error', 'The input "Days to event" was empty!' & _ @CRLF & 'Please enter number of days!!') GUICtrlSetState($idEditEvent + 9, $GUI_FOCUS) Return EndIf EndSwitch ; Create an array to hold the Event values Local $aValues[8][2] $aValues[0][0] = 7 ; Number of elements in the array $aValues[0][1] = '' $aValues[1][0] = 'Name' $aValues[1][1] = $sReadName ; Event Name $aValues[2][0] = 'Description' $aValues[2][1] = StringReplace(GUICtrlRead($idEditEvent + 6), @CRLF, ' ') ; Get data from edit $aValues[3][0] = 'EndDate' $aValues[3][1] = $sDTS ; Event end date $aValues[4][0] = 'Sound' $aValues[4][1] = GUICtrlRead($idEditEvent + 15) ; Get sound to play from input sound to play $aValues[5][0] = 'PlaySound' $aValues[5][1] = (GUICtrlRead($idEditEvent + 17) = $GUI_CHECKED) ? True : False ; To play or not play sound at event end $aValues[6][0] = 'Popup' $aValues[6][1] = (GUICtrlRead($idEditEvent + 18) = $GUI_CHECKED) ? True : False ; To show or not to show popup at event end $aValues[7][0] = 'Enabled' $aValues[7][1] = (GUICtrlRead($idEditEvent + 19) = $GUI_CHECKED) ? True : False ; If enabled or not enabled IniWriteSection($g_sEventFile, $aEvents[$iIndex], $aValues) ; Write data to ini file hWnd_Close() ; Close the gui UpdateGui(False) ; Update Countdown GUI EndFunc ;==>idBtn_UpdateEventClick Func idBtn_EventDeleteClick() ; Deletes the selected Event from the Events.ini file and if it's current active in the CountDown GUI ; refreshes the gui to remove it from that also ; First we warn the user that the event will be deletede If MsgBox(BitOR($MB_YESNO, $MB_TOPMOST, $MB_SETFOREGROUND, $MB_ICONWARNING), 'Delete Event', 'The Event ' & GUICtrlRead($idDelEvent + 2) & _ ' will be deletede!' & @CRLF & 'Do you want to continue?') = $IDNO Then Return ; Read the combo, to get the index of the selected Event Local $iIndex = _GUICtrlComboBox_GetCurSel($idDelEvent + 2) + 1 ; Add +1 to the index ; Now we get the sectionnames from the ini file Local $aEvents = IniReadSectionNames($g_sEventFile) ; Saves the sectionname that we need to delete Local $sEventToDelete = $aEvents[$iIndex] ; We deletes the event from the ini file IniDelete($g_sEventFile, $aEvents[$iIndex]) ; Closes the Delete event gui GUISwitch($hDeleteEvent) hWnd_Close() ; Check if the event is active in the CountDownGUI, by checking if it's located in the EventData array. ; We search for the "SectionName" in the aEventData array, at colum 3, sins Col 1 holds the enddate and col 2 holds Enabled If _ArraySearch($g_aEventData, $sEventToDelete, 0, 0, 0, 0, 1, 3) <> -1 Then UpdateGui(False) ; Check if Max events is lessere that current enabled events EventOnLoad(False) If $g_aEvents[0] < $g_iMaxEvents Then GUICtrlSetState($MenuItem_AddEvent, $GUI_ENABLE) EndFunc ;==>idBtn_EventDeleteClick Func idBtn_SoundBrowseClick() ; First we check if it's Add, Edit Event or Settings gui that is asking Switch WinGetHandle('[ACTIVE]') Case WinGetHandle($hAddEvent) ; If its Add event Local $iCtrlID = $idAddEvent Case WinGetHandle($hEditEvent) ; If its Edit event Local $iCtrlID = $idEditEvent Case WinGetHandle($hSettings) ; If it Settings Local $iCtrlID = $idInp_Sett_Sound - 15 ; We have a ctrlid for this, so we subtracts 15 from the id to match our input. EndSwitch ; Display an open dialog to select a list of file(s). Local $iExStyle = BitOR($OFN_PATHMUSTEXIST, $OFN_FILEMUSTEXIST) Local $sAudioFile = _WinAPI_OpenFileDlg('', @WorkingDir, 'Audio (*.wav;*.mp3)', 1, '', '', $iExStyle) ; We only add if there is something to add If $sAudioFile <> '' Then GUICtrlSetData($iCtrlID + 15, $sAudioFile) EndFunc ;==>idBtn_SoundBrowseClick Func idCombo_EventsChange() ; Here we handle the combo changes for Add,Edit and Delete events ; First we check if it's Add or Edit event gui that is asking Switch WinGetHandle('[ACTIVE]') ; Get winhandl from active GUI Case WinGetHandle($hAddEvent) ; If it's Add event ; If we have the Add Event gui ; First we read the combo Local $sRead = GUICtrlRead($idAddEvent + 2) ; Now we get the default event data from the settings ini file Local $aData = IniReadSection($g_sSetFile, _StringToHex($sRead)) ; Add the data to the inputs GUICtrlSetData($idAddEvent + 4, $sRead) ; Add Name of event to input GUICtrlSetData($idAddEvent + 6, $aData[1][1]) ; Add Description to the edit GUICtrlSetData($idAddEvent + 9, $aData[2][1]) ; Add number of days to input GUICtrlSetData($idAddEvent + 15, $aData[3][1]) ; Add sound to input ; Set the state of Soundplay CbSetState($idAddEvent + 17, StringToType($aData[4][1])) ; Set the state of popup checkbox CbSetState($idAddEvent + 18, StringToType($aData[5][1])) Case WinGetHandle($hEditEvent) ; If it's Edit event ; We have the edit event gui ; First we read the combo Local $iIndex = _GUICtrlComboBox_GetCurSel($idEditEvent + 2) + 1 ; Now we get the data from the inifile Local $aEvents = IniReadSectionNames($g_sEventFile) Local $aData = IniReadSection($g_sEventFile, $aEvents[$iIndex]) ; Add the data to the inputs GUICtrlSetData($idEditEvent + 4, $aData[1][1]) ; Add the name to Event Name input GUICtrlSetData($idEditEvent + 6, $aData[2][1]) ; Add Description GUICtrlSetData($idEditEvent + 13, $aData[3][1]) ; Add end date of event GUICtrlSetData($idEditEvent + 15, $aData[4][1]) ; Add the sound GUICtrlSetTip($idEditEvent + 15, $aData[4][1]) ;Update the state of the checkboxes CbSetState($idEditEvent + 17, StringToType($aData[5][1])) ; PlaySound checkbox CbSetState($idEditEvent + 18, StringToType($aData[6][1])) ; Popup Checkbox CbSetState($idEditEvent + 19, StringToType($aData[7][1])) ; Enabled checkbox Case WinGetHandle($hDeleteEvent) ; If it's Delete event ; We have the edit event gui ; First we read the combo Local $iIndex = _GUICtrlComboBox_GetCurSel($idDelEvent + 2) + 1 ; Now we get the data from the inifile Local $aEvents = IniReadSectionNames($g_sEventFile) Local $aData = IniReadSection($g_sEventFile, $aEvents[$iIndex]) ; Add the data to the inputs GUICtrlSetData($idDelEvent + 4, $aData[1][1]) ; Add the name to Event Name input GUICtrlSetData($idDelEvent + 6, $aData[2][1]) ; Add Description GUICtrlSetData($idDelEvent + 8, $aData[3][1]) ; Add end date of event CbSetState($idDelEvent + 9, StringToType($aData[7][1])) ; Enabled checkbox EndSwitch EndFunc ;==>idCombo_EventsChange Func UpdateGui($bStart = True) ; Adds events to the main gui ; Check if we have an event to add to the gui If $g_aEvents[1] = Null And $bStart = False Then Return ; If we don't have any events ; If the function is called with False, we deletes all controls If $bStart = False Then ; Delete existing controls, so we can recreate them For $i = 1 To $g_aEvents[0] GUICtrlDelete($g_idLbl_Event[$i]) ; Delete the Event Name Label GUICtrlDelete($g_idLbl_Days[$i]) ; Deletes the label Days Counter GUICtrlDelete($g_idLbl_Days[$i] + 1) ; Deletes the label Days GUICtrlDelete($g_idLbl_Hrs[$i]) ; Deletes the label Hrs counter GUICtrlDelete($g_idLbl_Hrs[$i] + 1) ; Deletes the label : after hrs GUICtrlDelete($g_idLbl_Min[$i]) ; Deletes the label min counter GUICtrlDelete($g_idLbl_Min[$i] + 1) ; Deletes the label : after min GUICtrlDelete($g_idLbl_Sec[$i]) ; Deletes the label sec counter GUICtrlDelete($g_idLbl_Sec[$i] + 1) ; Deletes the label we use as frame around the time counter GUICtrlDelete($g_idLbl_Sec[$i] + 2) ; Deletes the Group we use as spacer GUICtrlDelete($g_idLbl_Sec[$i] + 3) ; Deletes the label we use as a frame for the gui Next EndIf $g_aEvents = IniReadSectionNames($g_sEventFile) ; reload the array ; Check if there is any events If Not IsArray($g_aEvents) Then Dim $g_aEvents[2] = [1, Null] Return EndIf ; Trims disabled events EventOnLoad(False) ; We call the function with false to prevent the msg box about too many events. ; Just to be shure If $g_aEvents[1] = Null Then Return ; Updates the global GUIHeight $g_iGuiHeight = ($g_iSpace * $g_aEvents[0]) + 8 ; Switch to the CCD gui, else the labels would be created on the last active gui GUISwitch($hCountdownDays) For $i = 1 To $g_aEvents[0] ; Adds the events to the Countdown gui Local $sEventName = StringLeft(IniRead($g_sEventFile, $g_aEvents[$i], 'Name', ''), 24) $g_idLbl_Event[$i] = GUICtrlCreateLabel($sEventName, 8, 14 + (($i - 1) * $g_iSpace), 119, 20, $SS_CENTER) GUICtrlSetFont(-1, 12, 400, 0, "Arial Narrow") GUICtrlSetColor(-1, 0xFFFFFF) ; Navy blue GUICtrlSetTip(-1, SplitText(IniRead($g_sEventFile, $g_aEvents[$i], 'Description', ''), 45)) $g_idLbl_Days[$i] = GUICtrlCreateLabel("", 31, 34 + (($i - 1) * $g_iSpace), 32, 24, $SS_RIGHT) GUICtrlSetFont(-1, 14, 800, 0, "Arial Narrow") GUICtrlCreateLabel("Days", 65, 34 + (($i - 1) * $g_iSpace), 34, 24) GUICtrlSetFont(-1, 14, 400, 0, "Arial Narrow") $g_idLbl_Hrs[$i] = GUICtrlCreateLabel("", 22, 56 + (($i - 1) * $g_iSpace), 18, 24, $SS_CENTER) GUICtrlSetFont(-1, 14, 800, 0, "Arial Narrow") GUICtrlCreateLabel(":", 46, 56 + (($i - 1) * $g_iSpace), 8, 24) GUICtrlSetFont(-1, 14, 800, 0, "Arial Narrow") $g_idLbl_Min[$i] = GUICtrlCreateLabel("", 56, 56 + (($i - 1) * $g_iSpace), 18, 24, $SS_CENTER) GUICtrlSetFont(-1, 14, 800, 0, "Arial Narrow") GUICtrlCreateLabel(":", 80, 56 + (($i - 1) * $g_iSpace), 8, 24) GUICtrlSetFont(-1, 14, 800, 0, "Arial Narrow") $g_idLbl_Sec[$i] = GUICtrlCreateLabel("", 90, 56 + (($i - 1) * $g_iSpace), 18, 24, $SS_CENTER) GUICtrlSetFont(-1, 14, 800, 0, "Arial Narrow") ; Create a static lable to frame the Time countdown GUICtrlCreateLabel("", 16, 56 + (($i - 1) * $g_iSpace), 102, 24, BitOR($SS_GRAYFRAME, $WS_DISABLED, $SS_SUNKEN)) ; We add a horizontal line as a spacer between the events, but only if we have more that one. But we don't add one after the last If $i >= 1 And $i < $g_aEvents[0] And $g_aEvents[0] > 1 Then GUICtrlCreateGroup("", 0, 84 + (($i - 1) * $g_iSpace), 135, 9) GUICtrlCreateGroup("", -99, -99, 1, 1) EndIf $g_idLbl_Event[0] = $i Next ; Resizes the Frame label GUICtrlSetPos($idFrame, 0, 0, 136, $g_iGuiHeight) ; Get the position of the Countdown gui Local $aWinPos = WinGetPos($hCountdownDays) ; Updates the height of the Countdown gui, using the pos we got, and the new height using the updated global guiheight _WinAPI_SetWindowPos($hCountdownDays, $HWND_NOTOPMOST, $aWinPos[0], $aWinPos[1], 136, $g_iGuiHeight, $SWP_NOMOVE) ; Finaly we checks if we have exceeded or maxed out the allowed amounts of Events. ; If we have we disables the add event MenuItem, thereby preventing the user to add more events, until ; an Event is either disabled or deleted, making up space for a new one. If $g_aEvents[0] >= $g_iMaxEvents Then GUICtrlSetState($MenuItem_AddEvent, $GUI_DISABLE) EndFunc ;==>UpdateGui Func CbSetState($iCtrlID, $bEnabled) Switch $bEnabled ; Popup checkbox Case True GUICtrlSetState($iCtrlID, $GUI_CHECKED) Case False GUICtrlSetState($iCtrlID, $GUI_UNCHECKED) EndSwitch EndFunc ;==>CbSetState Func PosSave() Local $aPos = WinGetPos($hCountdownDays) IniWrite($g_sSetFile, 'Settings', 'Posx', $aPos[0]) IniWrite($g_sSetFile, 'Settings', 'Posy', $aPos[1]) EndFunc ;==>PosSave Func Countdown() If $g_aEvents[1] = Null Then Return ; If we don't have any events For $i = 1 To $g_aEvents[0] ; cycle through events Local $iGetSec = _DateDiff('s', _NowCalc(), $g_aEventData[$i][0]) ; grab seconds of difference from now to future date If $iGetSec <= 0 And $g_aEventData[$i][1] = True Then EventHandle($g_aEvents[$i], $i) EndIf Ticks_To_Time($iGetSec, $g_iDays, $g_iHours, $g_iMins, $g_iSecs) ; convert seconds to days/hours/minutes/seconds ; set color and data Switch $g_iDays Case 0 To 5 GUICtrlSetDataAndColor($g_idLbl_Days[$i], $g_iDays, 1) ; Red Case 6 To 10 GUICtrlSetDataAndColor($g_idLbl_Days[$i], $g_iDays, 2) ; Yellow Case Else GUICtrlSetDataAndColor($g_idLbl_Days[$i], $g_iDays, 3) ; Green EndSwitch ; If days = 0 we want to change the timer colors If $g_iDays = 0 Then Switch $g_iHours Case 0 To 6 GUICtrlSetDataAndColor($g_idLbl_Hrs[$i], $g_iHours, 1) ; Red GUICtrlSetDataAndColor($g_idLbl_Min[$i], $g_iMins, 1) ; Red GUICtrlSetDataAndColor($g_idLbl_Sec[$i], $g_iSecs, 1) ; Red Case 7 To 12 GUICtrlSetDataAndColor($g_idLbl_Hrs[$i], $g_iHours, 2) ; Yellow GUICtrlSetDataAndColor($g_idLbl_Min[$i], $g_iMins, 2) ; Yellow GUICtrlSetDataAndColor($g_idLbl_Sec[$i], $g_iSecs, 2) ; Yellow Case 13 To 23 GUICtrlSetDataAndColor($g_idLbl_Hrs[$i], $g_iHours, 3) ; Green GUICtrlSetDataAndColor($g_idLbl_Min[$i], $g_iMins, 3) ; Green GUICtrlSetDataAndColor($g_idLbl_Sec[$i], $g_iSecs, 3) ; Green EndSwitch Else ; If not we just keep them black GUICtrlSetDataAndColor($g_idLbl_Hrs[$i], $g_iHours) ; Black GUICtrlSetDataAndColor($g_idLbl_Min[$i], $g_iMins) ; Black GUICtrlSetDataAndColor($g_idLbl_Sec[$i], $g_iSecs) ; Black EndIf Next EndFunc ;==>Countdown Func EventHandle($sEvent, $iIndex) ; Here we handles the event when it's time is up o_O ; First we disable the event, to prevent it from caling this function more than once. IniWrite($g_sEventFile, $sEvent, 'Enabled', False) ; Set False in the ini file $g_aEventData[$iIndex][1] = False ; Update the EventData array from True to false ; We need to check if the we should play a sound and / or throw a popup Local $aData = IniReadSection($g_sEventFile, $sEvent) ; Error checker If @error Then MsgBox(BitOR($MB_ICONERROR, $MB_SETFOREGROUND, $MB_TOPMOST), 'Error reading event data', 'An error happend when trying to read the event data!' _ & @CRLF & 'The program will now close!!') Exit EndIf ; Check if a sound should be played If StringToType($aData[5][1]) = True Then SoundPlay($aData[4][1]) ; Check if a popup should be displayed If StringToType($aData[6][1]) = True Then ; Disable the on event mode, else the GuiGetMsg won't work Opt("GUIOnEventMode", 0) ; Create the popup window Local $iStyle = BitOR($WS_SYSMENU, $WS_POPUP, $DS_SETFOREGROUND, $WS_CAPTION) Local $iExStyle = BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW) Local $hPopup = GUICreate($aData[1][1], 405, 285, Default, Default, $iStyle, $iExStyle) Local $idEdit_Popup = GUICtrlCreateEdit("", 11, 8, 385, 233, BitOR($ES_CENTER, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL)) ; Set the Event description test to the edit GUICtrlSetData(-1, @CRLF & SplitText($aData[2][1]), 45) ;~ GUICtrlSetBkColor(-1, 0x4E4E4E) GUICtrlSetFont(-1, 18, 800, 0, "Arial Narrow") ; Boost the font size Local $idBtn_OK = GUICtrlCreateButton("OK", 165, 256, 75, 21, $BS_DEFPUSHBUTTON) GUISetState(@SW_SHOW) While 1 Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE SoundPlay('') ; Kill the sound if any GUIDelete($hPopup) ; Delete the gui ExitLoop ; And exit loop Case $idBtn_OK SoundPlay('') ; Kill the sound if any GUIDelete($hPopup) ; Delete the gui ExitLoop ; And exit loop EndSwitch WEnd Opt("GUIOnEventMode", 1) ; Reenable OnEventMode EndIf ; Set background label of the event to Yellow and text to Red - Indicate that the event is up GUICtrlSetColor($g_idLbl_Event[$iIndex], $COLOR_RED) ; Red GUICtrlSetBkColor($g_idLbl_Event[$iIndex], $COLOR_YELLOW) ; Yellow GUICtrlSetData($g_idLbl_Sec[$iIndex], '00') ; And set sec to 00 just becorse EndFunc ;==>EventHandle Func Ticks_To_Time($iSeconds, ByRef $idays, ByRef $iHours, ByRef $iMins, ByRef $iSecs) ; second conversion. ; modified: added days. added format style, to use 00 for time If Number($iSeconds) > 0 Then $idays = Int($iSeconds / 86400) $iSeconds = Mod($iSeconds, 86400) $iHours = StringFormat("%02d", Int($iSeconds / 3600)) $iSeconds = Mod($iSeconds, 3600) $iMins = StringFormat("%02d", Int($iSeconds / 60)) $iSecs = StringFormat("%02d", Mod($iSeconds, 60)) Return 1 Else Return SetError(1, 0, 0) EndIf EndFunc ;==>Ticks_To_Time Func GUICtrlSetDataAndColor($hWnd, $iCount, $iColor = 0) ; Set Day(s), Hour(s), Min(s), Sec(s) and color to the countdown labels Local $dRed, $dYellow, $dGreen, $dBlack Switch $iColor ; Check if we chould use a color Case 0 ; Black <- Default color $dBlack = 0x000000 Case 1 ; Red $dRed = 0xFF0000 Case 2 ; Yellow $dYellow = 0xFFFF00 Case 3 ; Green $dGreen = 0x008000 EndSwitch If GUICtrlRead($hWnd) <> $iCount Or GUICtrlRead($hWnd) = '' Then ; if data is different then change. helps with flickering GUICtrlSetData($hWnd, $iCount) GUICtrlSetColor($hWnd, $dRed & $dYellow & $dGreen & $dBlack) EndIf EndFunc ;==>GUICtrlSetDataAndColor Func CalcEndDate($idays, $sTime) ; Calculates a new date by adding a specified number of Days to an initial date Return _DateAdd('D', $idays, @YEAR & '/' & @MON & '/' & @MDAY & ' ' & $sTime) EndFunc ;==>CalcEndDate Func StringToType($vData) ; Converts a string to bool, Number or KeyWord Local $aData = StringRegExp($vData, "(?i)\bTrue\b|\bFalse\b|\bNull\b|\bDefault\b|\d{1,}", 3) If Not IsArray($aData) Then Return $vData Switch $aData[0] Case 'True' Return True Case 'False' Return False Case 'Null' Return Null Case 'Default' Return Default Case Else Return Number($aData[0]) EndSwitch EndFunc ;==>StringToType Func SplitText($sString, $iLenght = 45) #cs This splits a large text up into cunks at N lengt, at the last space within the nLength specified, and seperated with a @CRLF eg. 'A child asked his father, "How were people born?" So his father said, "Adam and Eve made babies, then their babies became adults and made babies, and so on." Would be formated as this: A child asked his father, "How were people born?" So his father said, "Adam and Eve made babies, then their babies became adults and made babies, and so on." #ce Local $sResult = StringRegExpReplace($sString, ".{1," & $iLenght - 1 & "}\K(\s{1,2}|$)", @CRLF) Return $sResult EndFunc ;==>SplitText1 point
-
1 point
-
You just need to check the next tagname, the following will only navigate and add links to the array where the next tagname doesn't match <img...> tag. #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A", 1) _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then ;~ Check to see if next element is an <img...> tag If $oLink.NextElementSibling.tagName <> "img" Then $oIE.Navigate($oLink.href, $ie_newtab) _IELoadWait($oIE) _ArrayAdd($aMoreInfo, $oLink.href) EndIf EndIf Next EndIf _ArrayDisplay($aMoreInfo)1 point
-
How to pass parameters from xml to auto it script? - (Moved)
Fr33b0w reacted to FrancescoDiMuro for a topic
@Sankesh Now you can work with a lot of samples #include <MsgBoxConstants.au3> #include <StringConstants.au3> Global $strFileContent = '<?xml version="1.0" encoding="UTF-8"?>"' & @CRLF & _ '<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">' & @CRLF & _ '<properties>' & @CRLF & _ '' & @CRLF & _ '<entry key="DBDefaultUserName">PIQ72</entry>' & @CRLF & _ '<entry key="DBDefaultPassword">PIQ72yut</entry>"', _ $strUsername = "", _ $strPassword = "" ; Getting the Username $arrResult = StringRegExp($strFileContent, '<entry key="DBDefaultUserName">([^<]*)</entry>', $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then $strUsername = $arrResult[0] ; Getting the Password $arrResult = StringRegExp($strFileContent, '<entry key="DBDefaultPassword">([^<]*)</entry>', $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arrResult) Then $strPassword = $arrResult[0] MsgBox($MB_ICONINFORMATION, "", "Username: " & $strUsername & @CRLF & _ "Password: " & $strPassword)1 point -
Moving Files while using FileFindNextFile [SOLVED]
abberration reacted to Dionysis for a topic
Thanks!1 point -
or you may like this popup : GUICreate("Get date", 250, 200, Default, Default, $WS_POPUP) Local $idDate = GUICtrlCreateMonthCal("", 10, 10,Default, Default, $MCS_NOTODAY) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd MsgBox($MB_SYSTEMMODAL, "Date", GUICtrlRead($idDate), 2)1 point
-
Use a calendar control on a input field [SOLVED]
Fr33b0w reacted to FrancescoDiMuro for a topic
@nend You could use something like this: #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #include <WindowsConstants.au3> Global $hdlGUI = GUICreate("", 320, 120) Global $idDateTimePicker = _GUICtrlDTP_Create($hdlGUI, 10, 5, 230, 20) ; GUICtrlCreateDate("", 10, 5, 230, 20, $DTS_SHOWNONE) _GUICtrlDTP_SetFormat($idDateTimePicker, " ") Global $idBtn = GUICtrlCreateButton("Calendar", 250, 5, 60, 20) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlDTP_Destroy($idDateTimePicker) ExitLoop Case $idBtn MsgBox($MB_ICONINFORMATION, "", GUICtrlRead($idDateTimePicker)) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR, _ $hdlWindowFrom, _ $intControlID_From, _ $intMessageCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) If @error Then Return $hdlWindowFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $intMessageCode = DllStructGetData($tNMHDR, "Code") Switch $hdlWindowFrom Case $idDateTimePicker Switch $intMessageCode Case $DTN_CLOSEUP If GUICtrlRead($idDateTimePicker) <> 0 Then _GUICtrlDTP_SetFormat($idDateTimePicker, "dd/MM/yyyy HH:mm") EndSwitch EndSwitch $tNMHDR = 0 Return $GUI_RUNDEFMSG EndFunc In few words, using the control create by _GUICtrlDTP_Create() function, you can set the format of the date to " ", in order to display no date (How to set a blank date to a DateTimePicker control). When you open the DateTimePicker control, and set a date, a format is set, so a date is set in the format you want. If you leave the DateTimePicker blank, the format is not set. In this way, you can have a blank (set to 0) DateTimePicker control1 point -
What is the point of the array? Its not used at all in the script posted above except for a loop? If you wanted to capture the urls into an array you would just use the objects href as below: #include <Array.au3> #include <IE.au3> Local $aMoreInfo[0] Local Const $ie_newtab = 0x0800 Local $oIE = _IECreate("http://repl.flexlink.com/os/products.htm?clicktype=A") _IELoadWait($oIE, 1, 1) Local $oLinks = _IETagNameGetCollection($oIE, "a") If IsObj($oLinks) Then For $oLink In $oLinks If $oLink.title = "More information" Then $oIE.Navigate($oLink.href, $ie_newtab) _IELoadWait($oIE) _ArrayAdd($aMoreInfo, $oLink.href) EndIf Next EndIf _ArrayDisplay($aMoreInfo)1 point
-
Autoclick on emulator
FrancescoDiMuro reacted to Jos for a topic
correct... as long as it is about other stuff than automating the game. Jos1 point -
your regexp is modify, this part probably not match nothing "(.*?)" </a>' because " " in your html suppose not exist because if you want catch wktl 150 simply (.*?) WKTL 150 </a>', i spoken use regexp buddy and find a correct regexp for your case is difficult for me help without a webpage ...try1 point
-
RoboCopy in AutoIT %ErrorLevel% always 0 in script but ok outside
gonzo070777 reacted to pixelsearch for a topic
Hi all, I tried what follows and all exitcodes match, no matter I run the script from AutoIt, using Runwait() or _RunDos(), or if I launch a cmd file directly from the command prompt : #include <Process.au3> ; for _RunDos() ; Global $iErrorLevel =_RunDos("C:\test\robocopy.exe C:\folder1 C:\folder2") Global $iErrorLevel = RunWait(@ComSpec & " /k " & "C:\test\robocop.cmd") MsgBox(0,"", "Exit code: " & $iErrorLevel & @CRLF & "@error: " & @error) Here is the content of robocop.cmd C:\test\robocopy.exe C:\folder1 C:\folder2 if %ERRORLEVEL% EQU 16 echo ***FATAL ERROR*** & goto end if %ERRORLEVEL% EQU 15 echo OKCOPY + FAIL + MISMATCHES + XTRA & goto end if %ERRORLEVEL% EQU 14 echo FAIL + MISMATCHES + XTRA & goto end if %ERRORLEVEL% EQU 13 echo OKCOPY + FAIL + MISMATCHES & goto end if %ERRORLEVEL% EQU 12 echo FAIL + MISMATCHES& goto end if %ERRORLEVEL% EQU 11 echo OKCOPY + FAIL + XTRA & goto end if %ERRORLEVEL% EQU 10 echo FAIL + XTRA & goto end if %ERRORLEVEL% EQU 9 echo OKCOPY + FAIL & goto end if %ERRORLEVEL% EQU 8 echo FAIL & goto end if %ERRORLEVEL% EQU 7 echo OKCOPY + MISMATCHES + XTRA & goto end if %ERRORLEVEL% EQU 6 echo MISMATCHES + XTRA & goto end if %ERRORLEVEL% EQU 5 echo OKCOPY + MISMATCHES & goto end if %ERRORLEVEL% EQU 4 echo MISMATCHES & goto end if %ERRORLEVEL% EQU 3 echo OKCOPY + XTRA & goto end if %ERRORLEVEL% EQU 2 echo XTRA & goto end if %ERRORLEVEL% EQU 1 echo OKCOPY & goto end if %ERRORLEVEL% EQU 0 echo No Change & goto end :end When C:\Folder1 and C:\Folder2 don't exist on HD, exitcode is 16 *** Fatal Error*** (it will display 16 in Msgbox and in the Dos command window) If C:\Folder1 and C:\Folder2 both exist, and there are new files in C:\Folder1, then exitcode will display 1 (okcopy), no matter you use the script in Autoit or the cmd file directly in dos command window. Then if you run the script again, an errorlevel 0 will be displayed everywhere, meaning no change) etc...1 point -
Moving Files while using FileFindNextFile [SOLVED]
Dionysis reacted to abberration for a topic
I made two folders on my desktop and got this code to work: #include <File.au3> $path = @DesktopDir & "\test\" $path2 = @DesktopDir & "\test2\" $hSearch = FileFindFirstFile($path & "yes*.txt") If $hSearch = -1 Then ConsoleWrite("Oops! No files found..." & @CRLF) FileChangeDir($path) While 1 $filename = FileFindNextFile($hSearch) If @error Then ExitLoop ;no more files If StringLeft($filename, 3) = "yes" Then ConsoleWrite('Moving file "' & $filename & '" to ' & $path & $path2 & '.' & @CRLF) FileMove($filename, $path2) If @error Then ConsoleWrite("Cannot Move File!") EndIf Wend ConsoleWrite("Operation Complete!")1 point -
RoboCopy in AutoIT %ErrorLevel% always 0 in script but ok outside
gonzo070777 reacted to Nine for a topic
Try this, works for me : #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt ("MustDeclareVars", 1) Opt("SendKeyDelay", 0) Run("cmd.exe") Local $handle = WinWait("[REGEXPTITLE:(?i)cmd.exe$]", "", 3) ControlSend($handle, "", "", "cd \apps" & @CRLF) ControlSend($handle, "", "", "robocopy C:\Apps\Mirc c:\Apps\Temp *.* /xf buttons2.ini /xd Local_Files /S /copy:DAT /dcopy:t /purge /fft /DST /R:1 /W:2" & @CRLF) ControlSend($handle, "", "", "Echo The Error level is %ERRORLEVEL%" & @CRLF) Sleep(5000) ; delay to check output. Delete line to continue without delay ControlSend($handle, "", "", "cls" & @CRLF) Sleep(2000) ControlSend($handle, "", "", "exit" & @CRLF)1 point -
Test this: Modified GraphGDIPlus.au3 (changed some functions from int to float to be more precise and changed save function): ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# =============================================================================== ; Title .........: GraphGDIPlus ; AutoIt Version: 3.3.0.0+ ; Language: English ; Description ...: A Graph control to draw line graphs, using GDI+, also double-buffered. ; Notes .........: ; ======================================================================================= ; #VARIABLES/INCLUDES# ================================================================== #include-once #include <GDIplus.au3> Global $aGraphGDIPlusaGraphArrayINTERNAL[1] ; ======================================================================================= ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Create ; Description ...: Creates graph area, and prepares array of specified data ; Syntax.........: _GraphGDIPlus_Create($hWnd,$iLeft,$iTop,$iWidth,$iHeight,$hColorBorder = 0xFF000000,$hColorFill = 0xFFFFFFFF) ; Parameters ....: $hWnd - Handle to GUI ; $iLeft - left most position in GUI ; $iTop - top most position in GUI ; $iWidth - width of graph in pixels ; $iHeight - height of graph in pixels ; $hColorBorder - Color of graph border (ARGB) ; $hColorFill - Color of background (ARGB) ; Return values .: Returns array containing variables for subsequent functions... ; Returned Graph array is: ; [1] graphic control handle ; [2] left ; [3] top ; [4] width ; [5] height ; [6] x low ; [7] x high ; [8] y low ; [9] y high ; [10] x ticks handles ; [11] x labels handles ; [12] y ticks handles ; [13] y labels handles ; [14] Border Color ; [15] Fill Color ; [16] Bitmap Handle ; [17] Backbuffer Handle ; [18] Last used x pos ; [19] Last used y pos ; [20] Pen (main) Handle ; [21] Brush (fill) Handle ; [22] Pen (border) Handle ; [23] Pen (grid) Handle ; ======================================================================================= Func _GraphGDIPlus_Create($hWnd, $iLeft, $iTop, $iWidth, $iHeight, $hColorBorder = 0xFF000000, $hColorFill = 0xFFFFFFFF, $iSmooth = 2) Local $graphics, $bitmap, $backbuffer, $brush, $bpen, $gpen, $pen Local $ahTicksLabelsX[1] Local $ahTicksLabelsY[1] Local $ahTicksX[1] Local $ahTicksY[1] Local $aGraphArray[1] ;----- Set GUI transparency to SOLID (prevents GDI+ glitches) ----- ;WinSetTrans($hWnd, "", 255) - causes problems when more than 2 graphs used ;----- GDI+ Initiate ----- _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($hWnd) ;graphics area $bitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth + 1, $iHeight + 1, $graphics);buffer bitmap $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ;buffer area _GDIPlus_GraphicsSetSmoothingMode($backbuffer, $iSmooth) ;----- Set background Color ----- $brush = _GDIPlus_BrushCreateSolid($hColorFill) _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $iWidth, $iHeight, $brush) ;----- Set border Pen + color ----- $bpen = _GDIPlus_PenCreate($hColorBorder) _GDIPlus_PenSetEndCap($bpen, $GDIP_LINECAPROUND) ;----- Set Grid Pen + color ----- $gpen = _GDIPlus_PenCreate(0xFFf0f0f0) _GDIPlus_PenSetEndCap($gpen, $GDIP_LINECAPROUND) ;----- set Drawing Pen + Color ----- $pen = _GDIPlus_PenCreate() ;drawing pen initially black, user to set _GDIPlus_PenSetEndCap($pen, $GDIP_LINECAPROUND) _GDIPlus_GraphicsDrawRect($backbuffer, 0, 0, $iWidth, $iHeight, $pen) ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, $iLeft, $iTop, $iWidth + 1, $iHeight + 1) ;----- register redraw ----- GUIRegisterMsg(0x0006, "_GraphGDIPlus_ReDraw") ;0x0006 = win activate GUIRegisterMsg(0x0003, "_GraphGDIPlus_ReDraw") ;0x0003 = win move ;----- prep + load array ----- Dim $aGraphArray[24] = ["", $graphics, $iLeft, $iTop, $iWidth, $iHeight, 0, 1, 0, 1, _ $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $hColorBorder, $hColorFill, _ $bitmap, $backbuffer, 0, 0, $pen, $brush, $bpen, $gpen] ;----- prep re-draw array for all graphs created ----- ReDim $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) + 1] $aGraphGDIPlusaGraphArrayINTERNAL[UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1] = $aGraphArray Return $aGraphArray EndFunc ;==>_GraphGDIPlus_Create Func _GraphGDIPlus_ReDraw($hWnd) ;----- Allows redraw of the GDI+ Image upon window min/maximize ----- Local $i _WinAPI_RedrawWindow($hWnd, 0, 0, 0x0100) For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 If $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Then ContinueLoop _GraphGDIPlus_Refresh($aGraphGDIPlusaGraphArrayINTERNAL[$i]) Next EndFunc ;==>_GraphGDIPlus_ReDraw ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Delete ; Description ...: Deletes previously created graph and related ticks/labels ; Syntax.........: _GraphGDIPlus_Delete($hWnd,ByRef $aGraphArray) ; Parameters ....: $hWnd - GUI handle ; $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iKeepGDIPlus - if not zero, function will not _GDIPlus_Shutdown() ; ======================================================================================= Func _GraphGDIPlus_Delete($hWnd, ByRef $aGraphArray, $iKeepGDIPlus = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $ahTicksY, $ahTicksLabelsY, $i, $aTemp ;----- delete x ticks/labels ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next ;----- delete y ticks/labels ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next ;----- delete graphic control ----- _GDIPlus_GraphicsDispose($aGraphArray[17]) _GDIPlus_BitmapDispose($aGraphArray[16]) _GDIPlus_GraphicsDispose($aGraphArray[1]) _GDIPlus_BrushDispose($aGraphArray[21]) _GDIPlus_PenDispose($aGraphArray[20]) _GDIPlus_PenDispose($aGraphArray[22]) _GDIPlus_PenDispose($aGraphArray[23]) If $iKeepGDIPlus = 0 Then _GDIPlus_Shutdown() _WinAPI_InvalidateRect($hWnd) ;----- remove form global redraw array ----- For $i = 1 To UBound($aGraphGDIPlusaGraphArrayINTERNAL) - 1 $aTemp = $aGraphGDIPlusaGraphArrayINTERNAL[$i] If IsArray($aTemp) = 0 Then ContinueLoop If $aTemp[1] = $aGraphArray[1] Then $aGraphGDIPlusaGraphArrayINTERNAL[$i] = 0 Next ;----- close array ----- $aGraphArray = 0 EndFunc ;==>_GraphGDIPlus_Delete ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Clear ; Description ...: Clears graph content ; Syntax.........: _GraphGDIPlus_Clear(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================= Func _GraphGDIPlus_Clear(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- Set background Color ----- _GDIPlus_GraphicsFillRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[21]) ;----- set border + Color ----- _GraphGDIPlus_RedrawRect($aGraphArray) EndFunc ;==>_GraphGDIPlus_Clear ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Refresh ; Description ...: refreshes the graphic ; Syntax.........: _GraphGDIPlus_Refresh(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; ======================================================================================== Func _GraphGDIPlus_Refresh(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw ----- _GDIPlus_GraphicsDrawImageRect($aGraphArray[1], $aGraphArray[16], $aGraphArray[2], _ $aGraphArray[3], $aGraphArray[4] + 1, $aGraphArray[5] + 1) EndFunc ;==>_GraphGDIPlus_Refresh ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeX ; Description ...: Allows user to set the range of the X axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray,$iLow,$iHigh,$iXTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the X axis (can be negative) ; $iHigh - the highest value for the X axis ; $iXTicks - [optional] number of ticks to show below axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeX(ByRef $aGraphArray, $iLow, $iHigh, $iXTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksX, $ahTicksLabelsX, $i ;----- load user vars to array ----- $aGraphArray[6] = $iLow $aGraphArray[7] = $iHigh ;----- prepare nested array ----- $ahTicksX = $aGraphArray[10] $ahTicksLabelsX = $aGraphArray[11] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksX) - 1) GUICtrlDelete($ahTicksX[$i]) Next Dim $ahTicksX[1] ;----- create new ticks ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksX[$i + 1] $ahTicksX[$i] = GUICtrlCreateLabel("", (($i - 1) * ($aGraphArray[4] / $iXTicks)) + $aGraphArray[2], _ $aGraphArray[3] + $aGraphArray[5], 1, 5) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlDelete($ahTicksLabelsX[$i]) Next Dim $ahTicksLabelsX[1] ;----- create new labels ----- For $i = 1 To $iXTicks + 1 ReDim $ahTicksLabelsX[$i + 1] $ahTicksLabelsX[$i] = GUICtrlCreateLabel("", _ ($aGraphArray[2] + (($aGraphArray[4] / $iXTicks) * ($i - 1))) - (($aGraphArray[4] / $iXTicks) / 2), _ $aGraphArray[3] + $aGraphArray[5] + 10, $aGraphArray[4] / $iXTicks, 13, 1) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsX) - 1) GUICtrlSetData($ahTicksLabelsX[$i], _ StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", (($i - 1) * ($aGraphArray[4] / $iXTicks)), _ $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[10] = $ahTicksX $aGraphArray[11] = $ahTicksLabelsX EndFunc ;==>_GraphGDIPlus_Set_RangeX ; #FUNCTION# ============================================================================ ; Name...........: _GraphGDIPlus_Set_RangeY ; Description ...: Allows user to set the range of the Y axis and set ticks and rounding levels ; Syntax.........: _GraphGDIPlus_SetRange_Y(ByRef $aGraphArray,$iLow,$iHigh,$iYTicks = 1,$bLabels = 1,$iRound = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iLow - the lowest value for the Y axis (can be negative) ; $iHigh - the highest value for the Y axis ; $iYTicks - [optional] number of ticks to show next to axis, if = 0 then no ticks created ; $bLabels - [optional] 1=show labels, any other number=do not show labels ; $iRound - [optional] rounding level of label values ; ======================================================================================= Func _GraphGDIPlus_Set_RangeY(ByRef $aGraphArray, $iLow, $iHigh, $iYTicks = 1, $bLabels = 1, $iRound = 0) If IsArray($aGraphArray) = 0 Then Return Local $ahTicksY, $ahTicksLabelsY, $i ;----- load user vars to array ----- $aGraphArray[8] = $iLow $aGraphArray[9] = $iHigh ;----- prepare nested array ----- $ahTicksY = $aGraphArray[12] $ahTicksLabelsY = $aGraphArray[13] ;----- delete any existing ticks ----- For $i = 1 To (UBound($ahTicksY) - 1) GUICtrlDelete($ahTicksY[$i]) Next Dim $ahTicksY[1] ;----- create new ticks ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksY[$i + 1] $ahTicksY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 5, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)), 5, 1) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetState(-1, 128) Next ;----- delete any existing labels ----- For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlDelete($ahTicksLabelsY[$i]) Next Dim $ahTicksLabelsY[1] ;----- create new labels ----- For $i = 1 To $iYTicks + 1 ReDim $ahTicksLabelsY[$i + 1] $ahTicksLabelsY[$i] = GUICtrlCreateLabel("", $aGraphArray[2] - 40, _ ($aGraphArray[3] + $aGraphArray[5]) - (($aGraphArray[5] / $iYTicks) * ($i - 1)) - 6, 30, 13, 2) GUICtrlSetBkColor(-1, -2) Next ;----- if labels are required, then fill ----- If $bLabels = 1 Then For $i = 1 To (UBound($ahTicksLabelsY) - 1) GUICtrlSetData($ahTicksLabelsY[$i], StringFormat("%." & $iRound & "f", _GraphGDIPlus_Reference_Pixel("p", _ (($i - 1) * ($aGraphArray[5] / $iYTicks)), $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]))) Next EndIf ;----- load created arrays back into array ----- $aGraphArray[12] = $ahTicksY $aGraphArray[13] = $ahTicksLabelsY EndFunc ;==>_GraphGDIPlus_Set_RangeY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Start ; Description ...: Move starting point of plot ; Syntax.........: _GraphGDIPlus_Plot_Start(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to start at ; $iY - y value to start at ; ======================================================================================== Func _GraphGDIPlus_Plot_Start(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- MOVE pen to start point ----- $aGraphArray[18] = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $aGraphArray[19] = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) EndFunc ;==>_GraphGDIPlus_Plot_Start ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Line ; Description ...: draws straight line to x,y from previous point / starting point ; Syntax.........: _GraphGDIPlus_Plot_Line(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw to ; $iY - y value to draw to ; ======================================================================================== Func _GraphGDIPlus_Plot_Line(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw line from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) ;~ _GDIPlus_GraphicsDrawLine($aGraphArray[17], $aGraphArray[18], $aGraphArray[19], $iX, $iY, $aGraphArray[20]) DllCall($ghGDIPDll, "int", "GdipDrawLine", "handle", $aGraphArray[17], "handle", $aGraphArray[20], "float", $aGraphArray[18], "float", $aGraphArray[19], "float", $iX, "float", $iY) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Line ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Point ; Description ...: draws point at coords ; Syntax.........: _GraphGDIPlus_Plot_Point(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Point(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) ;~ _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX-1, $iY-1, 2, 2, $aGraphArray[20]) DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $aGraphArray[17], "handle", $aGraphArray[20], "float", $iX-1, "float", $iY-1,"float", 2, "float", 2) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Point ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Plot_Dot ; Description ...: draws single pixel dot at coords ; Syntax.........: _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray,$iX,$iY) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iX - x value to draw at ; $iY - y value to draw at ; ======================================================================================== Func _GraphGDIPlus_Plot_Dot(ByRef $aGraphArray, $iX, $iY) If IsArray($aGraphArray) = 0 Then Return ;----- Draw point from previous point to new point ----- $iX = _GraphGDIPlus_Reference_Pixel("x", $iX, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]) $iY = _GraphGDIPlus_Reference_Pixel("y", $iY, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]) ;~ _GDIPlus_GraphicsDrawRect($aGraphArray[17], $iX, $iY, 1, 1, $aGraphArray[20]) ;draws 2x2 dot ?HOW to get 1x1 pixel????? DllCall($ghGDIPDll, "int", "GdipDrawRectangle", "handle", $aGraphArray[17], "handle", $aGraphArray[20], "float", $iX, "float", $iY,"float", 1, "float", 1) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- save current as last coords ----- $aGraphArray[18] = $iX $aGraphArray[19] = $iY EndFunc ;==>_GraphGDIPlus_Plot_Dot ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenColor ; Description ...: sets the Color for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray,$hColor,$hBkGrdColor = $GUI_GR_NOBKColor) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $hColor - the Color of the next item (ARGB) ; ======================================================================================== Func _GraphGDIPlus_Set_PenColor(ByRef $aGraphArray, $hColor) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen Color ----- _GDIPlus_PenSetColor($aGraphArray[20], $hColor) EndFunc ;==>_GraphGDIPlus_Set_PenColor ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenSize ; Description ...: sets the pen for the next drawing ; Syntax.........: _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray,$iSize = 1) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iSize - size of pen line ; ======================================================================================== Func _GraphGDIPlus_Set_PenSize(ByRef $aGraphArray, $iSize = 1) If IsArray($aGraphArray) = 0 Then Return ;----- apply pen size ----- _GDIPlus_PenSetWidth($aGraphArray[20], $iSize) EndFunc ;==>_GraphGDIPlus_Set_PenSize ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_PenDash ; Description ...: sets the pen dash style for the next drawing ; Syntax.........: GraphGDIPlus_Set_PenDash(ByRef $aGraphArray,$iDash = 0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $iDash - style of dash, where: ; 0 = solid line ; 1 = simple dashed line ; 2 = simple dotted line ; 3 = dash dot line ; 4 = dash dot dot line ; ======================================================================================== Func _GraphGDIPlus_Set_PenDash(ByRef $aGraphArray, $iDash = 0) If IsArray($aGraphArray) = 0 Then Return Local $Style Switch $iDash Case 0 ;solid line _____ $Style = $GDIP_DASHSTYLESOLID Case 1 ;simple dash ----- $Style = $GDIP_DASHSTYLEDASH Case 2 ;simple dotted ..... $Style = $GDIP_DASHSTYLEDOT Case 3 ;dash dot -.-.- $Style = $GDIP_DASHSTYLEDASHDOT Case 4 ;dash dot dot -..-..-.. $Style = $GDIP_DASHSTYLEDASHDOTDOT EndSwitch ;----- apply pen dash ----- _GDIPlus_PenSetDashStyle($aGraphArray[20], $Style) EndFunc ;==>_GraphGDIPlus_Set_PenDash ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridX ; Description ...: Adds X gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorY0 - [optional] RGB value, defining Color of Y=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridX(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorY0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[6] To $aGraphArray[7] Step $Ticks If $i = Number($aGraphArray[6]) Or $i = Number($aGraphArray[7]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", $i, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) Next EndSelect ;----- draw y=0 ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorY0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridX ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Set_GridY ; Description ...: Adds Y gridlines. ; Syntax.........: _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks=1, $hColor=0xf0f0f0) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; $Ticks - sets line at every nth unit assigned to axis ; $hColor - [optional] RGB value, defining Color of grid. Default is a light gray ; $hColorX0 - [optional] RGB value, defining Color of X=0 line, Default black ; ======================================================================================= Func _GraphGDIPlus_Set_GridY(ByRef $aGraphArray, $Ticks = 1, $hColor = 0xFFf0f0f0, $hColorX0 = 0xFF000000) If IsArray($aGraphArray) = 0 Then Return ;----- Set gpen to user color ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;----- draw grid lines ----- Select Case $Ticks > 0 For $i = $aGraphArray[8] To $aGraphArray[9] Step $Ticks If $i = Number($aGraphArray[8]) Or $i = Number($aGraphArray[9]) Then ContinueLoop _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", $i, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) Next EndSelect ;----- draw abcissa/ordinate ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColorX0) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ 1, _ _GraphGDIPlus_Reference_Pixel("x", 0, $aGraphArray[6], $aGraphArray[7], $aGraphArray[4]), _ $aGraphArray[5] - 1, _ $aGraphArray[23]) _GDIPlus_GraphicsDrawLine($aGraphArray[17], _ 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[4] - 1, _ _GraphGDIPlus_Reference_Pixel("y", 0, $aGraphArray[8], $aGraphArray[9], $aGraphArray[5]), _ $aGraphArray[23]) _GraphGDIPlus_RedrawRect($aGraphArray) ;----- re-set to user specs ----- _GDIPlus_PenSetColor($aGraphArray[23], $hColor) ;set Color back to user def EndFunc ;==>_GraphGDIPlus_Set_GridY ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_RedrawRect ; Description ...: INTERNAL FUNCTION - Re-draws the border ; Syntax.........: _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) ; Parameters ....: $aGraphArray - the array returned from _GraphGDIPlus_Create ; Notes..........: This prevents drawing over the border of the graph area ; ========================================================================================= Func _GraphGDIPlus_RedrawRect(ByRef $aGraphArray) If IsArray($aGraphArray) = 0 Then Return ;----- draw border ----- _GDIPlus_GraphicsDrawRect($aGraphArray[17], 0, 0, $aGraphArray[4], $aGraphArray[5], $aGraphArray[22]) ;draw border EndFunc ;==>_GraphGDIPlus_RedrawRect ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_Reference_Pixel ; Description ...: INTERNAL FUNCTION - performs pixel reference calculations ; Syntax.........: _GraphGDIPlus_Reference_Pixel($iType,$iValue,$iLow,$iHigh,$iTotalPixels) ; Parameters ....: $iType - "x"=x axis pix, "y" = y axis pix, "p"=value from pixels ; $iValue - pixels reference or value ; $iLow - lower limit of axis ; $iHigh - upper limit of axis ; $iTotalPixels - total number of pixels in range (either width or height) ; ========================================================================================= Func _GraphGDIPlus_Reference_Pixel($iType, $iValue, $iLow, $iHigh, $iTotalPixels) ;----- perform pixel reference calculations ----- Switch $iType Case "x" Return (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow)))) Case "y" Return ($iTotalPixels - (($iTotalPixels / ($iHigh - $iLow)) * (($iHigh - $iLow) * (($iValue - $iLow) / ($iHigh - $iLow))))) Case "p" Return ($iValue / ($iTotalPixels / ($iHigh - $iLow))) + $iLow EndSwitch EndFunc ;==>_GraphGDIPlus_Reference_Pixel ; #FUNCTION# ============================================================================= ; Name...........: _GraphGDIPlus_SaveImage ; Description ...: INTERNAL FUNCTION - save drawn image to file ; Syntax.........: _GraphGDIPlus_SaveImage($aGraphArray, $file) ; Parameters ....: ByRef $aGraphArray - the array returned from _GraphGDIPlus_Create ; $file - filename ; Autor .........: UEZ ; ========================================================================================= Func _GraphGDIPlus_SaveImage(ByRef $aGraphArray, $file) If IsArray($aGraphArray) = 0 Then Return _GDIPlus_ImageSaveToFile($aGraphArray[16], $file) If @error Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_GraphGDIPlus_SaveImage Func _GraphGDIPlus_DrawText(ByRef $aGraphArray, $sString, $iX, $iY, $iBrushColor = 0xFF000000, $sFont = "Arial", $iFontSize = 12, $iStyle = 0) If IsArray($aGraphArray) = 0 Then Return Local $hBrush = _GDIPlus_BrushCreateSolid($iBrushColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iStyle) Local $tLayout = _GDIPlus_RectFCreate($iX, $iY, 0, 0) _GDIPlus_GraphicsDrawStringEx($aGraphArray[17], $sString, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) Return 1 EndFunc ;==>_GraphGDIPlus_DrawText and add this line _GraphGDIPlus_DrawText($Graph, "Gamma Function in real time", 0, 0) to the example code in _Draw_Graph() function Func _Draw_Graph() ;----- Set line color and size ----- _GraphGDIPlus_Set_PenColor($Graph,0xFF325D87) _GraphGDIPlus_Set_PenSize($Graph,2) ;----- draw lines ----- $First = True _GraphGDIPlus_DrawText($Graph, "Gamma Function in real time", 0, 0) For $i = -5 to 5 Step 0.05 $y = _GammaFunction($i) If $First = True Then _GraphGDIPlus_Plot_Start($Graph,$i,$y) $First = False _GraphGDIPlus_Plot_Line($Graph,$i,$y) _GraphGDIPlus_Refresh($Graph) Next EndFunc Br, UEZ1 point
-
Another GDI+ atempts: one bar chart with legend, one simple pie and one exploded pie: #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GDIPlus.au3> #include <Array.au3> Opt('MustDeclareVars', 1) _GDIPlus_Startup() _Example() Func _Example() ;data array (some random values) Local $aValues[11][3] $aValues[0][0] = 10 Local $iM = 40 For $i = 1 To UBound($aValues) - 1 $aValues[$i][0] = "Grade " & $i $aValues[$i][1] = Random(0, $iM, 1) Next Local $sImg $sImg = _3D_PieChart($aValues, "Example 3D Pie Chart", $aValues[0][0] & " values array with random values [0..." & $iM & "]", True);exploded=True $sImg = _3D_PieChart($aValues, "Example 3D Pie Chart", $aValues[0][0] & " values array with random values [0..." & $iM & "]");simple $sImg = _3D_BarChart($aValues, "Example 3D Pie Chart", "10 values array with random values [0..." & $iM & "]") Local $iYes = MsgBox(36,"Simple 3D Chart Example", "Press Yes if you want to open the generated PNG's"&@CRLF&"or No otherwise."&@CRLF&"It will generate 3 images.") Switch $iYes Case 6 ShellExecute($sImg) Case 7 _Exit() EndSwitch EndFunc ;==>_Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _3D_BarChart ; Description ...: ; Syntax ........: _3D_BarChart($aArray[, $sTitle = "Main title"[, $sSubTitle = "Subtitle"[, $iW = 500[, $iH = 350[, ; $lBgColor = 0x80efefef]]]]]) ; Parameters ....: $aArray - An array of data ; |[i][0]=Label, ; |[i][1]=Value, ; |[i][2]=Colour. ; $sTitle - [optional] Title of the graph. Default is "Main title". ; $sSubTitle - [optional] Subtitle of the graph. Default is "Subtitle". ; $iW - [optional] Width of the canvas. Default is 500. ; $iH - [optional] Height of the canvas. Default is 350. ; $lBgColor - [optional] Background colour. Default is 0x80efefef. ; $sFolder - [optional] Folder path (without the leading "") where the images are saved. Default is @ScriptDir. ; Return values .: Image full path ; Return values .: None ; Author ........: Mihai Iancu (taietel at yahoo dot com) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _3D_BarChart($aArray, $sTitle = "Main title", $sSubTitle = "Subtitle", $iW = 500, $iH = 350, $lBgColor = 0x80efefef, $sFolder="") If $sFolder="" Then $sFolder=@ScriptDir Local $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $iDepth = 30 Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW + 120, "int", $iH + 50, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $hGraphic = _GDIPlus_ImageGetGraphicsContext($aResult[6]) _GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;create canvas $hBrush = _GDIPlus_BrushCreateSolid($lBgColor) Local $hPen = _GDIPlus_PenCreate(0x70101080) Local $aPoints[5][2] $aPoints[0][0] = 4 $aPoints[1][0] = 0 $aPoints[1][1] = 0 $aPoints[2][0] = $iW + 119 $aPoints[2][1] = 0 $aPoints[3][0] = $iW + 119 $aPoints[3][1] = $iH + 49 $aPoints[4][0] = 0 $aPoints[4][1] = $iH + 49 _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush) _GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints, $hPen) _GDIPlus_PenDispose($hPen) Local $iMax = 0, $iMin = 0 For $i = 1 To $aArray[0][0] If $iMax < $aArray[$i][1] Then $iMax = _Round($aArray[$i][1]) If $iMin > $aArray[$i][1] Then $iMin = $aArray[$i][1] $aArray[$i][2] = "0xFA" & Hex((Random(80, 190, 1) * 0x10000) + (Random(80, 190, 1) * 0x100) + Random(30, 190, 1), 6) Next Local $iFH = Floor($iH / 28) $hBrush = _GDIPlus_BrushCreateSolid(0xF0EF0000) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $x = ($iH + $iDepth - 60) / $aArray[0][0] If $x < 20 Then $hFont = _GDIPlus_FontCreate($hFamily, 8, 0) Else $hFont = _GDIPlus_FontCreate($hFamily, 10, 0) EndIf _GDIPlus_BrushSetSolidColor($hBrush, 0xf8efefcc) ;create bars For $j = 1 To $aArray[0][0] Local $iInalt = Int($aArray[$j][1] * ($iH - 2 * $iDepth) / $iMax) For $i = 0 To Int(2 * $iDepth / 3) Step 0.5 If $i = Int(2 * $iDepth / 3) Then _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0x111111) Else _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2]) EndIf If $aArray[$j][1] <> 0 Then _GDIPlus_GraphicsFillRect($hGraphic, $iDepth - $i + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + $i - $iInalt - $iDepth + 30, Int(Floor(($iW - $iDepth) / $aArray[0][0]) - 10), $iInalt, $hBrush) Else _GDIPlus_GraphicsFillRect($hGraphic, $iDepth - $i + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + $i - $iDepth + 26, Int(Floor(($iW - $iDepth) / $aArray[0][0]) - 10), 4, $hBrush) EndIf Next _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0xd5222222) If $aArray[$j][1] <> 0 Then $tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + Int(2 * $iDepth / 3) - $iInalt - $iDepth + 12, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH) Else $tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 10, $iH + Int(2 * $iDepth / 3) - $iDepth + 8, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH) EndIf _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0xe0111111) If $aArray[$j][1] <> 0 Then $tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 9, $iH + Int(2 * $iDepth / 3) - $iInalt - $iDepth + 11, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH) Else $tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]) + 9, $iH + Int(2 * $iDepth / 3) - $iDepth + 7, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH) EndIf _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush) Next ;title _GDIPlus_StringFormatSetAlign($hFormat, 1) $hFont = _GDIPlus_FontCreate($hFamily, 12, 0) _GDIPlus_BrushSetSolidColor($hBrush, 0x8fdedede) $tLayout = _GDIPlus_RectFCreate(1, 10, $iW + 116, 20) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0xee950000) $tLayout = _GDIPlus_RectFCreate(0, 10 - 1, $iW + 115, 20) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush) ;subtitle $hFont = _GDIPlus_FontCreate($hFamily, 10, 0) _GDIPlus_BrushSetSolidColor($hBrush, 0xFFb00000) $tLayout = _GDIPlus_RectFCreate(1, 28, $iW + 115, 20) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFont, $tLayout, $hFormat, $hBrush) If $x < 20 Then $hFont = _GDIPlus_FontCreate($hFamily, 6, 0) Else $hFont = _GDIPlus_FontCreate($hFamily, 8, 0) EndIf For $i = 1 To $aArray[0][0] _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$i][2]) _GDIPlus_GraphicsFillRect($hGraphic, $iW + 20, 50 + ($i - 1) * $x, 20, $x - 2, $hBrush) _GDIPlus_StringFormatSetAlign($hFormat, 0) _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$i][2]) $tLayout = _GDIPlus_RectFCreate($iW + 45, 50 + Int($x / 3.5) + ($i - 1) * $x, 70, $x - 2) _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$i][0], $hFont, $tLayout, $hFormat, $hBrush) Next Local $sImage = $sFolder & "" & $sTitle & "_bars.png" _GDIPlus_ImageSaveToFile($aResult[6], $sImage) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($aResult[6]) _GDIPlus_GraphicsDispose($hGraphic) Return $sImage EndFunc ;==>_3D_BarChart ; #FUNCTION# ==================================================================================================================== ; Name ..........: _3D_PieChart ; Description ...: ; Syntax ........: _3D_PieChart($aArray[, $sTitle = "Main title"[, $sSubTitle = "Subtitle"[, $bExplode = False[, $iW = 500[, ; $iH = 400[, $lBgColor = 0x80efefef]]]]]]) ; Parameters ....: $aArray - An array of data ; |[i][0]=Label, ; |[i][1]=Value, ; |[i][2]=Colour. ; $sTitle - [optional] Title of the graph. Default is "Main title". ; $sSubTitle - [optional] Subtitle of the graph. Default is "Subtitle". ; $bExplode - [optional] True if exploded pie, otherwise False. Default is False. ; $iW - [optional] Width of the canvas. Default is 500. ; $iH - [optional] Height of the canvas. Default is 400. ; $lBgColor - [optional] Background colour. Default is 0x80efefef. ; $sFolder - [optional] Folder path (without the leading "") where the images are saved. Default is @ScriptDir. ; Return values .: Image full path ; Author ........: Mihai Iancu (taietel at yahoo dot com) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _3D_PieChart($aArray, $sTitle = "Main title", $sSubTitle = "Subtitle", $bExplode = False, $iW = 500, $iH = 400, $lBgColor = 0x80efefef, $sFolder="") If $sFolder="" Then $sFolder=@ScriptDir Local $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $iDepth = 30 Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW + 1, "int", $iH + 50, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) $hGraphic = _GDIPlus_ImageGetGraphicsContext($aResult[6]) _GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;create canvas $hBrush = _GDIPlus_BrushCreateSolid($lBgColor) Local $aPoints[5][2] $aPoints[0][0] = 4 $aPoints[1][0] = 0 $aPoints[1][1] = 0 $aPoints[2][0] = $iW $aPoints[2][1] = 0 $aPoints[3][0] = $iW $aPoints[3][1] = $iH + $iDepth $aPoints[4][0] = 0 $aPoints[4][1] = $iH + $iDepth _GDIPlus_GraphicsFillPolygon($hGraphic, $aPoints, $hBrush) Local $hPen = _GDIPlus_PenCreate(0x70101080) _GDIPlus_GraphicsDrawPolygon($hGraphic, $aPoints, $hPen) _GDIPlus_PenDispose($hPen) Local $iMax = 0, $iMin = 0 Local $iSum For $i = 1 To $aArray[0][0] If $iMax < $aArray[$i][1] Then $iMax = _Round($aArray[$i][1]) If $iMin > $aArray[$i][1] Then $iMin = $aArray[$i][1] $iSum += $aArray[$i][1] $aArray[$i][2] = "0xFA" & Hex((Random(80, 190, 1) * 0x10000) + (Random(80, 190, 1) * 0x100) + Random(30, 190, 1), 6) Next _GDIPlus_BrushSetSolidColor($hBrush, 0xF0EF0000) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) $hFamily = _GDIPlus_FontFamilyCreate("Arial") ;title _GDIPlus_StringFormatSetAlign($hFormat, 1) $hFont = _GDIPlus_FontCreate($hFamily, 12, 0) _GDIPlus_BrushSetSolidColor($hBrush, 0x8fdedede) $tLayout = _GDIPlus_RectFCreate(1, 10, $iW - 4, 20) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0xee950000) $tLayout = _GDIPlus_RectFCreate(0, 9, $iW - 5, 20) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush) ;subtitle $hFont = _GDIPlus_FontCreate($hFamily, 10, 0) _GDIPlus_BrushSetSolidColor($hBrush, 0xFFb00000) $tLayout = _GDIPlus_RectFCreate(1, 28, $iW - 5, 20) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFont, $tLayout, $hFormat, $hBrush) Local $iInit = 5 For $i = 0 To $iDepth Step 0.5 For $j = 1 To $aArray[0][0] Local $iAng = ($aArray[$j][1] * 360 / $iSum) If $i > $iDepth - 1 Then _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] - $i * 0x202020) Else _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0x111111) EndIf If $bExplode Then _GDIPlus_GraphicsFillPie($hGraphic, $iDepth, 110 - $i, $iW - 2 * $iDepth - 120, $iH - 2 * $iDepth / 1.2 - 78, $iInit, $iAng - 4, $hBrush) Else _GDIPlus_GraphicsFillPie($hGraphic, $iDepth, 110 - $i, $iW - 2 * $iDepth - 120, $iH - 2 * $iDepth / 1.2 - 78, $iInit, $iAng, $hBrush) EndIf $iInit += $iAng Next Next #cs ;labels around the pie - still need some math adjustments... Local $pi = 3.14159265358979, $iAngle $iInit = 5 For $i = 1 To $aArray[0][0] $iAng = ($aArray[$i][1] * 360 / $iSum) Local $iRw = ($iW - 2 * $iDepth - 120) / 2 + 12.5 Local $iRh = ($iH - 2 * $iDepth / 1.2 - 78) / 2 +23 If $bExplode Then $iAngle = Round(($iInit + ($iAng-2) / 2) * $pi / 180,1) Else $iAngle = Round(($iInit + $iAng / 2) * $pi / 180,1) EndIf ;if we have 0 value, skip it: If $aArray[$i][1] <> 0 Then _GDIPlus_GraphicsDrawString($hGraphic, $aArray[$i][1], _ Round($iRw * (Cos($iAngle) + 1))+$iDepth-20, _ Round($iRh * (Sin($iAngle) + 1))+50+$iDepth-15, _ "Arial", 8, $hFormat) $iInit += $iAng Next #ce ;legend Local $x = Int(($iH - $iDepth - 20) / $aArray[0][0]) If $x < 20 Then $hFont = _GDIPlus_FontCreate($hFamily, 6, 0) Else $hFont = _GDIPlus_FontCreate($hFamily, 8, 0) EndIf For $j = 1 To $aArray[0][0] For $i = 0 To 3 Step 0.5 If $i < 2.5 Then _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] - 0x111111) Else _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0x202020) EndIf _GDIPlus_GraphicsFillRect($hGraphic, $iW - 110 - 2 * $i, 60 + ($j - 1) * $x + $i, 30, $x - 5, $hBrush) Next Next ;value label on the small cube in the legend For $j = 1 To $aArray[0][0] _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2] + 0xee333333) $tLayout = _GDIPlus_RectFCreate($iW - 113, 64 + ($j - 1) * $x + Int($x / 5), 30, $x - 2) _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0xee222222) $tLayout = _GDIPlus_RectFCreate($iW - 114, 63 + ($j - 1) * $x + Int($x / 5), 30, $x - 2) _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_StringFormatSetAlign($hFormat, 0) _GDIPlus_BrushSetSolidColor($hBrush, $aArray[$j][2]) $tLayout = _GDIPlus_RectFCreate($iW - 70, 60 + ($j - 1) * $x + Int($x / 5), 119, $x - 2) _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][0], $hFont, $tLayout, $hFormat, $hBrush) Next ;save the image Local $sImage If $bExplode Then $sImage = $sFolder & "" & $sTitle & "_expie.png" Else $sImage = $sFolder & "" & $sTitle & "_pie.png" EndIf _GDIPlus_ImageSaveToFile($aResult[6], $sImage) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BitmapDispose($aResult[6]) _GDIPlus_GraphicsDispose($hGraphic) Return $sImage EndFunc ;==>_3D_PieChart Func _Exit() _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit Func _Round($iNumber) If IsNumber($iNumber) Then $iNumber = Round(Ceiling($iNumber / 10) * 10, -1) Return $iNumber EndFunc ;==>_Round In the 3D_Pie function I have comented the part that writes the values around the pie. You can delete the #cs and #ce to see the results, but still needs some thinking. The script above outputs tree images (png) because I need them to be included in pdf reports. If you need to display on a GUI, just draw them with _GDIPlus_GraphicsDrawImageRectRect.1 point
-
engjcowi, I'm sorry for the delay but I had (and still do) a lot of work. Due to the fact that this example uses a lot of static controls (labels), when updating the whole chart is relatively slowly drawn. Here is an example with GDI that updates the chart every second, and the images are saved for later use (png format): #include <GuiConstantsEx.au3> #include <GDIPlus.au3> #include <Array.au3> Opt('MustDeclareVars', 1) _GDIPlus_Startup() _Example() While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit EndSwitch WEnd Func _Example() ;data array (some random values) Local $aValues[11][3] $aValues[0][0] = 10 Local $hGUI = GUICreate("3D Bar Chart in AutoIt (GDI+ style) - 2011 taietel", 420, 300) GUISetState() For $m=1 To 5 For $i = 1 To UBound($aValues) - 1 $aValues[$i][1] = Random(0, 100, 1) Next _3D_BarChart($hGUI, $aValues, "Example Chart no."&$m, "GDI+ attempt...") Sleep(1000) Next EndFunc ;==>_Main Func _3D_BarChart($hGUI, $aArray, $sTitle = "Main title", $sSubTitle = "Subtitle", $iX = 10, $iY = 10, $iW = 400, $iH = 280, $iDepth = 30, $lBgColor = 0x80cacafe) ;coded by taietel Local $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) If @error Then Return SetError(@error, @extended, 0) Local $hBmpBuff = $aResult[6] $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBmpBuff) _GDIPlus_GraphicsClear($hGraphic, 0x00FFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2) ;create canvas Local $hBgBrush = _GDIPlus_BrushCreateSolid($lBgColor) For $i = 0 To $iDepth Step 0.5 _GDIPlus_GraphicsFillRect($hGraphic, $i, $iDepth - $i, $iW - $iDepth, $iH - $iDepth, $hBgBrush) _GDIPlus_BrushSetSolidColor($hBgBrush, $lBgColor) Next Local $hPen = _GDIPlus_PenCreate(0xF0808080) _GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, 0, $iW, 0, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, $iH - $iDepth, $iW, $iH - $iDepth, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, 0, $iH - 1, $iW - $iDepth, $iH - 1, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, 0, 0, $iDepth, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, $iH - $iDepth, 0, $iH, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iW, $iH - $iDepth, $iW - $iDepth, $iH, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, 0, $iH, 0, $iDepth, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iDepth, $iH - $iDepth, $iDepth, 0, $hPen) _GDIPlus_GraphicsDrawLine($hGraphic, $iW - 1, 0, $iW - 1, $iH - $iDepth, $hPen) Local $iMax = 0, $iMin = 0 For $i = 1 To $aArray[0][0] If $iMax < $aArray[$i][1] Then $iMax = $aArray[$i][1] If $iMin > $aArray[$i][1] Then $iMin = $aArray[$i][1] Next Local $iFH = Floor($iH / 28) $hBrush = _GDIPlus_BrushCreateSolid(0xF0EF0000) $hFormat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hFormat, 1) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 8) _GDIPlus_BrushSetSolidColor($hBrush, 0xf8efefcc) ;create bars For $j = 1 To $aArray[0][0] $aArray[$j][2] = "0xFA" & Hex((Random(100, 180, 1) * 0x10000) + (Random(90, 140, 1) * 0x100) + Random(0, 150, 1), 6) Local $iInalt = Int($aArray[$j][1] * ($iH - $iDepth) / $iMax) For $i = 0 To Int(2 * $iDepth / 3) Step 0.5 If $i = Int(2 * $iDepth / 3) Then _GDIPlus_BrushSetSolidColor($hBgBrush, $aArray[$j][2] + 0x111111) Else _GDIPlus_BrushSetSolidColor($hBgBrush, $aArray[$j][2]) EndIf _GDIPlus_GraphicsFillRect($hGraphic, $iDepth - $i + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]), $iH + $i - $iInalt - $iDepth + 10, Int(Floor(($iW - $iDepth) / $aArray[0][0]) - 10), $iInalt - 4, $hBgBrush) Next _GDIPlus_StringFormatSetAlign($hFormat, 1) $tLayout = _GDIPlus_RectFCreate(Int($iDepth / 3) + ($j - 1) * Floor(($iW - $iDepth) / $aArray[0][0]), $iH + Int(2 * $iDepth / 3) - $iInalt - $iDepth - 10, Int($iDepth / 3) + Floor(($iW - $iDepth) / $aArray[0][0]), 2 * $iFH) _GDIPlus_GraphicsDrawStringEx($hGraphic, $aArray[$j][1], $hFont, $tLayout, $hFormat, $hBrush) Next _GDIPlus_StringFormatSetAlign($hFormat, 2) $hFont = _GDIPlus_FontCreate($hFamily, $iFH + 1, 0) _GDIPlus_BrushSetSolidColor($hBrush, 0xFF232323) $tLayout = _GDIPlus_RectFCreate(1, 5 - 1, $iW - 5, 2 * $iFH) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x55fefefe) $tLayout = _GDIPlus_RectFCreate(0, 5, $iW - 5, 2 * $iFH) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sTitle, $hFont, $tLayout, $hFormat, $hBrush) Local $hFontl = _GDIPlus_FontCreate($hFamily, $iFH - 1, 0) _GDIPlus_BrushSetSolidColor($hBrush, 0xFF444444) $tLayout = _GDIPlus_RectFCreate(1, 5 + Floor(2 * $iFH) - 1, $iW - 5, 2 * $iFH) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFontl, $tLayout, $hFormat, $hBrush) _GDIPlus_BrushSetSolidColor($hBrush, 0x55fefefe) $tLayout = _GDIPlus_RectFCreate(0, 5 + Floor(2 * $iFH), $iW - 5, 2 * $iFH) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sSubTitle, $hFontl, $tLayout, $hFormat, $hBrush) Local $sImage = @ScriptDir & "\" & $sTitle & ".png";save it in case it is needed _GDIPlus_ImageSaveToFile($hBmpBuff, $sImage) Local $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRectRect($hGraphicGUI, $hBmpBuff, 0, 0, $iW, $iH, $iX, $iY, $iW, $iH) ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_FontDispose($hFontl) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_PenDispose($hPen) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBgBrush) _GDIPlus_BitmapDispose($hBmpBuff) _GDIPlus_GraphicsDispose($hGraphicGUI) _GDIPlus_GraphicsDispose($hGraphic) Return $sImage EndFunc ;==>_3D_BarChart You can modify to fit your needs. Regards, taietel1 point
-
@engjcowi: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <Array.au3> Global $arNames[12] Global $arValues[12] GUICreate("3D Bar Graph on Tabs - Example", 610, 410) GUICtrlCreateTab(5, 5, 600, 400) $Tab1 = GUICtrlCreateTabItem("Tab1") $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December","|",2) For $i=0 To 11 $arValues[$i]=Random(0,200,1) Next _CreateBarChart("3D Bar Chart","Example 1",-1,30,560,360) $Tab2 = GUICtrlCreateTabItem("Tab2") For $i=0 To 11 $arNames[$i]=$i+1 Next For $i=0 To 11 $arValues[$i]=Random(0,200,1) Next _CreateBarChart("3D Bar Chart","Example 2",50,50,400,300) $Tab3 = GUICtrlCreateTabItem("Tab3") ReDim $arNames[16] ReDim $arValues[16] For $i=0 To 15 $arNames[$i]=$i+1 Next For $i=0 To 15 $arValues[$i]=Random(0,200,1) Next $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December|a|b|c|d","|",2) _CreateBarChart("3D Bar Chart","Example 3 - with legend",30,30,560,360) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; #FUNCTION# ==================================================================================================== ; Name...........: _CreateBarChart ; Description....: Create 3D bar graph with native AutoIt functions ; Syntax.........: _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400) ; Parameters.....: $sTitle1 - Title of the graph, [Optional] ; $sTitle2 - Subtitle of the graph, [Optional] ; $iX - left margin, [Optional] ; $iY - top margin, [Optional] ; $iW - width of the graph, [Optional] ; $iH - height of the graph, [Optional] ; ; Return values..: none ; Version........: 2 ; Author.........: Mihai Iancu (taietel at yahoo dot com) ; =============================================================================================================== Func _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400) Local $max=_ArrayMax($arValues,1);compare numerically ;Local $values = UBound($arValues) Local $arColours[UBound($arNames)] Local $color For $i=0 To UBound($arValues)-1 $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1) $arColours[$i]=$color Next ;set default values for the frame If $iX=-1 Then $iX=20 If $iY=-1 Then $iY=20 If $iW=-1 Then $iW=400 If $iH=-1 Then $iH=400 ;create frame for the chart $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH) ;title GUICtrlCreateLabel($sTitle1,$iX+15, $iY+10,$iW-30,-1,$SS_CENTER) GUICtrlSetColor(-1,0x002244) GUICtrlSetFont(-1, 9, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateLabel($sTitle2,$iX+15, $iY+25,$iW-30,-1,$SS_CENTER) GUICtrlSetColor(-1,0x002244) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Local $Canvas If IsString($arNames[1]) Then $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-110, $iH-60) GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5) For $i=0 To UBound($arNames)-1 GUICtrlCreateLabel($arNames[$i],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($arNames))*$i,($iW-$Canvas[2])/2-30,13,$SS_CENTER) GUICtrlSetColor(-1,$arColours[$i]-0x444444) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$arColours[$i]) Next GUICtrlCreateGroup("", -99, -99, 1, 1) Else $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60) For $i=0 To UBound($arNames)-1 GUICtrlCreateLabel($arNames[$i],$iX+52+(($Canvas[2]/UBound($arNames)))*$i+5, $iY+$iH-30) GUICtrlSetColor(-1,0x990000) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next EndIf ;draw the bars GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0) For $i=0 To UBound($arValues)-1 For $j=$Canvas[4]/2.5 To 0 Step -0.5 GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i]-0x333333, $arColours[$i]) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5+($Canvas[2]/UBound($arValues))*$i+$j, -2+$Canvas[3]-$j, 0.6*($Canvas[2]/UBound($arValues)), -($Canvas[3]/_RoundUp($max))*$arValues[$i]) GUICtrlSetState(-1,2048) Next Next GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) For $i=0 To UBound($arValues)-1 ;values from the top of the bars GUICtrlCreateLabel($arValues[$i],$iX+50+($Canvas[2]/UBound($arValues))*$i + $Canvas[4]/2.5 + 0.3*($Canvas[2]/UBound($arValues)), $iY+35+$Canvas[3]+ $Canvas[4]/2.5 -($Canvas[3]/_RoundUp($max))*$arValues[$i]) GUICtrlSetColor(-1,0x002244) GUICtrlSetFont(-1, 7, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next ;Y Axis For $i=0 To $Canvas[3] Step $Canvas[3]/5 GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT) GUICtrlSetColor(-1,0x990000) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next GUICtrlCreateGroup("", -99, -99, 1, 1) EndFunc #Region INTERNAL USE ONLY Func _RoundUp($m) Local $rv = Round(Ceiling($m/10)*10,-1) Return $rv EndFunc Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=30, $BgColor=0xEEEEEE) Local $iXCanvas=$iX+$iDepthCanvas Local $iYCanvas=$iY+10+2*$iDepthCanvas Local $iWCanvas=$iW-2*$iDepthCanvas Local $iHCanvas=$iH-2*$iDepthCanvas Local $BgColor2 = $BgColor - 0x333333 ;create bg for the bars For $i=0 To $iDepthCanvas GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0) GUICtrlSetBkColor(-1, $BgColor) GUICtrlSetColor(-1, $BgColor2) GUICtrlSetState(-1,2048) Next GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor) GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1) GUICtrlSetState(-1,2048) ;horizontal grid For $i=0 To $iHCanvas Step $iHCanvas/5 GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2) GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i) GUICtrlSetState(-1,2048) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor) GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas) GUICtrlSetState(-1,2048) Next Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2) Return $Canvas EndFunc #EndRegion INTERNAL USE ONLY1 point
-
Isakizada, try now: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <Array.au3> Global $arNames[12] Global $arValues[12] Example1() Func Example1() Local $gui = GUICreate("Example 1: 3D Bar Graph - left=20 (default) top=40", 850, 700) GUISetBkColor(0xffffff) $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December","|",2) For $i=0 To 11 $arValues[$i]=Random(0,200,1) Next _CreateBarChart("3D Bar Chart","Example 1",-1,40,500,400) GUISetState() While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($gui) Example2() EndSwitch WEnd EndFunc Func Example2() Local $gui = GUICreate("Example 2: 3D Bar Graph - Chart at different position", 650, 550) GUISetBkColor(0xffffff) For $i=0 To 11 $arNames[$i]=$i+1 Next For $i=0 To 11 $arValues[$i]=Random(0,200,1) Next _CreateBarChart("3D Bar Chart","Example 2",50,20,400,450) GUISetState() While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($gui) Example3() EndSwitch WEnd EndFunc Func Example3() ReDim $arNames[16] ReDim $arValues[16] Local $gui = GUICreate("Example 3: 3D Bar Graph - Two charts at different positions", 950, 750) GUISetBkColor(0xffffff) For $i=0 To 15 $arNames[$i]=$i+1 Next For $i=0 To 15 $arValues[$i]=Random(0,200,1) Next _CreateBarChart("3D Bar Chart","Example 3 - without legend",50,80,400,500) $arNames=StringSplit("January|February|March|April|May|June|July|August|September|October|November|December|a|b|c|d","|",2) _CreateBarChart("3D Bar Chart","Example 3 - with legend",500,100,400,600) GUISetState() While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($gui) ;Example3() Exit EndSwitch WEnd EndFunc ; #FUNCTION# ==================================================================================================== ; Name...........: _CreateBarChart ; Description....: Create 3D bar graph with native AutoIt functions ; Syntax.........: _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400) ; Parameters.....: $sTitle1 - Title of the graph, [Optional] ; $sTitle2 - Subtitle of the graph, [Optional] ; $iX - left margin, [Optional] ; $iY - top margin, [Optional] ; $iW - width of the graph, [Optional] ; $iH - height of the graph, [Optional] ; ; Return values..: none ; Version........: 2 ; Author.........: Mihai Iancu (taietel at yahoo dot com) ; =============================================================================================================== Func _CreateBarChart($sTitle1="",$sTitle2="",$iX=20,$iY=20,$iW=400,$iH=400) Local $max=_ArrayMax($arValues,1);compare numerically ;Local $values = UBound($arValues) Local $arColours[UBound($arNames)] Local $color For $i=0 To UBound($arValues)-1 $color = (Random(100, 255, 1) * 0x10000) + (Random(100, 255, 1) * 0x100) + Random(100, 255, 1) $arColours[$i]=$color Next ;set default values for the frame If $iX=-1 Then $iX=20 If $iY=-1 Then $iY=20 If $iW=-1 Then $iW=400 If $iH=-1 Then $iH=400 ;create frame for the chart $grp = GUICtrlCreateGroup("", $iX, $iY, $iW, $iH) ;title GUICtrlCreateLabel($sTitle1,$iX+15, $iY+10,$iW-30,-1,$SS_CENTER) GUICtrlSetColor(-1,0x002244) GUICtrlSetFont(-1, 9, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateLabel($sTitle2,$iX+15, $iY+25,$iW-30,-1,$SS_CENTER) GUICtrlSetColor(-1,0x002244) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Local $Canvas If IsString($arNames[1]) Then $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-110, $iH-60) GUICtrlCreateGroup("Legend", $Canvas[0]+$Canvas[2]+10, $Canvas[1]-5, ($iW-$Canvas[2])/2-10, $Canvas[3]+$Canvas[4]+5) For $i=0 To UBound($arNames)-1 GUICtrlCreateLabel($arNames[$i],$Canvas[0]+$Canvas[2]+20, $Canvas[1]+10+(($Canvas[3]+$Canvas[4]-15)/UBound($arNames))*$i,($iW-$Canvas[2])/2-30,13,$SS_CENTER) GUICtrlSetColor(-1,$arColours[$i]-0x444444) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$arColours[$i]) Next GUICtrlCreateGroup("", -99, -99, 1, 1) Else $Canvas = _CreateBarCanvas($iX+15, $iY+15, $iW-50, $iH-60) For $i=0 To UBound($arNames)-1 GUICtrlCreateLabel($arNames[$i],$iX+52+(($Canvas[2]/UBound($arNames)))*$i+5, $iY+$iH-30) GUICtrlSetColor(-1,0x990000) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next EndIf ;draw the bars GUICtrlCreateGraphic($Canvas[0]-0.5*$Canvas[4], $Canvas[1]+0.5*$Canvas[4], $Canvas[2], $Canvas[3],0) For $i=0 To UBound($arValues)-1 For $j=$Canvas[4]/2.5 To 0 Step -0.5 GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $arColours[$i]-0x333333, $arColours[$i]) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 5+($Canvas[2]/UBound($arValues))*$i+$j, -2+$Canvas[3]-$j, 0.6*($Canvas[2]/UBound($arValues)), -($Canvas[3]/_RoundUp($max))*$arValues[$i]) Next Next GUICtrlSetGraphic(-1,$GUI_GR_REFRESH) For $i=0 To UBound($arValues)-1 ;values from the top of the bars GUICtrlCreateLabel($arValues[$i],$iX+50+($Canvas[2]/UBound($arValues))*$i + $Canvas[4]/2.5 + 0.3*($Canvas[2]/UBound($arValues)), $iY+35+$Canvas[3]+ $Canvas[4]/2.5 -($Canvas[3]/_RoundUp($max))*$arValues[$i]) GUICtrlSetColor(-1,0x002244) GUICtrlSetFont(-1, 7, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next ;Y Axis For $i=0 To $Canvas[3] Step $Canvas[3]/5 GUICtrlCreateLabel(($i/$Canvas[3])*_RoundUp($max),$Canvas[0]-65,$Canvas[1]+$Canvas[3]+$Canvas[4]-$i,30,-1,$SS_RIGHT) GUICtrlSetColor(-1,0x990000) GUICtrlSetFont(-1, 8, 800, 0, "Arial") GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) Next GUICtrlCreateGroup("", -99, -99, 1, 1) EndFunc #Region INTERNAL USE ONLY Func _RoundUp($m) Local $rv = Round(Ceiling($m/10)*10,-1) Return $rv EndFunc Func _CreateBarCanvas($iX=0, $iY=0, $iW=400, $iH=400, $iDepthCanvas=30, $BgColor=0xEEEEEE) Local $iXCanvas=$iX+$iDepthCanvas Local $iYCanvas=$iY+10+2*$iDepthCanvas Local $iWCanvas=$iW-2*$iDepthCanvas Local $iHCanvas=$iH-2*$iDepthCanvas Local $BgColor2 = $BgColor - 0x333333 ;create bg for the bars For $i=0 To $iDepthCanvas GUICtrlCreateGraphic($iXCanvas+$i, $iYCanvas-$i, $iWCanvas, $iHCanvas, 0) GUICtrlSetBkColor(-1, $BgColor) GUICtrlSetColor(-1, $BgColor2) Next GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $iHCanvas) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor) GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas-1, $iHCanvas+$iDepthCanvas+1) ;horizontal grid For $i=0 To $iHCanvas Step $iHCanvas/5 GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor2) GUICtrlSetGraphic(-1, $GUI_GR_LINE, $iWCanvas, $i) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $i) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $BgColor) GUICtrlSetGraphic(-1, $GUI_GR_LINE, -$iDepthCanvas, $i+$iDepthCanvas) Next Local $Canvas = StringSplit($iXCanvas+$iDepthCanvas &"|"& $iYCanvas-$iDepthCanvas&"|"&$iWCanvas&"|"&$iHCanvas&"|"&$iDepthCanvas,"|",2) Return $Canvas EndFunc #EndRegion INTERNAL USE ONLY1 point
-
When you create control on the Tab by UDF function (_GUICtrlCreate) and not by internal AutoIt's function (GUICtrlCreate) you must show/hide this control yourself. #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <IPAddressConstants.au3> #include <TabConstants.au3> #include <GuiIPAddress.au3> #include <GuiTab.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 593, 453, 193, 115) $Tab1 = GUICtrlCreateTab(16, 24, 521, 385) $hTab = GUICtrlGetHandle($Tab1) GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) $TabSheet1 = GUICtrlCreateTabItem("TabSheet1") $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 56, 112, 130, 21) _GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0") $TabSheet2 = GUICtrlCreateTabItem("TabSheet2") $MyButton1 = GUICtrlCreateButton("MyButton1", 104, 120, 100, 30, 0) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $fValid $hWndTab = $hTab $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTab Switch $iCode Case $TCN_SELCHANGE If _GUICtrlTab_GetCurSel($hTab) = 0 Then ; zero based index of current selected TabItem _GUICtrlIpAddress_ShowHide ($IPAddress1, @SW_SHOW) Else _GUICtrlIpAddress_ShowHide ($IPAddress1, @SW_HIDE) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Core of solution is to catch $TCN_SELCHANGE notification - when selection changes and show/hide what you want. Here is original post by Gary which I used as start for my example. http://www.autoitscript.com/forum/index.ph...st&p=4211341 point
-
The code was based upon folder names in your first post, which does work, however it appears you want to sort by hierarchy maybe? So can you try: Local $aFolderPath, $x = 0 Local $aFolderPaths = _FileListToArrayRec(@ScriptDir, "*", 2, 1, 1, 2) _ArrayColInsert($aFolderPaths, 1) For $i = 1 To $aFolderPaths[0][0] $aFolderPath = StringSplit($aFolderPaths[$i][0], "\") If $aFolderPaths[$i - 1][1] = $aFolderPath[0] & "." & $x Then $x += 1 $aFolderPaths[$i][1] = $aFolderPath[0] & "." & $x Else $x = 0 $aFolderPaths[$i][1] = $aFolderPath[0] & "." & $x EndIf Next _ArraySort($aFolderPaths, 1, 1, 0, 1) _ArrayDisplay($aFolderPaths)0 points