1905russell

Moving Dash Rectangle

18 posts in this topic

Hello wise people of the forums – long time since I’ve asked for assistance – it’s me, the Autoit dabbling accountant who is not a programmer (my standard disclaimer).

Is there somewhere in the forums that I can find a snippet that creates a moving dashstyle rectangle, similar to the one displayed when copying (“^C”) in excel? I’ve searched, but surprisingly could not find. Your help is greatly appreciated.

Share this post


Link to post
Share on other sites



@1905russell are you actually trying to copy data in Excel, or just looking for the effect? If the latter, is this in a GUI, web app, etc.? The more information you provide the better we are able to assist.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the quick response JLogan3o13 - I'm just looking for the effect.

I'm making a little movie to illustrate a  software system that I have finally received the US patent for.

The movie uses a bunch of HotKeySets to fake what I can't program (while capturing the screen sequences).

This dash-rectangle would be HotkeySet to display at a selected x,y on top of any image displayed until HotKeySet turns it off and the recorded scene capture is over.

Am I making sense?

 

Edited by 1905russell
clarity

Share this post


Link to post
Share on other sites

Well obviously the above requested information I provided produced no help at all. So I tried to get a function written via Upwork/Freelancer (in Autoit or an exe) and I was ripped off by being charged for hours and hours (by mistake I was told) and nothing was ever produced. Upwork/Freelancer refunded me everything they had automatically taken from my credit card.

I know there are Autoit members that can do this easily. It’s for illustration purposes, please. There are many examples of code out there written in #C and other languages and the “marching ants” concept has been around for decades.

I have put together code using two approaches to create dash rectangles (with a hole) using forum snippets but they are static without animation. One uses _WinAPI_ExtCreatePen with $PS_DASH and the other uses _WinAPI_LineDDA. I have also tried to simply use splash image (and text) and then speed up the movie but it looks awful. I’m not a programmer.

I will donate again to Autoit or I will pay someone to help me please. My email for this project is rl@transaxy.com

Share this post


Link to post
Share on other sites

Maybe some of @UEZ code can help, hes a master of GdiPlus especially animations.

 

Share this post


Link to post
Share on other sites

Thanks Subz - I truly appreciate this - I had not found this before.  I'll go through these examples and maybe I'll figure out something. I know UEZ is the  animation expert and he could whip up something in seconds. There are others who are also pretty good but alas I think they find it infra dig to deal with me the accountant.  

Share this post


Link to post
Share on other sites

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   ;==>DashEdge

 

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Yes Yes this will work – Chimp you’re a Champ. Unfortunately I’m away from my main computer for a week and am now using a limited laptop. I’m going to massage your script to run in my mini-movie but I can see that for sure it will work. Thanks to you, my weeks of frustration and going bananas (pun intended) are over. I can’t wait to get back home to modify your code. Thanks again and Abadabadaba 

Share this post


Link to post
Share on other sites

Slightly modified version from Chimp's code:

#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)
    Local Static $fOffset = 0
    _GDIPlus_PenSetDashStyle($hPen, $GDIP_DASHSTYLEDOT)
    _GDIPlus_PenSetColor($hPen, $RectColor)

    DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) ;this is the key for the animated dotted line ;-)

    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

    $fOffset += 0.5


    If $show = -1 Then ; we have to stop?
        AdlibUnRegister("DashEdge")
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
        WinKill($hGUI)
    EndIf

EndFunc   ;==>DashEdge

^_^

2 people like this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

1 hour ago, 1905russell said:

Yes Yes this will work – Chimp you’re a Champ. Unfortunately I’m away from my main computer for a week and am now using a limited laptop. I’m going to massage your script to run in my mini-movie but I can see that for sure it will work. Thanks to you, my weeks of frustration and going bananas (pun intended) are over. I can’t wait to get back home to modify your code. Thanks again and Abadabadaba

You are welcome :)

 

46 minutes ago, UEZ said:

Slightly modified version from Chimp's code:

