Jump to content

armoros

Active Members
  • Posts

    500
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Like
    armoros got a reaction from PoojaKrishna in Error Get path by PID   
    Hi Dany

    I find also these helpful

    From SmOke_n

    $PID = Run("notepad.exe") WinWaitActive("") MsgBox(0x0,"PID/Path", _PidGetPath($PID)) Func _PidGetPath($pid = "", $strComputer = 'localhost') If $pid = "" Then $pid = WinGetProcess(WinGetTitle("")) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $objItem.ExecutablePath Then Return $objItem.ExecutablePath Next EndIf EndFunc ;==>_PidGetPath
    And this
    This it, and propose the


    #include <Array.au3> $aProcListEx = _ProcessListEx() $yourExe = "jqs.exe" If @error Then MsgBox(48, "_ProcessListEx - Error", StringFormat("There was an error to get ProcessList (@error = %i)", @error)) Else For $i = 1 to $aProcListEx[0][0] If $aProcListEx[$i][0] = $yourExe Then $Version = FileGetVersion($aProcListEx[$i][4],"FileVersion") MsgBox(0,"","Path to '" & $YourExe & "' is '" & $aProcListEx[$i][5] & "'" & @CRLF & "File Version is: " & $Version) EndIf Next EndIf ;=============================================================================== ; ; Function Name: _ProcessListEx() ; ; Function Description: Gets Process List with extended info, plus can retrieve only a processes with specific resources strings. ; ; Parameter(s): $sResourceName [Optional] - Resource name of the process filename, i.e. "CompiledScript". ; $sInResString [Optional] - String to check in the resource name. ; $iWholeWord [Optional] - Defines if the $sInResString will be compared as whole string (default is 1). ; ; Requirement(s): None. ; ; Return Value(s): On Success - Return 2-dimentional array, where: ; $aRet_List[0][0] = Total processes (array elements). ; $aRet_List[N][0] = Process Name. ; $aRet_List[N][6] = PID (Process ID). ; $aRet_List[N][7] = Process File Path. ; On Failure - Return '' (empty string) and set @error to: ; 1 - Unable to Open Kernel32.dll. ; 2 - Unable to Open Psapi.dll. ; 3 - No Processes Found. ; ; Author(s): G.Sandler (a.k.a MrCreatoR) - CreatoR's Lab (http://creator-lab.ucoz.ru) ; ;===================================================================== Func _ProcessListEx($sResourceName="", $sInResString="", $iWholeWord=1) Local $aProcList = ProcessList() Local $hKernel32_Dll = DllOpen('Kernel32.dll'), $hPsapi_Dll = DllOpen('Psapi.dll') Local $aOpenProc, $aProcPath, $sFileVersion, $aRet_List[1][8] If $hKernel32_Dll = -1 Then Return SetError(1, 0, '') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@SystemDir & 'Psapi.dll') If $hPsapi_Dll = -1 Then $hPsapi_Dll = DllOpen(@WindowsDir & 'Psapi.dll') If $hPsapi_Dll = -1 Then Return SetError(2, 0, '') Local $vStruct = DllStructCreate('int[1024]') Local $pStructPtr = DllStructGetPtr($vStruct) Local $iStructSize = DllStructGetSize($vStruct) For $i = 1 To UBound($aProcList)-1 $aOpenProc = DllCall($hKernel32_Dll, 'hwnd', 'OpenProcess', _ 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $aProcList[$i][9]) If Not IsArray($aOpenProc) Or Not $aOpenProc[0] Then ContinueLoop DllCall($hPsapi_Dll, 'int', 'EnumProcessModules', _ 'hwnd', $aOpenProc[0], _ 'ptr', $pStructPtr, _ 'int', $iStructSize, _ 'int_ptr', 0) $aProcPath = DllCall($hPsapi_Dll, 'int', 'GetModuleFileNameEx', _ 'hwnd', $aOpenProc[0], _ 'int', DllStructGetData($vStruct, 1), _ 'str', '', _ 'int', 2048) If Not IsArray($aProcPath) Or StringLen($aProcPath[3]) = 0 Then ContinueLoop $sFileVersion = FileGetVersion($aProcPath[3], $sResourceName) If $sResourceName = "" Or $sFileVersion = $sInResString Or _ ($iWholeWord = 0 And StringInStr($sFileVersion, $sInResString)) Then $aRet_List[0][0] += 1 ReDim $aRet_List[$aRet_List[0][0]+1][3] $aRet_List[$aRet_List[0][0]][0] = $aProcList[$i][0] ;Process Name $aRet_List[$aRet_List[0][0]][10] = $aProcList[$i][11] ;PID (Process ID) $aRet_List[$aRet_List[0][0]][12] = $aProcPath[3] ;Process File Path EndIf Next DllClose($hKernel32_Dll) DllClose($hPsapi_Dll) If $aRet_List[0][0] < 1 Then Return SetError(3, 0, '') Return $aRet_List EndFunc
  2. Like
    armoros reacted to FireFox in Winpcap filter and TCP/UDP packet splitter   
    Hi,
    I have worked on a project for a friend and it needed to retreive some data in UDP packets, it was a challenge because I didn't know anything about that packets, and after few days of work I have managed to do what I wanted.

    The hardest part was to set a very strict filter for the cpu usage and for the script optimisation, so here is one :

    ;use filters with _PcapStartCapture ;retreive only tcp packets containing AABBCCDD, at the start of 8 and with a length of 4; like the StringMid func. tcp[8:4] == 0xAABBCCDD ;8th byte from the beginning of the tcp DATA, 4bytes length; always include the 0x to specify you are dealing with hex.
    And some funcs to split the different data from packets :

    ;$hCapture is the handle returned by _PcapStartCapture ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCP_Recv ; Description ...: Retreives a TCP Packet and returns its data splitted ; Syntax.........: _TCP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) ; Parameters ....: $hCapture - Capture handle ; $iInstance - Instance of the packet to retreive ; $iTimeOut - Timeout ; Return values .: Success - Array containing the packet data ; Failure - -1 (timedout) ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: _UDP_Recv ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TCP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) Local $blPacketCaptured = False, $iTimer_Capture, $aPacket, $iPacket $iTimer_Capture = TimerInit() While (TimerDiff($iTimer_Capture) < $iTimeOut Or $iTimeOut = -1) $aPacket = _PcapGetPacket($hCapture) If IsArray($aPacket) Then If $iPacket = $iInstance Then Local $aTCPPacket[21] $aTCPPacket[0] = StringMid($aPacket[3], 3, 12) ;Destination Mac Address $aTCPPacket[1] = StringMid($aPacket[3], 15, 12) ;Source Mac Address $aTCPPacket[2] = StringMid($aPacket[3], 27, 4) ;Type $aTCPPacket[3] = StringMid($aPacket[3], 31, 2) ;Version & Header length $aTCPPacket[4] = StringMid($aPacket[3], 33, 2) ;Differientiated Services Field $aTCPPacket[5] = StringMid($aPacket[3], 35, 4) ;Total Length $aTCPPacket[6] = StringMid($aPacket[3], 39, 4) ;Identification $aTCPPacket[7] = StringMid($aPacket[3], 43, 4) ;Fragment offset $aTCPPacket[8] = StringMid($aPacket[3], 47, 2) ;Time to live $aTCPPacket[9] = StringMid($aPacket[3], 49, 2) ;Protocol $aTCPPacket[10] = StringMid($aPacket[3], 51, 4) ;Header checksum $aTCPPacket[11] = StringMid($aPacket[3], 55, 8) ;Source IP Address $aTCPPacket[12] = StringMid($aPacket[3], 63, 8) ;Destination IP Address $aTCPPacket[13] = StringMid($aPacket[3], 71, 4) ;Source port $aTCPPacket[14] = StringMid($aPacket[3], 75, 4) ;Destination port $aTCPPacket[15] = StringMid($aPacket[3], 79, 8) ;Sequence number $aTCPPacket[16] = StringMid($aPacket[3], 87, 8) ;Acknowledgment number $aTCPPacket[17] = StringMid($aPacket[3], 95, 4) ;Flags $aTCPPacket[18] = StringMid($aPacket[3], 99, 4) ;Window size value $aTCPPacket[19] = StringMid($aPacket[3], 103, 4) ;Checksum ;107 to 110 = NULL data $aTCPPacket[20] = StringTrimLeft($aPacket[3], 110) ;Data Return $aTCPPacket EndIf $iPacket += 1 EndIf Sleep(50) WEnd Return -1 EndFunc ;==>_TCP_Recv ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDP_Recv ; Description ...: Retreives an UDP Packet and returns its data splitted ; Syntax.........: _UDP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) ; Parameters ....: $hCapture - Capture handle ; $iInstance - Instance of the packet to retreive ; $iTimeOut - Timeout ; Return values .: Success - Array containing the packet data ; Failure - -1 (timedout) ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: _TCP_Recv ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _UDP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) Local $blPacketCaptured = False, $iTimer_Capture, $aPacket, $iPacket $iTimer_Capture = TimerInit() While (TimerDiff($iTimer_Capture) < $iTimeOut Or $iTimeOut = -1) $aPacket = _PcapGetPacket($hCapture) If IsArray($aPacket) Then If $iPacket = $iInstance Then Local $aUDPPacket[18] $aUDPPacket[0] = StringMid($aPacket[3], 3, 12) ;Source Mac Address $aUDPPacket[1] = StringMid($aPacket[3], 15, 12) ;Destination Mac Address $aUDPPacket[2] = StringMid($aPacket[3], 27, 4) ;Type $aUDPPacket[3] = StringMid($aPacket[3], 31, 2) ;Version & Header length $aUDPPacket[4] = StringMid($aPacket[3], 33, 2) ;Differientiated Services Field $aUDPPacket[5] = StringMid($aPacket[3], 35, 4) ;Total Length $aUDPPacket[6] = StringMid($aPacket[3], 39, 4) ;Identification $aUDPPacket[7] = StringMid($aPacket[3], 43, 4) ;Fragment offset $aUDPPacket[8] = StringMid($aPacket[3], 47, 2) ;Time to live $aUDPPacket[9] = StringMid($aPacket[3], 49, 2) ;Protocol $aUDPPacket[10] = StringMid($aPacket[3], 51, 4) ;Header checksum $aUDPPacket[11] = StringMid($aPacket[3], 55, 8) ;Source IP Address $aUDPPacket[12] = StringMid($aPacket[3], 63, 8) ;Destination IP Address $aUDPPacket[13] = StringMid($aPacket[3], 71, 4) ;Source port $aUDPPacket[14] = StringMid($aPacket[3], 75, 4) ;Destination port $aUDPPacket[15] = StringMid($aPacket[3], 79, 4) ;Length $aUDPPacket[16] = StringMid($aPacket[3], 83, 4) ;Checksum $aUDPPacket[17] = StringTrimLeft($aPacket[3], 86) ;Data Return $aUDPPacket EndIf $iPacket += 1 EndIf Sleep(50) WEnd Return -1 EndFunc ;==>_UDP_Recv ;for example convert the packet's source/dest IP Address to text ; #FUNCTION# ==================================================================================================================== ; Name...........: _HexIPAddressToText ; Description ...: Converts Hex IP Adress to text ; Syntax.........: _HexIPAddressToText($vhexIPAddress) ; Parameters ....: $vIPAddress - IP Address v4 (string, int) ; Return values .: Success - Converted IP Address ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _HexIPAddressToText($vhexIPAddress) Local $sIPAddress For $iOffset = 1 To 8 Step 2 $sIPAddress &= Dec(StringMid($vhexIPAddress, $iOffset, 2)) & "." Next Return StringTrimRight($sIPAddress, 1) EndFunc ;==>_UDP_DecodeIPAddress
    Ops, almost forgot the Winpcap UDF available here : http://opensource.grisambre.net/pcapau3/

    PS : If you find this helpful, please "like"/rate this post.

    Enjoy
  3. Like
    armoros reacted to z0mgItsJohn in New & Improved TCP Chat   
    It's a multi-client TCP chat room with a lot of features.

    Server

    IP, Port, Set Pw sets the password for the admin.
    $Max = Max amount of users that can be connected at a time.

    Client

    IP, Port, Username.
    * A username can only be in use by one person. (Case-insensitive.)


    Normal commands

    .pm username,message
    Allows you to sent a private message to a specific user.

    .stats
    Tells you who's online.

    .clear
    Clears the history.

    .save
    Saves the chat history.

    .disconnect or .exit
    Closes the chat window, disconnects you from the server, and re-opens the Connection Settings.

    Admin commands

    .admin password, .admin lol123
    Logs you in as an admin. (Only one admin can be logged in at a time.)

    .logout
    Logs you out of the admin position.

    .kick username, .kick John
    Kicks the desired user.

    .ip username, .ip John
    Gives you the IP of the desired user.

    .ban username, .ban John
    Kicks and IP bans the user.

    .unban ip address, .unban 127.0.0.1
    Removes the IP from the blocked list.

    .logs
    Opens the logs from the server. (Tells you who you've banned / un-banned, and their IP.)

    Red = Command, Blue = Parameter

    Download Link : http://www.mediafire.com/?a9fegzx2qn0t38c *Includes compiled versions (32 and 64 bit) and the source.

    Hope this helps some!

    - John
  4. Like
    armoros reacted to batfastad in [SOLVED] GUICtrlGetState and GUICtrlSetState... Bitwise comparison   
    Don't worry! Solved by RTFM!

    The answer is yes, I should do bitwise comparison...

    If BitAND(GUICtrlRead($RadioOutputPNG), $GUI_CHECKED) Then
    EDIT:
    For completeness, if you want to check that a radio/checkbox is checked AND enabled then I think you need to do two different comparisons.

    I was expecting this to work but it doesn't...

    If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED, $GUI_ENABLE) ThenBecause GUICtrlRead() doesn't return the state for checkboxes.

    Instead you have to additionally check GUICtrlGetState()...

    If BitAND(GUICtrlRead($CheckboxText), $GUI_CHECKED) AND BitAND(GUICtrlGetState($CheckboxText), $GUI_ENABLE) Then
    This is something that I just fell into because of the wording in the help under GUICtrlRead()... http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm
    In the table under the "Return Value" section, the "Checkbox, Radio" row has a link to this table of states... http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm#StateTable
    By linking to that table in the return value on the GUICtrlRead() page, I assumed that all the items in that table of states would be valid return values for GUICtrlRead() but it turns out to not be the case.

    I'm not an expert so I might be wrong here and I would appreciate someone correcting me if I am wrong
    But I hope this helps someone out!

    Cheers, B
  5. Like
    armoros got a reaction from Xandy in [Solved] Edit box-Characters 30000-Lines 673 -Restriction ?   
    Yes it does work. I can have now 2000000 char. and 43739 lines

    #include #include #include #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Edit1 = GUICtrlCreateEdit("", 8, 16, 609, 409) GUICtrlSetLimit(-1, 2000000) ; sets the limit to 2000000 characters or you can put the maximum 2147483647 as user PhoenixXL sugests GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
  6. Like
    armoros reacted to FireFox in Upload a photo to google search by image   
    @gil900
    I'm not going to use the _IE UDF as long as in my opinion the browser sucks and It's not a furtive way to do it, which also sucks.

    I will use the WinHTTP UDF or the curl exe, or in "pure" autoit.

    Br, FireFox.
  7. Like
    armoros reacted to JohnOne in Glitch in Send command?   
    Here is your original code in a more structured way, will help you to learn further of what you already know.


    WinWaitActive("Order Text to Print on Order.") ;wait for the correct window to pop up Switch MsgBox(4, "Which Supplier?", "Is it other than Exp or CZ?") ;primary elimination Case 6 _Do_This_1() Case 7 Switch MsgBox(4, "Which Supplier?", "Is it Express?") ; secondary elimination Case 6 ; if it is express fabrications, then fill the window with info below _Do_This_2() Case 7 ;info to fill if the order is going to CZ _Do_This_3() EndSwitch EndSwitch Func _Do_This_1() Sleep(200) Send(".") Sleep(200) Send("{DOWN}") Sleep(200) Send(".") Sleep(200) Send("{DOWN}") Sleep(200) Send(".") Sleep(200) Send("{DOWN}") Sleep(200) Send("Daniel Tyrkiel") Send("{DOWN}") Send("01252 89 3363") EndFunc ;==>_Do_This_1 Func _Do_This_2() WinActivate("Order Text to Print on Order.") WinWaitActive("Order Text to Print on Order.") Sleep(200) Send(".") Send("{DOWN}") $var3 = InputBox("Input Works Order Number", "Input works order and customer") ; prompt for bespoke info WinActivate("Order Text to Print on Order.") WinWaitActive("Order Text to Print on Order.") Sleep(1000) Send($var3) Send("{DOWN}") Sleep(200) Send(".") Send("{DOWN}") Send("Daniel Tyrkiel") Send("{DOWN}") Send("01252 89 3363") EndFunc ;==>_Do_This_2 Func _Do_This_3() WinActivate("Order Text to Print on Order.") WinWaitActive("Order Text to Print on Order.") Sleep(200) Send(".") Send("{DOWN}") $var3 = InputBox("Input Works Order Number", "Input works order and week of completion") ; prompt for bespoke info WinActivate("Order Text to Print on Order.") WinWaitActive("Order Text to Print on Order.") Sleep(1000) Send($var3) Send("{DOWN}") Send(".") Send("{DOWN}") Send("Daniel Tyrkiel") Send("{DOWN}") Send("01252 89 3363") EndFunc ;==>_Do_This_3
  8. Like
    armoros reacted to guinness in How to Code with AutoIT [not a programmer at all]   
    Look at GUIGetMsg in the help file, as this will tell you how to monitor when a button or checkbox is selected. You will also need to look at GUICtrlRead to read the input boxes and finally search the forum for _IsChecked, as this will tell you whether or not a checkbox is selected.

    Good luck.

    Oh, my advice look at youtube as well as the wiki section for an array of tutorials. Plus, if you're not a programmer don't expect to learn all of this overnight, no matter how good you are no one is that quick. Start small and then work big and never give up at the first sign of trouble.
  9. Like
    armoros reacted to wakillon in TinyUninstaller v1.0.0.7 Update of 2012-09-03   
    TinyUninstaller v1.0.0.7

    Uninstall your softs easily



    TipText over labels display Infos.
    Hold Left Ctrl key when clicking on a label for copy uninstall cmd to the clipboard.
    Gui is hiden when you launch a soft uninstall.
    Once uninstall is finished double click on tray icon for restore gui ( softs list will be refresh )
    There is no filtering in softs display ( Not as Windows do ! ), like that, you can easily uninstall drivers or Microsoft Windows Components !
    but be carefull...

    x64 Users : Do not Compil with X64 Version.

    Previous downloads : 43

    Source : TinyUnInstaller v1.0.0.7.au3

    executable : TinyUninstaller.exe.html
    (Once this html file downloaded, double click on it for start the download)
  10. Like
    armoros reacted to stormbreaker in how to make a single exe portable from au3   
    Take a look at source code for making Virtual Box portable.
  11. Like
    armoros reacted to paullab in PStools Front End (for easy Remote control of PC's)   
    A front end for the PStools Collection FROM Mark Russinovich
    (or any other program / system administration tool it is you want to add)
    it expects the pstools programs and dll to be in the same directory as the script

    What you see as the command line is executed this means that
    if you wish to change the command sent then simply edit it and hit 'Go'


    Uses Event mode to keep the command line updated
    (Well all except the last control changed)
    this is why there is the Click Here in the header

    It is easy to add your own tools to this
    Simply add another TAB with required parameters on itAdd a tabname change function that sets the $PSCommandLine input box to the required value

    Known issues
    Event mode works well except for changes in the last field
    Not all parameters for all tools are catered for (Only those I use regularly) (but you can add them manually)
    Validation is still a little loose so you need to know a little about PStools
    Does not handle things very well when the progrm being run wants an enter keypress
    PSloglist has not been completed (OK, not even started)
    Does not save previously entered values

    Now includes a checkbox to accept the Microsoft EULA

    Have a Look at this post
    for the most recent includes required.
    http://www.autoitscript.com/forum/index.php?showtopic=36245&view=findpost&p=646185
    PSTools.au3
    PSToolsAcceptEULA.au3
  12. Like
    armoros reacted to nergmlam in RunAsWait   
    Hi

    Try to see if you get any errors in your commandline box:

    RunAsWait("TAP","greatlakesind","Ct5gLe", 0, @Comspec & " /K Copy J:KmanAA.PDF J:KmanLINXX.PDF","",@SW_MAXIMIZE)


    And please note the following.

    When using RunAs and RunAsWait you need to make sure, that the secondary logon service is running, and if you run your script from your own computer using e.g. pseexec.exe to get access to a remote computer, both computers must run the secondary logon service. And the secondary logon service needs the workstation service and netlogon service. The netlogon service only runs on domain computers, not on workgroup computers.

    You also needs to select a "@workingDir" for the functions, that the end user have write access to.

    Sincerely

    Jorgen Malmgren
    IT-Programmer
    Denmark - UTC+1
    www.tryware.dk

    ;o) Your brain is like a parachute. It works best when it's
  13. Like
    armoros reacted to Mat in Why do game developers prefer Windows?   
    Because steam is pretty cool. Makes it easier for us to spend money.
  14. Like
    armoros reacted to Skitty in Making smaller EXEs?   
    Assembly.

    Learn it. Use it. Die a spartan in the programming world.
  15. Like
    armoros reacted to AdmiralAlkex in Making smaller EXEs?   
    Remember that you only need 1 interpreter, if your package consists of multiple scripts, then compile 1 to exe and everything else to a3x and you'll save quite a bit.
  16. Like
    armoros reacted to LiquidNitrogen in Text Editor v2.8 (**Updated 7-7-12**)   
    This a Text Editor I Made to Be Like Notepad and it Turned out better than i thought it would.

    (Updated (7-7-12)
    +Added HotKeys
    +Added Misc. Options (All Caps, All Lowercase, Readonly
    +Moved Default and Custom Options to there own Menus Under Edit
    +Cleaned up Code a little Bit
    +Added Cut, Copy, And Paste to Edit Menu
    -There is still a small Bug with word wrap. When you turn it off it appears to be off but its not. (Adds Horizontal Scroll bar at bottom)
    +Im Currently working on a 'Run Script' Option and have added it under an 'Action' Menu but it is disabled.
    (Updated 7-3-12)
    +Added Word Wrap Option
    +Fixed Save Bug
    (Updated 6-29-12)
    +Fixed a compilation bug

    It Would be best to download the Archive and Extract the Script because some stuff is wierd when you copy the code and paste it into a Script. Like Hotkeys Being displayed in the Menus.

    #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icon.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIEdit.au3> #include <Misc.au3> #include <GUIStatusBar.au3> #include <GUIMenu.au3> #include <SendMessage.au3> ;Created by ReaperX FileCheck() Main() SetFileAttr() Func FileCheck() If FileExists(@ScriptDir & "/config.ini") Then $CE = IniReadSectionNames(@ScriptDir & "/config.ini") If $CE[0] > 0 Then For $i = 2 To $CE[0] If Not FileExists($CE[$i]) Then IniDelete(@ScriptDir & "/config.ini", $CE[$i]) Next EndIf Main() Else IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "11") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", "") EndIf Sleep(100) EndFunc ;==>FileCheck Func Main() Global Const $GUI_TITLE = "Text Editor v2.8" Global Const $GUI_STYLE = BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS) Local $Ext = ".au3 ,.bat ,.vbs ,.htm ,.html" ; Script Types Allowed to Be Executed (Only Extensions) If IniRead(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1") = 1 Then Global $EDIT_STYLE = BitOR($ES_WANTRETURN, $WS_VSCROLL) Else Global $EDIT_STYLE = $GUI_SS_DEFAULT_EDIT EndIf $Main = GUICreate($GUI_TITLE, 650, 280, -1, -1, $GUI_STYLE) GUISetIcon("Icon.ico") ;File Menu ======================================================================== $FileMenu = GUICtrlCreateMenu("File") $New = GUICtrlCreateMenuItem("New Ctrl+N", $FileMenu) HotKeySet("^n", "_New") $Open = GUICtrlCreateMenuItem("Open Ctrl+O", $FileMenu) HotKeySet("^o", "_Open") $Save = GUICtrlCreateMenuItem("Save Ctrl+S", $FileMenu) HotKeySet("^s", "_Save") $SaveAs = GUICtrlCreateMenuItem("Save As...", $FileMenu) GUICtrlCreateMenuItem("", $FileMenu) $Exit = GUICtrlCreateMenuItem("Exit", $FileMenu) ;================================================================================= ;View Menu ======================================================================= $ViewMenu = GUICtrlCreateMenu("View") $DocInfo = GUICtrlCreateMenuItem("Document Info", $ViewMenu) ;================================================================================= ;Action Menu ===================================================================== $ActionMenu = GUICtrlCreateMenu("Action") $Run = GUICtrlCreateMenuItem("Run Script", $ActionMenu) GUICtrlSetState($Run, $GUI_DISABLE) ;================================================================================= ;Edit Menu ======================================================================= $EditMenu = GUICtrlCreateMenu("Edit") $Undo = GUICtrlCreateMenuItem("Undo Ctrl+Z", $EditMenu, 0) HotKeySet("^z", "_Undo") GUICtrlCreateMenuItem("", $EditMenu, 1) $Cut = GUICtrlCreateMenuItem("Cut Ctrl+X", $EditMenu, 2) $Copy = GUICtrlCreateMenuItem("Copy Ctrl+C", $EditMenu, 3) $Paste = GUICtrlCreateMenuItem("Paste Ctrl+P", $EditMenu, 4) GUICtrlCreateMenuItem("", $EditMenu, 5) $Find = GUICtrlCreateMenuItem("Find... Ctrl+F", $EditMenu, 6) HotKeySet("^f", "_Find") GUICtrlCreateMenuItem("", $EditMenu, 7) ;Edit -> Default Settings Menu =================================================== Local $DefaultSett = GUICtrlCreateMenu("Default Settings", $EditMenu, 8) $DefaultFont = GUICtrlCreateMenuItem("Edit Default Font", $DefaultSett) $DefaultBGColor = GUICtrlCreateMenuItem("Edit Default BG Color", $DefaultSett) $ResetDefaults = GUICtrlCreateMenuItem("Reset Default Settings", $DefaultSett) ;================================================================================= GUICtrlCreateMenuItem("", $EditMenu, 9) ;Edit -> Custom Settings Menu ==================================================== Local $CustomSett = GUICtrlCreateMenu("Custom Settings", $EditMenu, 10) $CustomFont = GUICtrlCreateMenuItem("Set Custom Font", $CustomSett) GUICtrlSetState(-1, $GUI_DISABLE) $CustomBGColor = GUICtrlCreateMenuItem("Set Custom BG Color", $CustomSett) GUICtrlSetState(-1, $GUI_DISABLE) $EraseCustomOpt = GUICtrlCreateMenuItem("Erase Custom Settings", $CustomSett) GUICtrlSetState(-1, $GUI_DISABLE) ;================================================================================= GUICtrlCreateMenuItem("", $EditMenu, 11) $SetFileAttr = GUICtrlCreateMenuItem("Set File Attributes", $EditMenu, 12) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateMenuItem("", $EditMenu, 13) ;Edit -> Misc Options Menu ======================================================= $MiscOptions = GUICtrlCreateMenu("Misc. Options", $EditMenu, 14) Local $Readonly = GUICtrlCreateMenuItem("Readonly", $MiscOptions) GUICtrlSetState(-1, $GUI_UNCHECKED) $CAPS = GUICtrlCreateMenuItem("All Caps (Not CAPS Lock)", $MiscOptions) GUICtrlSetState(-1, $GUI_UNCHECKED) $LOWERCASE = GUICtrlCreateMenuItem("All Lowercase", $MiscOptions) GUICtrlSetState(-1, $GUI_UNCHECKED) ;================================================================================= $SelectAll = GUICtrlCreateMenuItem("Select All Ctrl+A", $EditMenu, 15) HotKeySet("^a", "_SelectAll") $TimeAndDate = GUICtrlCreateMenuItem("Insert Time/Date F7", $EditMenu, 16) HotKeySet("{F7}", "_TimeAndDate") $SpeakText = GUICtrlCreateMenuItem("Speak Highlighted Text", $EditMenu, 17) $WordWrap = GUICtrlCreateMenuItem("Word Wrap", $EditMenu, 18) If IniRead(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1") = 1 Then GUICtrlSetState(-1, $GUI_CHECKED) Else GUICtrlSetState(-1, $GUI_UNCHECKED) EndIf ;================================================================================= ;Help Menu ======================================================================= $HelpMenu = GUICtrlCreateMenu("Help") $About = GUICtrlCreateMenuItem("About", $HelpMenu, 1) $AboutCustomSett = GUICtrlCreateMenuItem("Custom Settings", $HelpMenu, 2) ;================================================================================= ;Create Edit Control =================================================================================== Global $Edit = GUICtrlCreateEdit("", 0, 0, 650, 238, $EDIT_STYLE) ;======================================================================================================= ;Create Status bar ============================================================ Local $Parts[1] = [70] Global $StatusBar = _GUICtrlStatusBar_Create($Main, $Parts, $SB_SIMPLEID) _GUICtrlStatusBar_SetParts($StatusBar, $Parts) _GUICtrlStatusBar_SetText($StatusBar, "New Document") ;============================================================================== If FileExists("temp") Then GUICtrlSetData(-1, FileRead("temp")) ;For When and If Main() Has to be Called again. It Restores the Text in $Edit. FileDelete("temp") EndIf GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")) GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")) GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")) GUISetState() GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 If FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) = GUICtrlRead($Edit) Then IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit Else $Confirm = MsgBox(35, "Confirm", "Do You Want To Save Before Exiting?") If $Confirm = 6 Then If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit EndIf $SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir) FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite($SaveDir, GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit EndIf EndIf EndIf If $Confirm = 7 Then IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit EndIf Case $New _New() Case $Open _Open() Case $DefaultBGColor $NewBG = _ChooseColor(2) If Not @error Then IniWrite(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", $NewBG) GUICtrlSetBkColor($Edit, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")) EndIf Case $DefaultFont $NewFont = _ChooseFont(IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), 0, 400, False, False, False, $Main) If Not @error Then IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontsize", $NewFont[3]) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "attributes", $NewFont[1]) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontweight", $NewFont[4]) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", $NewFont[7]) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontname", $NewFont[2]) GUICtrlSetFont($Edit, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")) GUICtrlSetColor($Edit, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")) EndIf Case $ResetDefaults IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "11") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0") IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", "") MsgBox(64, "Ok", "Default Settings Reset. Your Custom Options Were not Changed.") Case $SaveAs $SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then GUICtrlSetState($SetFileAttr, $GUI_ENABLE) GUICtrlSetState($CustomFont, $GUI_ENABLE) GUICtrlSetState($CustomBGColor, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir) $INI = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "") $GetExt = StringTrimLeft($INI, StringLen($INI) - 3) ; Get the Extension of the Currently Opened File If StringInStr($Ext, $GetExt) Then GUICtrlSetState($Run, $GUI_ENABLE) FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) GUICtrlSetState($Save, $GUI_ENABLE) _GUICtrlStatusBar_SetText($StatusBar, "Saving...") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") EndIf Case $Save _Save() Case $TimeAndDate _TimeAndDate() Case $SpeakText $SelText = _GUICtrlEdit_GetSel($Edit) If $SelText[1] = 0 Then MsgBox(16, "Error!", "Select Text First!") Else Global $Voice = ObjCreate("Sapi.SpVoice") SpeakSelectedText(0.5, 100) EndIf Case $About MsgBox(64, "About", "Text Editor" & @LF & @LF & "Version: 2.8" & @LF & @LF & "Created By ReaperX (C) 2011 - 2012") Case $Find _Find() Case $SelectAll _SelectAll() Case $DocInfo MsgBox(0, "Information", "Characters: " & _GUICtrlEdit_GetTextLen($Edit) & @LF & "Lines: " & _GUICtrlEdit_GetLineCount($Edit)) Case $Cut Send("^x") Case $Copy Send("^c") Case $Paste GUICtrlSetData($Edit, GUICtrlRead($Edit) & ClipGet()) Case $Exit If GUICtrlRead($Edit) = FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit Else $Confirm = MsgBox(35, "Confirm", "Do You Want To Save Before Exiting?") If $Confirm = 6 Then If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) Exit EndIf $SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir) FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite($SaveDir, GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit Else IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit EndIf EndIf EndIf If $Confirm = 7 Then IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") Exit EndIf Case $Undo _Undo() Case $CustomBGColor $iFile = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!") $NewBG = _ChooseColor(2) If Not @error Then GUICtrlSetState($EraseCustomOpt, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", $iFile, "bgcolor", $NewBG) GUICtrlSetBkColor($Edit, IniRead(@ScriptDir & "/config.ini", $iFile, "bgcolor", "0xFFFFFF")) _GUICtrlStatusBar_SetText($StatusBar, "Custom Background Color Options Saved!") Sleep(1000) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")) EndIf Case $CustomFont $iFile = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!") $NewFont = _ChooseFont(IniRead(@ScriptDir & "/config.ini", $iFile, "fontname", "Arial"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontsize", "11"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontcolor", "0x000000"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontweight", "400")) If Not @error Then GUICtrlSetState($EraseCustomOpt, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", $iFile, "fontname", $NewFont[2]) IniWrite(@ScriptDir & "/config.ini", $iFile, "fontsize", $NewFont[3]) IniWrite(@ScriptDir & "/config.ini", $iFile, "attributes", $NewFont[1]) IniWrite(@ScriptDir & "/config.ini", $iFile, "fontweight", $NewFont[4]) IniWrite(@ScriptDir & "/config.ini", $iFile, "fontcolor", $NewFont[7]) GUICtrlSetFont($Edit, IniRead(@ScriptDir & "/config.ini", $iFile, "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", $iFile, "attributes", "0"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontname", "Arial")) GUICtrlSetColor($Edit, IniRead(@ScriptDir & "/config.ini", $iFile, "fontcolor", "0x000000")) _GUICtrlStatusBar_SetText($StatusBar, "Custom Font Options Saved!") Sleep(1000) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")) EndIf Case $EraseCustomOpt $iFile = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!") IniDelete(@ScriptDir & "/config.ini", $iFile) GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")) GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")) GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")) GUICtrlSetState($EraseCustomOpt, $GUI_DISABLE) _GUICtrlStatusBar_SetText($StatusBar, "Custom File Options Erased!") Sleep(1000) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")) Case $SetFileAttr $Attr = FileGetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!")) If Not @error Then SetFileAttr() Else MsgBox(16, "Error!", "The File Attributes Could Not be Retrieved!") EndIf Case $AboutCustomSett MsgBox(0, "About Custom Settings", "Custom BG and Font Settings are for Specific Files. You can open a file and have a Specific Background and Font color set for that file and No other file. This Doesnt mess with Default Settings. Default Settings Load When the Application first Opens and When no Custom Settings are Set For Any Open File.") Case $WordWrap If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($WordWrap, $GUI_UNCHECKED) GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "0") Else GUICtrlSetState($WordWrap, $GUI_CHECKED) GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL)) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1") EndIf Case $CAPS If BitAND(GUICtrlRead($CAPS), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($CAPS, $GUI_UNCHECKED) If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL)) Else GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT) EndIf Else GUICtrlSetState($CAPS, $GUI_CHECKED) If BitAND(GUICtrlRead($LOWERCASE), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($LOWERCASE, $GUI_UNCHECKED) If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_UPPERCASE)) Else GUICtrlSetStyle($Edit, $ES_UPPERCASE) EndIf EndIf Case $Readonly If BitAND(GUICtrlRead($Readonly), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($Readonly, $GUI_UNCHECKED) If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL)) Else GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT) EndIf Else GUICtrlSetState($Readonly, $GUI_CHECKED) If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_READONLY)) Else GUICtrlSetStyle($Edit, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) EndIf EndIf Case $LOWERCASE If BitAND(GUICtrlRead($LOWERCASE), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($LOWERCASE, $GUI_UNCHECKED) If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL)) Else GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT) EndIf Else GUICtrlSetState($LOWERCASE, $GUI_CHECKED) If BitAND(GUICtrlRead($CAPS), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($CAPS, $GUI_UNCHECKED) If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_LOWERCASE)) Else GUICtrlSetStyle($Edit, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) EndIf EndIf Case $Run $INI = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "") $GetExt = StringTrimLeft($INI, StringLen($INI) - 4) ; Get the Extension of the Currently Opened File If Not $INI = "" Then If StringInStr($Ext, $GetExt) Then ShellExecute($INI) If @Error Then MsgBox(16, "Run Script", "An Error Occurred!") EndIf EndIf EndIf EndSwitch WEnd EndFunc ;==>Main Func _Open() Global $Edit, $StatusBar, $SetFileAttr, $CustomBGColor, $CustomFont, $EraseCustomOpt, $Main, $Run Local $Ext = ".au3 ,.bat ,.vbs ,.htm ,.html" ; Script Types Allowed to Be Executed (Only Extensions) If WinActive($GUI_TITLE) Then If GUICtrlRead($Edit) = FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then $File = FileOpenDialog("Choose a Readable File", @ScriptDir, "All Files (*.*)|Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)") If Not @error Then GUICtrlSetState($SetFileAttr, $GUI_ENABLE) GUICtrlSetState($CustomFont, $GUI_ENABLE) GUICtrlSetState($CustomBGColor, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $File) ;$INI = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "") ;$GetExt = StringTrimLeft($INI, StringLen($INI) - 4) ; Get the Extension of the Currently Opened File ;If StringInStr($Ext, $GetExt) Then ;GUICtrlSetState($Run, $GUI_ENABLE) ;EndIf GUICtrlSetData($Edit, FileRead($File)) $A = IniReadSection(@ScriptDir & "/config.ini", $File) If Not @error Then GUICtrlSetFont($Edit, IniRead(@ScriptDir & "/config.ini", $File, "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", $File, "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", $File, "attributes", "0"), IniRead(@ScriptDir & "/config.ini", $File, "fontname", "Arial")) GUICtrlSetColor($Edit, IniRead(@ScriptDir & "/config.ini", $File, "fontcolor", "0x000000")) GUICtrlSetBkColor($Edit, IniRead(@ScriptDir & "/config.ini", $File, "bgcolor", "0xFFFFFF")) GUICtrlSetState($EraseCustomOpt, $GUI_ENABLE) EndIf _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File) If StringInStr(FileGetAttrib($File), "R") Then GUICtrlSetStyle($Edit, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) MsgBox(48, "Text Editor", "This File is set to Readonly and cannot be edited.") EndIf EndIf Else $Confirm = MsgBox(36, "Confirm", "Do You Want To Save Before Opening a New File?") If $Confirm = 6 Then If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") _GUICtrlStatusBar_SetText($StatusBar, "Saving...") Sleep(1000) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") $File = FileOpenDialog("Choose a Readable File", @ScriptDir, "All Files (*.*)|Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)") If Not @error Then GUICtrlSetState($SetFileAttr, $GUI_ENABLE) GUICtrlSetState($CustomFont, $GUI_ENABLE) GUICtrlSetState($CustomBGColor, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $File) GUICtrlSetData($Edit, FileRead($File)) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File) EndIf Else $SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir) FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite($SaveDir, GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") _GUICtrlStatusBar_SetText($StatusBar, "Saving...") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File) EndIf EndIf Else $File = FileOpenDialog("Choose a Readable File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then GUICtrlSetState($SetFileAttr, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $File) GUICtrlSetData($Edit, FileRead($File)) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File) EndIf EndIf EndIf EndIf EndFunc ;==>_Open Func _New() Global $Edit, $StatusBar If WinActive($GUI_TITLE) Then If GUICtrlRead($Edit) = FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then GUICtrlSetData($Edit, "") IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")) GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")) GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")) _GUICtrlStatusBar_SetText($StatusBar, "New Document") Else $Confirm = MsgBox(36, "Confirm", "Do You Want To Save Before Starting a New File?") If $Confirm = 6 Then If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") _GUICtrlStatusBar_SetText($StatusBar, "Saving...") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") GUICtrlSetData($Edit, "") GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")) GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")) GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")) EndIf $SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir) FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite($SaveDir, GUICtrlRead($Edit)) IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") _GUICtrlStatusBar_SetText($StatusBar, "Saving...") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") GUICtrlSetData($Edit, "") GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")) GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")) GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")) _GUICtrlStatusBar_SetText($StatusBar, "New Document") EndIf Else GUICtrlSetData($Edit, "") IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file") _GUICtrlStatusBar_SetText($StatusBar, "New Document") EndIf EndIf EndIf EndFunc ;==>_New Func _Save() Global $StatusBar, $SetFileAttr, $CustomBGColor, $CustomFont If WinActive($GUI_TITLE) Then If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")) Else $SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)") If Not @error Then GUICtrlSetState($SetFileAttr, $GUI_ENABLE) GUICtrlSetState($CustomFont, $GUI_ENABLE) GUICtrlSetState($CustomBGColor, $GUI_ENABLE) IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir) FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit)) _GUICtrlStatusBar_SetText($StatusBar, "Saving...") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "File Saved!") Sleep(500) _GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")) EndIf EndIf EndIf EndFunc ;==>_Save Func _SelectAll() Global $Edit If WinActive($GUI_TITLE) Then _GUICtrlEdit_SetSel($Edit, 0, _GUICtrlEdit_GetTextLen($Edit)) EndIf EndFunc ;==>_SelectAll Func _Undo() Global $Edit If WinActive($GUI_TITLE) Then _GUICtrlEdit_Undo($Edit) EndIf EndFunc ;==>_Undo Func _Find() Global $Edit If WinActive($GUI_TITLE) Then _GUICtrlEdit_Find($Edit) EndIf EndFunc ;==>_Find Func _TimeAndDate() Global $Edit If WinActive($GUI_TITLE) Then If @WDAY = 1 Then $Day = "Sunday" If @WDAY = 2 Then $Day = "Monday" If @WDAY = 3 Then $Day = "Tuesday" If @WDAY = 4 Then $Day = "Wednesday" If @WDAY = 5 Then $Day = "Thursday" If @WDAY = 6 Then $Day = "Friday" If @WDAY = 7 Then $Day = "Saturday" If @HOUR < 12 Then $i = "AM" If @HOUR > 12 Then $i = "PM" GUICtrlSetData($Edit, GUICtrlRead($Edit) & $Day & " - " & @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & " " & $i) EndIf EndFunc ;==>_TimeAndDate Func SetFileAttr() GUICreate("Set File Attributes", 200, 140) Local $Attr = FileGetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!")) Local $Readonly = GUICtrlCreateCheckbox("Readonly", 20, 20) If StringInStr($Attr, "R") Then GUICtrlSetState(-1, $GUI_CHECKED) Local $Archive = GUICtrlCreateCheckbox("Archive", 100, 20) If StringInStr($Attr, "A") Then GUICtrlSetState(-1, $GUI_CHECKED) Local $Hidden = GUICtrlCreateCheckbox("Hidden", 20, 40) If StringInStr($Attr, "H") Then GUICtrlSetState(-1, $GUI_CHECKED) Local $Compress = GUICtrlCreateCheckbox("Compress", 100, 40) If StringInStr($Attr, "C") Then GUICtrlSetState(-1, $GUI_CHECKED) Local $Apply = GUICtrlCreateButton("Apply", 40, 80, 50, 30) Local $Cancel = GUICtrlCreateButton("Cancel", 100, 80, 50, 30) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case -3 GUIDelete() ExitLoop Case $Apply ;Readonly ================================================================== If BitOR(GUICtrlRead($Readonly), $GUI_CHECKED) = $GUI_CHECKED Then FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+R") Else FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-R") EndIf ;Archive ==================================================================== If BitOR(GUICtrlRead($Archive), $GUI_CHECKED) = $GUI_CHECKED Then FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+A") Else FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-A") EndIf ;Hidden ===================================================================== If BitOR(GUICtrlRead($Hidden), $GUI_CHECKED) = $GUI_CHECKED Then FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+H") Else FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-H") EndIf ;Compress ================================================================= If BitOR(GUICtrlRead($Compress), $GUI_CHECKED) = $GUI_CHECKED Then FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+C") Else FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-C") EndIf MsgBox(64, "Ok", "File Attributes Set and Saved.") GUIDelete() ExitLoop Case $Cancel GUIDelete() ExitLoop EndSwitch WEnd EndFunc ;==>SetFileAttr Func SpeakSelectedText($iRate, $iVolume) Global $Voice Send("^C") Local $iText = ClipGet() $Voice.Rate = $iRate $Voice.Volume = $iVolume $Voice.Speak($iText) Local $iText = ClipPut("") EndFunc ;==>SpeakSelectedText Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) Global $StatusBar _GUICtrlStatusBar_Resize($StatusBar) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE
    Heres an Archive with the Updated Script (Also Compiled Version) and the Icon.
    Text Editor.rar
  17. Like
    armoros reacted to Melba23 in GUIExtender - Original version   
    New version 21 Feb 12

    New: You can now choose the manner in which the GUI extends/retracts by adding a parameter to _GUIExtender_Init. This parameter sets the fixed point of the GUI: Left/Top (default and current behaviour), Centre, Right/Bottom. This fixed point can be overridden for a specific section by using a similar parameter in a _GUIExtender_Section_Extend call. See the new examples for more details.

    Thanks to mechaflash213 for the idea.

    This is a non-scriptbreaking change - all current scripts will perform as before.

    New UDF, examples and zip in this post.

    Previous updates:



    A recent forum question asked how to have expandable sections in a GUI. Although the coding to do this was not too difficult, it was a bit messy and not too easy to modify for another GUI - as subsequent posts in the thread showed.

    So I thought I might develop a UDF to do the same thing, but in as transparent manner as possible - and came up with GUIExtender. This UDF allows you to have multiple sections within a GUI which can be static or extendable. The extendable sections can be extended and retracted either by UDF created buttons or programmatically. The controls on the sections are fully functional and there is no overlap problem when retracted (see the details section if you want to know how). And the UDF can be used in both MessageLoop and OnEvent modes.

    Here are several examples:




    Some details for the curious among you who might want to know a bit more about how GUIExtender works:




    New - And finally, the GUIExtender UDF itself - just put it in the same folder as the examples:

    #include-once ; #INDEX# ============================================================================================================ ; Title .........: GUIExtender ; AutoIt Version : v3.3 or higher ; Language ......: English ; Description ...: Extends and retracts user-defined sections of a GUI either vertically or horizontally ; Remarks .......: ; Note ..........: ; Author(s) .....: Melba23 ; ==================================================================================================================== ;#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #GLOBAL VARIABLES# ================================================================================================= ; Declare array to hold section data Global $aGUIExt_Section_Data[1][9] = [[0, 0, 1, 0, "", 9999]] ; [0][0] = Section count [n][0] = Initial section X/Y-coord ; [0][1] = Orientation - 0 = Vertical, 1 = Horizontal [n][1] = Section height/width (inc border) ; [0][2] = All state - 0 = all retracted, 1 = at least 1 extended [n][2] = Section state - 0 = Retracted, 1 = extended, 2 = static ; [0][3] = GUI handle [n][3] = Section anchor ControlID (invisible disabled label) ; [0][4] = Fixed point - 0 = Left/Top, 1 = Centre, 2 = Right/Bottom [n][4] = Section final ControlID ; [0][5] = Action all button ControlID [n][5] = Section action button ControlID ; [0][6] = Action all button extended text [n][6] = Section action button extended text ; [0][7] = Action all button retracted text [n][7] = Section action button retracted text ; [0][8] = Action all button type [n][8] = Section action button type ; Declare array to hold data about embedded objects Global $aGUIExt_Obj_Data[1][2] = [[0]] ; [0][0] = Object count ; [n][0] = Embedded object ControlID ; [n][1] = Original object handle ; Declare flag for section action Global $fGUIExt_SectionAction = False ; #CURRENT# ========================================================================================================== ; _GUIExtender_Init: Initialises the GUI containing the sections and sets orientation and fixed point ; _GUIExtender_Section_Start: Marks the start point of GUI section ; _GUIExtender_Section_End: Marks the end of a GUI section ; _GUIExtender_Section_Action: Creates normal or push buttons to action extension or retraction of GUI sections ; _GUIExtender_Action: Used in GUIGetMsg loops to detect clicks on section action buttons ; _GUIExtender_Restore: Used reset GUI after a MINIMIZE and RESTORE ; _GUIExtender_Section_Extend: Actions section extension or retraction programatically or via section action buttons ; _GUIExtender_Section_State: Returns state of section ; _GUIExtender_UDFCtrlCheck: Hides/Shows and moves UDF-created controls when sections are extended/retracted ; _GUIExtender_ActionCheck: Indicates when sections are extended/retracted so that _GUIExtender_UDFCtrlCheck can be called ; _GUIExtender_Obj_Data: Store additional info on embedded objects ; _GUIExtender_Clear: Called on GUI deletion to clear the data array ready for a new GUI to be initialised ; ==================================================================================================================== ; #INTERNAL_USE_ONLY#================================================================================================= ; _GUIExtender_Section_All_Extend: Actions all moveable sections ; _GUIExtender_Section_Action_Event: Used to detect clicks on section action buttons in OnEvent mode ; ==================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Init ; Description ...: Initialises the GUI containing the sections and sets orientation and fixed point ; Syntax.........: _GUIExtender_Init($hWnd[, $iOrient = 0[, $iFixed = 0]]) ; Parameters ....: $hWnd - Handle of GUI containing the sections ; $iOrient - 0 = Vert - GUI extends and retracts in vertical sense ; 1 = Horz - GUI extends and retracts in horizontal sense ; $iFixed - 0 = GUI Left/Top fixed (Default) ; 1 = GUI centre fixed ; 2 = GUI Right/Bottom fixed ; Requirement(s).: v3.3 + ; Return values .: Success: Returns 1 ; Failure: Returns 0 and sets @error as follows: ; 1 = Invalid handle ; 2 = Existing initialisation ; 3 = Invalid parameter with @extended set: 1 = $iOrient, 2 $iFixed ; Author ........: Melba23 ; Remarks .......: This function should be called before any controls are created within the GUI ; Only one GUI can be initialised at any one time. _GUIExtender_Clear must be called before a second ; GUI can be initialised. The previous GUI loses all extension/retraction ability ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Init($hWnd, $iOrient = 0, $iFixed = 0) ; Check valid handle If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) ; Check for existing initialisation If $aGUIExt_Section_Data[0][3] Then Return SetError(2, 0, 0) ; Check for valid parameters Switch $iOrient Case 0, 1 ; Valid Case Else Return SetError(3, 1, 0) EndSwitch Switch $iFixed Case 0, 1, 2 ; Valid Case Else Return SetError(3, 2, 0) EndSwitch ; Store GUI handle $aGUIExt_Section_Data[0][3] = $hWnd ; Store orientation $aGUIExt_Section_Data[0][1] = $iOrient ; Store fixed point $aGUIExt_Section_Data[0][4] = $iFixed ; Set resizing mode to prevent resizing of controls Opt("GUIResizeMode", 0x0322) ; $GUI_DOCKALL ; Set automatic restore function for OnEvent mode scripts GUISetOnEvent(-5, "_GUIExtender_Restore") ; $GUI_EVENT_RESTORE Return 1 EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Section_Start ; Description ...: Marks the start point of GUI section ; Syntax.........: _GUIExtender_Section_Start($iSection_Coord, $iSection_Size) ; Parameters ....: $iSection_Coord - Coordinates of left/top edge of section depending on orientation ; $iSection_Size - Width/Height of section ; Requirement(s).: v3.3 + ; Return values .: Success: Returns section ID ; Failure: Returns 0 and sets @error as follows: ; 1 = Section overlaps with previous section ; Author ........: Melba23 ; Remarks .......: The function creates a disabled label to act as an anchor for the section position ; The function must be called BEFORE any controls in the section have been cretaed ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Section_Start($iSection_Coord, $iSection_Size) If $aGUIExt_Section_Data[0][0] > 1 Then ; Check section start is after previous section end If $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0] - 1][0] + $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0] - 1][1] > $iSection_Coord Then Return SetError(1, 0, 0) EndIf ; Add new section $aGUIExt_Section_Data[0][0] += 1 ; ReDim array if required If UBound($aGUIExt_Section_Data) < $aGUIExt_Section_Data[0][0] + 1 Then ReDim $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0] + 1][9] EndIf ; Store passed position and size parameters $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][0] = $iSection_Coord $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][1] = $iSection_Size ; Set state to static if not already set If $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][2] = "" Then $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][2] = 2 ; Create a zero size disabled label to act as an anchor for the section If $aGUIExt_Section_Data[0][1] Then ; Depending on orientation $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][3] = GUICtrlCreateLabel("", $iSection_Coord, 0, 1, 1) Else $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][3] = GUICtrlCreateLabel("", 0, $iSection_Coord, 1, 1) EndIf GUICtrlSetBkColor(-1, -2) ; $GUI_BKCOLOR_TRANSPARENT GUICtrlSetState(-1, 128) ; $GUI_DISABLE ; Set dummy action ControlID if needed If $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][5] = "" Then $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][5] = 9999 ; Return section ID Return $aGUIExt_Section_Data[0][0] EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Section_End ; Description ...: Marks the end point of GUI section ; Syntax.........: _GUIExtender_Section_End() ; Parameters ....: None ; Requirement(s).: v3.3 + ; Return values .: None ; Author ........: Melba23 ; Remarks .......: The function must be called AFTER all the controls in the section have been created ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Section_End() ; Determine End ControlID for the section $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][4] = GUICtrlCreateDummy() - 1 EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Section_Action ; Description ...: Creates controls to action extension or retraction of GUI sections ; Syntax.........: _GUIExtender_Section_Action($iSection[, $sText_Extended = ""[, $sText_Retracted = ""[, $iX = 0[, $iY = 0[, $iW = 0[, $iH = 0[, $iType = 0[, $iEventMode = 0]]]]]]]]]) ; Parameters ....: $iSection - Section to action - 0 = all extendable sections ; $sText_Extended - Text on button when section is extended - default: small up/left arrow ; $sText_Retracted - Text on button when section is retracted - default: small down/right arrow ; $iX - Left side of the button ; $iY - Top of the button ; $iW - Width of the button ; $iH - Height of the button ; $iType - Type of button: ; 0 = pushbutton (default) ; 1 = normal button ; $iEventMode - Set to 1 if using OnEvent mode ; In this case, the control is automatically linked to the _GUIExtender_Section_Action_Event function ; Requirement(s).: v3.3 + ; Return values .: Success: Returns 1 ; Failure: Returns 0 and sets @error as follows: ; 1 = Control not created ; Author ........: Melba23 ; Remarks .......: Sections are static unless an action control has been set ; Omitting all optional parameters creates a section which can be actioned programmatically ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Section_Action($iSection, $sText_Extended = "", $sText_Retracted = "", $iX = 0, $iY = 0, $iW = 1, $iH = 1, $iType = 0, $iEventMode = 0) ; ReDim array if required If $iSection > 1 And UBound($aGUIExt_Section_Data) < $iSection + 1 Then ReDim $aGUIExt_Section_Data[$iSection + 1][9] EndIf ; Set state to extended indicating a extendable section $aGUIExt_Section_Data[$iSection][2] = 1 ; If default arrows required Local $iDef_Arrows = 0 If $sText_Extended = "" And $sText_Retracted = "" Then $iDef_Arrows = 1 If $aGUIExt_Section_Data[0][1] Then ; Dependiing on orientation $sText_Extended = 3 $sText_Retracted = 4 Else $sText_Extended = 5 $sText_Retracted = 6 EndIf EndIf ; What type of button? Switch $iType ; Pushbutton Case 0 ; Create normal button $aGUIExt_Section_Data[$iSection][5] = GUICtrlCreateButton($sText_Extended, $iX, $iY, $iW, $iH) Case Else ; Create pushbutton $aGUIExt_Section_Data[$iSection][5] = GUICtrlCreateCheckBox($sText_Extended, $iX, $iY, $iW, $iH, 0x1000) ; $BS_PUSHLIKE ; Set button state GUICtrlSetState(-1, 1) ; $GUI_CHECKED EndSwitch ; Check for error If $aGUIExt_Section_Data[$iSection][5] = 0 Then Return SetError(2, 0, 0) ; Change font if default arrows required If $iDef_Arrows Then GUICtrlSetFont($aGUIExt_Section_Data[$iSection][5], 10, 400, 0, "Webdings") ; Set event function if required If $iEventMode Then GUICtrlSetOnEvent($aGUIExt_Section_Data[$iSection][5], "_GUIExtender_Section_Action_Event") ; Store required text $aGUIExt_Section_Data[$iSection][6] = $sText_Extended $aGUIExt_Section_Data[$iSection][7] = $sText_Retracted ; Store button type $aGUIExt_Section_Data[$iSection][8] = $iType Return 1 EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Action ; Description ...: Used in GUIGetMsg loops to detect clicks on section action buttons and $GUI_EVENT_RESTORE events ; Syntax.........: _GUIExtender_Action($iMsg) ; Parameters ....: $iMsg - Return from GUIGetMsg ; Requirement(s).: v3.3 + ; Return values .: None ; Author ........: Melba23 ; Remarks .......: The return from GUIGetMsg is passed to this function to determine if a section action control was clicked ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Action($iMsg) ; If GUI is restored, run the restore function If $iMsg = -5 Then _GUIExtender_Restore() ; $GUI_EVENT_RESTORE ; Check if an action control has been clicked For $i = 0 To $aGUIExt_Section_Data[0][0] ; If action button clicked If $iMsg = $aGUIExt_Section_Data[$i][5] Then ; Check current state Switch $aGUIExt_Section_Data[$i][2] Case 0 _GUIExtender_Section_Extend($i, True) Case Else _GUIExtender_Section_Extend($i, False) EndSwitch ; Set flag for section action occurring $fGUIExt_SectionAction = True EndIf Next EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Restore ; Description ...: Used to reset GUI after a MINIMIZE and RESTORE ; Syntax.........: _GUIExtender_Restore() ; Parameters ....: None ; Requirement(s).: v3.3 + ; Return values .: None ; Author ........: Melba23 ; Remarks .......: The GUI is not correctly restored after a MINIMIZE if a section is retracted. This function cycles ; the highest extendable section to reset the correct position of the controls ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Restore() ; Hide the GUI to prevent excess flicker GUISetState(@SW_HIDE, $aGUIExt_Section_Data[0][3]) ; Look for the highest extendable function For $i = UBound($aGUIExt_Section_Data) - 1 To 1 Step -1 If $aGUIExt_Section_Data[$i][2] <> 2 Then ; Depending on current state, cycle extendable section Switch $aGUIExt_Section_Data[$i][2] Case 0 _GUIExtender_Section_Extend($i) _GUIExtender_Section_Extend($i, False) Case 1 _GUIExtender_Section_Extend($i, False) _GUIExtender_Section_Extend($i) EndSwitch ExitLoop EndIf Next ; Show GUI again GUISetState(@SW_SHOW, $aGUIExt_Section_Data[0][3]) EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Section_Extend ; Description ...: Actions section extension or retraction programatically or via section action buttons ; Syntax.........: _GUIExtender_Section_Extend($iSection[, $fExtend = True[, $iFixed]]) ; Parameters ....: $iSection - Section to action - 0 = all moveable sections ; $fExtend - True = extend; False = retract ; $iFixed - 0 = Left/Top fixed ; 1 = Expand/contract centred ; 2 = Right/bottom fixed ; Any other value = Default as set by _GUIExtender_Init (default) ; Requirement(s).: v3.3 + ; Return values .: Success: Returns 1 ; Failure: Returns 0 and sets @error as follows: ; 1 = Invalid section ID (@extended: 1 = not in array, 2 = no _Start function used) ; 2 = Section already in required state ; 3 = GUI minimized ; Author ........: Melba23 ; Remarks .......: This function is called by the UDF when the section action buttons are clicked, ; but can also be called programatically ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Section_Extend($iSection, $fExtend = True, $iFixed = 9) Local $aPos, $iCID, $iDelta_GUI ; Check GUI is not minimized If BitAND(WinGetState($aGUIExt_Section_Data[0][3]), 16) Then Return SetError(3, 0, 0) ; Check if all sections to be actioned If $iSection = 0 Then _GUIExtender_Section_All_Extend($fExtend) Return 1 EndIf ; Check for invalid section (either outside array or no _Start function called) If $iSection > UBound($aGUIExt_Section_Data) - 1 Then Return SetError(1, 1, 0) If $aGUIExt_Section_Data[$iSection][1] = "" Then Return SetError(1, 2, 0) ; Check if state already matches demand If ($aGUIExt_Section_Data[$iSection][2] = 1 And $fExtend = True) Or ($aGUIExt_Section_Data[$iSection][2] = 0 And $fExtend = False) Then Return SetError(2, 0, 0) ; Check Move state Switch $iFixed Case 0, 1, 2 ; Do nothing Case Else ; Set default value $iFixed = $aGUIExt_Section_Data[0][4] EndSwitch ; Get current GUI size and set function calculation values Local $aGUIPos = WinGetPos($aGUIExt_Section_Data[0][3]) Local $iGUI_Fixed = $aGUIPos[2] Local $iGUI_Adjust = $aGUIPos[3] If $aGUIExt_Section_Data[0][1] Then ; If Horz orientation $iGUI_Fixed = $aGUIPos[3] $iGUI_Adjust = $aGUIPos[2] EndIf ; Determine action required If $fExtend Then ; Change button text GUICtrlSetData($aGUIExt_Section_Data[$iSection][5], $aGUIExt_Section_Data[$iSection][6]) ; Force action control state if needed If $aGUIExt_Section_Data[$iSection][8] = 1 Then GUICtrlSetState($aGUIExt_Section_Data[$iSection][5], 1) ; $GUI_CHECKED ; Set section state $aGUIExt_Section_Data[$iSection][2] = 1 ; Add size of section being extended $iGUI_Adjust += $aGUIExt_Section_Data[$iSection][1] Else ; Change button text GUICtrlSetData($aGUIExt_Section_Data[$iSection][5], $aGUIExt_Section_Data[$iSection][7]) ; Force action control state if needed If $aGUIExt_Section_Data[$iSection][8] = 1 Then GUICtrlSetState($aGUIExt_Section_Data[$iSection][5], 4) ; $GUI_UNCHECKED ; Set section state $aGUIExt_Section_Data[$iSection][2] = 0 ; Subtract size of section being hidden $iGUI_Adjust -= $aGUIExt_Section_Data[$iSection][1] EndIf ; Hide all sections to prevent ghosting when changing GUI size For $i = $aGUIExt_Section_Data[1][3] To $aGUIExt_Section_Data[$aGUIExt_Section_Data[0][0]][4] GUICtrlSetState($i, 32) ; $GUI_HIDE Next ; Resize and possibly move GUI If $aGUIExt_Section_Data[0][1] Then ; Depending on orientation ; Calculate change in GUI size $iDelta_GUI = $aGUIPos[2] - $iGUI_Adjust ; Check GUI fixed point Switch $iFixed Case 0 WinMove($aGUIExt_Section_Data[0][3], "", Default, Default, $iGUI_Adjust, $iGUI_Fixed) Case 1 WinMove($aGUIExt_Section_Data[0][3], "", $aGUIPos[0] + Int($iDelta_GUI / 2), Default, $iGUI_Adjust, $iGUI_Fixed) Case 2 WinMove($aGUIExt_Section_Data[0][3], "", $aGUIPos[0] + $iDelta_GUI, Default, $iGUI_Adjust, $iGUI_Fixed) EndSwitch Else $iDelta_GUI = $aGUIPos[3] - $iGUI_Adjust Switch $iFixed Case 0 WinMove($aGUIExt_Section_Data[0][3], "", Default, Default, $iGUI_Fixed, $iGUI_Adjust) Case 1 WinMove($aGUIExt_Section_Data[0][3], "", Default, $aGUIPos[1] + Int($iDelta_GUI / 2), $iGUI_Fixed, $iGUI_Adjust) Case 2 WinMove($aGUIExt_Section_Data[0][3], "", Default, $aGUIPos[1] + $iDelta_GUI, $iGUI_Fixed, $iGUI_Adjust) EndSwitch EndIf ; Initial section position = section 1 start Local $iNext_Coord = $aGUIExt_Section_Data[1][0] ; Move sections to required position Local $iAdjust_X = 0, $iAdjust_Y = 0 For $i = 1 To $aGUIExt_Section_Data[0][0] ; Is this section visible? If $aGUIExt_Section_Data[$i][2] > 0 Then ; Get current position of section anchor $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $aGUIExt_Section_Data[$i][3]) If $aGUIExt_Section_Data[0][1] Then ; Depending on orientation ; Determine required change in X position for section controls $iAdjust_X = $aPos[0] - $iNext_Coord ; Determine if controls need to be moved back into the GUI If $aPos[1] > $iGUI_Fixed Then $iAdjust_Y = $iGUI_Fixed Else ; Determine required change in Y position for section controls $iAdjust_Y = $aPos[1] - $iNext_Coord ; Determine if controls need to be moved back into the GUI If $aPos[0] > $iGUI_Fixed Then $iAdjust_X = $iGUI_Fixed EndIf ; For all controls in this section For $j = $aGUIExt_Section_Data[$i][3] To $aGUIExt_Section_Data[$i][4] $iCID = $j ; Adjust the position $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $iCID) If @error Then For $k = 1 To $aGUIExt_Obj_Data[0][0] If $aGUIExt_Obj_Data[$k][0] = $j Then $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $aGUIExt_Obj_Data[$k][1]) $iCID = $aGUIExt_Obj_Data[$k][1] ExitLoop EndIf Next ; If not an object see if the ControlID returns a handle (an internal tab will not) If $iCID = $j And GUICtrlGetHandle($j) = 0 Then $iCID = "Ignore" EndIf If $iCID = "Ignore" Then ContinueLoop ; Move control ControlMove($aGUIExt_Section_Data[0][3], "", $iCID, $aPos[0] - $iAdjust_X, $aPos[1] - $iAdjust_Y) ; And show the control GUICtrlSetState($j, 16) ; $GUI_SHOW Next ; Determine start position for next visible section $iNext_Coord += $aGUIExt_Section_Data[$i][1] Else ; Get current position of hidden section anchor $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $aGUIExt_Section_Data[$i][3]) ; Determine if controls in this section need to be moved outside GUI to prevent possible overlap If $aGUIExt_Section_Data[0][1] Then ; Depending on orientation If $aPos[1] < $iGUI_Fixed Then For $j = $aGUIExt_Section_Data[$i][3] To $aGUIExt_Section_Data[$i][4] $iCID = $j ; Adjust the position $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $j) If @error Then For $k = 1 To $aGUIExt_Obj_Data[0][0] If $aGUIExt_Obj_Data[$k][0] = $j Then $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $aGUIExt_Obj_Data[$k][1]) $iCID = $aGUIExt_Obj_Data[$k][1] ExitLoop EndIf Next ; If not an object see if the ControlID returns a handle (an internal tab will not) If $iCID = $j And GUICtrlGetHandle($j) = 0 Then $iCID = "Ignore" EndIf If $iCID = "Ignore" Then ContinueLoop ; Move control ControlMove($aGUIExt_Section_Data[0][3], "", $iCID, $aPos[0], $aPos[1] + $iGUI_Fixed) Next EndIf Else If $aPos[0] < $iGUI_Fixed Then For $j = $aGUIExt_Section_Data[$i][3] To $aGUIExt_Section_Data[$i][4] $iCID = $j ; Adjust the position $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $j) If @error Then For $k = 1 To $aGUIExt_Obj_Data[0][0] If $aGUIExt_Obj_Data[$k][0] = $j Then $aPos = ControlGetPos($aGUIExt_Section_Data[0][3], "", $aGUIExt_Obj_Data[$k][1]) $iCID = $aGUIExt_Obj_Data[$k][1] ExitLoop EndIf Next ; If not an object see if the ControlID returns a handle (an internal tab will not) If $iCID = $j And GUICtrlGetHandle($j) = 0 Then $iCID = "Ignore" EndIf If $iCID = "Ignore" Then ContinueLoop ; Move control ControlMove($aGUIExt_Section_Data[0][3], "", $iCID, $aPos[0] + $iGUI_Fixed, $aPos[1]) Next EndIf EndIf EndIf Next ; Set correct "all" state if there is a "all" control If $aGUIExt_Section_Data[0][5] <> 9999 Then Local $iAll_State = 0 ; Check if any sections extended For $i = 1 To $aGUIExt_Section_Data[0][0] If $aGUIExt_Section_Data[$i][2] = 1 Then $iAll_State = 1 ExitLoop EndIf Next ; Sync "all" sections control Switch $iAll_State ; None extended Case 0 ; Clear flag $aGUIExt_Section_Data[0][2] = 0 ; Set text GUICtrlSetData($aGUIExt_Section_Data[0][5], $aGUIExt_Section_Data[0][7]) ; Set state if required If $aGUIExt_Section_Data[0][8] = 1 Then GUICtrlSetState($aGUIExt_Section_Data[0][5], 4) ; $GUI_UNCHECKED ; Some extended Case Else ; Set flag $aGUIExt_Section_Data[0][2] = 1 ; Set text GUICtrlSetData($aGUIExt_Section_Data[0][5], $aGUIExt_Section_Data[0][6]) ; Set state if required If $aGUIExt_Section_Data[0][8] = 1 Then GUICtrlSetState($aGUIExt_Section_Data[0][5], 1) ; $GUI_CHECKED EndSwitch EndIf Return 1 EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Section_State ; Description ...: Returns current state of section ; Syntax.........: _GUIExtender_Section_State($iSection) ; Parameters ....: $iSection - Section to check ; Requirement(s).: v3.3 + ; Return values .: Success: State of section: 0 = Retracted, 1 = Extended, 2 = Static ; Failure: Invalid section returns -1 and sets @error to 1 ; Author ........: Melba23 ; Remarks .......: This allows additional GUI controls to reflect the section state ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Section_State($iSection) If $iSection > UBound($aGUIExt_Section_Data) - 1 Then Return SetError(1, 0, -1) Return $aGUIExt_Section_Data[$iSection][2] EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_UDFCtrlCheck ; Description ...: Hides/Shows and moves UDF-created controls when sections are extended/retracted ; Syntax.........: _GUIExtender_UDFCtrlCheck($hControl_Handle, $iSection, $iX, $iY) ; Parameters ....: $hControl_Handle - Handle of UDF-created control ; $iSection - Section within which control is situated ; $iX, $iY - Coords of control - relative to section not to GUI ; Requirement(s).: v3.3 + ; Return values .: Success: Returns 1 ; Failure: Returns 0 and sets @error as follows: ; 1 = Invalid handle ; 2 = Invalid section ; 3 = Invalid coordinate value ; Author ........: Melba23 ; Remarks .......: ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_UDFCtrlCheck($hCtrl_Handle, $iSection, $iX, $iY) Local $iCtrl_Coord ; Check parameters If Not IsHWnd($hCtrl_Handle) Or Not WinExists($hCtrl_Handle) Then Return SetError(1, 0, 0) If $iSection > UBound($aGUIExt_Section_Data) - 1 Then Return SetError(2, 0, 0) If Not IsInt($iX) Or Not IsInt($iY) Then Return SetError(3, 0, 0) ; Is the section visible Switch _GUIExtender_Section_State($iSection) Case 1 ; If section extended then show the control ControlShow($aGUIExt_Section_Data[0][3], "", $hCtrl_Handle) ; Now check required position within the GUI - set intial value depending on orientation If $aGUIExt_Section_Data[0][1] = 0 Then $iCtrl_Coord = $iY + $aGUIExt_Section_Data[1][0] ; Set to offset withint section Else $iCtrl_Coord = $iX + $aGUIExt_Section_Data[1][0] EndIf ; Check which earlier sections are extended For $i = 1 To $iSection - 1 If _GUIExtender_Section_State($i) Then ; Add add their size if extended $iCtrl_Coord += $aGUIExt_Section_Data[$i][1] EndIf Next ; Now move control depending on orientation If $aGUIExt_Section_Data[0][1] = 0 Then WinMove($hCtrl_Handle, "", $iX, $iCtrl_Coord) Else WinMove($hCtrl_Handle, "", $iCtrl_Coord, $iY) EndIf Case 0 ; If section retracted hide the control ControlHide($aGUIExt_Section_Data[0][3], "", $hCtrl_Handle) EndSwitch ; Clear flag for section action $fGUIExt_SectionAction = False Return 1 EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_ActionCheck ; Description ...: Indicates when sections are extended/retracted so that _GUIExtender_UDFCtrlCheck can be called ; Syntax.........: _GUIExtender_ActionCheck() ; Parameters ....: None ; Requirement(s).: v3.3 + ; Return values .: Returns True if sections have been actioned ; Returns False after _GUIExtender_UDFCtrlCheck has been used to adjust UDF-created controls ; Author ........: Melba23 ; Remarks .......: ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_ActionCheck() Return $fGUIExt_SectionAction EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Obj_Data ; Description ...: Store additional info on embedded objects ; Syntax.........: _GUIExtender_Obj_Data($iCID, $oObj) ; Parameters ....: $iCID - Returned ControlID from GUICtrlCreateObj ; $iObj - Object reference number from initial object creation ; Requirement(s).: v3.3 + ; Return values .: Success: Returns 1 ; Failure: Returns 0 and sets @error to 1 ; Author ........: Melba23, DllCall from trancexx ; Remarks .......: This allows embedded objects to be used in the UDF ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Obj_Data($iCID, $iObj) ; Increase array size $aGUIExt_Obj_Data[0][0] += 1 ReDim $aGUIExt_Obj_Data[$aGUIExt_Obj_Data[0][0] + 1][2] ; Store ControlID $aGUIExt_Obj_Data[$aGUIExt_Obj_Data[0][0]][0] = $iCID ; Determine and store object handle Local $aRet = DllCall("oleacc.dll", "int", "WindowFromAccessibleObject", "idispatch", $iObj, "hwnd*", 0) If @error Or $aRet[0] Then Return SetError(1, 0, 0) $aGUIExt_Obj_Data[$aGUIExt_Obj_Data[0][0]][1] = $aRet[2] Return 1 EndFunc ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Clear ; Description ...: Called on GUI deletion to clear the data array ready for a new GUI to be initialised ; Syntax.........: _GUIExtender_Clear() ; Requirement(s).: v3.3 + ; Author ........: Melba23 ; Remarks .......: If the data array is not cleared the array is corrupted during initialisation and the UDF crashes ; Example........: Yes ;===================================================================================================================== Func _GUIExtender_Clear() ; Reset data array Global $aGUIExt_Section_Data[1][9] = [[0, 0, 1, 0, "", 9999]] EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _GUIExtender_Section_All_Extend ; Description ...: Actions all moveable sections ; Author ........: Melba23 ; Modified.......: ; Remarks .......: This function is used internally by _GUIExtender_Section_Extend when all sections are to be moved ; =============================================================================================================================== Func _GUIExtender_Section_All_Extend($fExtend = True) ; Set required state for extendable sections Local $iState = 0 If $fExtend Then $iState = 1 For $i = 1 To $aGUIExt_Section_Data[0][0] ; Check if section requires change of state If $aGUIExt_Section_Data[$i][2] <> 2 And $aGUIExt_Section_Data[$i][2] = Not($iState) Then ; Extend/Shrink as required _GUIExtender_Section_Extend($i, $fExtend) ; Set section state to match $aGUIExt_Section_Data[$i][2] = $iState ; Set section action control state Switch $fExtend Case True GUICtrlSetData($aGUIExt_Section_Data[$i][5], $aGUIExt_Section_Data[$i][6]) If $aGUIExt_Section_Data[$i][8] = 1 Then GUICtrlSetState($aGUIExt_Section_Data[$i][5], 1) ; $GUI_CHECKED Case False GUICtrlSetData($aGUIExt_Section_Data[$i][5], $aGUIExt_Section_Data[$i][7]) If $aGUIExt_Section_Data[$i][8] = 1 Then GUICtrlSetState($aGUIExt_Section_Data[$i][5], 4) ; $GUI_UNCHECKED EndSwitch EndIf Next EndFunc ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _GUIExtender_Section_Action_Event ; Description ...: Used to detect clicks on section action buttons in OnEvent mode ; Author ........: Melba23 ; Modified.......: ; Remarks .......: This function is called when section action button are clicked in OnEvent mode ; =============================================================================================================================== Func _GUIExtender_Section_Action_Event() _GUIExtender_Action(@GUI_CTRLID) EndFuncNew - For ease of downloading, here are all the above files in zip format:GUIExtender.zip

    As always, I welcome constructive comments and effusive compliments!

    M23
  18. Like
    armoros reacted to wakillon in TinyAu3FilesSearch v 1.0.0.8 Update of 25 june 2013   
    Despite sorting and storing your AutoIt scripts, have you ever been annoyed to retrieve a particular one ?

    TinyAu3FilesSearch can help you !


    Previous Downloads : 422
    Source : TinyAu3FilesSearch v1.0.0.8.au3
    Executable : TinyAu3FilesSearch.exe.html
    (Once this html file downloaded, double click on it for start the download)
    Faster than Microsoft Search you can also filter results by string in name, strings in file, excluding strings in file.
    Double click on listview selection for open it in SciTE editor
    Hold left Shift key and Left click on listview selection for open his parent folder.
    Columns can be sorted for help to filter and i have improved the management of the Root Search to avoid wasting time.
    Thanks to azjio for his recursive >FileSearch.
    Will be added to the next version of >SciTE Hopper.

    Only for AutoIt Scripts but hope it can help !
     
  19. Like
    armoros reacted to Kealper in _WinAPI_SetConsoleTitle UDF (With detailed example!)   
    Ok, so this has probably been posted before, but I was looking through the MSDN library randomly just a bit ago, and decided to play around a bit with some of the console-related functions.
    AutoIt can make basic console applications to provide users with some basic output (which is generally more efficient than outputting to a GUI), but wouldn't it be cool to be able to name your console windows just like you can name your GUI windows?

    Instead of it being called "C:\Users\Foobar\Desktop\MyEchoServer.exe" for instance, you could make your program call itself just "My Echo Server" and such.

    Here is the simple UDF on it's own, and below this is a nice little example detailing how you can use the function.

    ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_SetConsoleTitle ; Description ...: Change the AutoIt process's attached console title. ; Syntax ........: _WinAPI_SetConsoleTitle($sTitle[, $hDLL = "Kernel32.dll"]) ; Parameters ....: $sTitle - A string value. ; $hDLL - [optional] A handle value. Default is "Kernel32.dll". ; Return values .: True if the title was able to be changed, False if it was not able to be changed. ; Author ........: Ken "Kealper" Piper ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WinAPI_SetConsoleTitle($sTitle, $hDLL = "Kernel32.dll") Local $iRet = DllCall($hDLL, "bool", "SetConsoleTitle", "str", $sTitle) If $iRet[0] < 1 Then Return False Return True EndFunc
    And here is the example... For best results, save this to a file and compile it as a console application.
    If it isn't compiled as a console application, there is a quick and dirty DllCall in there to create a "dummy" console if it doesn't exist already which can serve to demonstrate the function anyways (but without any textual output).

    #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Create a new console window if it does not already exist, even if it is not compiled as a console executable. ;This DllCall is not part of the example, it only serves to ensure the example works correctly. ;Don't run through SciTE, the example will fail, and even this DllCall can't fix that. DllCall("Kernel32.dll", "bool", "AllocConsole") ;Don't just rely on this though, to get the most from this, compile as a console app! ;Begin actual example. ConsoleWrite("Keep an eye on the console's window title!" & @CRLF) Sleep(3000) ;First: Setting the title of your console window is as easy as this! _WinAPI_SetConsoleTitle("This is some custom text!") ;A simple count-down, so the first title change is visible for a few seconds before proceeding to the next example. For $i = 5 To 1 Step -1 ConsoleWrite("Proceeding in " & $i & "..." & @CRLF) Sleep(1000) Next ConsoleWrite("On to example two! This'll count to 50 and then exit." & @CRLF) ;Second: Something a bit more advanced. Changing the console's title rapidly. ;When changing the console's title rapidly, you should first open Kernel32.dll and then pass that handle ;as a second parameter to the function. This makes it use the open handle instead of having to open and ;close Kernel32.dll each time the function is called. This ends up making it more efficient. $Kernel32 = DllOpen("Kernel32.dll") ;Open Kernel32.dll. $Kernel32 now holds a handle to the opened file. For $i = 1 To 50 ;Count to 50 _WinAPI_SetConsoleTitle("Counting..." & $i, $Kernel32) ;Set the new title, and tell the function to use the open handle instead. Sleep(100) ;Wait 100ms, so the change can be easily seen by everyone. Without this, the change would happen too fast to notice. Next DllClose($Kernel32) ;Finally, because we like our resources, close the open handle since we no longer need it. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinAPI_SetConsoleTitle ; Description ...: Change the AutoIt process's attached console title. ; Syntax ........: _WinAPI_SetConsoleTitle($sTitle[, $hDLL = "Kernel32.dll"]) ; Parameters ....: $sTitle - A string value. ; $hDLL - [optional] A handle value. Default is "Kernel32.dll". ; Return values .: True if the title was able to be changed, False if it was not able to be changed. ; Author ........: Ken "Kealper" Piper ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _WinAPI_SetConsoleTitle($sTitle, $hDLL = "Kernel32.dll") Local $iRet = DllCall($hDLL, "bool", "SetConsoleTitle", "str", $sTitle) If $iRet[0] < 1 Then Return False Return True EndFunc
  20. Like
    armoros reacted to Gonk in A thank you to the dev staff and the community   
    I have been reading this forum, and site, for the past couple of years. I decided today that this post was long overdue. I have learned much and honestly there wasn't any issue I ever had with autoit that I couldn't find the answer already on the forums. I just wanted to extend a big thank you to all the devs and the people in the community to take time out of their day to help the "newbs" learn and, more importantly, understand our own code.

    Sincerely,

    A grateful (forever) noob
  21. Like
    armoros reacted to water in Compile and Autoit   
    @Compiled returns 1 if the script is a compiled exe file, and 0 if run (interpreted) from SciTE.
    This can be useful if you want to run some functions (check authorization etc.) when run on a customers PC as an exe but suppress the function when you develop and run the script from SciTE.
  22. Like
    armoros reacted to PhoenixXL in [Solved] Edit box-Characters 30000-Lines 673 -Restriction ?   
    Hey Positive Results..............
    I got that 2147483647 is the Maximum Value that a Edit Control Can Hold

    Using This Code
    #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiEdit.au3> #include <GuiConstantsEx.au3> Opt('MustDeclareVars', 1) $Debug_Ed = False ; Check ClassName being passed to Edit functions, set to True and use a handle to another control to see it work _Main() Func _Main() Local $hEdit ; Create GUI GUICreate("Edit Set Limit Text", 400, 300) $hEdit = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 2, 2, 394, 268) GUISetState() MsgBox(4160, "Information", "Text Limit: " & _GUICtrlEdit_GetLimitText($hEdit)) MsgBox(4160, "Information", "Setting Text Limit") Local $x=2147483630,$sdata While 1 _GUICtrlEdit_SetLimitText($hEdit,$x) $sdata=_GUICtrlEdit_GetLimitText($hEdit) ConsoleWrite("Information"&@TAB&"Text Limit: " &$sdata &@CRLF) If $sdata<=0 Then ExitLoop $x+=1 WEnd GUIDelete() EndFunc ;==>_Main


    Thumbs Up If it Helped


    Regards
    Phoenix XL
  23. Like
    armoros reacted to UEZ in Send command to Embeded CMD ?   
    Might be useful for you:


    ;Build 2013-01-28 #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0 #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_Obfuscated.au3" #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_UPX_Parameters=--best --lzma #include <GuiButton.au3> #include <GuiImageList.au3> ;~ #include <Array.au3>;~~~ #include <Constants.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <Misc.au3> #include <ScrollBarConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("CaretCoordMode", 0) Global $aPalette[21] = [0xFFFFFF, 0x000000, 0xC0C0C0, 0x808080, _ 0xFF0000, 0x800000, 0xFFFF00, 0x808000, _ 0x00FF00, 0x008000, 0x00FFFF, 0x008080, _ 0x0000FF, 0x000080, 0xFF00FF, 0x800080, _ 0xC0DCC0, 0xA6CAF0, 0xFFFBF0, 0xA0A0A4, 0xABCDEF] Global Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Global Const $aFullScreen = WinGetPos($hFullScreen) _GDIPlus_Startup() Global Const $iW = 736, $iH = 369, $sFont = "Lucida Console" Global $iFGColor = 0xC0C0C0, $iBGColor = 0x000000, $__Enum Global Const $hGUI = GUICreate("CMD Box Emulator 2012 Alpha Version by UEZ", 736, 450, -1, -1, -1, $WS_EX_CONTEXTHELP + $WS_EX_ACCEPTFILES) Global Const $idEdit = GUICtrlCreateEdit($hGUI, 0, 0, $iW, $iH, BitOR($ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE, $ES_WANTRETURN)) Global Const $hEdit = GUICtrlGetHandle($idEdit) Global $sCMDLine = @HomeDrive & @HomePath Global $sPrefix = StringStripWS(StringStripCR(ExecuteCMD("ver")), 3) Global $iPrefixLen = StringLen($sCMDLine & ">") Global Const $iColorTxt = $iFGColor GUICtrlSetData($idEdit, $sPrefix & @CRLF & _ "Copyright (c) 2009 Microsoft Corporation. All rights reserved." & @CRLF & @CRLF) GUICtrlSetFont($idEdit, 10, 600, 0, $sFont, 5) GUICtrlSetColor($idEdit, $iColorTxt) GUICtrlSetBkColor($idEdit, $iBGColor) _GUICtrlEdit_SetLimitText($hEdit, -1) Global Const $iStartx = 30, $iBtnWidth = 80, $iStarty = 390 Global Const $idButton_Dir = GUICtrlCreateButton("Dir", $iStartx, $iStarty, $iBtnWidth, 40) Global Const $hButton_Dir = GUICtrlGetHandle($idButton_Dir) Global Const $sButton_DirNN = _WinAPI_GetClassName($hButton_Dir) & _GetNN($hButton_Dir) Global Const $idButton_IPC = GUICtrlCreateButton("IPConfig", 2 * $iStartx + 1 * $iBtnWidth, $iStarty, $iBtnWidth, 40) Global Const $hButton_IPC = GUICtrlGetHandle($idButton_IPC) Global Const $sButton_IPCNN = _WinAPI_GetClassName($hButton_IPC) & _GetNN($hButton_IPC) Global Const $idButton_Ping = GUICtrlCreateButton("Ping", 3 * $iStartx + 2 * $iBtnWidth, $iStarty, $iBtnWidth, 40) Global Const $hButton_Ping = GUICtrlGetHandle($idButton_Ping) Global Const $sButton_PingNN = _WinAPI_GetClassName($hButton_Ping) & _GetNN($hButton_Ping) Global Const $idButton_RunBatch = GUICtrlCreateButton("Run Batch", 4 * $iStartx + 3 * $iBtnWidth, $iStarty, $iBtnWidth, 40, $BS_DEFPUSHBUTTON) GUICtrlSetBkColor(-1, 0xE0FFE0) Global Const $hButton_RunBatch = GUICtrlGetHandle($idButton_RunBatch) Global Const $sButton_RunBatchNN = _WinAPI_GetClassName($hButton_RunBatch) & _GetNN($hButton_RunBatch) Global Const $idButton_Exit = GUICtrlCreateButton("Exit", $iW - $iBtnWidth - $iStartx, $iStarty, $iBtnWidth, 40) Global Const $hButton_Exit= GUICtrlGetHandle($idButton_Exit) Global Const $sButton_ExitNN = _WinAPI_GetClassName($hButton_Exit) & _GetNN($hButton_Exit) Global Const $idLable_ChgBGColor = GUICtrlCreateLabel("Change BG Color", 5 * $iStartx + 4 * $iBtnWidth, $iStarty - 10) Global Const $idLable_ChgFGColor = GUICtrlCreateLabel("Change FG Color", 5 * $iStartx + 4 * $iBtnWidth, $iStarty + 14) Global Const $idLable_ChgFont = GUICtrlCreateLabel("Change Font", 5 * $iStartx + 4 * $iBtnWidth, $iStarty + 36) Global $iStyle = $BS_SPLITBUTTON + $BCSS_NOSPLIT If @OSBuild < 6000 Then $iStyle = Default Global Const $idButton_ChgBGColor = GUICtrlCreateButton("", 5 * $iStartx + 4 * $iBtnWidth + 92, $iStarty - 12, 40, 18, $iStyle) Global Const $hButton_ChgBGColor = GUICtrlGetHandle($idButton_ChgBGColor) Global Const $sButton_ChgBGColorNN = _WinAPI_GetClassName($hButton_ChgBGColor) & _GetNN($hButton_ChgBGColor) _GUICtrlButton_SetSplitInfo($hButton_ChgBGColor, -1, $BCSS_NOSPLIT) Global Const $idButton_ChgFGColor = GUICtrlCreateButton("", 5 * $iStartx + 4 * $iBtnWidth + 92, $iStarty + 12, 40, 18, $iStyle) Global Const $hButton_ChgFGColor = GUICtrlGetHandle($idButton_ChgFGColor) Global Const $sButton_ChgFGColorNN = _WinAPI_GetClassName($hButton_ChgFGColor) & _GetNN($hButton_ChgFGColor) _GUICtrlButton_SetSplitInfo($hButton_ChgFGColor, -1, $BCSS_NOSPLIT) Global Const $idButton_ChgFont = GUICtrlCreateButton("...", 5 * $iStartx + 4 * $iBtnWidth + 92, $iStarty + 34, 40, 18, $BS_TOP) Global Const $hButton_ChgFont = GUICtrlGetHandle($idButton_ChgFont) Global Const $sButton_ChgFontNN = _WinAPI_GetClassName($hButton_ChgFont) & _GetNN($hButton_ChgFont) Global $hImage_BG = _GUIImageList_Create(14, 10, 5, 3) Global $hBmp_BG = _WinAPI_CreateSolidBitmap($hButton_ChgBGColor, $iBGColor, 14, 10) _GUIImageList_Add($hImage_BG, $hBmp_BG) _GUICtrlButton_SetImageList($hButton_ChgBGColor, $hImage_BG, 1) Global $hImage_FG = _GUIImageList_Create(14, 10, 5, 3) _GUIImageList_Add($hImage_FG, _WinAPI_CreateSolidBitmap($hButton_ChgFGColor, $iFGColor, 14, 10)) _GUICtrlButton_SetImageList($hButton_ChgFGColor, $hImage_FG, 1) Global $hBitmap = CreateCaretBitmap() Global $aBlinkTime = DllCall('user32.dll', 'int', 'GetCaretBlinkTime') Global $iBlinkTime_save = $aBlinkTime[0] Global $iBlinkTime = Int($aBlinkTime[0] * 0.9) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() _GUICtrlEdit_AppendText($hEdit, $sCMDLine & ">") GUISetIcon(@SystemDir & "\cmd.exe", 0, $hGUI) ;~ ControlClick("", "", $idEdit) Global $aCaretPos[2], $sFile, $aFont Global $hEditWndProc = DllCallbackRegister("EditWndProc", "lresult", "hwnd;uint;wparam;lparam") Global $hOldEditProc = _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, DllCallbackGetPtr($hEditWndProc)) $aCaretPos = GetCaretPos() ;~ DllCall('user32.dll', 'int', 'SetCaretPos', 'int', $aCaretPos[0] + 100, 'int', $aCaretPos[1]) GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES") Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Exit GUIRegisterMsg($WM_DROPFILES, "") GUIRegisterMsg($WM_COMMAND, "") _WinAPI_DeleteObject($hBmp_BG) _GUIImageList_Destroy($hImage_BG) _GUIImageList_Destroy($hImage_FG) _WinAPI_DeleteObject($hBitmap) _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $hOldEditProc) DllCallbackFree($hEditWndProc) DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $iBlinkTime_save) _GDIPlus_Shutdown() GUIDelete() Exit Case $idButton_Dir If ControlGetFocus($hGUI) <> $sButton_DirNN Then ContinueCase SendCommand2CMD("dir") Case $idButton_IPC If ControlGetFocus($hGUI) <> $sButton_IPCNN Then ContinueCase SendCommand2CMD("ipconfig") Case $idButton_Ping If ControlGetFocus($hGUI) <> $sButton_PingNN Then ContinueCase SendCommand2CMD("ping autoitscript.com -n 10") Case $idButton_RunBatch If ControlGetFocus($hGUI) <> $sButton_RunBatchNN Then ContinueCase $sFile = FileOpenDialog("Select a batch file to execute", "", "Batch File (*.cmd; *.bat)", 3, "", $hGUI) If @error Then MsgBox(64, "Information", "Aborted", 5, $hGUI) ContinueCase EndIf SendCommand2CMD($sFile) Case $idButton_ChgBGColor If ControlGetFocus($hGUI) <> $sButton_ChgBGColorNN Then ContinueCase ChooseColorBG($hGUI, $hButton_ChgBGColor, $aPalette, $hImage_BG, "BG") Case $idButton_ChgFGColor If ControlGetFocus($hGUI) <> $sButton_ChgFGColorNN Then ContinueCase ChooseColorBG($hGUI, $hButton_ChgFGColor, $aPalette, $hImage_FG, "FG") Case $idButton_ChgFont If ControlGetFocus($hGUI) <> $sButton_ChgFontNN Then ContinueCase $aFont = _ChooseFont($sFont, 10, 0, 600, False, False, False, $hGUI) If @error Then ContinueLoop GUICtrlSetFont($idEdit, $aFont[3], $aFont[4], $aFont[1], $aFont[2], 5) ControlFocus($hGUI, "", $idEdit) EndSwitch Until False Func ChooseColorBG($hGUI, $hControl, ByRef $aPalette, $hImageList, $xG) GUISetState(@SW_DISABLE, $hGUI) Local $aCtrlPos = MouseGetPos() Local Const $iUB = UBound($aPalette) - 1, $iWX = 4, $iWY = 5 Local Const $dx = 4, $dy = 4, $iSizeW = 24, $iSizeH = 24 Local $iW = $iWX * ($iSizeW + $dx) - $dx, $iH = $iWY * ($iSizeH + $dy) - $dy + 45 Local $iX = $aCtrlPos[0] - $dx, $iY = $aCtrlPos[1] - $dy If ($iX + $iW) > $aFullScreen[2] Then $iX -= $iW - $dx * 2 If ($iY + $iH) > $aFullScreen[3] Then $iY -= $iH - $dY * 2 Local Const $hGUI_Color = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, $WS_EX_DLGMODALFRAME, $hGUI) Local Const $idButton_CC = GUICtrlCreateButton("More", $iW / 2 - 30, $iWY * ($iSizeH + $dy) + 5, 60, 30) Local $x, $y, $z Local $aCLabels[$iUB] While $z < $iUB $aCLabels[$z] = GUICtrlCreateLabel("", $x * ($iSizeW + $dx), $y * ($iSizeH + $dy), $iSizeW, $iSizeH, $SS_SUNKEN) GUICtrlSetBkColor($aCLabels[$z], $aPalette[$z]) $x = Mod($x + 1, $iWX) If Not $x Then $y += 1 $z += 1 WEnd Local Const $min = $aCLabels[0], $max = $aCLabels[0] + UBound($aCLabels) - 1 GUISetState(@SW_SHOW, $hGUI_Color) Local $aInfo, $c Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_CC $c = _ChooseColor(2, 0, 2, $hGUI_Color) If @error Then ContinueLoop $aPalette[$iUB] = "0x" & Hex($c, 6) ChangeColor($max + 1, $min, $hControl, $hImageList, $xG) ExitLoop EndSwitch $aInfo = GUIGetCursorInfo($hGUI_Color) Switch $aInfo[2] Case 1 If $aInfo[4] >= $min And $aInfo[4] <= $max Then ChangeColor($aInfo[4], $min, $hControl, $hImageList, $xG) ExitLoop EndIf EndSwitch Until False GUISetState(@SW_ENABLE, $hGUI) GUIDelete($hGUI_Color) ControlFocus($hGUI, "", $idEdit) EndFunc Func ChangeColor($iID, $min, $hControl, $hImageList, $xG) _GUIImageList_Remove($hImageList) _WinAPI_DeleteObject($hBmp_BG) Local Const $iColor = $aPalette[$iID - $min] $hBmp_BG = _WinAPI_CreateSolidBitmap($hControl, $iColor, 14, 10) _GUIImageList_Add($hImageList, $hBmp_BG) _GUICtrlButton_SetImageList($hControl, $hImageList, 1) If $xG = "BG" Then GUICtrlSetBkColor($idEdit, $iColor) Else GUICtrlSetColor($idEdit, $iColor) _WinAPI_DeleteObject($hBitmap) $hBitmap = CreateCaretBitmap(9, 14, "0xFF" & Hex($iColor, 6)) EndIf EndFunc Func SendCommand2CMD($sCommand) ControlFocus($hGUI, "", $idEdit) ControlSend($hGUI, "", $idEdit, $sCommand & @LF) EndFunc ;==>SendCommand2CMD Func EditWndProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_KEYDOWN Switch $wParam Case 0x25 ;left $aCaretPos = GetCaretPos() If ($aCaretPos[0] / 9) <= $iPrefixLen Then DllCall('user32.dll', 'int', 'SetCaretPos', 'int', $aCaretPos[0] + 1, 'int', $aCaretPos[1]) $aCaretPos = GetCaretPos() Return 1 EndIf Case 0x0D ;enter Local $sCMD = StringMid(_GUICtrlEdit_GetLine($hEdit, _GUICtrlEdit_LineFromChar($hEdit)), $iPrefixLen + 1) If $sCMD <> "" Then ExecuteCMDRT($sCMD) $sCMDLine = StringReplace(ExecuteCMD("cd"), @CRLF, "") ExecuteCMD("cd /d " & $sCMDLine) EndIf $iPrefixLen = StringLen($sCMDLine & ">") _GUICtrlEdit_AppendText($hEdit, $sCMDLine & ">") _GUICtrlEdit_SetSel($hEdit, -1, -1) _GUICtrlEdit_Scroll($hEdit, $SB_SCROLLCARET) $aCaretPos = GetCaretPos() Sleep(30) Return 1 Case 0x08, 0x24, 0x26, 0x28 ;backspace, home, arraow up, arrow down If _GUICtrlEdit_LineLength($hEdit) < $iPrefixLen Then _GUICtrlEdit_AppendText($hEdit, ">") $aCaretPos = GetCaretPos() EndIf Return 1 EndSwitch Case $WM_LBUTTONDOWN DllCall('user32.dll', 'int', 'SetCaretPos', 'int', $aCaretPos[0], 'int', $aCaretPos[1]) Return 1 EndSwitch Return _WinAPI_CallWindowProc($hOldEditProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>EditWndProc Func GetCaretPos() ;http://msdn.microsoft.com/en-us/library/ms648402(v=vs.85).aspx Local Const $Point = "LONG x;LONG y;" Local $sPoint = DllStructCreate($Point) DllCall("User32.dll", "int", "GetCaretPos", "ptr", DllStructGetPtr($sPoint)) Local $aPos[2] = [DllStructGetData($sPoint, "x") - 1, DllStructGetData($sPoint, "y")] Return $aPos EndFunc ;==>GetCaretPos Func ExecuteCMDRT($sCommand) Local $iPID, $line If StringMid($sCommand, 2, 1) = ":" Then $iPID = Run(@ComSpec & ' /c "' & $sCommand & '"', StringRegExpReplace($sCommand, "(.+\\)(.*)", "$1"), @SW_HIDE, $STDERR_MERGED) ;set working dir to path of file Else $iPID = Run(@ComSpec & ' /c "' & $sCommand & '"', $sCMDLine, @SW_HIDE, $STDERR_MERGED) EndIf While 1 $line = StdoutRead($iPID) If @error Then ExitLoop _GUICtrlEdit_AppendText($hEdit, Oem2Ansi($line)) WEnd _GUICtrlEdit_AppendText($hEdit, @CRLF) EndFunc ;==>ExecuteCMDRT Func ExecuteCMD($sCommand) Local $iPID = Run(@ComSpec & ' /c "' & $sCommand & '"', $sCMDLine, @SW_HIDE, $STDERR_MERGED) Local $line While 1 $line &= StdoutRead($iPID) If @error Then ExitLoop WEnd Return Oem2Ansi($line) EndFunc ;==>ExecuteCMD Func Oem2Ansi($text) Local $aText = DllCall("user32.dll", "Int", "OemToChar", "str", $text, "str", "") Return $aText[2] EndFunc ;==>Oem2Ansi Func CreateCaretBitmap($iW = 9, $iH = 14, $iColor = 0xFFC0C0C0) Local Const $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) Local Const $hBitmap = $aResult[6] Local Const $hCtx = _GDIPlus_ImageGetGraphicsContext($hBitmap) Local Const $hBrush = _GDIPlus_BrushCreateSolid($iColor) _GDIPlus_GraphicsFillRect($hCtx, 0, $iH - 3, $iW, $iH, $hBrush) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hCtx) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBitmap EndFunc ;==>CreateCaretBitmap Func WM_DROPFILES($hWnd, $msg, $wParam, $lParam) Local $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "int", $wParam, "int", -1, "ptr", 0, "int", 0) If @error Then Return SetError(1, 0, 0) Local $tBuffer = DllStructCreate("char[256]") DllCall("shell32.dll", "int", "DragQueryFile", "int", $wParam, "int", 0, "ptr", DllStructGetPtr($tBuffer), "int", DllStructGetSize($tBuffer)) Local Const $sDroppedFiles = DllStructGetData($tBuffer, 1) ;~ Switch StringRight($sDroppedFiles, 4) ;~ Case ".cmd", ".bat" _GUICtrlEdit_AppendText($hEdit, $sDroppedFiles) $aCaretPos = GetCaretPos() ;~ EndSwitch DllCall("shell32.dll", "none", "DragFinish", "int", $wParam) $tBuffer = 0 WinActivate($hWnd) Return "GUI_RUNDEFMSG" EndFunc ;==>WM_DROPFILES Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Switch BitShift($wParam, 16) Case $EN_SETFOCUS DllCall('user32.dll', 'int', 'CreateCaret', 'hwnd', $lParam, 'ptr', $hBitmap, 'int', 0, 'int', 0) DllCall('user32.dll', 'int', 'ShowCaret', 'hwnd', $lParam) DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $iBlinkTime) $aBlinkTime = DllCall('user32.dll', 'int', 'GetCaretBlinkTime') $iBlinkTime = $aBlinkTime[0] Case $EN_KILLFOCUS DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam) DllCall('user32.dll', 'int', 'DestroyCaret') DllCall('user32.dll', 'int', 'SetCaretBlinkTime', 'uint', $aBlinkTime[0]) EndSwitch Return "GUI_RUNDEFMSG" EndFunc ;==>WM_COMMAND Func _GetNN($hWnd) Local $List, $Text, $ID = 0 $Text = _WinAPI_GetClassName($hWnd) If Not $Text Then Return -1 EndIf $List = _WinAPI_EnumChildWindows(_WinAPI_GetAncestor($hWnd, $GA_ROOT), 0) If @error Then Return -1 EndIf For $i = 1 To $List[0][0] If $List[$i][1] = $Text Then $ID += 1 EndIf If $List[$i][0] = $hWnd Then ExitLoop EndIf Next If Not $ID Then Return -1 EndIf Return $ID EndFunc ;==>_GetNN Func _WinAPI_EnumChildWindows($hWnd, $fVisible = 1) If Not _WinAPI_GetWindow($hWnd, 5) Then Return SetError(1, 0, 0) EndIf Local $hEnumProc = DllCallbackRegister('__EnumWindowsProc', 'int', 'hwnd;lparam') Dim $__Enum[101][2] = [[0]] DllCall('user32.dll', 'int', 'EnumChildWindows', 'hwnd', $hWnd, 'ptr', DllCallbackGetPtr($hEnumProc), 'lparam', $fVisible) If (@error) Or (Not $__Enum[0][0]) Then $__Enum = 0 EndIf DllCallbackFree($hEnumProc) If Not IsArray($__Enum) Then Return SetError(1, 0, 0) EndIf __Inc($__Enum, -1) Return $__Enum EndFunc ;==>_WinAPI_EnumChildWindows Func __EnumWindowsProc($hWnd, $fVisible) If ($fVisible) And (Not _WinAPI_IsWindowVisible($hWnd)) Then Return 1 EndIf __Inc($__Enum) $__Enum[$__Enum[0][0]][0] = $hWnd $__Enum[$__Enum[0][0]][1] = _WinAPI_GetClassName($hWnd) Return 1 EndFunc ;==>__EnumWindowsProc Func __Inc(ByRef $aData, $iIncrement = 100) Select Case UBound($aData, 2) If $iIncrement < 0 Then ReDim $aData[$aData[0][0] + 1][UBound($aData, 2)] Else $aData[0][0] += 1 If $aData[0][0] > UBound($aData) - 1 Then ReDim $aData[$aData[0][0] + $iIncrement][UBound($aData, 2)] EndIf EndIf Case UBound($aData, 1) If $iIncrement < 0 Then ReDim $aData[$aData[0] + 1] Else $aData[0] += 1 If $aData[0] > UBound($aData) - 1 Then ReDim $aData[$aData[0] + $iIncrement] EndIf EndIf Case Else Return 0 EndSelect Return 1 EndFunc ;==>__Inc
    Download: Pseudo CMD Box.au3 (previous downloads: 55)

    It is neither a real CMD window nor CMD box embedded. Further it is not fully compatible with cmd currently because some commands are not executed properly.

    Br,
    UEZ
  24. Like
    armoros reacted to JScript in [Tutorial] - Learning about Window (GUI) - a brief explanation!   
    @guinness, @armoros and all

    I accept suggestions, corrections, additions, after all: this tutorial is for all of us!

    Regards,

    João Carlos.
  25. Like
    armoros reacted to JScript in [Tutorial] - Learning about Window (GUI) - a brief explanation!   
    This short tutorial is intended for beginners in programming GUIs!

    Chapter 01 - Introduction (What is a Window?)



    Chapter 02 - Creating your 1st window.



    To be continued...

    Regards,

    João Carlos.
×
×
  • Create New...