darkshark Posted December 17, 2011 Share Posted December 17, 2011 (edited) Hi ppl, fine?I'm trying to draw rectangles like this:I'm trying to draw rectangles on my screen the same way I draw rectangles in paint!I click somewhere and drag the mouse to another place, and the rectangle will be drawn!how can I do this?I tried it with graphics, but I could notand I would like to draw them on my screen, not in a GUI...if someone can help me, i'll be very grateful! Edited December 17, 2011 by darkshark Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 17, 2011 Moderators Share Posted December 17, 2011 darkshark, Perhaps this will help? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path ; Create GUI $hMain_GUI = GUICreate("Select Rectangle", 240, 50) $hRect_Button = GUICtrlCreateButton("Mark Area", 10, 10, 80, 30) $hCancel_Button = GUICtrlCreateButton("Cancel", 150, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hCancel_Button FileDelete(@ScriptDir & "Rect.bmp") Exit Case $hRect_Button GUISetState(@SW_HIDE, $hMain_GUI) Mark_Rect() ; Capture selected area $sBMP_Path = @ScriptDir & "Rect.bmp" _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False) GUISetState(@SW_SHOW, $hMain_GUI) ; Display image $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100) $hPic = GUICtrlCreatePic(@ScriptDir & "Rect.bmp", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1) GUISetState() EndSwitch WEnd ; ------------- Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x000000) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() $iX1 = $aMouse_Pos[0] $iY1 = $aMouse_Pos[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) WEnd ; Get second mouse position $iX2 = $aMouse_Pos[0] $iY2 = $aMouse_Pos[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) EndFunc ;==>Mark_Rect Any use? M23 darkshark, PoojaKrishna and IAMK 3 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted December 17, 2011 Share Posted December 17, 2011 You can get handle/DC to desktop (it's in fact ListView) and then you can use WinAPI functions for drawing to this DC. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
darkshark Posted December 17, 2011 Author Share Posted December 17, 2011 darkshark, Perhaps this will help? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path ; Create GUI $hMain_GUI = GUICreate("Select Rectangle", 240, 50) $hRect_Button = GUICtrlCreateButton("Mark Area", 10, 10, 80, 30) $hCancel_Button = GUICtrlCreateButton("Cancel", 150, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hCancel_Button FileDelete(@ScriptDir & "Rect.bmp") Exit Case $hRect_Button GUISetState(@SW_HIDE, $hMain_GUI) Mark_Rect() ; Capture selected area $sBMP_Path = @ScriptDir & "Rect.bmp" _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False) GUISetState(@SW_SHOW, $hMain_GUI) ; Display image $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100) $hPic = GUICtrlCreatePic(@ScriptDir & "Rect.bmp", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1) GUISetState() EndSwitch WEnd ; ------------- Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x000000) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() $iX1 = $aMouse_Pos[0] $iY1 = $aMouse_Pos[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) WEnd ; Get second mouse position $iX2 = $aMouse_Pos[0] $iY2 = $aMouse_Pos[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) EndFunc ;==>Mark_Rect Any use? M23 Yeah, it's help a lot! I can adapt it to what i want! thank you so much!! Link to comment Share on other sites More sharing options...
darkshark Posted December 17, 2011 Author Share Posted December 17, 2011 You can get handle/DC to desktop (it's in fact ListView) and then you can use WinAPI functions for drawing to this DC.I do not knew that!I will also try just to see how it works!Thank you for your help! Link to comment Share on other sites More sharing options...
Zedna Posted December 17, 2011 Share Posted December 17, 2011 I will also try just to see how it works!Here is some simple script to begin withYou can find many on this forum ... Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
darkshark Posted December 18, 2011 Author Share Posted December 18, 2011 Here is some simple script to begin withYou can find many on this forum ...i will see it!i'm reading the post!thanks a lot! Link to comment Share on other sites More sharing options...
Malkey Posted December 18, 2011 Share Posted December 18, 2011 Here is a simple example at draws the pixels of a rectangle to the desktop, #include <WinAPI.au3> _WinAPI_DrawRect(20, 20, @DesktopWidth / 2, @DesktopHeight / 2, 0x0000FF) Func _WinAPI_DrawRect($start_x, $start_y, $iWidth, $iHeight, $iColor) Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) Local $tRect = DllStructCreate($tagRECT) DllStructSetData($tRect, 1, $start_x) DllStructSetData($tRect, 2, $start_y) DllStructSetData($tRect, 3, $iWidth) DllStructSetData($tRect, 4, $iHeight) Local $hBrush = _WinAPI_CreateSolidBrush($iColor) _WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush) ; clear resources _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>_WinAPI_DrawRect Here is a more complex example that draws your rectangles to a layered window on the desktop. expandcollapse popup#include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> ; Modified from http://www.autoitscript.com/forum/index.php?s=&showtopic=97126&view=findpost&p=698489 Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client Main() Func Main() Local $hBitmap, $hGui, $hGraphic, $hImage2, $GuiSizeX = @DesktopWidth, $GuiSizeY = @DesktopHeight Local $GuiSize = 70, $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend Local $iX1 = 0, $iY1 = 0, $tPoint, $pPoint, $hBMPBuff, $hGraphicGUI, $hPen, $aMPos, $aMPosNew Local $iOpacity = 255, $dll = DllOpen("user32.dll") $hGui = GUICreate("L1", $GuiSizeX, $GuiSizeY, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetState() _GDIPlus_Startup() $hWnd = _WinAPI_GetDC(0) $hDC = _WinAPI_CreateCompatibleDC($hWnd) $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSizeX, $GuiSizeY) _WinAPI_SelectObject($hDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphic) $hGraphicGUI = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) _GDIPlus_GraphicsClear($hGraphic); Add ,0x01000000) to disable underling desktop $hPen = _GDIPlus_PenCreate(0xffff0000, 3) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $GuiSizeX);$iWidth ) DllStructSetData($tSize, "Y", $GuiSizeY);$iHeight) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) $tPoint = DllStructCreate($tagPOINT); Create point destination structure here $pPoint = DllStructGetPtr($tPoint); Create pointer to this dll data structure, $pPTDest parameter DllStructSetData($tPoint, "X", $iX1) DllStructSetData($tPoint, "Y", $iY1) _WinAPI_UpdateLayeredWindow($hGui, $hWnd, $pPoint, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) Do Select Case _IsPressed("01", $dll); Ctrl mouse button to move $aMPos = MouseGetPos() Do Sleep(10) Until Not _IsPressed("01", $dll) $aMPosNew = MouseGetPos() ;_GDIPlus_GraphicsDrawLine($hGraphic, $aMPosNew[0], $aMPosNew[1], $aMPos[0], $aMPos[1], $hPen) ; I used _Iif() from Misc.au3 instead using of _Min() from Math.au3. _GDIPlus_GraphicsDrawRect($hGraphic, _Iif($aMPos[0] < $aMPosNew[0], $aMPos[0], $aMPosNew[0]), _Iif($aMPos[1] < $aMPosNew[1], $aMPos[1], $aMPosNew[1]), Abs($aMPosNew[0] - $aMPos[0]), Abs($aMPosNew[1] - $aMPos[1]), $hPen) _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) Case _IsPressed("04", $dll) Or _IsPressed("11", $dll) ; Middle mouse button 0r Ctrl key <======= Clear screen of rectangles. _GDIPlus_GraphicsClear($hGraphic) _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) EndSelect Sleep(50) Until _IsPressed("1B", $dll); ESC key DllClose($dll) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphicGUI) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_ReleaseDC(0, $hWnd) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hDC) _GDIPlus_Shutdown() EndFunc ;==>Main PoojaKrishna and guestscripter 2 Link to comment Share on other sites More sharing options...
DaisyDuke Posted March 8, 2012 Share Posted March 8, 2012 Thanks Malkey for your examples, I noticed though that$iWidth and $iHeight of the _WinAPI_DrawRect function are actually the bottom right x and y coords. Do you know how to make the rectangle (1st example) to stay on top of everything until the gui closes? The rectangle is drawn outside the gui.Cheers Link to comment Share on other sites More sharing options...
Malkey Posted March 9, 2012 Share Posted March 9, 2012 (edited) Thanks Malkey for your examples, I noticed though that $iWidth and $iHeight of the _WinAPI_DrawRect function are actually the bottom right x and y coords. Do you know how to make the rectangle (1st example) to stay on top of everything until the gui closes? The rectangle is drawn outside the gui. Cheers @DaisyDuke Thanks for the heads up. You are correct. The _WinAPI_DrawRect function is actually the bottom right x and y coordinates.. This post's _WinAPI_FrameRect example has been modified to allow using width and height. This example also shows the inadequacy of using _WinAPI_FrameRect to draw directly to desktop. There is no GUI used. There is no on top of desktop. The pixels of the rectangle become part of the desktop. For the rectangle to stay on top (remain the top most window), a GUI is needed. And if you are going to use a GUI it might as well be a layered, topmost GUI (see second example, this post). First example - using _WinAPI_FrameRect. #include <WinAPI.au3> #include <WindowsConstants.au3> Global $tRect While 1 ; refresh desktop _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), $tRect, 0, BitOR($RDW_INVALIDATE, $RDW_ALLCHILDREN)) _WinAPI_DrawRect(20, 20, 40, 40, 0x0000FF) Sleep(10) WEnd Func _WinAPI_DrawRect($start_x, $start_y, $iWidth, $iHeight, $iColor) Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $tRect = DllStructCreate($tagRECT) DllStructSetData($tRect, 1, $start_x) DllStructSetData($tRect, 2, $start_y) DllStructSetData($tRect, 3, $iWidth + $start_x) ; x-coordinate of the lower-right corner of the rectangle DllStructSetData($tRect, 4, $iHeight + $start_y) ; y-coordinate of the lower-right corner of the rectangle Local $hBrush = _WinAPI_CreateSolidBrush($iColor) _WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush) ; clear resources _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>_WinAPI_DrawRect Second example - Layered, Topmost GUI expandcollapse popup#include <GDIPlus.au3> #include <WindowsConstants.au3> #include <Misc.au3> If _Singleton(@ScriptName, 1) = 0 Then Exit _DrawRect(20, 20, 40, 40) Do Sleep(10) Until _IsPressed("1B"); ESC key If WinExists("L1", "") Then GUIDelete(WinGetHandle("L1")) Func _DrawRect($x, $y, $w, $h) Local $hBitmap, $hGui, $hGraphic, $GuiSizeX = @DesktopWidth, $GuiSizeY = @DesktopHeight Local $GuiSize = 70, $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend, $hPen Local $iOpacity = 255 $hGui = GUICreate("L1", $GuiSizeX, $GuiSizeY, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetState() _GDIPlus_Startup() $hWnd = _WinAPI_GetDC(0) $hDC = _WinAPI_CreateCompatibleDC($hWnd) $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSizeX, $GuiSizeY) _WinAPI_SelectObject($hDC, $hBitmap) $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 3) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $GuiSizeX) DllStructSetData($tSize, "Y", $GuiSizeY) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _GDIPlus_GraphicsDrawRect($hGraphic, $x, $y, $w, $h, $hPen) ; <-- Graphics to layered wimdow. _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_ReleaseDC(0, $hWnd) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hDC) _GDIPlus_Shutdown() EndFunc ;==>_DrawRect Edited March 9, 2012 by Malkey Link to comment Share on other sites More sharing options...
t2d2c2 Posted May 22, 2014 Share Posted May 22, 2014 darkshark, Perhaps this will help? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #Include <ScreenCapture.au3> #Include <Misc.au3> Global $iX1, $iY1, $iX2, $iY2, $aPos, $sMsg, $sBMP_Path ; Create GUI $hMain_GUI = GUICreate("Select Rectangle", 240, 50) $hRect_Button = GUICtrlCreateButton("Mark Area", 10, 10, 80, 30) $hCancel_Button = GUICtrlCreateButton("Cancel", 150, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hCancel_Button FileDelete(@ScriptDir & "Rect.bmp") Exit Case $hRect_Button GUISetState(@SW_HIDE, $hMain_GUI) Mark_Rect() ; Capture selected area $sBMP_Path = @ScriptDir & "Rect.bmp" _ScreenCapture_Capture($sBMP_Path, $iX1, $iY1, $iX2, $iY2, False) GUISetState(@SW_SHOW, $hMain_GUI) ; Display image $hBitmap_GUI = GUICreate("Selected Rectangle", $iX2 - $iX1 + 1, $iY2 - $iY1 + 1, 100, 100) $hPic = GUICtrlCreatePic(@ScriptDir & "Rect.bmp", 0, 0, $iX2 - $iX1 + 1, $iY2 - $iY1 + 1) GUISetState() EndSwitch WEnd ; ------------- Func Mark_Rect() Local $aMouse_Pos, $hMask, $hMaster_Mask, $iTemp Local $UserDLL = DllOpen("user32.dll") ; Create transparent GUI with Cross cursor $hCross_GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight - 20, 0, 0, $WS_POPUP, $WS_EX_TOPMOST) WinSetTrans($hCross_GUI, "", 8) GUISetState(@SW_SHOW, $hCross_GUI) GUISetCursor(3, 1, $hCross_GUI) Global $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) GUISetBkColor(0x000000) ; Wait until mouse button pressed While Not _IsPressed("01", $UserDLL) Sleep(10) WEnd ; Get first mouse position $aMouse_Pos = MouseGetPos() $iX1 = $aMouse_Pos[0] $iY1 = $aMouse_Pos[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $UserDLL) $aMouse_Pos = MouseGetPos() $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0) $hMask = _WinAPI_CreateRectRgn($iX1, $aMouse_Pos[1], $aMouse_Pos[0], $aMouse_Pos[1] + 1) ; Bottom of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1, $iY1, $iX1 + 1, $aMouse_Pos[1]) ; Left of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($iX1 + 1, $iY1 + 1, $aMouse_Pos[0], $iY1) ; Top of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) $hMask = _WinAPI_CreateRectRgn($aMouse_Pos[0], $iY1, $aMouse_Pos[0] + 1, $aMouse_Pos[1]) ; Right of rectangle _WinAPI_CombineRgn($hMaster_Mask, $hMask, $hMaster_Mask, 2) _WinAPI_DeleteObject($hMask) ; Set overall region _WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask) If WinGetState($hRectangle_GUI) < 15 Then GUISetState() Sleep(10) WEnd ; Get second mouse position $iX2 = $aMouse_Pos[0] $iY2 = $aMouse_Pos[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hRectangle_GUI) GUIDelete($hCross_GUI) DllClose($UserDLL) EndFunc ;==>Mark_Rect Any use? M23 How to set drag-area (rectangle - area within border) with color? Netol 1 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