Sign in to follow this  
Followers 0
GAM

Graphics

2 posts in this topic

Hi,

I would like to move a dot on the GUI in accordance with the x and y coordinates. Its something like am trying draw continous graph.

Can someone help please.

Thanks

GAM


Neil

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
_GDIPlus_Startup()
HotKeySet('{ESC}', '_Close')

If Not IsDeclared('WM_LBUTTONDOWN') Then Global Const $WM_LBUTTONDOWN = 0x0201
If Not IsDeclared('WM_RBUTTONDOWN') Then Global Const $WM_RBUTTONDOWN = 0x0204
If Not IsDeclared('WM_RBUTTONUP')   Then Global Const $WM_RBUTTONUP   = 0x0205

Global Const $tagMSLLHOOKSTRUCT = _
    $tagPOINT & ';' & _
    'dword mouseData;' & _
    'dword flags;' & _
    'dword time;' & _
    'ulong_ptr dwExtraInfo;'

Global $hFunc, $pFunc
Global $hHook
Global $hGUI
Global $hGraphics, $hBitmap, $hContext, $hBrushYellow

$hGUI = GUICreate('', 50, 50, MouseGetPos(0)-25, MouseGetPos(1)-25, $WS_POPUP, BitOR($WS_EX_TRANSPARENT, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(50, 50, $hGraphics)
$hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hBrushYellow = _GDIPlus_BrushCreateSolid(0x7FFFFF00)
$hBrushRed = _GDIPlus_BrushCreateSolid(0x9FFF0000)
_GDIPlus_GraphicsFillEllipse($hContext, 0, 0, 50, 50, $hBrushYellow)

GUISetState()
SetBitmap($hGUI, $hBitmap, 230)

$hFunc = DllCallbackRegister('_MouseHookProc', 'lresult', 'int;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, _WinAPI_GetModuleHandle(0))

While 1
    Sleep(20)
WEnd


Func _MouseHookProc($iCode, $iwParam, $ilParam)
    Local $tMSLLHS = DllStructCreate($tagMSLLHOOKSTRUCT, $ilParam)
    
    If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
    
    Switch $iwParam
        Case $WM_MOUSEMOVE
            WinMove($hGUI, '', DllStructGetData($tMSLLHS, 1)-25, DllStructGetData($tMSLLHS, 2)-25)
        Case $WM_LBUTTONDOWN, $WM_RBUTTONDOWN
            _GDIPlus_GraphicsClear($hContext, 0)
            _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, 50, 50, $hBrushRed)
            SetBitmap($hGUI, $hBitmap, 230)
        Case $WM_LBUTTONUP, $WM_RBUTTONUP
            _GDIPlus_GraphicsClear($hContext, 0)
            _GDIPlus_GraphicsFillEllipse($hContext, 0, 0, 50, 50, $hBrushYellow)
            SetBitmap($hGUI, $hBitmap, 230)
    EndSwitch
    
    Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc

Func _Close()
    Exit
EndFunc

Func OnAutoItExit()
    GUIDelete()
    _GDIPlus_BrushDispose($hBrushRed)
    _GDIPlus_BrushDispose($hBrushYellow)
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    DllCallbackFree($hFunc)
EndFunc

Func SetBitmap($hGUI, $hImage, $iOpacity)
  Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

  $hScrDC  = _WinAPI_GetDC(0)
  $hMemDC  = _WinAPI_CreateCompatibleDC($hScrDC)
  $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
  $hOld    = _WinAPI_SelectObject($hMemDC, $hBitmap)
  $tSize   = DllStructCreate($tagSIZE)
  $pSize   = DllStructGetPtr($tSize  )
  DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
  DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
  $tSource = DllStructCreate($tagPOINT)
  $pSource = DllStructGetPtr($tSource)
  $tBlend  = DllStructCreate($tagBLENDFUNCTION)
  $pBlend  = DllStructGetPtr($tBlend)
  DllStructSetData($tBlend, "Alpha" , $iOpacity)
  DllStructSetData($tBlend, "Format", 1)
  _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
  _WinAPI_ReleaseDC   (0, $hScrDC)
  _WinAPI_SelectObject($hMemDC, $hOld)
  _WinAPI_DeleteObject($hBitmap)
  _WinAPI_DeleteDC    ($hMemDC)
EndFunc

Edited by Authenticity

Share this post


Link to post
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
Sign in to follow this  
Followers 0