Michel Claveau Posted June 13, 2009 Share Posted June 13, 2009 (edited) Hi! With this code: expandcollapse popup#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 June 13, 2009 by Michel Claveau Link to comment Share on other sites More sharing options...
oMBRa Posted June 13, 2009 Share Posted June 13, 2009 GetDC returns an handle to a device context, but _GDIPlus_GraphicsCreateFromHWND wants an handle to a window Link to comment Share on other sites More sharing options...
martin Posted June 13, 2009 Share Posted June 13, 2009 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 expandcollapse popup#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 More sharing options...
oMBRa Posted June 13, 2009 Share Posted June 13, 2009 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: expandcollapse popup#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 More sharing options...
Michel Claveau Posted June 13, 2009 Author Share Posted June 13, 2009 (edited) 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 June 13, 2009 by Michel Claveau Link to comment Share on other sites More sharing options...
Michel Claveau Posted June 13, 2009 Author Share Posted June 13, 2009 Hi, Martin! Your code is OK for me. Thanks. Link to comment Share on other sites More sharing options...
oMBRa Posted June 13, 2009 Share Posted June 13, 2009 it's not an error, that happens because some windows or desktop refreshes, you have to keep drawing the square Link to comment Share on other sites More sharing options...
Yashied Posted June 13, 2009 Share Posted June 13, 2009 To keep the image, you need to draw it in the window. See carefully martin`s example. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
MapScribe Posted March 8, 2017 Share Posted March 8, 2017 On 6/13/2009 at 2:26 AM, martin said: expandcollapsepopup expandcollapse popup#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 More sharing options...
MapScribe Posted March 8, 2017 Share Posted March 8, 2017 Gah, I found my issue. If possible can somebody delete my posts? (Sorry for the double post I can't seem to find a delete or edit option) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now