Jump to content
Sign in to follow this  
careca

How to prevent _GDIPlus_GraphicsDrawImage to draw over controls?

Recommended Posts

careca

Hello, having an issue where i want to draw an image with the size of the GUI, but don't want it to go on top of the controls, i was thinking about using _WinAPI_RedrawWindow, but then i'd need to specify each control, and maybe there's a better way.

Also, when using this, i don't understand why it's not redrawing the rectangle i specify, like this:

Local $tRect = DllStructCreate($tagRECT)
DllStructSetData($tRect, 'Left', 8)
DllStructSetData($tRect, 'Top', 10)
DllStructSetData($tRect, 'Right', 585 + 8)
DllStructSetData($tRect, 'Bottom', 250 + 10)

_WinAPI_RedrawWindow($GUI, $tRect, 0, $RDW_NOCHILDREN)

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
UEZ

You have to exclude the regions occupied by controls from the gdi+ regions.

Here a very old example I wrote (so don't blame me):

;coded by UEZ 2009
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIplus.au3>
#include <WindowsConstants.au3>

Local Const $width = @DesktopWidth / 2
Local Const $height = @DesktopHeight / 2
Opt("GUIOnEventMode", 1)

Local $fps = 0, $fps_diff, $fps_maintimer, $fps_timer, $display_FPS = -15
Local $trig = ACos(-1)  / 180
Local $max_dots = 100
Local $max_speed = 8
Local $iWidth = 10
Local $iHeight = 10
Local $hGUI = GUICreate("Border Collision with " & $max_dots & " objects! 0 FPS", $width, $height, -1, -1, Default, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
Local $Button = GUICtrlCreateButton("Exit", $width / 2 - 50, $height / 2 - 15, 100, 30)
Local $Input = GUICtrlCreateInput("Coded by UEZ", $width / 4, $height - 40, $width / 2, 20, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphics)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)
Local $hBrush_Clear = _GDIPlus_BrushCreateSolid(0xFF000000)

;~ Global Const $GW_CHILD = 5
;~ Global Const $GW_HWNDNEXT = 2
Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $width, $height)
Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
Global $aRect
Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion)
_GDIPlus_RegionDispose($hRegion)

GUISetState()

GUICtrlSetOnEvent($Button, "Close")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")


Dim $coordinates[$max_dots][5], $angle
Dim $hBrush[$max_dots]
Initialize()

$fps_maintimer = TimerInit()
Do
    For $x = -0x7FFFFFFF To 0x7FFFFFFF
        $fps_timer = TimerInit()
        Draw_Dots()
        Calculate_New_Position()
        Sleep(30)
        $fps_diff = TimerDiff($fps_timer)
        If TimerDiff($fps_maintimer) > 999 Then ;calculate FPS
            $fps = Round(1000 / $fps_diff, 2)
            $fps_maintimer = TimerInit()
        EndIf
        WinSetTitle($hGUI, "", "Border Collision with " & $max_dots & " objects! " & $fps & " FPS")
    Next
Until False

Func Initialize()
    For $k = 0 To $max_dots - 1
        $hBrush[$k] = _GDIPlus_BrushCreateSolid(Random(0xD0808080, 0xD0FFFFFF, 1))
        New_Coordinates($k)
    Next
EndFunc   ;==>Initialize

Func Draw_Dots()
    Local $i, $temp_x, $temp_y
    _GDIPlus_GraphicsFillRect($hBackbuffer, 0, 0, $width, $height, $hBrush_Clear)
    For $i = 0 To $max_dots - 1
        _GDIPlus_GraphicsFillEllipse($hBackbuffer, $coordinates[$i][0], $coordinates[$i][1], $iWidth, $iHeight, $hBrush[$i])
    Next
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $width, $height)
EndFunc   ;==>Draw_Dots

Func New_Coordinates($k)
    $coordinates[$k][0] = $width / 2 ;Random($width / 20, $width - $width / 20, 1);start x position
    $coordinates[$k][1] = $height / 2 ;Random($height / 20, $height - $height / 20, 1) ;start y position
    $coordinates[$k][2] = Random(1, $max_speed, 1) ;speed of pixel
    $angle = Random(0, 359, 1)
;~ ConsoleWrite("Angle: " & $angle & "°" & @CRLF)
    $coordinates[$k][3] = $coordinates[$k][2] * Cos($angle * $trig)
    $coordinates[$k][4] = $coordinates[$k][2] * Sin($angle * $trig)
EndFunc   ;==>New_Coordinates

Func Calculate_New_Position()
    Local $k
    For $k = 0 To $max_dots - 1
        $coordinates[$k][0] += $coordinates[$k][3] ;increase x coordinate with appropriate slope
        $coordinates[$k][1] += $coordinates[$k][4] ;increase y coordinate with appropriate slope
        If $coordinates[$k][0] <= 0 Then ;border collision x left
            $coordinates[$k][0] = 1
            $coordinates[$k][3] *= -1
        ElseIf $coordinates[$k][0] >= $width - $iWidth Then ;border collision x right
            $coordinates[$k][0] = $width - ($iWidth + 1)
            $coordinates[$k][3] *= -1
        EndIf
        If $coordinates[$k][1] <= 0 Then ;border collision y top
            $coordinates[$k][1] = 1
            $coordinates[$k][4] *= -1
        ElseIf $coordinates[$k][1] >= $height - $iHeight Then ;border collision y bottom
            $coordinates[$k][1] = $height - ($iHeight + 1)
            $coordinates[$k][4] *= -1
        EndIf
    Next
EndFunc   ;==>Calculate_New_Position

Func close()
    For $k = 0 To $max_dots - 1
        _GDIPlus_BrushDispose($hBrush[$k])
    Next
    _GDIPlus_BrushDispose($hBrush_Clear)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>close

Br,

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
careca

Yes, thank you, but im letting this go, as i encountered a whole lot of problems, trying to put a background on a window with some controls, been trying to make those controls transparent, for instance, the sliders have a background i can't remove, buttons created with GUICtrlCreatePic become transparent, it's very weird this transparent world.

In contrast, labels can be done transparent, but the letters become weird, with bits transparent too.

Thank you.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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  

×