Jump to content

Pb GDI+ (self delete draw?)


Recommended Posts

Hi!

With this code:

#include <GDIPlus.au3>


test()
Exit

 


Func test()
    Local $hWnd, $hGraphic

    $hWnd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsDrawRect($hGraphic, 10, 10, 100, 100)
    _GDIPlus_GraphicsDrawRect($hGraphic, 9, 9, 102, 102)
    _GDIPlus_GraphicsDrawRect($hGraphic, 8, 8, 104, 104)
    _GDIPlus_GraphicsDrawRect($hGraphic, 7, 7, 106, 106)
    _GDIPlus_GraphicsDrawRect($hGraphic, 6, 6, 108, 108)

    _GDIPlus_GraphicsDrawRect($hGraphic, 30,30, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 40,40, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 50,50, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 60,60, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 70,70, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 80,80, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 90,90, 90, 90)

 sleep(15000)
 MsgBox(0,32,32,2)
 sleep(3000)
    _GDIPlus_GraphicsDispose ($hGraphic)
 Sleep(128)
    _GDIPlus_Shutdown ()
 MsgBox(0,37,37,2)
 Sleep(25)
EndFunc

The pictures are (self?) deleted before the msgBox of line 32 ; during the sleep(15000).

Why ?

Thanks for answers.

Edited by Michel Claveau
Link to comment
Share on other sites

GetDC returns an handle to a device context, but _GDIPlus_GraphicsCreateFromHWND wants an handle to a window

Yes but even if you use

$hWnd = WinGetHandle("Program Manager")

it doesn't work.

I don't see what's wrong but this works

#include <GDIPlus.au3>
#include <windowsconstants.au3>

Global $Gui

$Gui = GUICreate("draw",@DesktopWidth,@DesktopHeight,0,0,$WS_POPUP,$WS_EX_LAYERED);,BitOr($WS_EX_TRANSPARENT,$WS_EX_LAYERED))
GUISetBkColor(0x123456)
_API_SetLayeredWindowAttributes($Gui, 0x123456, 255)
GUISetState()
test()
Exit



Func test()
    Local $hWnd, $hGraphic

    $hWnd = $Gui;DllCall("user32.dll", "int", "GetDC", "hwnd", 0)

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsDrawRect($hGraphic, 10, 10, 100, 100)
    _GDIPlus_GraphicsDrawRect($hGraphic, 9, 9, 102, 102)
    _GDIPlus_GraphicsDrawRect($hGraphic, 8, 8, 104, 104)
    _GDIPlus_GraphicsDrawRect($hGraphic, 7, 7, 106, 106)
    _GDIPlus_GraphicsDrawRect($hGraphic, 6, 6, 108, 108)
;sleep(3000)
    _GDIPlus_GraphicsDrawRect($hGraphic, 30,30, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 40,40, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 50,50, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 60,60, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 70,70, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 80,80, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 90,90, 90, 90)

;sleep(15000)
 MsgBox(0,32,32,2)
 sleep(3000)
    _GDIPlus_GraphicsDispose ($hGraphic)
 Sleep(128)
    _GDIPlus_Shutdown ()
 MsgBox(0,37,37,2)
 Sleep(25)
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                 $hwnd - Handle of GUI to work on
;                 $i_transcolor - Transparent color
;                 $Transparency - Set Transparancy of GUI
;                 $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                 Error: 0
;                  @error: 1 to 3 - Error from DllCall
;                  @error: 4 - Function did not succeed - use
;                              _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
        Case Else
            Return 1
    EndSelect
EndFunc  ;==>_API_SetLayeredWindowAttributes
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Yes but even if you use

$hWnd = WinGetHandle("Program Manager")

it doesn't work.

Yes, I noticed it too, here is an example using GDI:

#include <WindowsConstants.au3>
#include <WinApi.au3>

test()

Exit

Func test()
    Local $hWnd, $hGraphic

    $hDC = _WinAPI_GetWindowDC(0)
    $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x000000)
    $oPen = _WinAPI_SelectObject($hDC, $hPen)
    _WinAPi_DrawRect($hDC, 10, 10, 100, 100)

;~   _GDIPlus_GraphicsDrawRect($hGraphic, 10, 10, 100, 100)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 9, 9, 102, 102)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 8, 8, 104, 104)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 7, 7, 106, 106)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 6, 6, 108, 108)

;~   _GDIPlus_GraphicsDrawRect($hGraphic, 30,30, 90, 90)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 40,40, 90, 90)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 50,50, 90, 90)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 60,60, 90, 90)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 70,70, 90, 90)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 80,80, 90, 90)
;~   _GDIPlus_GraphicsDrawRect($hGraphic, 90,90, 90, 90)
    _WinAPI_SelectObject($hDC, $oPen)
    _WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc

