Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/13/2014 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. JLogan3o13

    Locking Computer

    Better yet, get a badge with a proximity sensor. All you have to be is within 5 feet.
    1 point
  3. Bert

    Locking Computer

    I know what you could do....Have a script running that puts up a splash screen that fills the entire screen. The only way to hide it is to put in your USB stick. WHen the script sees the stick, it hides the splash screen. You remove the stick, it puts the splash screen back. This is not 100% secure for CTRL-ALT-DEL can close the script but you have to know what your doing. May I ask however - why not simply use the Windows key +L to lock the workstation when you leave the workstation and then use your password to get back in when you come back. Pretty much everyone else does that and it works great.
    1 point
  4. Melba23

    AutoTyping Scripts

    JScriptinghomework, JLogan3o13 is quite right - please read the Forum rules (the link is also at bottom right of each page) - particularly the bit about not discussing game automation - before you post again. Thread locked. But welcome to the AutoIt forum - and see you soon with a legitimate question I hope. M23
    1 point
  5. You have also missed our forum rules. Please read them to see that discussion of game automation (mainly because it is pathetic and lame) is prohibited here
    1 point
  6. If you set the GUI background colour with GUISetBkColor() and happen to forget the colour you set it as, then why not try GUIGetBkColor() Function: #include-once #include <WinAPIGdi.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: GUIGetBkColor ; Description ...: Retrieves the RGB value of the GUI background. ; Syntax ........: GUIGetBkColor($hWnd) ; Parameters ....: $hWnd - A handle of the GUI. ; Return values .: Success - RGB value ; Failure - 0 ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func GUIGetBkColor($hWnd) Local $iColor = 0 If IsHWnd($hWnd) Then Local $hDC = _WinAPI_GetDC($hWnd) $iColor = _WinAPI_GetBkColor($hDC) _WinAPI_ReleaseDC($hWnd, $hDC) EndIf Return $iColor EndFunc ;==>GUIGetBkColor Example use of Function: #include <MsgBoxConstants.au3> #include 'GUIGetBkColor.au3' Example() Func Example() Local $hGUI = GUICreate('GUIGetBkColor() Example', 500, 350) GUISetState(@SW_SHOW, $hGUI) Local $aColor = [0x0000FF, 0x8FFF9F, 0xEC4841, 0xB0E35D, 0x440BFD] ; Random colour array. Local $iColor = 0 For $i = 0 To UBound($aColor) - 1 GUISetBkColor($aColor[$i]) Sleep(20) $iColor = GUIGetBkColor($hGUI) ; Pass the GUI handle to the function. MsgBox($MB_SYSTEMMODAL, '', 'Background Color: ' & _ConvertToHexFormat($aColor[$i]) & @CRLF & _ 'GUIGetBkColor() Hex Format: ' & _ConvertToHexFormat($iColor) & @CRLF & _ 'GUIGetBkColor() Returned: ' & $iColor, 0, $hGUI) Next GUIDelete($hGUI) EndFunc ;==>Example Func _ConvertToHexFormat($iColor) Return Hex($iColor, 6) EndFunc ;==>_ConvertToHexFormat
    1 point
  7. John117, I would do it like this: #include <GUIConstants.au3> #include <TabConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include "GUIScrollbars_Ex.au3" Opt("GUIOnEventMode", 1) HotKeySet("{ESC}", "_Exit") $Form1 = GUICreate("Form1", 800, 600, Default, Default) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $tab = GUICtrlCreateTab(10, 10, 780, 560, $TCS_BUTTONS) GUICtrlSetOnEvent(-1, "_Tab") $tab1 = GUICtrlCreateTabItem("tab1") GUICtrlSetState(-1, $GUI_SHOW); will be display first $Left = 600 $Top = 40 $Heigth = 20 $Width = 120 $tab2 = GUICtrlCreateTabItem("Tab2") Dim $F[1000] $aLeft = 20 $aTop = 150 $aHeigth = 20 $Rows = (1 + (100 * 6)) ;rows = 50 ; Close Tab definiton GUICtrlCreateTabItem("") $hTab_Win0 = GUICreate("", 780, 400, 10, 150, $WS_POPUP, $WS_EX_MDICHILD, $Form1) GUISetBkColor(0xFF0000) ; Just to show the GUI clearly $aTop = 20 For $x = 1 To $Rows Step 7 $F[$x] = GUICtrlCreateInput($x, 20, $aTop, 30, $aHeigth) $F[$x + 1] = GUICtrlCreateInput($x + 1, 20 + 30 + 2, $aTop, 30, $aHeigth) $F[$x + 2] = GUICtrlCreateCombo($x + 2, 20 + 30 + 30 + 4, $aTop, 120, $aHeigth) $F[$x + 3] = GUICtrlCreateInput($x + 3, 20 + 30 + 30 + 120 + 6, $aTop, 300, $aHeigth) $F[$x + 4] = GUICtrlCreateCombo($x + 4, 20 + 30 + 30 + 120 + 300 + 8, $aTop, 120, $aHeigth) $F[$x + 5] = GUICtrlCreateCombo($x + 5, 20 + 30 + 30 + 120 + 300 + 120 + 10, $aTop, 40, $aHeigth) $F[$x + 6] = GUICtrlCreateCombo($x + 6, 20 + 30 + 30 + 120 + 300 + 120 + 40 + 12, $aTop, 80, $aHeigth) $aTop = $aTop + 22 Next _GUIScrollbars_Generate($hTab_Win0, 0, 2000) GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_SHOW, $hTab_Win0) While 1 Sleep(20) WEnd Func _Tab() Switch GUICtrlRead($tab) Case 0 GUISetState(@SW_SHOW, $hTab_Win0) Case 1 GUISetState(@SW_HIDE, $hTab_Win0) EndSwitch EndFunc ;==>_Tab Func _Exit() Exit EndFunc ;==>_ExitPlease ask if anything is unclear. Glad you like the Scrollbars UDF. M23
    1 point
  8. Uten

    A simple Trace udf.

    Just a simple tracing udf I have used for a while. The nice thing is that it works with sysinternals debugview. Probably easier to get it from here when I need it Regards Uten EDIT: Clarified text comment in code. Thanks to Valuater. Trace.au3
    1 point
  9. From time to time a thread pops up in the forum to measure the time (or how many iterations can be done in a given time) a block of code takes to execute. most solutions use TimeInit and TimeDiff to do the measures. This is not a accurate way to measure the time spent by the code block. The reason is that TimeDiff measure the time spent by all processes on the system and not just the one we want to measure. So, a better approach in AutoIt is to use GetProcessTimes in kernel32.dll. I have created two udfs to resemble TimerInit and TimerDiff. They are called ProfileInit and ProfileDiff. They operate on the running process. ProfileDiff will return an array containing the time in 100 nanoseconds intervals since ProfileInit was called. Usage: Local $foo Local $i, $j, $k Local $time, $ts, $pi[1] $pi = ProfileInit() ;ArrayDump($pi, "Profile Inint:") $ts = Timerinit() For $i = 0 to 3 For $j = 1 to 100000 $k += Random(-5, 5, 1) next Local $pd = ProfileDiff($pi) $time = TimerDiff($ts) ;K=kernel-time, U=User-time spendt by the process identified by @AutoItPID ;Dividing by 10000 to get ms ConsoleWrite(StringFormat( "SUM:=%d\tT:%.6d, K:%d, U:%d, K+U:%d ms", $k, $time, $pd[1], $pd[2], Round(($pd[1]+$pd[2])/10000, 0)) & @LF) $k = 0 next $Process = 0oÝ÷ Ù Enjoy, Uten.. EDIT: Forgot some globals.
    1 point
×
×
  • Create New...