Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/08/2013 in all areas

  1. BugFix version - 27 Dec 23 Fixed: No default value set for the MaxWidth parameter - took 12 years for someone to notice it! New UDF and new examples below and in zip. I just realised that although I have posted versions of this UDF many times in Help topics, I had never actually posted a "final" version here in Example scripts - better late than never, I suppose! StringSize takes a text string and calculates the size of label required to hold it as well as formatting the string to fit. Now AutoIt will, of course, size a label automatically to fit a text string, but it will not format the string in any way - what you use as the string is what you get in the label. If you do set any label sizes the text will be wrapped, but you can only determine the correct size of the label by trial and error. StringSize will, however, reformat the string to fit in a given width and tell you the required height so that you can read it all - whatever the font type or size - and you do not have to do the formatting beforehand. Here is a simple example to show what I mean (you need the UDF in the same folder for all the examples): And here is an example showing how StringSize can deal with different fonts and text sizes: You can see that the GUI is perfectly sized each time and that the button is always the right size and in the right place. StringSize returns an array which contains the formatted text to display and the size of the label needed to display it. All you need to do is to use the array elements when you create your label. Try changing the values in $aFont and $aSize if you want to try you own favourites - but beware, StringSize will return an error if you make the size so large that it cannot fit a word into the label width. NEW A more complex example showing how formatted and unformatted text can be sized correctly. The width of GUI holding the unformatted text varies randomly in width (the current value is displayed at top right): NEW And a final example showing how you can get your text in the largest possible font to fit in a given space: Finally here is the UDF itself: And all 5 files in zip format: StringSize.zip I hope you find this useful - I certainly do. M23
    1 point
  2. This UDF allows to create formatted label using pseudo element RichLabel (RichEdit actually). Formating is set by using special modificator similar to <font> tag in Html. Notes: This UDF is a transformation-continuation of related UDF Example: Download: GUIRichLabel_1.2.zip Small syntax related fix: GUIRichLabel_1.1.zip GUIRichLabel_1.1.zip History version:
    1 point
  3. jdelaney

    WinWaitActive?

    Are you always logged in when this runs? If not, then you will not be able to make the window active. http://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F Using WinExists will work (loop until it does), and then wait for the WinGetState to include is visible, and is enabled...then use controlsend instead of send
    1 point
  4. Exit

    WinWaitActive?

    Second Winwaitactive has a systax error. Should read: WinWaitActive("[classname:TMessageForm]")
    1 point
  5. water

    Excel to Webform

    Start with _ExcelBookOpen, _ExcelReadArray and _ExcelBookClose to read your data. Functions _IECreate or _IEAttach, _IEFormGetObjByName and _IEFormElementSetValue, _IEQuit will show how to insert the data. Details plus examples can be found in the help file.
    1 point
  6. Varian

    WinWaitActive?

    Have you tried a simple Activate/Wait util Active loop? Do WinActivate("classname=TMessageForm") Sleep(10) Until WinActive("classname=TMessageForm")
    1 point
  7. guinness

    IP Tool

    I thought I recognised _WMIArrayToString.
    1 point
  8. What do you get if you try: #include <OutlookEX.au3> #include <Array.au3> $oOutlook = _OL_Open() ConsoleWrite("_OL_Open: " & @error & @LF) $Local_Folder = _OL_FolderAccess($oOutlook, "Path\To\Folder\With\Mail\Items") ConsoleWrite("_OL_FolderAccess: " & @error &@extended & @LF) $listofmail = _OL_ItemFind($oOutlook, $Local_Folder[1], $olMail, "", "", "", "UnRead,EntryID,SenderEmailAddress,Subject,Body") ConsoleWrite("_OL_ItemFind: " & @error & @LF) _ArrayDisplay($listofmail) Is the first column set to True for unread mails?
    1 point
  9. 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
    1 point
  10. I rewrote the example using the longest line in the label's text to determine the width of the text rectangle. And added a padding parameter for height. This is what I found. A problem with fonts, "Georgia" and "Comic Sans MS" was the attribute parameter (regular, 0), used in _GDIPlus_FontCreate(), does not exist for those fonts. Once the padding is determined for a particular font, the padding works for all different attributes (bold, italics,...) of the font, that the font allows. The green labels have padding. #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GDIPlus.au3> $Gui = GUICreate("GDI label depth anomalies", 600, 400) GUISetState() $msg = "This is the first line." & @CRLF & _ "and another" & @CRLF & _ "followed by another" & @CRLF & _ "and another" & @CRLF & _ "and yet another" & @CRLF & _ "and another" & @CRLF & _ "and one more" & @CRLF & _ "and finally the last" $label0 = _GUICtrlCreateLabelEx($msg, 5, 5, $SS_LEFT, 0x00ff00, 9, 400, 0, "Segoe UI", 0, -16) $label1 = _GUICtrlCreateLabelEx($msg, 205, 5, $SS_CENTER, 0x00ff00, 9, 400, 0, "Times New Roman", 0, 2) $label2 = _GUICtrlCreateLabelEx($msg, 405, 5, $SS_RIGHT, 0xffff00, 9, 400, 0, "Arial") $label3 = _GUICtrlCreateLabelEx($msg, 5, 205, $SS_LEFT, 0xffff00, 9, 400, 2, "Georgia"); Bold -1, Italics - 2, Bold Italics - 3 only $label4 = _GUICtrlCreateLabelEx($msg, 205, 205, $SS_CENTER, 0xffff00, 9, 400, 0, "Microsoft Sans Serif") $label5 = _GUICtrlCreateLabelEx($msg, 405, 205, $SS_RIGHT, 0x00ff00, 9, 400, 3, "Comic Sans MS", -8, -15) ;Bold -1, Bold Italics - 3 only While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit WEnd Exit ; ============== _GUICtrlCreateLabelEx ======================================================== ;$sText -The text of the control. ;$left - The left side of the control ;$top - The top of the control. ;$style - $SS_LEFT, $SS_CENTER, $SS_RIGHT from Label/Static Styles ;$BkGndCol - background color The RGB color to use. ;$size - Fontsize ;$weight - Font weight (default 400 = normal). ;$attribute [optional] To define 0 - Normal weight or thickness 2 underlined:4 strike: ; 8 char format (add together the values of all the styles required, 2+4 = italic and underlined) ;$fontname - The name of the font to use. ;$iPadWidth - Integer, add/substract spaces to string $sText width. ;$iPadHeight - Integer, add/substract spaces to string $sText height. ;$iMultiLineRectWidth - Will cause multi lines if less than width of string, $sText, rectangle (when no @CRLF). ; Func _GUICtrlCreateLabelEx($sText, $left, $top, $style = $SS_CENTER, $BkGndCol = $GUI_BKCOLOR_TRANSPARENT, $size = 10, _ $weight = 400, $attribute = 0, $fontname = "Arial", $iPadWidth = 0, $iPadHeight = 0, $iMultiLineRectWidth = @DesktopWidth) Local $hWin, $hRetLabel, $hGraphic, $hFamily, $hGDIFont, $tLayout, $aInfo, $hWdith, $hHeight, $bFlag = False If StringRegExp($sText, "\x0a|\x0d", 0) = 1 Then $aText = StringRegExp($sText, "\w.*[^\x0a|\x0d]", 3) Local $MavChar = 0 For $x = 1 To UBound($aText) - 1 If StringLen($aText[$x]) > StringLen($aText[$MavChar]) Then $MavChar = $x Next $sMeasure = $aText[$MavChar] $bFlag = True Else $sMeasure = $sText EndIf $hWin = WinGetHandle("[ACTIVE]") _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWin) $hFamily = _GDIPlus_FontFamilyCreate($fontname) $hGDIFont = _GDIPlus_FontCreate($hFamily, $size, $attribute) $hFormat = _GDIPlus_StringFormatCreate() $tLayout = _GDIPlus_RectFCreate($left, $top, $iMultiLineRectWidth, @DesktopHeight) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMeasure, $hGDIFont, $tLayout, $hFormat) $hWdith = DllStructGetData($aInfo[0], 3) $hHeight = DllStructGetData($aInfo[0], 4) If $bFlag Then $hHeight = $hHeight * UBound($aText) If Mod($attribute, 2) = 1 Then $attribute = $attribute - 1 $hRetLabel = GUICtrlCreateLabel($sText, $left, $top, $hWdith + $iPadWidth, $hHeight + $iPadHeight, $style) GUICtrlSetBkColor(-1, $BkGndCol) GUICtrlSetFont(-1, $size, $weight, $attribute, $fontname) _WinAPI_RedrawWindow($hWin, 0, 0, BitOR($RDW_ERASE, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN)) _GDIPlus_FontDispose($hGDIFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Return $hRetLabel EndFunc ;==>_GUICtrlCreateLabelEx
    1 point
×
×
  • Create New...