Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/23/2021 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. Really ? If there is no security alert then exit ? Really ? So you absolutely want a security alert ? Man, how about this book :
    1 point
  3. Nine

    Screen scraping

    Glad you made it work. Yes, but I will not, it would make my UDF slower. This is out of question. However, here the way you can calculate the delta of Window and Client Area : #include <StructureConstants.au3> #include <Constants.au3> #include <WinAPIConv.au3> #include "..\GetScreen\GetScreen.au3" Local $hWnd = WinGetHandle("[CLASS:SciTEWindow]") ; this calculates the screen position of the window Local $aWin = WinGetPos($hWnd) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "", "Window not found") Local $Width = $aWin[2], $Height = $aWin[3] ; this calculates the screen position of the client area of the window Local $tPoint = DllStructCreate($tagPOINT) $tPoint.X = 0 $tPoint.Y = 0 _WinAPI_ClientToScreen($hWnd, $tPoint) Local $xDiff = $tPoint.X - $aWin[0], $yDiff = $tPoint.Y - $aWin[1] MsgBox($MB_SYSTEMMODAL, "", "Diff from Window to Client = " & $xDiff & "/" & $yDiff) _GetScreen_Initialize($Width, $Height) _GetScreen_GetWindow($hWnd) Local $color = _GetScreen_GetPixel(52+$xDiff, 122+$yDiff) ; 52 and 122 are client coordinates MsgBox($MB_SYSTEMMODAL, "", Hex($color, 6)) You just need to calculate it once (at the beginning of the script) and reuse the deltas for each call to get pixel...
    1 point
  4. if you are using WinWait for the popup, there is a timeout option you can set to 30. if WinWait("Firewall", "", 30) = 0 then exit
    1 point
  5. Ha... I was able to solve my problems with @Melba23 UDF: Here is finall script: #include <AutoItConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiScrollBars.au3> #include <StringConstants.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> #include "GUIScrollbars_Ex.au3" _Example() Func _Example() Local $i_Count = 30 Local $a_Options_List[$i_Count + 1] $a_Options_List[0] = $i_Count For $i = 1 To $i_Count $a_Options_List[$i] = 'Test #' & $i Next ConsoleWrite("- " & _GUI__Choose_Options('Testing', $a_Options_List) & @CRLF) EndFunc ;==>_Example Func _GUI__Choose_Options($s_Description, $a_Options_List = "", $i_GUI_Left = Default, $i_GUI_Top = Default, $i_GUI_Width = Default, $hWnd_Parent = 0) If $i_GUI_Left = Default Then $i_GUI_Left = -1 If $i_GUI_Top = Default Then $i_GUI_Top = -1 If $i_GUI_Width = Default Then $i_GUI_Width = 400 Local $i_Left = 5 ; The distance of the labels from the left edge of the window Local $i_Label_Top = 10 Local $i_Label_Height = 80 Local $i_Button_Top = 5 Local $i_Button_Width = $i_GUI_Width - 35 Local $i_Button_Height = 25 Local $i_Spacing = 1 #Region _GUI__Choose_Options - GUI Creation Local $i_GUI_Height = 600 Local $hWND_DateForm = GUICreate("", $i_GUI_Width, $i_GUI_Height, $i_GUI_Left, $i_GUI_Top, -1, -1, $hWnd_Parent) WinSetOnTop($hWND_DateForm, "", $WINDOWS_ONTOP) GUICtrlCreateLabel("", $i_Left, $i_Label_Top, $i_GUI_Width - 10, $i_Label_Height) GUICtrlSetBkColor(-1, 0x88AABB) Local $id_Label1 = GUICtrlCreateLabel("", $i_Left + 5, $i_Label_Top + 5, $i_GUI_Width - 15, $i_Label_Height - 5) GUICtrlSetBkColor(-1, 0x88AABB) Local $i_Child_top = $i_Label_Height + 15 Local $hChild = GUICreate("Scroll area", $i_GUI_Width - 5, $i_GUI_Height - $i_Label_Height - 30, 0, $i_Child_top, $WS_POPUP, $WS_EX_MDICHILD, $hWND_DateForm) Local $i_bottom Local $a_List_of_Button_ID[$a_Options_List[0] + 1] Local $a_List_of_Dummy_ID = $a_List_of_Button_ID For $IDX_Item = 1 To $a_Options_List[0] GUISwitch($hWND_DateForm) $a_List_of_Dummy_ID[$IDX_Item] = GUICtrlCreateDummy() If $IDX_Item > 0 And $IDX_Item < 10 Then GUISwitch($hChild) $a_List_of_Button_ID[$IDX_Item] = GUICtrlCreateButton( _ $IDX_Item & ". " & $a_Options_List[$IDX_Item], _ $i_Left, $i_Button_Top, $i_Button_Width, $i_Button_Height, BitOR($BS_LEFT, $WS_GROUP)) Else GUISwitch($hChild) $a_List_of_Button_ID[$IDX_Item] = GUICtrlCreateButton( _ Chr(Asc('A') + $IDX_Item - 10) & ". " & $a_Options_List[$IDX_Item], _ $i_Left, $i_Button_Top, $i_Button_Width, $i_Button_Height, BitOR($BS_LEFT, $WS_GROUP)) EndIf $i_bottom = $i_Button_Top + $i_Button_Height ; Bottom edge of the last Button $i_Button_Top = $i_bottom + $i_Spacing ; Top of next Button Next Local $iMaxScrollHeight = $i_Button_Top _GUIScrollbars_Generate($hChild, 0, $iMaxScrollHeight) Local $temp_var = $a_Options_List[0] Local $a_accelerators_for_Buttons[($temp_var * 2) + 1][2] Local $a_accelerators_for_Dummy = $a_accelerators_for_Buttons Local $i_Accelerators_Counter = 0 Local $i_Accelerator_Upper_Char = '' Local $i_Accelerator_Lower_Char = '' For $IDX_Item = 1 To $a_Options_List[0] If $IDX_Item > 9 Then $i_Accelerator_Upper_Char = Chr(Asc('A') + $IDX_Item - 10) $i_Accelerator_Lower_Char = Chr(Asc('a') + $IDX_Item - 10) Else $i_Accelerator_Upper_Char = "{NUMPAD" & $IDX_Item & "}" $i_Accelerator_Lower_Char = $IDX_Item EndIf $a_accelerators_for_Buttons[($IDX_Item * 2) - 1][0] = $i_Accelerator_Lower_Char $a_accelerators_for_Buttons[($IDX_Item * 2) - 1][1] = $a_List_of_Button_ID[$IDX_Item] $a_accelerators_for_Buttons[($IDX_Item * 2)][0] = $i_Accelerator_Upper_Char $a_accelerators_for_Buttons[($IDX_Item * 2)][1] = $a_List_of_Button_ID[$IDX_Item] $a_accelerators_for_Dummy[($IDX_Item * 2) - 1][0] = $i_Accelerator_Lower_Char $a_accelerators_for_Dummy[($IDX_Item * 2) - 1][1] = $a_List_of_Dummy_ID[$IDX_Item] $a_accelerators_for_Dummy[($IDX_Item * 2)][0] = $i_Accelerator_Upper_Char $a_accelerators_for_Dummy[($IDX_Item * 2)][1] = $a_List_of_Dummy_ID[$IDX_Item] $i_Accelerators_Counter += 2 Next $a_accelerators_for_Buttons[0][0] = $i_Accelerators_Counter $a_accelerators_for_Dummy[0][0] = $i_Accelerators_Counter ;~ _ArrayDisplay($a_accelerators_for_Buttons, '$a_accelerators_for_Buttons') ;~ _ArrayDisplay($a_accelerators_for_Dummy, '$a_accelerators_for_Dummy') ; Accelerators must be set for both Main and Child window because when you drag Main window then Accelerators for Child window will not be fired GUISetAccelerators($a_accelerators_for_Buttons, $hChild) GUISetAccelerators($a_accelerators_for_Dummy, $hWND_DateForm) GUICtrlSetData($id_Label1, $s_Description) GUISetState(@SW_SHOW, $hWND_DateForm) GUISetState(@SW_SHOW, $hChild) #EndRegion _GUI__Choose_Options - GUI Creation #Region - _GUI__Choose_Options - Handling messages Local $i_Selected_item = 0 Local $v_Return_Value = "" Local $a_GUI_Messages While 1 $a_GUI_Messages = GUIGetMsg($GUI_EVENT_ARRAY) If $a_GUI_Messages[0] = $GUI_EVENT_NONE Then ; do nothing ElseIf $a_GUI_Messages[1] = $hWND_DateForm And $a_GUI_Messages[0] = $GUI_EVENT_CLOSE Then ExitLoop ;~ ElseIf $a_GUI_Messages[1] <> $hChild And $a_GUI_Messages[1] <> $hWND_DateForm Then ;~ ; .... Else For $IDX_Check = 1 To $a_Options_List[0] If $a_List_of_Button_ID[$IDX_Check] = $a_GUI_Messages[0] Or $a_List_of_Dummy_ID[$IDX_Check] = $a_GUI_Messages[0] Then $v_Return_Value = GUICtrlRead($a_List_of_Button_ID[$IDX_Check]) $i_Selected_item = $IDX_Check $v_Return_Value = _RegExpFirstMatch($v_Return_Value, '.+?\. (.+)') ExitLoop 2 ; exit from ForNext and also from WhileWend EndIf Next EndIf WEnd #EndRegion - _GUI__Choose_Options - Handling messages GUIDelete($hChild) GUIDelete($hWND_DateForm) Return SetError(0, $i_Selected_item, $v_Return_Value) EndFunc ;==>_GUI__Choose_Options Func _RegExpFirstMatch($s_Data, $s_Pattern) Local $a_Results = StringRegExp($s_Data, $s_Pattern, $STR_REGEXPARRAYGLOBALMATCH) If @error Then Return SetError(@error, @extended, '') Return SetError(0, UBound($a_Results), $a_Results[0]) EndFunc ;==>_RegExpFirstMatch
    1 point
  6. I have nothing I can use for testing right now, but I can say in the past I used PLINK for my Putty automation. If you use the AutoIT window info tool and you do not see any text listed, then you will not get anything from WinGetText() I want to say you can have Putty pretty much log everything to a log file as its running, and then you can read that file as a workaround.
    1 point
  7. Nine

    Tabs in Menu

    A few comments on your While Loop : 1- You should not declare variables inside a loop, declare it before (best practices) 2- Use Switch instead of Select, will easily allow you to have multiple ids in a single case 3- GUICtrlRead on radio and check boxes can only return 2 values (see help file). No need to bitAnd the result. Local $sFile While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $Button_Cancel, $mExit Exit Case $mOpen $sFile = FileOpenDialog(" Open some File...", @WindowsDir, "All(*.*)") Case $Radio_Shake_No If GUICtrlRead($Radio_Shake_No) = $GUI_CHECKED Then GUICtrlSetState($Input_Shakespeed, $GUI_DISABLE) Case $Radio_Shake_Yes If GUICtrlRead($Radio_Shake_Yes) = $GUI_CHECKED Then GUICtrlSetState($Input_Shakespeed, $GUI_ENABLE) Case $mHelp_Fragezeichen MsgBox(289, "Help", "Just ask Annika.") Case $mEndpoint_ABS GUICtrlSetState($wave, $GUI_SHOW) EndSwitch WEnd
    1 point
  8. Zedna

    Tabs in Menu

    From helpfile for GUICtrlCreateTabItem(): To select a specific tabitem to be shown when the GUI opens use GUICtrlSetState(-1, $GUI_SHOW) as shown in the example.
    1 point
  9. mLipok

    Tabs in Menu

    https://www.autoitscript.com/wiki/Forum_FAQ#How_can_I_post_.22code.22_on_the_forum_.3F
    1 point
  10. Melba23

    _GUIScrollBars Question

    buymeapc, Personally I would do it like this: #include <GUIScrollBars_Ex.au3> $iLeft = 5 ; The distance of the labels from the left edge of the window $iTop = 40 ; First label's distance from the top edge of the window $iWidth = 100 ; Width of labels $iHeight = 25 ; Height of labels $iSpacing = 30 ; Vertical distance between the labels $hGUI = GUICreate('Calculate exact scrollheight for dynamic labels after maximize window', 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX)) GUICtrlCreateTab(2, 2, 496, 496) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM) GUICtrlCreateTabItem("Example") $hGUI2 = GUICreate("", 488, 464, $iLeft, 26, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) For $i = 1 To 50 GUICtrlCreateLabel('Label ' & $i, $iLeft, $iTop, $iWidth, $iHeight) GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetResizing(-1, $GUI_DOCKALL) ; Prevent resizing $bot = $iTop + $iHeight ; Bottom edge of the last label $iTop = $bot + $iSpacing ; Top of next label Next $cButton = GUICtrlCreateButton("Maximize", 400, 40, 50, 30) GUICtrlCreateTabItem("") $iMaxScrollHeight = $iTop _GUIScrollbars_Generate($hGUI2, 0, $iMaxScrollHeight) GUISetState(@SW_SHOW, $hGUI) GUISetState(@SW_SHOW, $hGUI2) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; Get new GUI size Local $aGUI_Size = WinGetClientSize($hGUI) ; Get current scroll bar position $iPos = _GUIScrollBars_GetScrollInfoPos($hGUI2, $SB_VERT) ; And set scrollbar to top _GUIScrollBars_SetScrollInfoPos($hGUI2, $SB_VERT, 0) ; Resize scroll GUI WinMove($hGUI2, "", Default, Default, ($aGUI_Size[0] - 14), ($aGUI_Size[1] - 34)) ; Reset scrollbar position _GUIScrollBars_SetScrollInfoPos($hGUI2, $SB_VERT, $iPos) Case $cButton GUISetState(@SW_MAXIMIZE) EndSwitch Wend And was there any particular reason why you did not post this in the UDF thread so that I would be guaranteed to see it? M23
    1 point
×
×
  • Create New...