Sign in to follow this  
Followers 0
Chimp

transparent paint?, How to?

7 posts in this topic

#1 ·  Posted (edited)

Hi

Is it possible to draw using a semitransparent paint?
In short, I would like to paint on a Label control that contains text, and at the same time be able to see through the paint, so to see the text behind.
Something like using an highlighter.

Only to show the effect that I would achieve, here are two listings. The first, using transparency on the whole gui, allows to draw an ellipse into the gui's body showing at the same time what's beneath the ellipse's border. (the inner of the ellipse should be totally transparent.) Click on the GUI and drag to draw the ellipse.

#include <Misc.au3> ; for _IsPressed (01 Left mouse button)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>

Opt("MouseCoordMode", 0)

Global $hUser32dll = DllOpen("user32.dll") ; for _IsPressed

Local $aPos

; -- Create the GUI -------------------------------
Global $hGUI = GUICreate("Preview of an ellipse (click and drag to draw)", 400, 400, 100, 100, -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))

Local $iTransparent = 0x0FF0FF ; tansparent color

; This sets which color to be transparent and opacity of the whole window
_WinAPI_SetLayeredWindowAttributes($hGUI, $iTransparent, 127) ; last param opacity intensity: 0 totally transp, 255 NOT transp

GUISetBkColor($iTransparent, $hGUI) ; background becomes transparent

GUISetState(@SW_SHOW)

; MAIN LOOP
While 1
    $aPos = MouseGetPos()
    $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) ; $GUI_EVENT_ARRAY -> returns an array containing the event and extended information
    Select
        Case $aMsg[0] = $GUI_EVENT_CLOSE
            ConsoleWrite("Bye" & @LF)
            Exit ; End()
    EndSelect

    If _IsPressed("01", $hUser32dll) Then
        ; draw the ellipse following mouse position.
        ; returns only when left mouse button is released
        _Preview_Ellipse($hGUI, $aPos[0], $aPos[1], 24)
    EndIf

WEnd


Func _Preview_Ellipse($hGUIx, $iX, $iY, $iPenSize = 9, $iColor = 0xFF0000, $iFill = 0x0FF0FF)

    ; Creates $tagRECT structure with the coordinates of the specified rectangle
    Local $tRECT = _WinAPI_CreateRect($iX, $iY, $iX, $iY)

    Local $hDC = _WinAPI_GetWindowDC($hGUIx)
    Local $hPen = _WinAPI_CreatePen($PS_SOLID, $iPenSize, $iColor) ; border size and color
    Local $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, $iFill) ; fill color
    Local $hObj1 = _WinAPI_SelectObject($hDC, $hBrush)
    Local $hObj2 = _WinAPI_SelectObject($hDC, $hPen)

    Local $aPreviousPos[2], $aPos[2]

    While _IsPressed("01", $hUser32dll) ; stay here till left mouse button is released

        ; get the mouse coordinates:
        ; $aPos[0] = X coord (horizontal), $aPos[1] = Y coord (vertical)
        $aPos = MouseGetPos()

        ; if mouse has mooved then redraw the ellipse accordingly
        If $aPreviousPos[0] <> $aPos[0] Or $aPreviousPos[1] <> $aPos[1] Then ; mouse has mooved

            ; take track of new mouse position
            $aPreviousPos[0] = $aPos[0]
            $aPreviousPos[1] = $aPos[1]

            ; DllStructSetData($tRECT, 1, $iX) ; initial point is fixed
            ; DllStructSetData($tRECT, 2, $iY)

            DllStructSetData($tRECT, 3, $aPos[0]) ; new mouse position
            DllStructSetData($tRECT, 4, $aPos[1])

            ; erase content of the gui (erase the previous ellipse)
            _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW))

            ; Draws the new ellipse (based on new mouse position)
            _WinAPI_Ellipse($hDC, $tRECT)

        EndIf
        ;
    WEnd ; if left button is released then exit

    ; free resources
    _WinAPI_SelectObject($hDC, $hObj1)
    _WinAPI_SelectObject($hDC, $hObj2)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hGUIx, $hDC)
    _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; erase content of the gui

EndFunc   ;==>_Preview_Ellipse

 

This second listing is a botched attempt to achieve the same effect on a Label control located on a normal window (not transparent).

#include <Misc.au3> ; for _IsPressed (01 Left mouse button)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>

Opt("MouseCoordMode", 0)

Global $hUser32dll = DllOpen("user32.dll") ; for _IsPressed

Local $aPos

; -- Create the GUI -------------------------------
Global $hGUI = GUICreate("Preview of an ellipse (click and drag to draw)", 400, 400, 100, 100) ; , -1, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))

; Label
Local $s = StringReplace(StringFormat('%22s', ""), " ", "the quick brown fox jumps over the lazy dog ")
Local $hLabel = GUICtrlGetHandle(GUICtrlCreateLabel($s, 10, 10, 250, 250))
GUICtrlSetBkColor(-1, 0xAAAA00)

; Local $iTransparent = 0x0FF0FF ; tansparent color

; This sets which color to be transparent and opacity of the whole window
; _WinAPI_SetLayeredWindowAttributes($hGUI, $iTransparent, 127) ; last param opacity intensity: 0 totally transp, 255 NOT transp

; GUISetBkColor($iTransparent, $hGUI) ; background becomes transparent

GUISetState(@SW_SHOW)

; MAIN LOOP
While 1
    $aPos = MouseGetPos()
    $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) ; $GUI_EVENT_ARRAY -> returns an array containing the event and extended information
    Select
        Case $aMsg[0] = $GUI_EVENT_CLOSE
            ConsoleWrite("Bye" & @LF)
            Exit ; End()
    EndSelect

    If _IsPressed("01", $hUser32dll) Then
        ; draw the ellipse following mouse position.
        ; returns only when left mouse button is released
        _Preview_Ellipse($hLabel, $aPos[0], $aPos[1], 24)
    EndIf

WEnd


