Jump to content

Draw lines on desktop


Recommended Posts

Hello,

Is there a way to draw lines on the desktop? Without using a form that is.

Thanks!

It can be difficult because the DeskTop refreshes and destroys what you've drawn. See a similar requirement in this thread though the solution I suggested used a transparent window so th elines looked like they were on the desktop. If you forced the window to stay uder all others then it would not be possible to see that it was not on the DeskTop.

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

To use this example.

The line will start where the left mouse button is first held down and will end where the button is released;.

Middle mouse button or Ctrl key to clear all lines; and,

Esc key to exit.

;
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

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, 6)

    $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)
                _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
                _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
;
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...