Nothing2Lose Posted August 18, 2010 Posted August 18, 2010 Hi, I am writing a script using GDI+ library. I want to draw to lines (Horizontal & Vertical) through a point (coordinate = mouse coordinate) and delete the old lines when mouse move. I used Redrawwindow. It deleted the lines perfectly but the screen ... (you know, like refreshing desktop). That's my trouble. Can anyone help me? Thank you!
UEZ Posted August 18, 2010 Posted August 18, 2010 (edited) Is this what you mean? expandcollapse popup#include <GDIPLus.au3> #include <GUIConstants.au3> Opt("MouseCoordMode", 2) Opt("GUIOnEventMode", 1) $w = 400 $h = 400 $hWnd = GUICreate("GDI+ Test", 400, 400) GUISetState() _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hBitmap = _GDIPlus_BitmapCreateFromGraphics(400, 400, $hGraphic) $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hPen = _GDIPlus_PenCreate(0xFF000000, 2) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") AdlibRegister("_ReDraw", 20) GUIRegisterMsg(0x000F, "_ReFresh") ;$WM_PAINT = 0x000F OnAutoItExitRegister("_Exit") While Sleep(2000) WEnd Func _ReDraw() _GDIPlus_GraphicsClear($hBuffer, 0xFFFFFFFF) _GDIPlus_GraphicsDrawEllipse($hBuffer, 0, 0, $w, $h, $hPen) $mpos = MouseGetPos() If $mpos[0] > 0 And $mpos[0] < $w And $mpos[1] > 0 And $mpos[1] < $h Then _GDIPlus_GraphicsDrawLine($hBuffer, $mpos[0], 0, $mpos[0], $h, $hPen) _GDIPlus_GraphicsDrawLine($hBuffer, 0, $mpos[1], $w, $mpos[1], $hPen) EndIf _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $w, $h) EndFunc Func _ReFresh() _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $w, $h) Return "GUI_RUNDEFMSG" EndFunc Func _Exit() GUIRegisterMsg(0x000F, "") AdlibUnRegister("_ReDraw") _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hBuffer) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() GUIDelete($hWnd) Exit EndFunc Br, UEZ Edited August 18, 2010 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Nothing2Lose Posted August 18, 2010 Author Posted August 18, 2010 Thanks! I want to draw them on the desktop
UEZ Posted August 18, 2010 Posted August 18, 2010 And what about this version? expandcollapse popup;coded by UEZ #include <GDIPLus.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> Opt("MouseCoordMode", 0) Opt("GUIOnEventMode", 1) $w = @DesktopWidth $h = @DesktopHeight $hWnd = GUICreate("GDI+ Test", $w, $h, 0, 0, 0, $WS_EX_LAYERED + $WS_EX_TOPMOST) GUISetState() _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $w, $hGraphic) $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) $hPen = _GDIPlus_PenCreate(0xFFA0A0A0, 2) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) $ScreenDc = _WinAPI_GetDC($hWnd) $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) $dc = _WinAPI_CreateCompatibleDC($ScreenDc) _WinAPI_SelectObject($dc, $gdibitmap) ; _WinAPI_UpdateLayeredWindow parameters $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $w) DllStructSetData($tSize, "Y", $h) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) $alpha = 0xFF DllStructSetData($tBlend, "Alpha", $alpha) DllStructSetData($tBlend, "Format", 1) $tPoint = DllStructCreate($tagPOINT) $pPoint = DllStructGetPtr($tPoint) DllStructSetData($tPoint, "X", 0) DllStructSetData($tPoint, "Y", 0) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $mpos_ox = 0 $mpos_oy = 0 While Sleep(50) _GDIPlus_GraphicsClear($hBuffer, 0x00000000) $mpos = MouseGetPos() If $mpos[0] <> $mpos_oy Or $mpos[1] <> $mpos_oy Then _GDIPlus_GraphicsDrawLine($hBuffer, $mpos[0], 0, $mpos[0], $h, $hPen) _GDIPlus_GraphicsDrawLine($hBuffer, 0, $mpos[1], $w, $mpos[1], $hPen) $mpos_ox = $mpos[0] $mpos_oy = $mpos[1] EndIf $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_SelectObject($dc, $gdibitmap) _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2) _WinAPI_DeleteObject($gdibitmap) WEnd Func _Exit() _WinAPI_DeleteDC($dc) _WinAPI_ReleaseDC($hWnd, $ScreenDc) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hBuffer) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() GUIDelete($hWnd) $tSize = "" $tSource = "" $tBlend = "" $tPoint = "" Exit EndFunc 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Nothing2Lose Posted August 23, 2010 Author Posted August 23, 2010 Thanks so much! It works perfectly!!!
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