Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/06/2015 in all areas

  1. mLipok

    SMTP Mailer UDF

    I very long time was using In the end, I found that at present my needs I need to modify it. And here it is: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;~ #AutoIt3Wrapper_Run_Debug_Mode=Y ;(Y/N) Run Script with console debugging. Default=N #Region INCLUDE ;################################## ; Include ;################################## #include <file.au3> #EndRegion INCLUDE #Region Variables ;################################## ; Variables ;################################## Global Enum _ $g__INetSmtpMailCom_ERROR_FileNotFound = 1, _ $g__INetSmtpMailCom_ERROR_Send, _ $g__INetSmtpMailCom_ERROR_ObjectCreation, _ $g__INetSmtpMailCom_ERROR_COUNTER Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory. Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification Global Const $g__cdoAnonymous = 0 ; Do not authenticate Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication Global Const $g__cdoNTLM = 2 ; NTLM ; Delivery Status Notifications Global Const $g__cdoDSNDefault = 0 ; None Global Const $g__cdoDSNNever = 1 ; None Global Const $g__cdoDSNFailure = 2 ; Failure Global Const $g__cdoDSNSuccess = 4 ; Success Global Const $g__cdoDSNDelay = 8 ; Delay Global Const $g__cdoDSNSuccessFailOrDelay = 14 ; Success, failure or delay #EndRegion Variables #Region Example Script ;################################## ; Example Script ;################################## ;~ _Example() Func _Example() Local $sSmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED Local $sFromName = "Name" ; name from who the email was sent Local $sFromAddress = "your@Email.Address.com" ; address from where the mail should come Local $sToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED Local $sSubject = "Userinfo" ; subject from the email - can be anything you want it to be Local $sBody = "" ; the messagebody from the mail - can be left blank but then you get a blank mail Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed Local $sCcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed Local $sBccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low" Local $sUsername = "******" ; username for the account used from where the mail gets sent - REQUIRED Local $sPassword = "********" ; password for the account used from where the mail gets sent - REQUIRED Local $iIPPort = 25 ; port used for sending the mail Local $bSSL = False ; enables/disables secure socket layer sending - set to True if using httpS ; Local $iIPPort = 465 ; GMAIL port used for sending the mail ; Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS Local $bIsHTMLBody = False Local $iDSNOptions = $g__cdoDSNDefault Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions) If @error Then MsgBox(0, "_INetSmtpMailCom(): Error sending message", _ "Error code: " & @error & @CRLF & @CRLF & _ "Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _ "Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _ "Description (rc): " & $rc & @CRLF & @CRLF & _ "ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _ ) ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF) EndIf EndFunc ;==>_Example #EndRegion Example Script #Region UDF Functions ; The UDF ; #FUNCTION# ==================================================================================================================== ; Name ..........: _INetSmtpMailCom ; Description ...: ; Syntax ........: _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress[, $s_Subject = ""[, $as_Body = ""[, ; $s_AttachFiles = ""[, $s_CcAddress = ""[, $s_BccAddress = ""[, $s_Importance = "Normal"[, $s_Username = ""[, ; $s_Password = ""[, $IPPort = 25[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]]) ; Parameters ....: $s_SmtpServer - A string value. ; $s_FromName - A string value. ; $s_FromAddress - A string value. ; $s_ToAddress - A string value. ; $s_Subject - [optional] A string value. Default is "". ; $s_Body - [optional] A string value. Default is "". ; $s_AttachFiles - [optional] A string value. Default is "". ; $s_CcAddress - [optional] A string value. Default is "". ; $s_BccAddress - [optional] A string value. Default is "". ; $s_Importance - [optional] A string value. Default is "Normal". ; $s_Username - [optional] A string value. Default is "". ; $s_Password - [optional] A string value. Default is "". ; $IPPort - [optional] An integer value. Default is 25. ; $bSSL - [optional] A binary value. Default is False. ; $bIsHTMLBody - [optional] A binary value. Default is False. ; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault. ; Return values .: None ; Author ........: Jos ; Modified ......: mLipok ; Remarks .......: ; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/ ; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/ ; Example .......: Yes ; =============================================================================================================================== Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault) ; init Error Handler _INetSmtpMailCom_ErrObjInit() Local $objEmail = ObjCreate("CDO.Message") If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) ; Clear previous Err information _INetSmtpMailCom_ErrHexNumber(0) _INetSmtpMailCom_ErrDescription('') _INetSmtpMailCom_ErrScriptLine('') $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject ; Select whether or not the content is sent as plain text or HTM If $bIsHTMLBody Then $objEmail.Textbody = $s_Body & @CRLF Else $objEmail.HTMLBody = $s_Body EndIf ; Add Attachments If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0) EndIf Next EndIf ; Set Email Configuration $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = $g__cdoBasic $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL ;Update Configuration Settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low" EndSwitch ; Set DSN options If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then $objEmail.DSNOptions = $iDSNOptions $objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress ;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress EndIf ; Update Importance and Options fields $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then _INetSmtpMailCom_ErrObjCleanUp() Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) EndIf ; CleanUp $objEmail = "" _INetSmtpMailCom_ErrObjCleanUp() EndFunc ;==>_INetSmtpMailCom ; ; Com Error Handler Func _INetSmtpMailCom_ErrObjInit($bParam = Default) Local Static $oINetSmtpMailCom_Error = Default If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then $oINetSmtpMailCom_Error = '' Return $oINetSmtpMailCom_Error EndIf If $oINetSmtpMailCom_Error = Default Then $oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc") EndIf Return $oINetSmtpMailCom_Error EndFunc ;==>_INetSmtpMailCom_ErrObjInit Func _INetSmtpMailCom_ErrObjCleanUp() _INetSmtpMailCom_ErrObjInit('CleanUp') EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp Func _INetSmtpMailCom_ErrHexNumber($vData = Default) Local Static $vReturn = 0 If $vData <> Default Then $vReturn = $vData Return $vReturn EndFunc ;==>_INetSmtpMailCom_ErrHexNumber Func _INetSmtpMailCom_ErrDescription($sData = Default) Local Static $sReturn = '' If $sData <> Default Then $sReturn = $sData Return $sReturn EndFunc ;==>_INetSmtpMailCom_ErrDescription Func _INetSmtpMailCom_ErrScriptLine($iData = Default) Local Static $iReturn = '' If $iData <> Default Then $iReturn = $iData Return $iReturn EndFunc ;==>_INetSmtpMailCom_ErrScriptLine Func _INetSmtpMailCom_ErrFunc() _INetSmtpMailCom_ErrObjInit() _INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8)) _INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3)) _INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine) SetError(1); something to check for when this function returns Return EndFunc ;==>_INetSmtpMailCom_ErrFunc #EndRegion UDF Functions Creating this modification, I had to: 1. Object Error Handler used only for the duration of the function of Use, 2. Automatic ErrorHandler CleanUp so that previous ErrorHandler took the job. 3. Ability to get ErrorNumber and ErrorDescription ErrorScriptLine information even after the end of the function 4. Elimination of most global variables mLipok EDIT: attached SmtpMailer_UDF.au3 file EDIT 2: Any comments are welcome. EDIT 3: Script CleanUp EDIT 4: Download moved to "Download Section" (previously downloaded 379 times) EDIT 5: at 2016/01/31 there was many script breaking changes
    1 point
  2. What is NetFlare Web Server? NetFlare is a standalone web server written in pure AutoIt3 with some features: Virtual Hosts Server-side scripting For testing virtual host capability, editing etchosts file is required in most cases. File: C:WindowsSystem32driversetchosts 127.0.0.1 this.is.my.dom 127.0.0.1 private.mycompany.com Souce code (Daemon Main): #include "./Lib/Net/Http/HttpServer.au3" #include "./Lib/IO/Console.au3" _Main() Func _Main() HttpServer_SetPort(80) HttpServer_RegisterHost("this.is.my.dom") HttpServer_RegisterHost("private.mycompany.com", @ScriptDir & "\WebRoot\custompath\deeper\private.mycompany.com") ConsoleWrite("NetFlare Web Server 0.2, By Dhilip89" & @CRLF & @CRLF) ConsoleWrite("Registered virtual hosts: " & @CRLF) $HostList = HttpServer_GetRegisteredHosts() For $i = 0 To HttpServer_CountRegisteredHosts() - 1 ConsoleWrite("[" & $i+1 & "] " & $HostList[$i] & @CRLF) Next HttpServer_Start() ConsoleWrite(@CRLF & "Server is running..." & @CRLF) While 1 Sleep(1000) WEnd EndFunc - Screenshots (0.2): Screenshots (0.3): Animated GIF (Stress testing, using meta refresh): <= Click or download to view Download Links: (Version 0.1): http://www.mediafire.com/download/an1gngni6qeh5x9/NetFlare_v0.1.zip (Version 0.2): http://www.mediafire.com/download/3a88m1sgyrth48a/NetFlare_v0.2.zip (Version 0.3): http://www.mediafire.com/download/q3prydlbkygl7jd/NetFlare_v0.3.zip
    1 point
  3. I found what is the issue with TAB This is code generated by GUIBuilderNxt ; Script generated by GUIBuilderNxt Prototype 1.0 #include <Constants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> Const $style = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_MINIMIZEBOX) Global $h_main = GuiCreate("GuiBuilderNxt", 398, 329, -1, -1, $style) Global $Tab_0 = GuiCtrlCreateTab("Tab1", 10, 10, 150, 150) GuiSetState(@SW_SHOWNORMAL) Do Switch GuiGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case Else ; EndSwitch Until False but it should look that ; Script generated by GUIBuilderNxt Prototype 1.0 #include <Constants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> Const $style = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_MINIMIZEBOX) Global $h_main = GuiCreate("GuiBuilderNxt", 398, 329, -1, -1, $style) Global $Tab = GuiCtrlCreateTab(10, 10, 150, 150) Global $Tab_0 = GUICtrlCreateTabItem("Tab1") GUICtrlCreateTabItem("") ; end tabitem definition GuiSetState(@SW_SHOWNORMAL) Do Switch GuiGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case Else ; EndSwitch Until False summary: ;bad Global $Tab_0 = GuiCtrlCreateTab("Tab1", 10, 10, 150, 150) ;good Global $Tab = GuiCtrlCreateTab(10, 10, 150, 150) Global $Tab_0 = GUICtrlCreateTabItem("Tab1") GUICtrlCreateTabItem("") ; end tabitem definition
    1 point
  4. I seem to be in an all to generous mood today, but it's my pleasure.
    1 point
  5. Local $title = "Problem Ejecting USB Mass Storage Device" While 1 If WinExists("[TITLE:" & $title & "]") Then WinClose("[TITLE:" & $title & "]") EndIf WEnd something like this?
    1 point
  6. 1 point
  7. Oh! I want this knowledge! I will go study more (much more).
    1 point
  8. MikahS, you are brilliant too I just pointed him into the right direction, but you showed him working code.
    1 point
  9. Simple example with the IE UDF functionality. Get all links: #include <IE.au3> #include <MsgBoxConstants.au3> Global $url = "http://www.yelp.de/search?find_desc=Hotels&find_loc=Berlin&ns=1" Local $oIE = _IECreate($url) Local $oLinks = _IELinkGetCollection($oIE) Local $iNumLinks = @extended Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF For $oLink In $oLinks $sTxt &= $oLink.href & @CRLF Next MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt) Only difference between this and helpfile example (_IELinkGetCollection()) is *_IECreate() & $url, so it should be pretty easy to start using the IE UDF.
    1 point
  10. Hi All, I have a script which uses _IEAction() to click on a "Browse..." button and I then get a "Choose File to Upload" dialog. However, after the the _IEAction() call, my script does not run anything else. It cannot detect the dialog window and it just seems to freeze up and run nothing after that line. Does anyone know what might be happening here? I posted on this page which seems to be the exact same issue, but there has been no activity in a long time and no one is following it so I thought I would open a new topic. Any help would be great! Thanks
    1 point
  11. I try build a service with interactive GUI too. It not work very well, it's run on Session 0. Not good. I knew many IPC (Interprocess comunication), but I discover many limitations too (_Pipes is very cool, realy like it). But, the best way was create a TCP/IP comunicaton betwen applications (for me). Have more work... But is cool. There are many and great examples in the forum, I have time to test >this example of communication. I build a windows service, running in a administrative account. It answer for any client (any account). Work very very well. I use JSON to code/chain the data. Very well too.
    1 point
  12. UPDATED - see first post. (v2.2) Added a right-click option to relocate Bought ebooks, to what is essentially another username. Basically, the Bought username is taken from whatever user is current, and a bracketed {b} added. So, if you had Fred, all Fred's bought ebooks would be moved to Fred {b}. The house-keeping benefit of that option should be obvious. Bugfix for missing Else statement, so CANCEL now works with recursive ADD ebook URL. Added missing rename entry process for SAVED file location, so each user has their own. NOTES - Not a major update, but important for the bugfix. And I did in the end, find an item I had overlooked updating in last update, but I suspect most have never used the Save to csv file option, which was just a path being stored. Each user now gets their own path stored. If you were one of the few who downloaded the last update (only a small handful), you may have to manually rename or delete that Save path entry (sorry, but it seemed unlikely you would have used it, and I only wanted one checking function each time the program starts). Personally, I would just forget about changing anything and just set the path, when and if you ever use that option again, using the program itself to do so ... as it will only be one orphan ini entry. Just a little rant!
    1 point
  13. When I open CheckBox Properties Window , Why I can not close it with ESC key ? EDIT: Buttons in "Choose Control Type" Window are not pushed (I mean when I click them they should down, but now they are not)
    1 point
  14. jdelaney

    Locate File Types

    You can always change dirs to the root of the folder you want to search from, and run command: dir /s *.avi dir /s *.mp3 It's quick...else you would have to look for the _filelisttoarrayrecursive function...I believe it's in the beta, and newer releases, but I'm using an older autoit version, so it's not there yet.
    1 point
  15. jguinch

    Locate File Types

    I made a script in this sense. Look at in my signature, for _DirGetSizeByExtension, with _Example2().
    1 point
  16. Ascend4nt

    GUI Fun!

    GUI Fun! Not enough posts here are about just plain fun stuff to do with AutoIt, at least not lately. So I figure, why not dig up one of my old UDFs, clean it up a bit, and throw it very emphatically at you lot of misfits! One way of mucking about with AutoIt and Windows that can be entertaining is creating shaped GUIs. Sure, GUIs with regions are nothing new here or in general on the Windows platform. But have you ever just wanted to stare at colorful shapes flying across your screen, for no apparent reason? Well, my friend, you've come to the right place. The first UDF I've put up pretty simple. Boxes, circles, triangles, diamonds, and stars are what I bring you, in technicolor wonder. I will probably add a few more examples when I find the time.. However, its my hope that more people add to this thread - and maybe provide links to other topics or posts where some nifty GUI fun is to be had! GUI related Threads & UDFs of Interest >GUI design concepts (started by Guinness) >Perforator - Perforated GUIs (and really anything GUI or GDI+-related by UEZ) >PNG as GUI >Multiple PNG images as GUI elements >FreeText - Text shape GUIs >Visible Controls on a Transparent Window >Layered Window without Image >AnyGUI - Extend the GUI of any Window >_UskinLibrary - Skinning w/DLL >XSkin - More GUI Skinning >GUIExtender, >GUIFrame, >Toast and other nice UDFs by Melba23 >GIF Animation >GDI+ Animated Waiting / Loading Screens My Examples I should point out other GUI manipulation UDF's I've uploaded in the past, as they too can provide some amusement. >GUIBox - Rubber-band GUIs >Full-screen Crosshairs >BarSweep (very simple example) >BoxSelection (another simple example) Okay, on to the new stuff! _GUIShapes is a UDF with functions to create GUI's shapes like Circles, Boxes, Triangles, Stars, and Diamonds. These GUI's have no interactive elements or controls and are click-through-able, meaning that a click on the GUI will pass through to whatever window is underneath. _LineTraverser is a UDF with functions to create a well, line traverser. Given a start and end point, it will allow you to step through a given line without needing to do any extra work on your behalf. This uses Bresenham's line algorithm to calculate the individual steps. I know this one isn't related to GUI, but its what I used for my second 'GUI fun' example below. Pacman Line-Traversing GUI (>static or >animated). That's right, I managed to animate a GUI! Check it! (now included in the ZIP) Examples that follow will be bundled with the ZIP. Have fun! Updates: GUIShapesExample - whacky shapes flying all over the screen!!! #include "_GUIShapes.au3" ;~ #include <WinAPI.au3> ; already included in <_GUIShapes.au3> ; ======================================================================================================== ; <GUIShapesExample.au3> ; ; Example use of <_GUIShapes.au3> UDF ; ; This example creates a bunch of random GUI shapes with random attributes, and moves ; everything around - randomly. ; ; Author: Ascend4nt ; ======================================================================================================== ; ---------------------- MAIN CODE ------------------------------- Local $iShapeGUIs = 20, $aShapeGUIs[$iShapeGUIs], $iTimer, $iRand, $aRet Local $iRandX, $iRandY, $iRandColor, $iRandLength Local $iTriangles = 0, $iCircles = 0, $iStars = 0, $iDiamonds = 0, $iBoxes = 0 For $i = 0 To $iShapeGUIs - 1 ; Everything random! $iRandX = Random(0, @DesktopWidth - 20, 1) $iRandY = Random(0, @DesktopHeight - 20, 1) $iRandLength = Random(12, 300, 1) $iRandColor = Random(0x111111, 0xFFFFFF, 1) ; Choose a GUI shape at random, with semi-random attributes Switch Random(0, 5, 1) Case 0 $aShapeGUIs[$i] = _TriangleGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iTriangles, 1) * Random(1, 10, 1), Default, Mod($i, 4), $iRandColor) $iTriangles += 1 Case 1 $aShapeGUIs[$i] = _CircleGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iCircles, 1) * Random(1, 10, 1), Default, $iRandColor) $iCircles += 1 Case 2 $aShapeGUIs[$i] = _StarGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iStars, 1) * Random(1, 10, 1), $iRandColor) $iStars += 1 Case 3 $aShapeGUIs[$i] = _DiamondGUICreate($iRandX, $iRandY, $iRandLength, Default, BitAND($iDiamonds, 1) * Random(1, 10, 1), $iRandColor) $iDiamonds += 1 Case Else ; 4 $aShapeGUIs[$i] = _BoxGUICreate($iRandX, $iRandY, $iRandLength, BitAND($iBoxes, 1) * Random(1, 10, 1), Default, $iRandColor) $iBoxes += 1 EndSwitch ; Show the randomly created GUI GUISetState(@SW_SHOWNOACTIVATE, $aShapeGUIs[$i]) ; And set a random transparency too WinSetTrans($aShapeGUIs[$i], '', Random(50, 255, 1)) Next ConsoleWrite("GUI Totals: Triangles:" & $iTriangles & ", Circles:" & $iCircles & ", Stars:" & $iStars & ", Diamonds:" & $iDiamonds & ", Boxes:" & $iBoxes & @CRLF) ; Timer for moving shapes $iTimer = TimerInit() While 1 ; Exit on 'ESC' keypress (BitAND() test for down-state) If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop Sleep(10) ; Move a random GUI every 30+ms If TimerDiff($iTimer) >= 30 Then $iRand = Random(0, $iShapeGUIs - 1, 1) ; Set GUI above other windows WinSetOnTop($aShapeGUIs[$iRand], "", 1) ; Move to a random position WinMove($aShapeGUIs[$iRand], "", Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), Default, Default, 2) ; Reset timer $iTimer = TimerInit() EndIf WEnd _ LineTraverserExample - Where's the ball? Huh, where is it, Fido?! Ooh, there it is! Fetch the ball! Gooood circle.. #include "_GUIShapes.au3" #include "_LineTraverser.au3" ;~ #include <WinAPI.au3> ; ======================================================================================================== ; <LineTraverserExample.au3> ; ; Simple Example of using the <_LineTraverser.au3> and <_GuiShapes.au3> UDF's ; ; A little red-ball will display, and a hollow ball will move towards it. ; A line will be drawn to show how the path from the hollow ball to the red-ball target should work, ; and then the hollow ball moves to it in $iStep increments. ; ; ; Author: Ascend4nt ; ======================================================================================================== Global Const $iStep = 2 Local $hHollowCircle, $hDestCircle, $iExt Local $iXTarget, $iYTarget, $aLineTraverser ; Create the 2 circle GUIs $hHollowCircle = _CircleGUICreate(Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), 81, 10, Default, Random(0x111111, 0xFFFFFF, 1)) $hDestCircle = _CircleGUICreate(1, 1, 17, 0, 17, 0xFF0000) ; Set initial target point $iXTarget = Random(0, @DesktopWidth - 20, 1) $iYTarget = Random(0, @DesktopHeight - 20, 1) ; Source/Target are same to start off with $aLineTraverser = _LineTraverserCreate($iXTarget, $iYTarget, $iXTarget, $iYTarget) ; Move windows to start positions WinMove($hHollowCircle, '', $aLineTraverser[0], $aLineTraverser[1]) ; + Center of hollow circle, - half of target circle WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8) ; Transparency on 'seeker' circle WinSetTrans($hHollowCircle, '', 150) ; Show both GUIs, and put on top of all windows WinSetState($hDestCircle, '', @SW_SHOWNOACTIVATE) WinSetState($hHollowCircle, '', @SW_SHOWNOACTIVATE) WinSetOnTop($hHollowCircle, '', 1) WinSetOnTop($hDestCircle, '', 1) While 1 ; Exit on 'ESC' keypress (in down state) If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop ; < 10 ms sleep with an API call DllCall("kernel32.dll",'none','Sleep','dword',3) If Not _LineTraverserStep($aLineTraverser, $iStep) Then $iExt = @extended ; Was there movement? Then moooove If $iExt Then WinMove($hHollowCircle, '', $aLineTraverser[0], $aLineTraverser[1]) EndIf $aPos = WinGetPos($hHollowCircle) ; Debug check. Should never be hit, so long as Window is moved to each step (including any last steps - see @extended) If $iXTarget <> $aPos[0] Or $iYTarget <> $aPos[1] Then ConsoleWrite("Mismatch: TargetX:" & $iXTarget & ", TraverserX:" & $aLineTraverser[0] & ", Current X:" & $aPos[0] & _ ", TargetY:" & $iYTarget & ", TraverserY:" & $aLineTraverser[1] & ", Current Y:" & $aPos[1] & ", @extended:" & $iExt & @CRLF) EndIf ; A little extra sleep to make it clear we've reached our destination. DllCall("kernel32.dll",'none','Sleep','dword',6) ; Now we'll set a new destination (with a visible line) Dim $iXTarget = Random(0, @DesktopWidth - 20, 1), $iYTarget = Random(0, @DesktopHeight - 20, 1) ; Create a new Line-Traverser (no need to explicitly destroy the last one, it was just an array of numbers) $aLineTraverser = _LineTraverserCreate($aLineTraverser[0], $aLineTraverser[1], $iXTarget, $iYTarget) ; + Center of hollow circle, - center of target circle WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8) ;~ Draw the line on-screen to give a visual indicator of the path that the hollow circle should take ;~ (note that the line will be overwritten by ANY screen activity, but that's fine for the example) ; Get DC to screen $hDC = _WinAPI_GetDC(0) ; Create pen and select it into DC $hPen = _WinAPI_CreatePen(0, 3, 0xFFFFFF) $hPenOld = _WinAPI_SelectObject($hDC, $hPen) ; Note we add 40 (for the center of the hollow circle GUI) _WinAPI_DrawLine($hDC, $aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1) ; Select the old pen back _WinAPI_SelectObject($hDC, $hPenOld) ; Clean up pen and then release DC _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) ; What fun drawing with GDI is =| Else WinMove($hHollowCircle, '', $aLineTraverser[0], $aLineTraverser[1]) EndIf WEnd GUIShapesFun.zip ~prev downloads: 60
    1 point
  17. I never thought about this. I also didn't want to define every detail of this challenge. You have approximately 50 lines of code to play with. I think two small examples in the same file is acceptable, providing the examples are readable. I don't want jaberwacky to have to deal with multiple entries from the same participant. Make sure you have tested your code thoroughly before submission. Also you don't have to tick every box on the list. For me the most important is #7. convey the ease of use of AutoIt to beginners. Same answer to boththose.
    1 point
  18. Ascend4nt

    GUI Fun!

    Well, Lakes.. I hope you're happy! After hours of wading through mathematics crap I finally figured out that up was down and vice versa. And well.. Pacman has cometh forth to do its evil bidding upon your computer screen! This was actually pretty fun to figure out the maths with, although I totally forgot that the cartesian coordinate system does not match the Windows coordinate system. And I didn't want to tweak around with Mapping modes or whatnot.. so I just flipped things around and hacked out a coordinate system that works (a counterclockwise upside-down one, but hey.. thats pretty much how I see the world) Here it is (you'll need the ZIP from the first post): *Edit: Fixed borked ATan() related maths Pacman Line-Traversing GUI Goodness #include "_LineTraverser.au3" #include "_GUIShapes.au3" #include <WinAPI.au3> ; ======================================================================================================== ; <LineTraverserPacmanExample.au3> ; ; Simple Example of using the <_LineTraverser.au3> and <_GuiShapes.au3> UDF's ; ; A little red-ball displays, while a 'Pacman' GUI moves towards it along a line ; An actual line is drawn onscreen to show the path from 'Pacman' to the red-ball target GUI, ; and then the PacGUI moves to it in $iStep increments. ; ; Additional Functions: ; _GUIApplyPacman() ; Converts a square GUI into a Pacman-shaped GUI. Regions are recreated ; ; each time, based on the input ; Atan2_Radians() ; An 'atan2()' function ; ; Author: Ascend4nt ; ======================================================================================================== Global Const $iStep = 2 Local $hPacMan, $hDestCircle, $iExt Local $iXTarget, $iYTarget, $aLineTraverser ; Create the Pacman GUI and apply shape to it $hPacMan = GUICreate("", 81, 81,Random(0, @DesktopWidth - 20, 1), Random(0, @DesktopHeight - 20, 1), 0x80000000, 0x08000080 + 0x20) GUISetBkColor(Random(0x111111, 0xFFFFFF, 1), $hPacMan) _GUIApplyPacman($hPacMan, 0) ; Red-dot GUI $hDestCircle = _CircleGUICreate(1, 1, 17, 0, 17, 0xFF0000) ; Set initial target point $iXTarget = Random(0, @DesktopWidth - 20, 1) $iYTarget = Random(0, @DesktopHeight - 20, 1) ; Source/Target are same to start off with $aLineTraverser = _LineTraverserCreate($iXTarget, $iYTarget, $iXTarget, $iYTarget) ; Move windows to start positions WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1]) ; + Center of hollow circle, - half of target circle WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8) ; Transparency on 'seeker' circle WinSetTrans($hPacMan, '', 150) ; Show both GUIs, and put on top of all windows WinSetState($hDestCircle, '', @SW_SHOWNOACTIVATE) WinSetState($hPacMan, '', @SW_SHOWNOACTIVATE) WinSetOnTop($hPacMan, '', 1) WinSetOnTop($hDestCircle, '', 1) While 1 ; Exit on 'ESC' keypress (in down state) If BitAND(_WinAPI_GetAsyncKeyState(0x1B), 0x8000) Then ExitLoop ; < 10 ms sleep with an API call DllCall("kernel32.dll",'none','Sleep','dword',3) If Not _LineTraverserStep($aLineTraverser, $iStep) Then $iExt = @extended ; Was there movement? Then moooove If $iExt Then WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1]) EndIf $aPos = WinGetPos($hPacMan) ; Debug check. Should never be hit, so long as Window is moved to each step (including any last steps - see @extended) If $iXTarget <> $aPos[0] Or $iYTarget <> $aPos[1] Then ConsoleWrite("Mismatch: TargetX:" & $iXTarget & ", TraverserX:" & $aLineTraverser[0] & ", Current X:" & $aPos[0] & _ ", TargetY:" & $iYTarget & ", TraverserY:" & $aLineTraverser[1] & ", Current Y:" & $aPos[1] & ", @extended:" & $iExt & @CRLF) EndIf ; A little extra sleep to make it clear we've reached our destination. DllCall("kernel32.dll",'none','Sleep','dword',6) ; Now we'll set a new destination (with a visible line) Dim $iXTarget = Random(0, @DesktopWidth - 20, 1), $iYTarget = Random(0, @DesktopHeight - 20, 1) ; Create a new Line-Traverser (no need to explicitly destroy the last one, it was just an array of numbers) $aLineTraverser = _LineTraverserCreate($aLineTraverser[0], $aLineTraverser[1], $iXTarget, $iYTarget) ; + Center of hollow circle, - center of target circle WinMove($hDestCircle, '', $iXTarget + 40 - 8, $iYTarget + 40 - 8) ; Apply Pacman GUI with calculated angle of line it should point towards _GUIApplyPacman($hPacMan, Atan2_Radians($iYTarget - $aLineTraverser[1], $iXTarget - $aLineTraverser[0])) ; Draw the line on-screen to give a visual indicator of the path that the hollow circle should take ; (note that the line will be overwritten by ANY screen activity, but that's fine for the example) ; Get DC to screen $hDC = _WinAPI_GetDC(0) ; Create pen and select it into DC $hPen = _WinAPI_CreatePen(0, 3, 0xFFFFFF) $hPenOld = _WinAPI_SelectObject($hDC, $hPen) ; Note we add 40 (for the center of the hollow circle GUI) _WinAPI_DrawLine($hDC, $aPos[0] + 40 - 1, $aPos[1] + 40 - 1, $iXTarget + 40 - 1, $iYTarget + 40 - 1) ; Select the old pen back _WinAPI_SelectObject($hDC, $hPenOld) ; Clean up pen and then release DC _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) ; What fun drawing with GDI is =| ;Sleep(4000) Else WinMove($hPacMan, '', $aLineTraverser[0], $aLineTraverser[1]) EndIf WEnd Exit ; ================================================================================================================= ; Func _GUIApplyPacman($hGUI, $fAngleInRads) ; ; Takes a GUI and applies a 'Pacman' shape to it. The angle of Pacman's mouth is based upon the $fAngleinRads ; variable (the mouth is a 90 degree angle rotated towards the angle given) ; ; Returns: ; Success: 1, @error = 0 ; Failure: 0, @error set ; ; Author: Ascend4nt ; ================================================================================================================= Func _GUIApplyPacman($hGUI, $fAngleInRads) Local $aPos, $aVertices, $hEllipseRgn = 0, $hPieRegion = 0 Local $iCenterXY $aPos = WinGetPos($hGUI) If @error Then Return SetError(1, 0, 0) $iCenterXY = $aPos[2] / 2 #cs ;; -------------- ; Vertices array: ; --------------- ; These vertices make up the mouth. 0.78539816 is a 45 degree difference (in Radians) ; Note that the multipler should typically be Radius, not $aPos[2] as here, if we were creating a line ; to the circumference of the circle. However, that would cause a weird triangle-inside-a-circle effect ; when combining Regions. So we overextend it and let Windows clip the line at the GUI borders, ; which does its job of covering up the outer parts of the circle ; ---------------------------------------------------------------- #ce Dim $aVertices[3][2] = [ _ [ $iCenterXY, $iCenterXY ], _ ; We over-extend the lines here ($aPos[2] is way longer than the radius) [ $iCenterXY + $aPos[2] * Cos($fAngleInRads - 0.78539816), $iCenterXY + $aPos[2] * Sin($fAngleInRads - 0.78539816) ], _ [ $iCenterXY + $aPos[2] * Cos($fAngleInRads + 0.78539816), $iCenterXY + $aPos[2] * Sin($fAngleInRads + 0.78539816) ] _ ] Do ; Create a Basic Elliptical region $hEllipseRgn = _WinAPI_CreateEllipticRgn(_WinAPI_CreateRect(0, 0, $aPos[2], $aPos[3])) If $hEllipseRgn = 0 Then SetError(10) ExitLoop EndIf ; Create the Pacman Pie area $hPieRegion = _WinAPI_CreatePolygonRgn($aVertices, 0, -1, 1) If $hPieRegion = 0 Then SetError(12) ExitLoop EndIf ; Combine, put resulting region in $hEllipseRgn. RGN_AND = 1, RGN_OR = 2, RGN_XOR = 3, RGN_DIFF = 4 If Not _WinAPI_CombineRgn($hEllipseRgn, $hEllipseRgn, $hPieRegion, 4) Then SetError(14) ExitLoop EndIf ; Don't need this anymore (already combined with the Region injected into the GUI) _WinAPI_DeleteObject($hPieRegion) ; Set the region into the GUI. (GUI will then own it so there's no need to delete it) If Not _WinAPI_SetWindowRgn($hGUI, $hEllipseRgn, True) Then SetError(16) ExitLoop EndIf Return 1 Until 1 Local $iErr = @error, $iExt = @extended ; Cleanup _WinAPI_DeleteObject($hEllipseRgn) _WinAPI_DeleteObject($hPieRegion) Return SetError($iErr, $iExt, 0) EndFunc ;==>_GUIApplyPacman ; ================================================================================================================= ; Func Atan2_Radians($fY, $fX) ; ; Atan2() implementation, based on Wikipedia description. See notes ; ; atan2() differs from atan() in that it maps atan(Y/X) to correct Quadrants ; ; References: ; https://en.wikipedia.org/wiki/Atan2 ; https://en.wikipedia.org/wiki/Radian ; https://en.wikipedia.org/wiki/Cosine#Unit-circle_definitions ; ; Returns: Atan2() result in radians (for the flipped counterclockwise system) ; ; Author: Ascend4nt ; ================================================================================================================= Func Atan2_Radians($fY, $fX) Local Const $f_PI = 3.14159265 Local Const $f_PIHalf = $f_PI / 2 ;~ ConsoleWrite("Atan2 entry, $fY = " & $fY & ", $fX = " & $fX & @CRLF) If $fX = 0 Then ; Technically 'undefined' If $fY = 0 Then Return 0.0 If $fY < 0 Then Return -$f_PIHalf Else ; $fY >= 0 Return $f_PIHalf EndIf EndIf Local $fTmp = ATan($fY / $fX) If $fX < 0 Then If $fY < 0 Then Return $fTmp - $f_PI Else Return $fTmp + $f_PI EndIf Else ; $fX > 0 ; already checked == 0 at start Return $fTmp EndIf EndFunc ;==>Atan2_Radians
    1 point
  19. DarkBoost, Easy when you know how! #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $GUIMINWID = 300, $GUIMINHT = 100;set your restrictions here Global $GUIMAXWID = 800, $GUIMAXHT = 500 GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") $hGUI = GUICreate("Test", 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) GUISetState() $aPos = WinGetPos($hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_MAXIMIZE ;WinMove($hGUI, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam) $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, $GUIMINWID) ; min X DllStructSetData($tagMaxinfo, 8, $GUIMINHT) ; min Y DllStructSetData($tagMaxinfo, 9, $GUIMAXWID ); max X DllStructSetData($tagMaxinfo, 10, $GUIMAXHT ) ; max Y Return 0 EndFunc ;==>WM_GETMINMAXINFO All clear? M23
    1 point
×
×
  • Create New...