Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/13/2018 in all areas

  1. [New Version] - 27 Jan 22 New: The GUIScrollbar_Ex UDF now recognises Win-D and taskbar desktop clearance commands and runs the correct minimize/restore code automatically. The previous UDF _Minimize and _Restore commands have been superceded by a single _EventMonitor function which runs in the script idle loop. This is a script-breaking change, but I hope that the additional functionality is worth the small effort it will take to alter your scripts. New UDFs, examples in zip file below. Previous changes: Changelog.txt Are you bemused by scrollbars? > Do you find them too difficult to use? > Then you need the GUIScrollbars_Ex UDF! Just download the zip at the end of the post and run this short script with the UDF in the same folder. No tricky calculations, no complicated functions to master - just easy to use, accurate scrollbars with one command! [size=5]#include <guiconstantsex.au3> #include "GUIScrollbars_Ex.au3" ; Create GUI with red background $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xFF0000, $hGUI) ; Create a 1000x1000 green label GUICtrlCreateLabel("", 0, 0, 1000, 1000) GUICtrlSetBkColor(-1, 0x00FF00) GUISetState() ; Generate scrollbars - Yes, this is all you need to do!!!!!!!!!!!!!!!!!!!! _GUIScrollbars_Generate($hGUI, 1000, 1000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd[/size] Try it today and see how easy it is! I have been trying for some time to understand how scrollbars work and how to get them closely to match the area I want to display. After much research and headscratching I have come up with 2 UDFs which I hope will be of use to others. Apologies for the length of this post, but scrollbars are complex beasts and as I did this mainly for the less experienced user I want to make sure that they understand what is going on. The 2 UDFs are: GUIScrollbars_Ex.au3 - This gives you scrollbars sized to your GUI in one simple command - with no other includes or commands needed. The UDF is designed for those who would not normally use scrollbars because the whole process looks too complicated. It also includes a command to enable you to scroll page by page, thus making it easy to scroll to anywhere on the GUI with only simple calulations based on the values you used to create the GUIs. [New] Ability to have recalculated scrollbars on resizeable GUIs. GUIScrollbars_Size.au3 - This calculates the Page and Max numbers for the user to feed into the _GUIScrollbar_SetScrollInfoPage/Max commands. The UDF is aimed at the more experienced user and is particularly useful when you have a GUI with a dynamic scroll size (i.e. adding or subtracting controls to the scrollable area as the script runs). First, a short tutorial for those who are interested in how the scrollbars affect your GUI and what it is that the UDFs calculate: All the files mentioned here are in a downloadable zip file at the end of the post. GUIScrollbars_Size.au3 As mentioned previously, the GUIScrollbars_Size.au3 UDF is aimed at the more experienced user who wants to use the full range of _GUIScrollbar comands, but would like a quick way of getting the required Page and Max values. It uses no other include files so you will need to include GUIScrollbars.au3 yourself, as well as the necessary GUIRegisterMsg and procedures for WM_VSCROLL and WM_HSCROLL. The syntax is simple - the size of the scrollable GUI and either the handle of the GUI you have created to hold the scrollbars or the size of the one you are going to create. It returns a 6-element array including the Page and Max values for the scrollbars and factors to compensate for the "shrinkage" of the GUI if you had already drawn some controls and wished to add others. Of interest, the returned Max value is biased not to clip the edges of the GUI - reducing it by 1 makes a tighter fit but can lead to some clipping. (If that does not make sense, please see the tutorial above for more details) The Size_Example_1 script to show the UDF in action - the "Pass Size" button shows the effect of creating the scrollbars BEFORE the controls, the "Pass Handle" button shows what happens if the scrollbars are created AFTER the controls. If you do not understand why there is a difference - go and read the tutorial above ! You will need to have the GUIScrollbar_Size.au3 UDF in the same folder. Where this UDF really helps is if you have a scrollable GUI of variable size - if the number of controls varies with user selections for example. All you need to do is to rerun the UDF with the new size of the scrollable GUI and it produces a new Max value for you to use. The Size_Example_2 script shows how the function enables you to dynamically size your scrollbars depending on the number of controls required. As before it requires the GUIScrollbar_Size.au3 UDF in the same folder. -------- Now the "simple" GUIScrollbars_Ex.au3 (which is actually the more complex internally as you would expect). This UDF is intended to be the single point of call for creating scrollbars on a GUI - it will automatically add the GUIScrollbars UDF and the WM_VSCROLL and WM_HSCROLL GUIRegisterMsg commands and procedures to your script - so you need no commands other than those within the UDF itself. These commands are _GUIScrollbars_Generate and _GUIScrollbars_Scroll_Page. As you might expect, _GUIScrollbars_Generate generates scrollbars for your GUI. It is usually called AFTER you have added all the controls and all you need to use it is the GUI handle and the size of the underlying GUI you want to scroll. If you so wish, you can also decide to generate the scrollbars BEFORE the controls on the scrollable GUI, and you can choose if you want to risk not quite reaching the edge of the GUI when the scrollbars are at the maximum position. So a basic call could be as simple as: _GUIScrollbars_Generate ($hGUI, 1000, 1000) which would put scrollbars on the $hGUI window allowing a 1000x1000 underlying GUI to be displayed. _GUIScrollbars_Scroll_Page lets you scroll a page at a time. If your GUI was 200 pixels wide, you would have 1000/200 = 5 pages to scroll before reaching the edge - no need to know what the actual Page and Max values are, just use this simple division based on the number you use to draw the GUIs. So: _GUIScrollbars_Scroll_Page ($hGUI, 3) would scroll to the third page - it would display the area between 400 and 600 pixels of the full 1000 pixel width. If you ask for a page over the maximum available, you just scroll to the maximum position - asking for page 1 resets you to the origin. Ex_Example_1 shows the UDF working. You can decide whether to have both or just one scrollbar, whether to create the scrollbars before or after the controls, and whether you want the maximum scroll to be tight to the edge or leave a border. Just select the options you want - the script selects a random width and height for both the scrollbar GUI and the underlying GUI - and press the "Scroll" button to show a single page scroll down and/or right followed by a scroll to the bottom right corner of the GUI. There are labels to let you see the size of the GUI and the accuracy of the page scrolls (please read the tutorial above to understand why these are almost certainly inaccurate). The script requires the GUIScrollbars_Ex.au3 UDF in the same folder. Ex_Example_2 is a really simple example to show how easy generating scrollbars can now become! As you can see - no other includes, no GUIRegisterMsg commands, no WM_H/VSCROLL procedure functions. Just accurate scrolling and proportional thumb sizes. Ex_Example_3 shows the automatic calculation of control positions. Ex_Example_4 shows how to initiate the cursor keys to scroll the GUI as well. [New] Ex_Example_5 shows how to use the new _GUIScrollbarsEx_Resizer function. I hope these 2 UDFs are useful to AutoIt users - I certainly find them so. Here is a zip file with the UDFs and examples: Scrollbars.zip My grateful thanks to the authors of the GUIScrollbars and WinAPI UDFs for their code, some of which I have plundered. And as always I welcome constructive criticism and/or effusive congratulations. M23
    1 point
  2. Several reasons a drive won't get mapped. If your current user is a local account, you'll need to pass in credentials to map to a remote computer. If you are using a network account, but running elevated, you will also need to pass in credentials. If you are using a network account, and not running elevated, windows automagically use your login credentials to map a drive. So if you have the permissions on the server you are mapping you will automatically succeed in the mapping. Other reasons a drive will failed to get mapped is if there is already another mapped drive to that server. There are workarounds for this, you can instead map by the IP. I'd suggest you attempt to pass in credentials to the function, with a user that has the rights on the target machine.
    1 point
  3. Thanks to a post by JamesB I discovered adding User Call Tips was possible. This script does it for you so you can add ToolTips for functions that are not included with AutoIt, and could even be for your own functions in the script you are working on. The toolTips can be updated or removed at any time. Updates are shown as comments at start of script. ; AddCallTips.au3 ;automates adding User Call Tips to SciTE. See SciTE help for User Call Tips. Const $version = "V1.5" ;version changes ;1.5 Allowed for having functions in UDF which must not be given Call Tips. Useful for internal functions. ;1.4 rewote functions UpdateCallTips and replaceUCT ;1.31 Removed \V at start of search patter for StringREgExpr/Replace ;1.3 Improved matching function names so if parameters have been changed update still works etc. ;1.2 Added warnings for invalid files, too few comment chars and no Key Word for comments. ; Rearranged things a bit to improve readabilty. Simplified some things. ;1.1 change default folder to last folder used for fileopendialog {Bowmore} ; made folder for backups and added numbered backups ;next line only used when developing the script ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### $Form2 = GUICreate("Add User Call Tips", 380, 443, 303, 219) $Label1 = GUICtrlCreateLabel("UDF whose functions are to be added", 12, 8, 187, 17) $IpUDFpath = GUICtrlCreateInput("", 12, 27, 351, 21) $BtnBrowse = GUICtrlCreateButton("&Browse", 206, 5, 50, 20, 0) $BtnApply = GUICtrlCreateButton("&Apply the above changes to Scite UserCallTips", 12, 301, 353, 25, 0) $Group1 = GUICtrlCreateGroup("Options", 8, 175, 362, 113) $ChkCommentLimit = GUICtrlCreateCheckbox("&Limit maximum comment length", 200, 194, 163, 17) GUICtrlSetState(-1, $GUI_CHECKED) $RadioReplaceAll = GUICtrlCreateRadio("&Replace existing CallTips", 12, 194, 137, 17) $RadioReplaceWarn = GUICtrlCreateRadio("&Warn before replacing Call Tips", 12, 217, 169, 17) $RadioReplaceNone = GUICtrlCreateRadio("Do &not replace existing Call Tips", 11, 240, 170, 17) GUICtrlSetState(-1, $GUI_CHECKED) $InputMaxChar = GUICtrlCreateInput("80", 238, 215, 32, 21) $Label4 = GUICtrlCreateLabel("characters", 276, 218, 54, 17) $ChkShowSummary = GUICtrlCreateCheckbox("&Show result summary", 200, 265, 145, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetState(-1, $GUI_HIDE) $Label5 = GUICtrlCreateLabel("", 189, 184, 1, 99) GUICtrlSetBkColor(-1, 0xD4D0C8) $Label7 = GUICtrlCreateLabel("to", 223, 217, 13, 17) $RadioRemoveAll = GUICtrlCreateRadio("Remo&ve all Call Tips for this UDF", 12, 265, 174, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) $EdResults = GUICtrlCreateEdit("", 15, 352, 347, 81, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) $LabResSummary = GUICtrlCreateLabel("Result summary", 16, 335, 78, 17) $Group2 = GUICtrlCreateGroup("Key words in UDF (must be in a comment before the function.)", 8, 64, 362, 97) $Key = GUICtrlCreateLabel("the text after this Keyword", 18, 84, 126, 17) $Label6 = GUICtrlCreateLabel("to exclude the Function", 25, 117, 115, 17) $Label8 = GUICtrlCreateLabel(" from UserCallTips", 28, 132, 89, 17) $IpKeyDescription = GUICtrlCreateInput("Description:", 155, 86, 201, 21) $IpKeyExclude = GUICtrlCreateInput("Internal Use", 155, 121, 201, 21) $Label2 = GUICtrlCreateLabel("is the comment", 28, 97, 75, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### WinSetTitle($Form2, "", "Add User Call Tips " & $version) Const $ReplaceNone = 0 Const $ReplaceAll = 1 Const $ReplaceWarn = 2 Const $RemoveAll = -1 Global $iniFile = @ScriptDir & "\UserCallTips.ini" Global $SavedKWDesc = IniRead($iniFile, "Keywords", "UserCallTip", "Description:"), $KWDesc Global $SavedKWExclude = IniRead($iniFile, "Keywords", "Exclude", "Internal Use"), $KWExclude Global $lastfile = IniRead($iniFile, "Keywords", "LastFile", "") Global $lastCTCommentLimit = IniRead($iniFile, "Keywords", "MaxComment", 100) Global $lastFolder = StringLeft($lastfile, StringInStr($lastfile, '\', 0, -1)) GUICtrlSetData($IpUDFpath, $lastfile) GUICtrlSetData($IpKeyDescription, $SavedKWDesc) GUICtrlSetData($InputMaxChar, $lastCTCommentLimit) If StringInStr($lastfile, '\') Then $lastFolder = StringLeft($lastfile, StringInStr($lastfile, '\', 0, -1)) EndIf Global $nMsg, $file While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ChkCommentLimit HideOrShowCommentLimit(GUICtrlRead($ChkCommentLimit) = $GUI_UNCHECKED) Case $BtnBrowse $file = FileOpenDialog("Select the UDF", $lastFolder, "AutoIt File (*.au3)", 3) GUICtrlSetData($IpUDFpath, $file) Case $BtnApply If Not ApplyChanges() Then GUICtrlSetData($EdResults, "No action taken") EndSwitch WEnd ;ApplyChanges ;returns true if changes made otherwise it returns false Func ApplyChanges() Local $CTresult, $UDFfile, $CallTipCommentLimit, $opt If GUICtrlRead($IpKeyDescription) = '' Then If WarningA(262144 + 4, "WARNING", "You have no Key Word for comments." & @CRLF & " No Comments will be added." & @CRLF _ & "Do you wish to proceed?", $IpKeyDescription) <> 6 Then Return False EndIf $UDFfile = GUICtrlRead($IpUDFpath) If $UDFfile = '' Or Not FileExists($UDFfile) Then If WarningA(262144, "ERROR", "You must enter a valid AU3 script!", $IpUDFpath) <> 6 Then Return False EndIf GUICtrlSetData($EdResults, "") $KWDesc = GUICtrlRead($IpKeyDescription) $KWExclude = GUICtrlRead($IpKeyExclude) If GUICtrlRead($RadioReplaceAll) = $GUI_CHECKED Then $opt = $ReplaceAll ElseIf GUICtrlRead($RadioReplaceWarn) = $GUI_CHECKED Then $opt = $ReplaceWarn ElseIf GUICtrlRead($RadioRemoveAll) = $GUI_CHECKED Then $opt = $RemoveAll Else $opt = $ReplaceNone;do not replace any EndIf If $opt <> $RemoveAll Then;a new Call Tip could be written If GUICtrlRead($ChkCommentLimit) = $GUI_CHECKED Then $CallTipCommentLimit = GUICtrlRead($InputMaxChar) If $CallTipCommentLimit < 40 Then If WarningA(262144 + 4, "WARNING", "You have set fewer than 40 characters for comments." & @CRLF _ & "Do you wish to proceed?", $InputMaxChar) <> 6 Then Return False EndIf Else $CallTipCommentLimit = 0;0 means no maximum EndIf EndIf If $opt = $RemoveAll Then If MsgBox(262144 + 4, "Confirm", "Do you want to remove all the Call Tips for " & _ @CRLF & $UDFfile & "?") <> 6 Then Return False EndIf $CTresult = UpDateCallTips($UDFfile, $KWDesc, $opt, $CallTipCommentLimit) GUICtrlSetData($EdResults, $CTresult) ;MsgBox(262144, "Reult", $CTresult) If $SavedKWDesc <> $KWDesc Then If MsgBox(262144 + 4, "Key word for Description changed to '" & $KWDesc & "'", "Do yu want to save the new keyword for next time?") = 6 Then IniWrite($iniFile, "Keywords", "UserCallTip", $KWDesc) EndIf EndIf If $SavedKWExclude <> $KWExclude Then If MsgBox(262144 + 4, "Key word for Exclusion has changed to '" & $KWExclude & "'", "Do yu want to save the new keyword for next time?") = 6 Then IniWrite($iniFile, "Keywords", "Exclude", $KWExclude) EndIf EndIf IniWrite($iniFile, "Keywords", "LastFile", GUICtrlRead($IpUDFpath)) If $CallTipCommentLimit <> $lastCTCommentLimit Then IniWrite($iniFile, "Keywords", "MaxComment", $CallTipCommentLimit) $lastCTCommentLimit = $CallTipCommentLimit EndIf Return True EndFunc;==>ApplyChanges Func HideOrShowCommentLimit($dohide) Local $hidestate = $GUI_SHOW If $dohide Then $hidestate = $GUI_HIDE GUICtrlSetState($Label4, $hidestate) GUICtrlSetState($Label7, $hidestate) GUICtrlSetState($InputMaxChar, $hidestate) EndFunc;==>HideOrShowCommentLimit Func UpDateCallTips($udf, $CallTipKeyword, $mode, $maxComment) Local $sCT, $fudf, $CallTipComment = '', $Func = '', $s2 Local $sect, $line, $fw, $CTadded = 0, $CTdoneBefore = 0, $CTreplaced = 0, $CTremoved = 0 Local $AutoItProdexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") Local $UCTFile = $AutoItProdexePath & "\Scite\api\au3.user.calltips.api" Local $result, $backupNum, $backPath, $fnName, $ArraysCT Local $Usemode $sCT = FileRead($UCTFile) $ArraysCT = StringSplit(StringReplace($sCT, @CR, ''), @LF) $fudf = FileOpen($udf, 0) While 1 $line = FileReadLine($fudf) If @error <> 0 Then ExitLoop $line = StringStripWS($line, 3) If StringLeft($line, 1) = ';' Then;it's a comment line so see if it's got the Call Tip in it $sect = StringLeft(StringStripWS(StringRight($line, StringLen($line) - 1), 1), StringLen($CallTipKeyword)) If $sect = $CallTipKeyword Then;yes found Call Tip key word so strip out the Call Tip $CallTipComment = StringRight($line, StringLen($line) - StringInStr($line, $CallTipKeyword) - StringLen($CallTipKeyword)) $CallTipComment = StringStripWS($CallTipComment, 3) If $maxComment > 0 Then $CallTipComment = StringLeft($CallTipComment, $maxComment) EndIf If StringInStr($line, $KWExclude) And $mode <> $ReplaceNone Then $Usemode = $RemoveAll Else $Usemode = $mode EndIf EndIf ;look for functions If StringLeft($line, 5) = 'Func ' Then $Func = getfunc($line);get the function name with parameter details ;$sline includes the parameters, but these could change so we must only look for ; the fn name preceded by any number of spaces and followed by any number of spaces then '(' $fnName = StringStripWS(StringLeft($Func, StringInStr($Func, '(') - 1), 3) replaceUCT($fnName, $ArraysCT, $Func & $CallTipComment, $Usemode, $CTadded, $CTdoneBefore, $CTreplaced, $CTremoved) EndIf If StringLeft($line, 7) = 'EndFunc' Then $CallTipComment = '' WEnd FileClose($fudf) If $CTreplaced + $CTremoved + $CTadded > 0 Then;if a change made ;backup calltips file before changing it $backupNum = 1 $backPath = $AutoItProdexePath & "\Scite\api\BAKs\" If Not FileExists($backPath) Then DirCreate($backPath) EndIf While FileExists($backPath & "BAK" & $backupNum & "au3.user.calltips.api") $backupNum += 1 WEnd FileCopy($AutoItProdexePath & "\Scite\api\au3.user.calltips.api", $backPath & "BAK" & $backupNum & "au3.user.calltips.api") $fw = FileOpen($UCTFile, 2) For $n = 1 To UBound($ArraysCT) - 1 If StringStripWS($ArraysCT[$n], 3) <> '' Then FileWriteLine($fw, $ArraysCT[$n]) Next FileClose($fw) EndIf $result &= "Call Tip changes" & @CRLF If $CTadded > 0 Then $result &= $CTadded & ' added.' & @CRLF Else $result = "No User Call Tips were added!" & @CRLF EndIf If $CTdoneBefore > 0 Then $s2 = ' function was' If $CTdoneBefore > 1 Then $s2 = ' functions were' $result &= $CTdoneBefore & $s2 & ' already included.' & @CRLF EndIf If $CTreplaced > 0 Then $s2 = ' function was' If $CTreplaced > 1 Then $s2 = ' functions were' $result &= $CTreplaced & $s2 & ' replaced.' & @CRLF EndIf $result &= @CRLF If $CTremoved > 0 Then $result &= $CTremoved & " removed" & @CRLF Else $result &= "No call tips removed" EndIf Return $result EndFunc;==>UpDateCallTips ;Returns the function name and parameters from the line without the preceding "Func" text Func getfunc($sf) Local $sm, $spos, $lBracket = 0, $rBracket = 0, $endfunc = 0 $sf = StringReplace($sf, "Func ", '') For $spos = 1 To StringLen($sf) $sm = StringMid($sf, $spos, 1) Switch $sm Case '(' $lBracket += 1 Case ')' $rBracket += 1 EndSwitch If $lBracket > 0 And $lBracket = $rBracket Then $endfunc = $spos ExitLoop EndIf Next If $endfunc > 0 Then Return StringLeft($sf, $endfunc) SetError(-1) Return '' EndFunc;==>getfunc ;Replace the line beginning with $sline in $sText with $NewUCT Func replaceUCT($sline, ByRef $sText, $NewUCT, $repMode, ByRef $PCTadded, ByRef $PCTdoneBefore, ByRef $PCTreplaced, ByRef $PCTremoved) Local $n For $n = 1 To UBound($sText) - 1 If StringRegExp($sText[$n], "(?i)\h*\Q" & $sline & "\E\h*\(") Then $PCTdoneBefore += 1 Switch $repMode Case $RemoveAll $sText[$n] = '';$NewUCT $PCTremoved += 1 Case $ReplaceNone ;already included so do nthing Case $ReplaceAll $sText[$n] = $NewUCT $PCTreplaced += 1 Case $ReplaceWarn If MsgBox(262144 + 4, "Confirmation", "Replace the call tip for function" & @CRLF & $sline & ' ?') <> 6 Then Return $sText[$n] = $NewUCT $PCTreplaced += 1 EndSwitch Return;found and actioned so job done EndIf Next ;haven't found the function so what do we do? Switch $repMode Case $RemoveAll Return Case $ReplaceAll, $ReplaceNone $PCTadded += 1 $n = UBound($sText) ReDim $sText[$n + 1] $sText[$n] = $NewUCT EndSwitch EndFunc;==>replaceUCT Func WarningA($Wtype, $WTitle, $WMessage, $WID, $thenFocus = True) Local $result GUICtrlSetBkColor($WID, 0xff3300) $result = MsgBox($Wtype, $WTitle, $WMessage) Sleep(500) GUICtrlSetBkColor($WID, 0xffffff) If $thenFocus Then GUICtrlSetState($WID, $GUI_FOCUS) Return $result EndFunc;==>WarningA mgrefCallTips
    1 point
×
×
  • Create New...