Leaderboard
Popular Content
Showing content with the highest reputation on 02/18/2017 in all areas
-
Scrollbars Made Easy - New version 27 Jan 22
pixelsearch reacted to Melba23 for a topic
[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. M231 point -
a possible way... #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() ; declare parameters to set the dashed rectangle; (out of screen and hidden at startup) Global $show = 0, $xPosition = @DesktopWidth, $yPosition = @DesktopHeight, $Width = 10, $Height = 10 Global $RectColor = 0xFFFF0000 ; FFRRGGBB Global $PixelThickness = 4 DashEdge() ; initialize the rectangle AdlibRegister("DashEdge", 100) ; set the refresh rate ; Your scipt here.... Local $Timer = TimerInit() Do ; ... when you need a dotted rectangle somewhere on the screen ; just set the following variables accordingly ... ; ; here we use random values $show = 1 $xPosition = Random(10, 600, 1) $yPosition = Random(10, 600, 1) $Width = Random(200, 500, 1) $Height = Random(150, 400, 1) $RectColor = Random(0, 16777215, 1) + 4278190080 ; 0xFF000000 to 0xFFFFFFFF Sleep(1500) Until TimerDiff($Timer) >= 10000 ; show demo for ten seconds ; The end $show = -1 ; set -1 to dispose all DashEdge() ; Clean up GDI+ resources Func DashEdge() ; following static variables are generated and initialized only the first time this function is called Local Static $AlphaKey = 0xFF0FF0FF ; this color will set background transparent (can be changed) Local Static $hGUI = GUICreate("", $Width, $Height, $xPosition, $yPosition, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST + $WS_EX_TRANSPARENT) Local Static $Dummy = _WinAPI_SetLayeredWindowAttributes($hGUI, $AlphaKey, 0, $LWA_COLORKEY) Local Static $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Local Static $hPen = _GDIPlus_PenCreate($RectColor, $PixelThickness) _GDIPlus_PenSetColor($hPen, $RectColor) ; dots and dashes alternate If _GDIPlus_PenGetDashStyle($hPen) = $GDIP_DASHSTYLEDOT Then _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDASH) Else _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT) EndIf Local $aWinPos = WinGetPos($hGUI) ; check if we need to move the rectangle If $aWinPos[0] <> $xPosition Or $aWinPos[1] <> $yPosition Or $aWinPos[2] <> $Width Or $aWinPos[3] <> $Height Then _GDIPlus_GraphicsDispose($hGraphic) WinMove($hGUI, "", $xPosition, $yPosition, $Width, $Height) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) EndIf ; show or hide dashes as from the $show variable If $show = 1 Then GUISetState(@SW_SHOW, $hGUI) If $show = 0 Then GUISetState(@SW_HIDE, $hGUI) _GDIPlus_GraphicsClear($hGraphic, $AlphaKey) ; erase rect _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $Width, $Height, $hPen) ; draw again If $show = -1 Then ; we have to stop? AdlibUnRegister("DashEdge") _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() WinKill($hGUI) EndIf EndFunc ;==>DashEdge1 point
-
'cmd /c arp -a | findstr "192.168" | findstr "static"'1 point
-
[Solved] Notify user if new file were saved in a certian folder
KickStarter15 reacted to Melba23 for a topic
KickStarter15, If it works for you then the answer is : Yes! I would have done it very differently as I explained above, but that does not make mine the only solution. As to cleaning up the code - I would suggest using a loop to fade the notification: GUISetState(@SW_SHOW) WinSetTrans($popup, "", 255) ; Use the GUI handle as you have it Sleep(1000) For $iTrans = 240 to 0 Step -10 WinSetTrans($popup, "", $iTrans) Sleep(200) Next GUISetState(@SW_HIDE) EndFunc M231 point -
@Subz : pretty much the same thing than #4 : #Include <Array.au3> #Include <AutoItConstants.au3> Local $iPid = Run("cmd /c arp -a","",@SW_HIDE,$STDOUT_CHILD) ProcessWaitClose($iPid) Local $sArp = StdoutRead($iPid) Local $aArpTable = StringRegExp($sArp, "((?:\d+\.){3}\d+)\h+((?:[[:xdigit:]]{2}-){5}[[:xdigit:]]{2})\h+(\V+)", 3) Local $aArpTable2D[ UBound($aArpTable) / 3 + 1][3] = [[UBound($aArpTable) / 3]] For $i = 0 To UBound($aArpTable) - 1 Step 3 $aArpTable2D[$i / 3 + 1][0] = $aArpTable[$i] $aArpTable2D[$i / 3 + 1][1] = $aArpTable[$i + 1] $aArpTable2D[$i / 3 + 1][2] = $aArpTable[$i + 2] Next _ArrayDisplay($aArpTable2D) @JeffQOOQAAA : just take the code in #4 and replace the regex ligne with #6. You didn't try ?1 point
-
@rootx: So the way to proceed would be; create a dummy script with these includes and confirm your AV flags it up. Disable all includes and start re-enabling them one by one to identify what parts (there may be multiple, or perhaps it's a combination?) your AV doesn't like. Since you have other encrypted scripts that do not trip up your AV, it's not the decryption engine itself. You may be able to narrow it down to a single UDF (which you may not even need in your app). I've never had false positives myself, so I cannot quickly point the finger at any particular include for you. Alternatively, the problem may lie in your own code (once encrypted); in that case, try disabling large chunks of (inserting immediate returns in UDFs and commenting out the rest) and see what that does. This kind of hunt can actually be quite fun.1 point
-
heroeda, Something like this should work for you: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; Define the correct sequence for the input $sMatch = "123" ; Create a GUI $hGUI = GUICreate("Test", 500, 500) ; With an input and a button $cInput = GUICtrlCreateInput("", 10, 10, 200, 20) $cCheck = GUICtrlCreateButton("Check", 10, 50, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cCheck ; Button pressed ; Read input $sInput = GUICtrlRead($cInput) ; Compare to required string = force case sensitive string comparison by using the == operator If $sInput == $sMatch Then MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "Compare", "Success!!") Else MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Compare", "Failed" & @CRLF & @CRLF & "Try again") EndIf ; Clear input and reset focus GUICtrlSetData($cInput, "") GUICtrlSetState($cInput, $GUI_FOCUS) EndSwitch WEnd M231 point
-
[Solved] Notify user if new file were saved in a certian folder
KickStarter15 reacted to Melba23 for a topic
KickStarter15, I have used the FileSystemMonitor and ReadDirectoryChanges UDFs to monitor folders for changes. My personal preference goes to the former as it is self-contained while the latter requires a DLL. As to the pop-up notification, look at my Toast & Notify UDFs (links in my sig below). M231 point -
For my part, I manage the antivirus protection for my company's network. I make an exclusion rule for each compiled (based on the full path name) and I have zero false positive. I asked the question to the support : can I avoid a false positive by signing the program. The answer is : "no. You have to submit your exe file to the false positive form on our web site". Same thing for each antivirus.1 point
-
@Melba23 You inspired me. But tell me what you think of such a modification: #include <GuiConstantsEx.au3> #include <GuiTab.au3> #include <StaticConstants.au3> ; Tab colours Global $aTabColours[4] = [0xFFC0C0, 0xC0FFC0, 0xC0C0FF, 0xC0C0C0] ; Create GUI Global $hGUI = GUICreate ("Test", 400,300) GUISetBkColor (0) ; Create label to cover tab "tab" Global $ahColourTab[4] For $i = 0 to 3 $ahColourTab[$i] = GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN)) Next ;~ Global $hColourTab = GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN)) ; Create tab Global $hTab = GUICtrlCreateTab(5, 5,390, 290) Global $hTab_Handle = GUICtrlGetHandle($hTab) ; Create tab items and colour them For $i = 0 To 3 GUICtrlCreateTabItem ("Tab item - " & $i) _GUICtrlTab_SetBkColor($hGUI, $hTab, $aTabColours[$i]) GUICtrlCreateLabel('This is TAB #' & $i & ' content.',100,50) GUICtrlCreateTabItem ("") Next GUISetState() ; Pre sets of colours For $i = 3 To 0 Step -1 _GUICtrlTab_ClickTab($hTab_Handle, $i) TabEvent() Next _GUICtrlTab_SetCurSel($hTab_Handle,0) _GUICtrlTab_SetCurFocus($hTab_Handle,0) TabEvent() While 1 Switch GUIGetMsg () Case $GUI_EVENT_CLOSE Exit Case $ahColourTab[0] _GUICtrlTab_ClickTab($hTab_Handle, 0) Case $ahColourTab[1] _GUICtrlTab_ClickTab($hTab_Handle, 1) Case $ahColourTab[2] _GUICtrlTab_ClickTab($hTab_Handle, 2) Case $ahColourTab[3] _GUICtrlTab_ClickTab($hTab_Handle, 3) ;~ Case $hTab ; not needed because you click in Label not in Tab ;~ TabEvent() EndSwitch WEnd Func TabEvent() ; Set values Local $iTab_X = 5, $iTab_Y = 5, $iTab_Margin = 1 ; Get index of current tab Local $iTab_Index = GUICtrlRead($hTab) ; Get coordinates of TabItem Local $aTab_Coord = _GUICtrlTab_GetItemRect($hTab_Handle, $iTab_Index) ; Get text of TabItem Local $sTab_Text = _GUICtrlTab_GetItemText($hTab_Handle, $iTab_Index) ; Place label GUICtrlSetPos($ahColourTab[$iTab_Index], $iTab_X + $aTab_Coord[0] + $iTab_Margin, $iTab_Y + $aTab_Coord[1] + $iTab_Margin, $aTab_Coord[2] - $aTab_Coord[0] - ($iTab_Margin * 2), $aTab_Coord[3] - $aTab_Coord[1] - ($iTab_Margin * 2) + 5) ; Set text GUICtrlSetData($ahColourTab[$iTab_Index], $sTab_Text) ; Set colour GUICtrlsetBkColor($ahColourTab[$iTab_Index],$aTabColours[$iTab_Index] ) ; Set focus _GUICtrlTab_SetCurFocus($hTab_Handle,$iTab_Index) EndFunc Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor) ; Get tab position Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32) ; Get size of user area Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1) ; Create label GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + $aTab_Rect[3] + 4, $aTabPos[2] - 6, $aTabPos[3] - $aTab_Rect[3] - 7) ; Colour label GUICtrlSetBkColor(-1, $sBkColor) ; Disable label GUICtrlSetState(-1, $GUI_DISABLE) EndFunc ;==>_GUICtrlTab_SetBkColor EDIT: I notice that my example not needed this: ; Case $hTab ; TabEvent()1 point