Func _Preview_Ellipse($hGUIx, $iX, $iY, $iPenSize = 9, $iColor = 0xFF0000, $iFill = 0x0FF0FF)

    ; Creates $tagRECT structure with the coordinates of the specified rectangle
    Local $tRECT = _WinAPI_CreateRect($iX, $iY, $iX, $iY)

    Local $hDC = _WinAPI_GetWindowDC($hGUIx)
    Local $hPen = _WinAPI_CreatePen($PS_SOLID, $iPenSize, $iColor) ; border size and color
    Local $hBrush = _WinAPI_CreateBrushIndirect($BS_SOLID, $iFill) ; fill color
    Local $hObj1 = _WinAPI_SelectObject($hDC, $hBrush)
    Local $hObj2 = _WinAPI_SelectObject($hDC, $hPen)

    Local $aPreviousPos[2], $aPos[2]

    While _IsPressed("01", $hUser32dll) ; stay here till left mouse button is released

        ; get the mouse coordinates:
        ; $aPos[0] = X coord (horizontal), $aPos[1] = Y coord (vertical)
        $aPos = MouseGetPos()

        ; if mouse has mooved then redraw the ellipse accordingly
        If $aPreviousPos[0] <> $aPos[0] Or $aPreviousPos[1] <> $aPos[1] Then ; mouse has mooved

            ; take track of new mouse position
            $aPreviousPos[0] = $aPos[0]
            $aPreviousPos[1] = $aPos[1]

            ; DllStructSetData($tRECT, 1, $iX) ; initial point is fixed
            ; DllStructSetData($tRECT, 2, $iY)

            DllStructSetData($tRECT, 3, $aPos[0]) ; new mouse position
            DllStructSetData($tRECT, 4, $aPos[1])

            ; erase content of the gui (erase the previous ellipse)
            _WinAPI_RedrawWindow($hGUIx, $tRECT, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW))

            ; Draws the new ellipse (based on new mouse position)
            _WinAPI_Ellipse($hDC, $tRECT)

        EndIf
        ;
    WEnd ; if left button is released then exit

    ; free resources
    _WinAPI_SelectObject($hDC, $hObj1)
    _WinAPI_SelectObject($hDC, $hObj2)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hGUIx, $hDC)
    _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; erase content of the gui

EndFunc   ;==>_Preview_Ellipse

I'm sure to be on the wrong way (I admit my knowledge on graphics is close to zero)

How can I achieve that effect?
Thanks on advance for any help.

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



#2 ·  Posted (edited)

I made a little progress, learned that the alpha component of the color structure is there precisely to allow the transparency of color....
This new listing works quite well, but there is a boring flickering while drawing the ellipse.

the flikering could be reduced if I could use the extended styles $WS_EX_COMPOSITED, $WS_EX_LAYERED in the GUICreate() function. Unfortunatelly if I use those styles, the drawing of the ellipse doesn't works anymore.

Anyone knows how to allow the use of the $WS_EX_COMPOSITED, $WS_EX_LAYERED styles or any other way to eliminate flicker?

Thank You

Click on text in the Label and drag to draw the ellipse (and to see the boring flickering).

#include <Misc.au3> ; for _IsPressed (01 Left mouse button)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>
#include <GDIPlus.au3>
; Start GDIPlus
_GDIPlus_Startup()

Opt("MouseCoordMode", 2)

Global $hUser32dll = DllOpen("user32.dll") ; for _IsPressed

Local $aPos

; -- Create the GUI -------------------------------
Global $hGUI = GUICreate("Preview of an ellipse (click and drag to draw)", 400, 400, 100, 100);, Default,BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED))

; Label
Local $s = StringReplace(StringFormat('%22s', ""), " ", "the quick brown fox jumps over the lazy dog ")
Local $hLabel = GUICtrlGetHandle(GUICtrlCreateLabel($s, 10, 10, 250, 250))
GUICtrlSetBkColor(-1, 0xAAAA00)
GUISetState(@SW_SHOW)

; MAIN LOOP
While 1
    $aPos = MouseGetPos()
    $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
    Select
        Case $aMsg[0] = $GUI_EVENT_CLOSE
            ConsoleWrite("Bye" & @LF)
            Exit ; End
    EndSelect

    If _IsPressed("01", $hUser32dll) Then
        ; draw the ellipse following mouse position.
        ; returns only when left mouse button is released
        _Preview_Ellipse($hLabel, $aPos[0], $aPos[1], 20) ; X Y starting point, pensize
    EndIf

WEnd


Func _Preview_Ellipse($hGUIx, $iX, $iY, $iPenSize = 9, $iColor = 0xFF0000, $iFill = 0x0FF0FF)

    ; Creates $tagRECT structure with the coordinates of the specified rectangle
    Local $tRECT = _WinAPI_CreateRect($iX, $iY, $iX, $iY)
    Local $aRect[4]

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUIx)

    ; Create solid brush
    ; The alpha component of color 0xAAnnnnnn determines the transparency of the color
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xAA00FF00)
    Local $hPen = _GDIPlus_PenCreate2($hBrush, $iPenSize)

    Local $aPreviousPos[2], $aPos[2]

    While _IsPressed("01", $hUser32dll) ; stay here till left mouse button is released

        ; get the mouse coordinates:
        ; $aPos[0] = X coord (horizontal), $aPos[1] = Y coord (vertical)
        $aPos = MouseGetPos()

        ; if mouse has mooved then redraw the ellipse accordingly
        If $aPreviousPos[0] <> $aPos[0] Or $aPreviousPos[1] <> $aPos[1] Then ; mouse has mooved

            ; take track of new mouse position
            $aPreviousPos[0] = $aPos[0]
            $aPreviousPos[1] = $aPos[1]

            ; some attempts to erase the ellipse
            ; _WinAPI_RedrawWindow($hGUI, "", "", BitOR($RDW_ERASE, $RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME, $RDW_ALLCHILDREN))
             _WinAPI_RedrawWindow($hGUIx, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW))
            ; _WinAPI_InvalidateRect($hGUI, $tRect, True) ; Redraws just the defined rectangle by the $tRect structure
            ; _GDIPlus_GraphicsClear($hGraphics, 0x00FFFFFF)

            ; Adjust coordinates of the rectangle
            If $aPos[0] < $iX Then
                $aRect[0] = $aPos[0]
                $aRect[2] = $iX
            Else
                $aRect[0] = $iX
                $aRect[2] = $aPos[0]
            EndIf

            If $aPos[1] < $iY Then
                $aRect[1] = $aPos[1]
                $aRect[3] = $iY
            Else
                $aRect[1] = $iY
                $aRect[3] = $aPos[1]
            EndIf

            ; populate the rect structure used for deleting ellipse by the function _WinAPI_InvalidateRect above
            DllStructSetData($tRECT, 1, $aRect[0] - $iPenSize) ; initial point is fixed
            DllStructSetData($tRECT, 2, $aRect[1] - $iPenSize)
            DllStructSetData($tRECT, 3, $aRect[2] + $iPenSize) ; new mouse position
            DllStructSetData($tRECT, 4, $aRect[3] + $iPenSize)

            ; Draws the new ellipse (based on new mouse position)
            _GDIPlus_GraphicsDrawEllipse($hGraphics, $aRect[0], $aRect[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1], $hPen)

        EndIf
        ;
    WEnd ; if left button is released then exit

    ; free resources
    _WinAPI_DeleteObject($hPen)
    _WinAPI_DeleteObject($hBrush)
    _GDIPlus_GraphicsDispose ( $hGraphics )
    _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INVALIDATE, $RDW_ERASE, $RDW_UPDATENOW)) ; erase content of the gui

