Alex1986 Posted September 22, 2015 Share Posted September 22, 2015 (edited) Hii want Get Mouse Pos Form Two Point To Draw Line with use GDIExample : if KeyDown CTRL then $BEGINPoint = MouseGetPos , if KeyUp CTRL $ENDPoint = MouseGetPos , Draw Line $BEGINPoint To $ENDPointMy Code :#include <WindowsConstants.au3> #include <WinAPI.au3> #Include <GDIPlus.au3> #include <Misc.au3> Local $PointA , $PointB , $Cunt = 0 _GDIPlus_Startup () $hDC = _WinAPI_GetWindowDC(0) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) $Color = 0xFF000000 $hPen = _GDIPlus_PenCreate($Color,2) While 1 If $PointA + $PointB = 0 And _IsPressed(43) Then ; 43 = Key C $PointA = MouseGetPos() $Cunt = 1 EndIf if $Cunt = 1 Then If _IsPressed(43) Then $PointB = MouseGetPos() _GDIPlus_GraphicsDrawLine($hGraphic, $PointA[0] , $PointB[0] , $PointA[1] , $PointB[1], $hPen) $PointA = 0 $PointB = 0 $Cunt = 0 EndIf EndIf WEnd _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE+$RDW_ALLCHILDREN) _WinAPI_ReleaseDC(0, $hDC) _GDIPlus_Shutdown() Edited September 22, 2015 by Alex1986 Link to comment Share on other sites More sharing options...
kylomas Posted September 22, 2015 Share Posted September 22, 2015 Alex1986,You may be able to adapt this from UEZ...expandcollapse popup#Include <ScreenCapture.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global Const $HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, 0) Global Const $hGUI = GUICreate("Mark screen by UEZ", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) GUISetState(@SW_SHOW, $hGUI) Global Const $hGraphic_Bg = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP) _GDIPlus_GraphicsDrawImage($hGraphic_Bg, $hBmp, 0, 0) _WinAPI_DeleteObject($HBITMAP) Global Const $pen_size = 1 Global Const $hPen = _GDIPlus_PenCreate(0xff000000, $pen_size) GUISetOnEvent(-3, "_Exit") OnAutoItExitRegister("_Exit") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI) Global Const $om = MouseGetCursor() While Sleep(100000) WEnd Func Draw() Local $aMC, $mxo, $myo $aMC = GUIGetCursorInfo($hGUI) Sleep(50) Do GUISetCursor(0, 1, $hGUI) $mxo = $aMC[0] $myo = $aMC[1] $aMC = GUIGetCursorInfo($hGUI) If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then _GDIPlus_GraphicsDrawLine($hGraphic_Bg, $aMC[0], $aMC[1], $mxo, $myo, $hPen) $mxo = $aMC[0] $myo = $aMC[1] EndIf Until Not $aMC[2] EndFunc Func _Exit() GUISetCursor($om, 1, $hGUI) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "") _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic_Bg) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunckylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Alex1986 Posted September 22, 2015 Author Share Posted September 22, 2015 Alex1986,You may be able to adapt this from UEZ...expandcollapse popup#Include <ScreenCapture.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global Const $HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, 0) Global Const $hGUI = GUICreate("Mark screen by UEZ", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) GUISetState(@SW_SHOW, $hGUI) Global Const $hGraphic_Bg = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP) _GDIPlus_GraphicsDrawImage($hGraphic_Bg, $hBmp, 0, 0) _WinAPI_DeleteObject($HBITMAP) Global Const $pen_size = 1 Global Const $hPen = _GDIPlus_PenCreate(0xff000000, $pen_size) GUISetOnEvent(-3, "_Exit") OnAutoItExitRegister("_Exit") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI) Global Const $om = MouseGetCursor() While Sleep(100000) WEnd Func Draw() Local $aMC, $mxo, $myo $aMC = GUIGetCursorInfo($hGUI) Sleep(50) Do GUISetCursor(0, 1, $hGUI) $mxo = $aMC[0] $myo = $aMC[1] $aMC = GUIGetCursorInfo($hGUI) If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then _GDIPlus_GraphicsDrawLine($hGraphic_Bg, $aMC[0], $aMC[1], $mxo, $myo, $hPen) $mxo = $aMC[0] $myo = $aMC[1] EndIf Until Not $aMC[2] EndFunc Func _Exit() GUISetCursor($om, 1, $hGUI) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "") _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic_Bg) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunckylomasBut this draw in GUI , i want draw direct in Screen without ScreenCapture .Thank You . Link to comment Share on other sites More sharing options...
kylomas Posted September 22, 2015 Share Posted September 22, 2015 (edited) But this draw in GUI , i want draw direct in Screen without ScreenCapture .Yes, that is where the "adapt" part comes in... Edit: I have this snippet...#include <WindowsConstants.au3> #include <WinAPI.au3> Local $hDC, $hPen, $obj_orig, $x1 = 0, $x2 = @DesktopWidth, $y1 = 0, $y2 = 0 _line() Func _line() $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00ff) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) While $y1 < @DesktopHeight _WinAPI_DrawLine($hDC, $x1, $y1, $x2, $y1) _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN) $y1 += 1 WEnd _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>_lineMaybe it's useful. I probably should not have even responded to this thread as I never do this kind of thing. Edited September 22, 2015 by kylomas additional info Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Alex1986 Posted September 22, 2015 Author Share Posted September 22, 2015 Look This https://www.youtube.com/watch?v=NxmJDueHwD8 Link to comment Share on other sites More sharing options...
UEZ Posted September 22, 2015 Share Posted September 22, 2015 Well, when you directly draw on the desktop you risk to loose your drawing when the DC gets refreshed!Here an modified version from kylomas' post #4expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> AutoItSetOption("GUIOnEventMode", 1) Global $hGUI, $hDC, $hPen, $obj_orig $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) WinSetTrans($hGUI, "", 1) GUISetState() _line() Func _line() $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00ff) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI) GUISetOnEvent(-3, "_Exit") Do Until Not Sleep(1000) EndFunc ;==>_line Func Draw() Local $aMC, $mxo, $myo $aMC = GUIGetCursorInfo($hGUI) Do GUISetCursor(0, 1, 0) $mxo = $aMC[0] $myo = $aMC[1] $aMC = GUIGetCursorInfo($hGUI) If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then _WinAPI_DrawLine($hDC, $aMC[0], $aMC[1], $mxo, $myo) _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE) $mxo = $aMC[0] $myo = $aMC[1] EndIf Sleep(10) Until Not $aMC[2] EndFunc Func _Exit() _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) Exit EndFunc 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Alex1986 Posted September 22, 2015 Author Share Posted September 22, 2015 Thanks , how clear this , what is name Function Clear Pen 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