Func _WinAPi_DrawRect($hDC, $iX, $iY, $iWidth, $iHeight)
    _WinAPI_DrawLine($hDC, $iX, $iY, $iWidth, $iY)
    _WinAPI_DrawLine($hDC, $iWidth, $iY, $iWidth, $iHeight)
    _WinAPI_DrawLine($hDC, $iWidth, $iHeight, $iX, $iHeight)
    _WinAPI_DrawLine($hDC, $iX, $iHeight, $iX, $iY)

EndFunc
Link to comment
Share on other sites

Hi!

Sorry, don't work.

Add that:

Sleep(12000)
MsgBox(0,31,31,2)oÝ÷ Ø¢·­ë)Þ±«­¢+Ù}]¥¹A%}M±Ñ=©Ð ÀÌØí¡°ÀÌØí½A¸¤)}]¥¹A%}±Ñ=©Ð ÀÌØí¡A¸¤)}]¥¹A%}I±Í À°ÀÌØí¡

and run the script.

The rectangle is deleted during the sleep...

Edited by Michel Claveau
Link to comment
Share on other sites

  • 7 years later...
On 6/13/2009 at 2:26 AM, martin said:

expandcollapsepopup

#include <GDIPlus.au3>
#include <windowsconstants.au3>

Global $Gui

$Gui = GUICreate("draw",@DesktopWidth,@DesktopHeight,0,0,$WS_POPUP,$WS_EX_LAYERED);,BitOr($WS_EX_TRANSPARENT,$WS_EX_LAYERED))
GUISetBkColor(0x123456)
_API_SetLayeredWindowAttributes($Gui, 0x123456, 255)
GUISetState()
test()
Exit



Func test()
    Local $hWnd, $hGraphic

    $hWnd = $Gui;DllCall("user32.dll", "int", "GetDC", "hwnd", 0)

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsDrawRect($hGraphic, 10, 10, 100, 100)
    _GDIPlus_GraphicsDrawRect($hGraphic, 9, 9, 102, 102)
    _GDIPlus_GraphicsDrawRect($hGraphic, 8, 8, 104, 104)
    _GDIPlus_GraphicsDrawRect($hGraphic, 7, 7, 106, 106)
    _GDIPlus_GraphicsDrawRect($hGraphic, 6, 6, 108, 108)
;sleep(3000)
    _GDIPlus_GraphicsDrawRect($hGraphic, 30,30, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 40,40, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 50,50, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 60,60, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 70,70, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 80,80, 90, 90)
    _GDIPlus_GraphicsDrawRect($hGraphic, 90,90, 90, 90)

;sleep(15000)
 MsgBox(0,32,32,2)
 sleep(3000)
    _GDIPlus_GraphicsDispose ($hGraphic)
 Sleep(128)
    _GDIPlus_Shutdown ()
 MsgBox(0,37,37,2)
 Sleep(25)
EndFunc

;===============================================================================
;
; Function Name:   _API_SetLayeredWindowAttributes
; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
; Parameter(s):
;                 $hwnd - Handle of GUI to work on
;                 $i_transcolor - Transparent color
;                 $Transparency - Set Transparancy of GUI
;                 $isColorRef - If True, $i_transcolor is a COLORREF-Strucure, else an RGB-Color
; Requirement(s):  Layered Windows
; Return Value(s): Success: 1
;                 Error: 0
;                  @error: 1 to 3 - Error from DllCall
;                  @error: 4 - Function did not succeed - use
;                              _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    If Not $isColorRef Then
        $i_transcolor = Hex(String($i_transcolor), 6)
        $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $LWA_COLORKEY + $LWA_ALPHA)
    Select
        Case @error
            Return SetError(@error, 0, 0)
        Case $Ret[0] = 0
            Return SetError(4, 0, 0)
        Case Else
            Return 1
    EndSelect
EndFunc  ;==>_API_SetLayeredWindowAttributes
 
Func test()
    Local $hWnd, $hGraphic
    Local $hPen = _GDIPlus_PenCreate(0xFFFEDCBA, 4) ; <<<<<<<
    $hWnd = $Gui;DllCall("user32.dll", "int", "GetDC", "hwnd", 0)

    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsDrawRect($hGraphic, 150, 50, 280, 500, $hPen) ; <<<<<<<

;sleep(15000)
 MsgBox(0,32,32,2)
 sleep(3000)
    _GDIPlus_PenDispose($hPen) ; <<<<<<<
    _GDIPlus_GraphicsDispose ($hGraphic)
 Sleep(128)
    _GDIPlus_Shutdown ()
 MsgBox(0,37,37,2)
 Sleep(25)
EndFunc

I tried editing a part of your code to change the color of the rectangles to no avail. I realize the thread is 8-years-old but hoping for an answer without the need to make a new thread. 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...