EndFunc   ;==>_Preview_Ellipse

 

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

#3 ·  Posted (edited)

I'm not sure but without creating a child GUI it is not possible to get a flickerless graphic handle.

#include <Misc.au3> ; for _IsPressed (01 Left mouse button)
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>
#include <GDIPlus.au3>
; Start GDIPlus
_GDIPlus_Startup()

Opt("MouseCoordMode", 2)

Global $hUser32dll = DllOpen("user32.dll") ; for _IsPressed

Global $aPos, $iW = 250, $iH = 250

; -- Create the GUI -------------------------------
Global $hGUI = GUICreate("Preview of an ellipse (click and drag to draw)", 400, 400, 100, 100);, Default,BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED))

; Label
Global $s = StringReplace(StringFormat('%22s', ""), " ", "the quick brown fox jumps over the lazy dog ")
Global $hLabel = GUICtrlGetHandle(GUICtrlCreateLabel($s, 10, 10, 250, 250))
GUICtrlSetBkColor(-1, 0xAAAA00)
GUISetState(@SW_SHOW)

Global $hGUI_Child = GUICreate("", $iW, $iH, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
_WinAPI_SetParent($hGUI_Child, $hLabel)
GUISetState(@SW_SHOWNA, $hGUI_Child)

Global $hBrush = _GDIPlus_BrushCreateSolid(0xA0FFFFFF)
Global Const $hDC = _WinAPI_GetDC($hGUI_Child)
Global Const $hGfxDC = _WinAPI_CreateCompatibleDC($hDC)
Local Const $hBitmapGDI = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) ;_WinAPI_CreateDIB($iW, $iH)
Global $hObjOld = _WinAPI_SelectObject($hGfxDC, $hBitmapGDI)

Global $tSize = DllStructCreate($tagSIZE)
$tSize.x = $iW
$tSize.y = $iH
Global $tSource = DllStructCreate($tagPOINT)
Global $tBlend = DllStructCreate($tagBLENDFUNCTION)
$tBlend.Alpha = 0xFF
$tBlend.Format = 1
Global $tDest = DllStructCreate($tagPOINT), $pPoint = DllStructGetPtr($tDest)
$tDest.x = $iW
$tDest.y = $iH

Global $hGfx = _GDIPlus_GraphicsCreateFromHDC($hGfxDC)
_GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)


; MAIN LOOP
While 1
    $aPos = MouseGetPos()
    $aMsg = GUIGetMsg($GUI_EVENT_ARRAY)
    Select
        Case $aMsg[0] = $GUI_EVENT_CLOSE
            _WinAPI_SelectObject($hGfxDC, $hObjOld)
            _WinAPI_ReleaseDC($hLabel, $hDC)
            _WinAPI_DeleteDC($hGfxDC)
            _WinAPI_DeleteObject($hBitmapGDI)
            _GDIPlus_GraphicsDispose($hGfx)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_Shutdown()
            ConsoleWrite("Bye" & @LF)
            Exit ; End
    EndSelect

    If _IsPressed("01", $hUser32dll) Then
        ; draw the ellipse following mouse position.
        ; returns only when left mouse button is released
;~         _Preview_Ellipse($hLabel, $aPos[0], $aPos[1], 20) ; X Y starting point, pensize
        _Preview_Ellipse2()
    EndIf

WEnd

Func _Preview_Ellipse2()
    While _IsPressed("01", $hUser32dll)
        _WinAPI_BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, $CAPTUREBLT)
        _GDIPlus_GraphicsFillEllipse($hGfx, 0, 0, MouseGetPos(0), MouseGetPos(1), $hBrush)
        _WinAPI_UpdateLayeredWindow($hGUI_Child, $hDC, Null, $tSize, $hGfxDC, $tSource, 0, $tBlend, $ULW_ALPHA)
        Sleep(20)
    WEnd
EndFunc

 

Edited by UEZ

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

Hi Herr @UEZ :),  many thanks for your input.
Unfortunately if I try to run the script as is, it doesn't shows any ellipse. When I click and drag on the GUI nothing happens...
I had already tried before to use a child window and/or also to use the  $WS_EX_LAYERED style directly on the main GUI, but in both cases the drawing of the ellipse it doesn't anymore. (I'm using AutoIt 3.3.14.2 on win7 x64)
I see instead that you are sucessfully running your script on your system. What's your system?
I'm a bit confused because I don't know if I have some weird problem on my system or if the $WS_EX_LAYERED style has some restrictions of use...
I will try to look further into the matter...
Thanks again for your very welcome aid :)


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

#5 ·  Posted (edited)

Signore Chimp,

I tried that script on Win10 x64 version 1607. I will try it in my vm Win7 just after my meeting.

 

Tested on Win7 (vm) with enabled Aero -> not working. :o Seems to be a problem with _WinAPI_SetParent() function.

 

Try these lines instead:

...
Global $hGUI_Child = GUICreate("", $iW, $iH, 10, 10, $WS_POPUP, BitOr($WS_EX_MDICHILD, $WS_EX_LAYERED), $hGUI)
;~ _WinAPI_SetParent($hGUI_Child, $hGUI)
GUISetState(@SW_SHOWNA, $hGUI_Child)
...

 

Edited by UEZ
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

#6 ·  Posted (edited)

Hi @UEZ

with using those new lines from post #5 your script works very well.

