name22

GDI+ Desktop Drawing

Jun 29th, 2011
875
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GDIPlus.au3>
  2. #include <GUIConstants.au3>
  3. #include <WindowsConstants.au3>
  4. #include <WinAPI.au3>
  5. #include <Misc.au3>
  6. #include <Constants.au3>
  7.  
  8. ; - Author: name22 (www.autoit.de)
  9.  
  10. Opt("GUIOnEventMode", 1)
  11.  
  12. HotKeySet("{ESC}", "_Exit")
  13.  
  14. $vU32DLL = DllOpen("User32.dll")
  15.  
  16. $iGUIColorBG = 0xFFFFFFFF
  17. $iGUIWidth = @DesktopWidth
  18. $iGUIHeight = @DesktopHeight
  19.  
  20. $hWnd = GUICreate("Test", $iGUIWidth, $iGUIHeight, 0, 0, BitOR(0x80000000, 0x08000000), BitOR(0x00080000, 0x00000008, 0x00000080))
  21. GUISetState()
  22.  
  23. _GDIPlus_Startup()
  24.  
  25. $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
  26. $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphic)
  27. $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
  28. _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
  29.  
  30. $hPen = _GDIPlus_PenCreate(0xFF000000, 2)
  31.  
  32. $hDC = _WinAPI_GetDC($hWnd)
  33. $hCDC = _WinAPI_CreateCompatibleDC($hDC)
  34.  
  35. $tSize = DllStructCreate($tagSIZE)
  36. $pSize = DllStructGetPtr($tSize)
  37. DllStructSetData($tSize, "X", $iGUIWidth)
  38. DllStructSetData($tSize, "Y", $iGUIHeight)
  39. $tSource = DllStructCreate($tagPOINT)
  40. $pSource = DllStructGetPtr($tSource)
  41. $tBlend = DllStructCreate($tagBLENDFUNCTION)
  42. $pBlend = DllStructGetPtr($tBlend)
  43. DllStructSetData($tBlend, "Alpha", 255)
  44. DllStructSetData($tBlend, "Format", 1)
  45. $tPoint = DllStructCreate($tagPOINT)
  46. $pPoint = DllStructGetPtr($tPoint)
  47. DllStructSetData($tPoint, "X", 0)
  48. DllStructSetData($tPoint, "Y", 0)
  49.  
  50. GUIRegisterMsg($WM_PAINT, "_ReDraw")
  51. $aMousePosOld = MouseGetPos()
  52.  
  53. While True
  54.     $aMousePosNew = MouseGetPos()
  55.     If _IsPressed("10", $vU32DLL) Then
  56.         If $aMousePosOld[0] <> $aMousePosNew[0] Or $aMousePosOld[1] <> $aMousePosNew[1] Then _GDIPlus_GraphicsDrawLine($hBuffer, $aMousePosOld[0], $aMousePosOld[1], $aMousePosNew[0], $aMousePosNew[1], $hPen)
  57.         _ReDraw()
  58.     EndIf
  59.     If BitOR(WinGetState($hWnd), 2) <> 2 Then _WinAPI_SetWindowPos($hWnd, $HWND_TOPMOST, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))
  60.     $aMousePosOld = $aMousePosNew
  61. WEnd
  62.  
  63. Func _ReDraw()
  64.     Local $hBitmapTmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
  65.     _WinAPI_SelectObject($hCDC, $hBitmapTmp)
  66.     _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hCDC, $pSource, 0, $pBlend, 2)
  67.     _WinAPI_DeleteObject($hBitmapTmp)
  68. EndFunc
  69.  
  70. Func _Exit()
  71.     _GDIPlus_GraphicsDispose($hGraphic)
  72.     _GDIPlus_GraphicsDispose($hBuffer)
  73.     _GDIPlus_BitmapDispose($hBitmap)
  74.     _GDIPlus_PenDispose($hPen)
  75.     _GDIPlus_Shutdown()
  76.     DllClose($vU32DLL)
  77.     Exit
  78. EndFunc
RAW Paste Data