.... the master's touch makes the difference!... :)
 

p.s.
@UEZ, the _GDIPlus_PenSetDashStyle allows the $GDIP_DASHSTYLECUSTOM parameter  as a user-defined, custom dashed line, but I've not found how to set the custom dashed line. Here (http://csharphelper.com/blog/2015/02/draw-lines-with-custom-dash-patterns-in-c/) there is a brief explanation on how to setup the custom dashed line, but I don't know how to do it in AutoIt. Do you know how to make use of the  $GDIP_DASHSTYLECUSTOM parameter?? Thank You

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#11 ·  Posted

@Chimp - that could be done this way:

Local Static $fOffset = 0

    _GDIPlus_PenSetColor($hPen, $RectColor)
    
    Local $iCount = 4, $tArray = DllStructCreate("float;float;float;float")
    DllStructSetData($tArray, 1, 5.0)   ;dash length
    DllStructSetData($tArray, 2, 2.0)   ;space length
    DllStructSetData($tArray, 3, 15.0)  ;dash length
    DllStructSetData($tArray, 4, 4.0)   ;space length
    DllCall($__g_hGDIPDll, "int", "GdipSetPenDashArray", "handle", $hPen, "struct*", $tArray, "long", $iCount) ;This method will set the DashStyle enumeration for this Pen object to DashStyleCustom. 
    
    DllCall($__g_hGDIPDll, "int", "GdipSetPenDashOffset", "handle", $hPen, "float", $fOffset) ;this is the key for the animated dotted line ;-)

 

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#12 ·  Posted

@UEZ, ... it works. Very interesting, it allows nice effects.
Thank You!.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#13 ·  Posted

1 hour ago, Chimp said:

@UEZ, ... it works. Very interesting, it allows nice effects.
Thank You!.

Prego. :)


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#14 ·  Posted

UEZ,

Bravo!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

@UEZ I have always been in awe of your work and was blown away by the fact that you would take an interest in assisting me by expanding on Chimp’s code with your brilliance. I’m so excited and have ants in my pants to get back home to watch them march in my mini-movie. This week, if time allows, I hope to revisit the museum of your inspirer in St Petersburg. He was innovating rock star with his art, as you are with yours. Thank you so much.

Share this post


Link to post
Share on other sites

#16 ·  Posted

How true !  (both assertions)  :)

Share this post


Link to post
Share on other sites

#17 ·  Posted

1905russell,

I agree with both of your assertions: UEZ is indeed our GDI guru and the St Pete's Dali museum is one of my favourites too.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

Regarding assertion 1: guys, keep well grounded - no need to exaggerate. :>

Assertion 2: well, maybe one day I will be in St. Petersburg to visit my avatar's art...


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Miliardsto
      By Miliardsto
      Hello . I implemented script like this
      But the vars $iX1 $iY1 are counting from the desktop start and I want it coords by window
      This not work with this script Opt("MouseCoordMode", 0)
      Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x00FF00) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() global $iX1 = Round($aMouse_Pos[0], 2) global $iY1 = Round($aMouse_Pos[1], 2) ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) ; Get second mouse position global $iX2 = Round($aMouse_Pos[0], 2) global $iY2 = Round($aMouse_Pos[1], 2) ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf If _IsPressed("01", $UserDLL) = 0 Then _GDIPlus_Startup () $hDC = _WinAPI_GetWindowDC(0) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) ;Stworz pedzel i kolor, width ;$hPen = _GDIPlus_PenCreate(0x00FF00) ; Rysowanie linii ;_GDIPlus_GraphicsDrawLine($hGraphic,$iX1,$iY1,$iX2,$iY2,$hPen) ; middle of rectangle $xMiddle = ( $iX1 + $iX2 ) / 2 $yMiddle = ( $iY1 + $iY2 ) / 2 _GDIPlus_GraphicsDrawRect( $hGraphic, $xMiddle-20, $yMiddle-20, 40, 40) EndIf WEnd GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) EndFunc ;==>Mark_Rect