Many thanks for your instructive help :graduated:

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

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
Sign in to follow this  
Followers 0

  • Similar Content

    • Simpel
      howto: colored layer over updating EDIT control
      By Simpel
      Hi,
      I'm trying to create a console reader. All is working but I have a problem with the look. I want the line numbers with another backgroundcolor in silver. I made this with a small silver label. The edit control over the label has a transparent background.
      But if I start the prog then i can see how the line numbers wipe the silver background off. And if I click into the Edit then the silver label disappears completely.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <StaticConstants.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $g_iZaehler = 0 Global $g_hGUI = GUICreate("Console: StdoutRead" , 800, 800, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $text = GUICtrlCreateEdit("",10,30,780,760, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY + $ES_NOHIDESEL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $g_LaZeilen = GUICtrlCreateLabel("Zeilen: " & StringFormat("% 5d", $g_iZaehler), 680, 10, 100, 9, $SS_LEFTNOWORDWRAP) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) Global $g_hCbFreeze = GUICtrlCreateCheckbox("&Freeze", 13, 5, 90) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlCreateLabel("", 11, 31, 42, 758) ; soll die Ziffern andersfarbig hinterlegen GUICtrlSetBkColor(-1, $COLOR_SILVER) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW) Global $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) While 1 Sleep(200) $g_iZaehler += 1 $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) WEnd Func _Exit() Exit EndFunc Do you have any suggestions.
      Regards, Conrad
    • PINTO1927
      png with background transparent into gui without border
      By PINTO1927
      Hi guys, I would like to make a gui borderless viewing a png image with transparent background.
       
      pretty much has to be visible only the png image with no background..you have any simple example?
      Thank's
      GUICtrlCreatePic  
      still it provides the image with the background...
    • InunoTaishou
      Valentines Hearts
      By InunoTaishou
      Credit's go to @UEZ for his post from 5 years ago for the GDI+ Heart!
      Really, I was just bored... I didn't have a valentine (:'( )so I whipped this up in a couple of hours. Pretty sure I cleaned up all my resources properly but it's late and I'm tired.
      $HAPPY_VALENTINES is the string that is shown in the middle of the screen
      $MAX_HEART_COUNT controls how many hearts are displayed
      When you first run it it will display a tooltip with the % of the string drawn (since it needs to drawn line by line). The larger the heart, the longer it'll take to draw it. Once it's been drawn once it's saved (@TempDir & "\heart.png") and will be reloaded on each startup. It will check to make sure that the heart saved is the size in the current script. If the sizes don't match it deletes the old saved heart and redraws the correct size. (I.e., if the heart saved is 350px wide and the $MAX_HEART_SIZE is 250, it deletes the old heart.png and remakes it the correct size)
      ; Coded by InunoTaishou ; Credits to UEZ for the code to draw a heart #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> #pragma compile(Icon, "heart.ico") Opt("MustDeclareVars", 1) Opt("GUICloseOnEsc", 1) Opt("TrayIconHide", 1) _GDIPlus_Startup() Global Const $HAPPY_VALENTINES = "Happy Valentine's Day AutoIT" ; maximum hearts to be drawn Global Const $MAX_HEART_COUNT = 50 ; bounding rectangle that encloses the above string, width and height Global Const $VALENTINE_STRING_WIDTH = 400 Global Const $VALENTINE_STRING_HEIGHT = 150 Global Const $MIN_HEART_SIZE = 50 Global Const $MAX_HEART_SIZE = 300 Global Const $RECT_HAPPY_VALENTINES[4] = [(@DesktopWidth / 2) - ($VALENTINE_STRING_WIDTH / 2), (@DesktopHeight / 2) - ($VALENTINE_STRING_HEIGHT / 2), $VALENTINE_STRING_WIDTH, $VALENTINE_STRING_HEIGHT] ; x, y, width, height Global Const $MIN_TIMEOUT = 3000 Global Const $MAX_TIMEOUT = 7000 Global Const $MIN_VERTICAL_SPEED = 2 Global Const $MAX_VERTICAL_SPEED = 5 Global Const $MIN_HORIZONTAL_OFFSET = 100 Global Const $MAX_HORIZONTAL_OFFSET = 175 Global Const $PNG_HEART_PATH = @TempDir & "\heart.png" Global Const $HWND_PEN = _GDIPlus_PenCreate(0, 1) Global Const $HWND_FONT_FAMILY = _GDIPlus_FontFamilyCreate("Segoe UI") Global Const $HWND_FONT_VALENTINE = _GDIPlus_FontCreate($HWND_FONT_FAMILY, 32) Global Const $RECT_VALENTINE = _GDIPlus_RectFCreate($RECT_HAPPY_VALENTINES[0], $RECT_HAPPY_VALENTINES[1], $RECT_HAPPY_VALENTINES[2], $RECT_HAPPY_VALENTINES[3]) Global Const $RECT_FPS = _GDIPlus_RectFCreate(0, 0, 50, 16) Global Const $HWND_FONT_FPS = _GDIPlus_FontCreate($HWND_FONT_FAMILY, 8.5) Global Const $HWND_STRING_FORMAT_VALENTINE = _GDIPlus_StringFormatCreate() Global Const $HWND_STRING_FORMAT_FPS = _GDIPlus_StringFormatCreate() Global Const $HWND_VALENTINE_TEXT_BRUSH = _GDIPlus_BrushCreateSolid(0xFFFF0000) Global Const $HWND_BK_BRUSH = _GDIPlus_BrushCreateSolid(0xFF1A1A1A) Global Const $HWND_FPS_BRUSH = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Global Const $pi = ACos(-1) Global Const $dy = 30 Global $dist, $p, $l, $r, $col Global $heart_buffer[$MAX_HEART_COUNT][12] Global $frmMain = GUICreate("<3", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) Global $fps_counter = 0 Global $fps = 0 Global $hWnd_graphic = _GDIPlus_GraphicsCreateFromHWND($frmMain) Global $hWnd_bitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hWnd_graphic) Global $hWnd_backbuffer = _GDIPlus_ImageGetGraphicsContext($hWnd_bitmap) GDIPValentinesDay() Func GDIPValentinesDay() Local Const $hWnd_heart_bitmap = CreateHeartBitmap($MAX_HEART_SIZE, ($MAX_HEART_SIZE - 1), ($MAX_HEART_SIZE / 2)) ; center text _GDIPlus_StringFormatSetAlign($HWND_STRING_FORMAT_VALENTINE, 1) _GDIPlus_StringFormatSetLineAlign($HWND_STRING_FORMAT_VALENTINE, 1) ; set smoothing _GDIPlus_GraphicsSetSmoothingMode($hWnd_backbuffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetSmoothingMode($hWnd_graphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) GUISetBkColor(0x000000, $frmMain) _WinAPI_SetLayeredWindowAttributes($frmMain, 0x000000, 255) GUISetState(@SW_SHOW, $frmMain) SetHeartsMap() AdlibRegister("CalculateFps", 1000) Do _GDIPlus_GraphicsClear($hWnd_backbuffer, 0xFF000000) For $i = 0 To $MAX_HEART_COUNT - 1 ; if there is a timer If ($heart_buffer[$i][4] <> -1) Then ; if the timer has reached the timeout If (TimerDiff($heart_buffer[$i][5]) > $heart_buffer[$i][4]) Then ; shrink the heart $heart_buffer[$i][2] -= 1 $heart_buffer[$i][3] -= 1 EndIf EndIf ; if the heart has a horizontal move If ($heart_buffer[$i][7]) Then ; if the number of pixels moved in the x position is greater than the max pixels to move horizontally If (Abs($heart_buffer[$i][10]) > Abs($heart_buffer[$i][9])) Then If ($heart_buffer[$i][11] > 35) Then ; change direction $heart_buffer[$i][8] *= -1 ; reset the jerk counter $heart_buffer[$i][11] = 0 Else $heart_buffer[$i][11] += 1 EndIf EndIf ; adjust the x offset $heart_buffer[$i][0] += $heart_buffer[$i][8] ; adjust how many pixels the heart has moved in that direction $heart_buffer[$i][10] += $heart_buffer[$i][8] EndIf ; if the y position of the heart is <= 0 or the heart width <= 2, reset that heart If ($heart_buffer[$i][1] <= ($heart_buffer[$i][2] * -1) Or $heart_buffer[$i][2] <= 2) Then SetHeartStats($i) _GDIPlus_GraphicsDrawImageRect($hWnd_backbuffer, $hWnd_heart_bitmap, $heart_buffer[$i][0], $heart_buffer[$i][1], $heart_buffer[$i][2], $heart_buffer[$i][3]) ; adjust y coordinate of heart $heart_buffer[$i][1] -= $heart_buffer[$i][6] Next _GDIPlus_GraphicsFillRect($hWnd_backbuffer, $RECT_HAPPY_VALENTINES[0], $RECT_HAPPY_VALENTINES[1], $RECT_HAPPY_VALENTINES[2], $RECT_HAPPY_VALENTINES[3], $HWND_BK_BRUSH) _GDIPlus_GraphicsDrawStringEx($hWnd_backbuffer, $HAPPY_VALENTINES, $HWND_FONT_VALENTINE, $RECT_VALENTINE, $HWND_STRING_FORMAT_VALENTINE, $HWND_VALENTINE_TEXT_BRUSH) _GDIPlus_GraphicsFillRect($hWnd_backbuffer, 0, 0, 50, 16, $HWND_BK_BRUSH) _GDIPlus_GraphicsDrawStringEx($hWnd_backbuffer, "FPS: " & $fps_counter, $HWND_FONT_FPS, $RECT_FPS, $HWND_STRING_FORMAT_FPS, $HWND_FPS_BRUSH) _GDIPlus_GraphicsDrawImage($hWnd_graphic, $hWnd_bitmap, 0, 0) $fps += 1 Sleep(10) Until (GUIGetMsg() = $GUI_EVENT_CLOSE) AdlibUnRegister("CalculateFps") _GDIPlus_PenDispose($HWND_PEN) _GDIPlus_GraphicsDispose($hWnd_graphic) _GDIPlus_BitmapDispose($hWnd_bitmap) _GDIPlus_BitmapDispose($hWnd_heart_bitmap) _GDIPlus_FontFamilyDispose($HWND_FONT_FAMILY) _GDIPlus_FontDispose($HWND_FONT_VALENTINE) _GDIPlus_StringFormatDispose($HWND_STRING_FORMAT_VALENTINE) _GDIPlus_BrushDispose($HWND_VALENTINE_TEXT_BRUSH) _GDIPlus_BrushDispose($HWND_BK_BRUSH) _GDIPlus_FontDispose($HWND_FONT_FPS) _GDIPlus_StringFormatDispose($HWND_STRING_FORMAT_FPS) _GDIPlus_BrushDispose($HWND_FPS_BRUSH) _GDIPlus_Shutdown() GUIDelete($frmMain) Return 0 EndFunc ;==>GDIPValentinesDay Func CalculateFps() $fps_counter = $fps $fps = 0 EndFunc ;==>CalculateFps Func SetHeartsMap() For $i = 0 To $MAX_HEART_COUNT - 1 SetHeartStats($i) Next EndFunc ;==>SetHeartsMap Func SetHeartStats(Const ByRef $iIndex) ; determine horizontal direction to move Local Const $multiply_by = (Random(0, 1, 1) ? 1 : -1) Local $valid_position = False Local $y_offset = 0 ; width of heart $heart_buffer[$iIndex][2] = Ceiling(Random($MIN_HEART_SIZE, $MAX_HEART_SIZE, 1) / 10) * 10 ; height of heart $heart_buffer[$iIndex][3] = $heart_buffer[$iIndex][2] - 1 Do ; x position of heart $heart_buffer[$iIndex][0] = Random(0, @DesktopWidth, 1) ; y position of heart $heart_buffer[$iIndex][1] = Random(@DesktopHeight - $MIN_HEART_SIZE - $y_offset, @DesktopHeight, 1) For $i = 0 To $MAX_HEART_COUNT - 1 If ($i = $iIndex) Then ContinueLoop ; make sure the heart doesn't start in the same spot as another heart If (_WinAPI_PtInRectEx($heart_buffer[$iIndex][0], $heart_buffer[$iIndex][1], $heart_buffer[$i][0], $heart_buffer[$i][1], $heart_buffer[$i][0] + $heart_buffer[$i][2], $heart_buffer[$i][1] + $heart_buffer[$i][3])) Then $valid_position = False $y_offset += 5 ExitLoop Else $valid_position = True EndIf Next Until ($valid_position) If (Random(0, 3, 1) = False) Then ; add timeout for some hearts $heart_buffer[$iIndex][4] = Random($MIN_TIMEOUT, $MAX_TIMEOUT, 1) ; init timer for that heart $heart_buffer[$iIndex][5] = TimerInit() Else $heart_buffer[$iIndex][4] = -1 $heart_buffer[$iIndex][5] = 0 EndIf ; set vertical move speed $heart_buffer[$iIndex][6] = Random($MIN_VERTICAL_SPEED, $MAX_VERTICAL_SPEED, 1) If (Random(0, 4, 1)) Then ; horizontal moving is true $heart_buffer[$iIndex][7] = True ; set horizontal move speed $heart_buffer[$iIndex][8] = Random($MIN_VERTICAL_SPEED / 2, $MAX_VERTICAL_SPEED / 2, 1) * $multiply_by ; set the max pixels to move horizontally $heart_buffer[$iIndex][9] = Random($MIN_HORIZONTAL_OFFSET, $MAX_HORIZONTAL_OFFSET, 1) * $multiply_by ; set the pixels the heart has moved in this direction $heart_buffer[$iIndex][10] = 0 ; set the counter to 0, this controls how long to wait before adjusting direction once it's reached the max horizontal offset. (makes the heart not jerk left/right) $heart_buffer[$iIndex][11] = 0 Else ; horizontal moving is false $heart_buffer[$iIndex][7] = False $heart_buffer[$iIndex][8] = 0 $heart_buffer[$iIndex][9] = 0 $heart_buffer[$iIndex][10] = 0 $heart_buffer[$iIndex][11] = 0 EndIf EndFunc ;==>SetHeartStats Func CreateHeartBitmap(Const ByRef $iW, Const ByRef $iH, Const ByRef $iRadius) Local $hWnd_heart_graphic = _GDIPlus_GraphicsCreateFromHWND($frmMain) Local $hWnd_heart_bitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hWnd_heart_graphic) Local $hWnd_heart_buffer = _GDIPlus_ImageGetGraphicsContext($hWnd_heart_bitmap) Local $percent = 0 If (Not FileExists(@TempDir & "\heart.png")) Then ToolTip("Drawing heart, please wait ... 0% complete") _GDIPlus_GraphicsSetSmoothingMode($hWnd_heart_buffer, 2) _GDIPlus_GraphicsClear($hWnd_heart_buffer, 0x00000000) For $y = 1 To $iH For $x = 1 To $iW $dist = Sqrt((($iW / 2) - $x) ^ 2 + (($iH / 2) - $y) ^ 2) $p = ATan2(($iW / 2) - $x, ($iH / 2) - $y) $l = Abs($p) / $pi $r = (13 * $l - 22 * $l ^ 2 + 10 * $l ^ 3) / (6 - 5 * $l) * $iRadius If $dist <= $r Then $col = "0xFFFF0000" Else $col = "0x00000000" EndIf _GDIPlus_PenSetColor($HWND_PEN, $col) _GDIPlus_GraphicsDrawRect($hWnd_heart_buffer, $x, $y - $dy, 1, 1, $HWND_PEN) Next $percent = Round((($y * $iW) / ($iH * $iW)) * 100, 0) ToolTip("Drawing heart, please wait ..." & @CRLF & @TAB & @TAB & $percent & "% complete" & @CRLF & "[" & StringPercent($percent) & "]") Next ToolTip("") _GDIPlus_ImageSaveToFile($hWnd_heart_bitmap, $PNG_HEART_PATH) Else $hWnd_heart_bitmap = _GDIPlus_ImageLoadFromFile($PNG_HEART_PATH) ; if the saved image is not the proper size, remake it If (_GDIPlus_ImageGetWidth($hWnd_heart_bitmap) <> $MAX_HEART_SIZE) Then _GDIPlus_BitmapDispose($hWnd_heart_bitmap) _GDIPlus_GraphicsDispose($hWnd_heart_graphic) Do FileDelete($PNG_HEART_PATH) Until (Not FileExists($PNG_HEART_PATH)) Return CreateHeartBitmap($iW, $iH, $iRadius) EndIf EndIf _GDIPlus_GraphicsDispose($hWnd_heart_graphic) Return $hWnd_heart_bitmap EndFunc ;==>CreateHeartBitmap Func StringPercent(Const ByRef $iPercent) Local $string_return = "" For $i = 0 To $iPercent $string_return &= "|" Next For $i = $iPercent To 100 $string_return &= " " Next Return $string_return EndFunc ;==>StringPercent Func ATan2($y, $x) Return (2 * ATan($y / ($x + Sqrt($x * $x + $y * $y)))) EndFunc ;==>ATan2 Most of it should be pretty self explanatory. There's a lot of comments too.
      And since I like to see pictures of the code people post, here's mine! (The script is animated, my picture is not ;))

       
      Edit: Moved the Drawn string and rectangle outside the for loop for each heart. Increased FPS dramatically! Lol Also included the .ico and .exe
      Valentines Hearts.au3
      Valentines Hearts.exe
      heart.ico
    • InunoTaishou
      Scrolling GDI Images
      By InunoTaishou
      Hello again! Working on another project I'm using for a game called PokeMMO. Let me first say I am not automating any part of the game. I set the current location and the script will then display the available Pokemon in the area (In a transparent GUI, making the game the parent).
      The GUI height is based on the height of the game window, setting the max number of sprites displayed based on that. If there are more sprites than can be displayed I'm trying to make it so when you hover over the top/bottom it will scroll the images up/down, wrapping around in one vertical circle. I started working on it and managed to make it scroll up but it looked messy, didn't work properly, and just didn't seem right...
      Maybe it's because it's late, I've been working on this and my simple editor all day, lack of sleep, lack of food, I'm giving up for now but posting this in the hopes someone can point me in the right direction and show me what kind of algorithm I need to use to make it work lol
      Here's a link to the images used: http://imgur.com/a/AMtWn
      (Images in order should be named Hoothoot.png, Pidgey.png, Rattata.png, and Caterpie.png)
      #include <GDIPlus.au3> #include <Array.au3> #include <File.au3> #include <GUIConstants.au3> #include <GDIPlus.au3> #include <String.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ScreenCapture.au3> #include <Color.au3> #include <Misc.au3> HotKeySet("+{Esc}", "Close") AutoItSetOption("GuiOnEventMode", 1) AutoItSetOption("MustDeclareVars", 1) Global const $INI_PATH = @ScriptDir & "\PokeTracker.ini" Global $x Global $y Global $max_height = 0 Global $new_size = 0 Global $sprite_width = 56 Global $sprite_height = 56 Global $current_location = "Route 1" Global $possible_locations Global $frmTracker Global $frmResize Global $lblTitleBar Global $hWnd_graphics Global $hWnd_bitmap Global $hWnd_gdi_buffer Global $hWnd_family Global $hWnd_format Global $hWnd_brush Global $hWnd_pen Global $scroll = False Global $frm_tracker_state = @SW_HIDE Global $pokemon_count = 4 Global $pokemon_in_location[] = [5, "Pidgey", "Rattata", "Caterpie", "Hoothoot"] Global $hWnd_dll WinMain() Func WinMain() $hWnd_dll = DllOpen("user32.dll") _GDIPlus_Startup() ; Create the tracker GUI $frmTracker = GUICreate("PokeTracker", $sprite_width, $sprite_height * $pokemon_count, -1, -1, $WS_POPUP, $WS_EX_LAYERED) ; Create a label that can be used to drag the tracker $lblTitleBar = GUICtrlCreateLabel("", 0, 0, $sprite_width, $sprite_height, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetOnEvent($lblTitleBar, "Resize") ; Set colors of the GUI and label GUISetBkColor(0x000000, $frmTracker) GUICtrlSetBkColor($lblTitleBar, $GUI_BKCOLOR_TRANSPARENT) ; Set the GUI to transparent _WinAPI_SetLayeredWindowAttributes($frmTracker, 0x000000, 255) GUISetState(@SW_SHOW, $frmTracker) ; Create GDI handles used for drawing the sprites $hWnd_graphics = _GDIPlus_GraphicsCreateFromHWND($frmTracker) $hWnd_bitmap = _GDIPlus_BitmapCreateFromGraphics($sprite_width, $sprite_height * $pokemon_count, $hWnd_graphics) $hWnd_gdi_buffer = _GDIPlus_ImageGetGraphicsContext($hWnd_bitmap) ; Set the GDI objects to smooth _GDIPlus_GraphicsSetSmoothingMode($hWnd_gdi_buffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hWnd_graphics, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) ; Create GDI Handles used for writing the Strings $hWnd_format = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($hWnd_format, 1) $hWnd_brush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $hWnd_pen = _GDIPlus_PenCreate(0xFF1F1F1F, 1) $hWnd_family = _GDIPlus_FontFamilyCreate("Segoe UI") UpdateTracker() While (True) Sleep(100) WEnd EndFunc ;==>WinMain Func Close() ; Free GDI Resources _GDIPlus_StringFormatDispose($hWnd_format) _GDIPlus_BrushDispose($hWnd_brush) _GDIPlus_FontFamilyDispose($hWnd_family) _GDIPlus_PenDispose($hWnd_pen) _GDIPlus_BitmapDispose($hWnd_bitmap) _GDIPlus_GraphicsDispose($hWnd_graphics) _GDIPlus_Shutdown() ; Delete the current location file FileDelete(@ScriptDir & "\Images\Current Location.png") Exit (0) EndFunc ;==>Close Func Resize() If (Not _IsPressed(11, $hWnd_dll)) Then Return Local $abscoord_tracker = WinGetPos($frmTracker) $frmResize = GUICreate("", $abscoord_tracker[2] - 14, $abscoord_tracker[3], $abscoord_tracker[0], $abscoord_tracker[1], $WS_SIZEBOX, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetOnEvent($GUI_EVENT_CLOSE, "SetTrackerSize", $frmResize) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") GUISetBkColor(0x000000, $frmResize) ;_WinAPI_SetLayeredWindowAttributes($frmResize, 0x000000, 255) GUISetState(@SW_SHOW, $frmResize) GUISetState(@SW_DISABLE, $frmTracker) GUISetState(@SW_LOCK, $frmTracker) EndFunc Func SetTrackerSize() Local $abscoord_resize = WinGetPos($frmResize) Local $abscoord_tracker = WinGetPos($frmTracker) GUIDelete($frmResize) $frmResize = Null $new_size = $abscoord_resize[3] $max_height = $new_size GUISetState(@SW_ENABLE, $frmTracker) GUISetState(@SW_UNLOCK, $frmTracker) WinMove($frmTracker, "", $abscoord_resize[0], $abscoord_resize[1], $abscoord_resize[2], $new_size) GUICtrlSetPos($lblTitleBar, 0, 0, $sprite_width, $new_size) _GDIPlus_GraphicsDispose($hWnd_graphics) _GDIPlus_BitmapDispose($hWnd_bitmap) $hWnd_graphics = _GDIPlus_GraphicsCreateFromHWND($frmTracker) $hWnd_bitmap = _GDIPlus_BitmapCreateFromGraphics($sprite_width, $new_size, $hWnd_graphics) $hWnd_gdi_buffer = _GDIPlus_ImageGetGraphicsContext($hWnd_bitmap) _GDIPlus_GraphicsSetSmoothingMode($hWnd_gdi_buffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsSetTextRenderingHint($hWnd_graphics, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) UpdateTracker() EndFunc Func UpdateTracker() _GDIPlus_GraphicsClear($hWnd_gdi_buffer, 0x00000000) If ($pokemon_count >= 1 and IsArray($pokemon_in_location)) Then For $i = 1 To $pokemon_count ; Split the data for the pokemon_in_location Local $pokemon_data = StringSplit($pokemon_in_location[$i], ',') ; Rectangle for the area of the sprite and string Local $rect_pokemon_image[4] = [0, ($i - 1) * $sprite_height, $sprite_width, $sprite_height] ; If there is a Pokemon name in the $pokemon_data array ($pokemon_data[1] = Pokemon Name) If ($pokemon_data[0] >= 1) Then Local $hWnd_image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Sprites\" & $pokemon_data[1] & ".png") _GDIPlus_GraphicsDrawImageRect($hWnd_gdi_buffer, $hWnd_image, $rect_pokemon_image[0], $rect_pokemon_image[1], $rect_pokemon_image[2], $rect_pokemon_image[3]) _GDIPlus_ImageDispose($hWnd_image) EndIf ; If there are 2 pieces of data for the Pokemon [1] = Pokemon name, [2] = Rarity If ($pokemon_data[0] = 2) Then Local $hWnd_path = _GDIPlus_PathCreate() Local $rect_layout = _GDIPlus_RectFCreate($rect_pokemon_image[0], $rect_pokemon_image[1], $rect_pokemon_image[2], $rect_pokemon_image[3] - ($sprite_height / 2)) _GDIPlus_PathAddString($hWnd_path, $pokemon_data[2], $rect_layout, $hWnd_family, 0, 14, $hWnd_format) _GDIPlus_GraphicsDrawPath($hWnd_gdi_buffer, $hWnd_path, $hWnd_pen) _GDIPlus_GraphicsFillPath($hWnd_gdi_buffer, $hWnd_path, $hWnd_brush) _GDIPlus_GraphicsFillPath($hWnd_gdi_buffer, $hWnd_path, $hWnd_brush) _GDIPlus_PathDispose($hWnd_path) EndIf Next EndIf _GDIPlus_GraphicsDrawImage($hWnd_graphics, $hWnd_bitmap, 0, 0) Return $GUI_RUNDEFMSG EndFunc ;==>UpdateTracker Func WM_PAINT($hWndFrom, $iMsg, $wParam, $lParam) Return UpdateTracker() EndFunc ;==>WM_PAINT Func WM_WINDOWPOSCHANGING($hWndFrom, $iMsg, $wParam, $lParam) Local $abscoord_pokemmo = WinGetPos("[Class:LWJGL]") If (Not IsArray($abscoord_pokemmo)) Then Return $GUI_RUNDEFMSG Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam) Local $iLeft = DllStructGetData($stWinPos, 3) Local $iTop = DllStructGetData($stWinPos, 4) Local $iWidth = DllStructGetData($stWinPos, 5) Local $iHeight = DllStructGetData($stWinPos, 6) If ($iHeight > $abscoord_pokemmo[3] + 64) Then DllStructSetData($stWinPos, 6, $abscoord_pokemmo[3] - 64) If $iLeft < $abscoord_pokemmo[0] + 8 Then DllStructSetData($stWinPos, 3, $abscoord_pokemmo[0] + 8) If $iTop < $abscoord_pokemmo[1] + 30 Then DllStructSetData($stWinPos, 4, $abscoord_pokemmo[1] + 30) If $iLeft > $abscoord_pokemmo[0] + $abscoord_pokemmo[2] - $iWidth - 8 Then DllStructSetData($stWinPos, 3, $abscoord_pokemmo[0] + $abscoord_pokemmo[2] - $iWidth - 8) If $iTop > $abscoord_pokemmo[1] + $abscoord_pokemmo[3] - $iHeight - 8 Then DllStructSetData($stWinPos, 4, $abscoord_pokemmo[1] + $abscoord_pokemmo[3] - $iHeight - 8) If ($iLeft < $abscoord_pokemmo[0] + 167 and $iTop < $abscoord_pokemmo[1] + 64) Then If ($iTop < $abscoord_pokemmo[1] + 64) Then DllStructSetData($stWinPos, 4, $abscoord_pokemmo[1] + 64) EndIf EndFunc ;==>WM_WINDOWPOSCHANGING ; Not used, was going to use it for a second GUI that would dictate the size of the buffer to draw (how many rows/columns to draw and each Pokemon) Func WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) Local $abscoord_pokemmo = WinGetPos("[Class:LWJGL]") Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, $sprite_width) ; min width DllStructSetData($tagMaxinfo, 8, $sprite_height) ; min height DllStructSetData($tagMaxinfo, 9, $sprite_width) ; max width DllStructSetData($tagMaxinfo, 10, $max_height) ; max height Return $GUI_RUNDEFMSG EndFunc Func WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam) Local $abscoord_mouse = MouseGetPos() Local $abscoord_tracker = WinGetPos($frmTracker) Local $mouse_in_point If (Not IsArray($abscoord_tracker)) Then Return $GUI_RUNDEFMSG EndIf If (_WinAPI_PtInRectEx($abscoord_mouse[0], $abscoord_mouse[1], $abscoord_tracker[0], $abscoord_tracker[1], $abscoord_tracker[0] + $abscoord_tracker[2], $abscoord_tracker[1] + $sprite_height)) Then $mouse_in_point = True While ($mouse_in_point) $abscoord_mouse = MouseGetPos() $abscoord_tracker = WinGetPos($frmTracker) $mouse_in_point = _WinAPI_PtInRectEx($abscoord_mouse[0], $abscoord_mouse[1], $abscoord_tracker[0], $abscoord_tracker[1], $abscoord_tracker[0] + $abscoord_tracker[2], $abscoord_tracker[1] + $sprite_height) Wend ElseIf (_WinAPI_PtInRectEx($abscoord_mouse[0], $abscoord_mouse[1], $abscoord_tracker[0], $abscoord_tracker[1] + $abscoord_tracker[3] - $sprite_height, $abscoord_tracker[0] + $abscoord_tracker[1], $abscoord_tracker[1] + $abscoord_tracker[3])) Then ToolTip("bottom", 0, 0) Else ToolTip("") EndIf Return $GUI_RUNDEFMSG EndFunc  
    • explorerpl
      Adobe AIR like window
      By explorerpl
      It's been long enough since I started looking for a solution, so I post this with a clear conscious. 
      I am developing an application that would render keystrokes and click on the screen, much like KeyCastr on Mac OS. I did this once in the past. Back then I faced with the same problem - making a nice semitransparent window. I solved it by using Adobe AIR for the interface and Visual Basic for the data. VB was the server capturing the keystrokes and mouse events and passing them via TCP over localhost to Adobe AIR (compiled to exe). This solution worked quite ok. I even tried reviving it few hours before posting it with no success.
      Important note - this is NOT a keylogger, though it shares some core functionality with such application. I do not ask for tips on capturing keyboards events (though if someone could post something useful I'd be grateful). 
      These are some posts that I've found on the forum:
      https://www.autoitscript.com/forum/topic/137618-two-questions-about-layered-gui/#comment-963975
      https://www.autoitscript.com/forum/topic/102961-multiple-png-images-as-gui-elements/
      https://www.autoitscript.com/forum/topic/47651-png-as-gui-drop-shadows-curved-edges-you-name-it/
      https://www.autoitscript.com/forum/topic/102920-advanced-gui-udf-design/
      https://www.autoitscript.com/forum/topic/157841-gui-fun/#comment-1144334
      https://www.autoitscript.com/forum/topic/140053-just-the-text/#comment-983400
      and even more...
      The reason for not using an existing application is that there aren't many for windows, they look ugly, and they do not behave the way I need them too.
      I've tried these approaches, but I'm either to stupid to understand them fully or I'm simply missing something. The main problem that I'm having is having the window transparent and displaying a label with text on top of it. As you know regular controls will not be transparent. I figured out that making a child window (transparent) on top of the parent transparent window might be the solution (I figured it out myself before finding some posts about it so I'm pretty proud of myself :)). Still... even if I do so the text is not anti-aliased and simply looks ugly.
      I could really use an example code that creates a window that has a PNG as a background with a nice label on top that has drop shadow (two labels? one black for the shadow and one white for the text). The window should also be dragable with a mouse.
      Here's a video with my old app running (start watching from 0:50): https://www.youtube.com/watch?v=C7fSpZntpfA
      Here's a similar application called KeyPose: http://jungsbluth.de/magnus/blog/keypose/keypose.html
      At some point I thought I'd just create a flash object on my window and make it transparent (I've seen this done even back in Windows 98). The difficulty here is that it's not a binary transparency, but a 32bpc one - real, smooth alpha channel like in a PNG, which is what most of the code I've seen is doing. Unfortunately I wasn't able to check that code, because I fail to create the Shockwave.Shockwave.11 object. I've installed the Flash player and the Shockwave player manually, registered the OCX, but no success.
      TL;DR
      Honestly - the solution to all my problems and problems other users are having would be replicating the behavior of such apps, that take an SWF and make a windowless EXE out of them. Just take a look at the attached file. Please note that the BG is semi-transparent, the labels are anti-aliased with a drop shadow. This is my old solution using Adobe AIR (Flash). I'd like to replicate that as closely as possible.
      I really hope some good soul will help me with this.
      Thank you.