Jump to content

Recommended Posts

Posted

Hi

According to the helpfile the 0 in the below line can be changed to an x,y coordinate.

_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)

Apparently the line looks like this:

Global Const $tagPOINT = "int X;int Y"

Can someone shed some light on how you can use this to move a png on the main gui. I've done a lot of playing, tried the MSDN webpage and helpfile but not a whole lot on this topic. Is this a red herring. Is there another way?

Picea

PS: Full function below for context

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", $AC_SRC_ALPHA)
    _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  ;==>SetBitmap
Posted

Hi

According to the helpfile the 0 in the below line can be changed to an x,y coordinate.

_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)

Apparently the line looks like this:

Global Const $tagPOINT = "int X;int Y"

Can someone shed some light on how you can use this to move a png on the main gui. I've done a lot of playing, tried the MSDN webpage and helpfile but not a whole lot on this topic. Is this a red herring. Is there another way?

Picea

$tagPOINT is an AutoIt constant defined in the include file, StructureConstants.au3.

$tagPOINT contains the string, "int X;int Y", representing the structure to be created using DllStructCreate ().

When the dll data structure is created

$tPoint = DllStructCreate($tagPOINT)

a pointer to that structure can be made

$pPoint = DllStructGetPtr($tPoint)

Data is set to the dll structure

DllStructSetData($tPoint, "X", $iX1)

DllStructSetData($tPoint, "Y", $iY1)

$iX1 and $iY1 are variables containing the X and Y integer values.

From the help file under WinAPI_UpdateLayeredWindow, the third parameter, $pPTDest, needs to be a pointer. So $pPoint is the pointer to be used as the third parameter.

This script uses the $pPTDest parameter for moving a layered window.

With each Do Until loop, the updated X, Y values are set to the $tagPOINT type dll data structure, which the pointer, $pPTDest, is pointing to. In the script $pPTDest is called $pPoint.

And, the layered window is updated with _WinAPI_UpdateLayeredWindow().

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

; Modifed script using Timer and WinMove, from
; http://www.autoitscript.com/forum/index.php?s=&showtopic=91482&view=findpost&p=658747

Global Const $iOpacity = 255
;Global Const $ULW_ALPHA         = 2
Global $hGui, $hGraphic, $blueBrush, $hImage2, $iPath
Global $dll = DllOpen("user32.dll")
Global $GuiSize = 100, $hWnd, $hDC, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
Global Const $WM_LBUTTONDOWN = 0x0201; Drag Window 1 of 3 addin
Global $t1, $iX1 = 100, $iY1 = 100, $tPoint, $pPoint, $Speed = 3, $iValX = $Speed, $iValY = $Speed

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

Main()

Func Main()
    Local $hBitmap, $Pinsel, $flg = True
    $hGui = GUICreate("L1", $GuiSize, $GuiSize, -1, -1, 0, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
    GUISetState()

    _GDIPlus_Startup()
    $hWnd = _WinAPI_GetDC(0)
    $hDC = _WinAPI_CreateCompatibleDC($hWnd)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $GuiSize, $GuiSize); $iWidth, $iHeight)
    _WinAPI_SelectObject($hDC, $hBitmap)
    $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC)
    ;$iPath =  "C:\file.png"
    ;$hImage2 = _GDIPlus_ImageLoadFromFile($iPath)
    $Pinsel = _GDIPlus_PenCreate(0xFF0000FF, 20)
    _GDIPlus_GraphicsDrawArc($hGraphic, 10, 10, $GuiSize - 20, $GuiSize - 20, 180, 360, $Pinsel)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $GuiSize);$iWidth )
    DllStructSetData($tSize, "Y", $GuiSize);$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
        _GDIPlus_GraphicsClear($hGraphic)
        _GDIPlus_GraphicsDrawArc($hGraphic, 10, 10, $GuiSize - 20, $GuiSize - 20, 180, 360, $Pinsel)

        If $iX1 >= @DesktopWidth - $GuiSize Then $iValX = -1 * $Speed
        If $iX1 < 1 Then $iValX = 1 * $Speed
        If $iY1 >= @DesktopHeight - 95 Then $iValY = -1 * $Speed
        If $iY1 < 1 Then $iValY = 1 * $Speed

        $iX1 += $iValX
        $iY1 += $iValY

        DllStructSetData($tPoint, "X", $iX1) ; Update point destination dll data structure X value.
        DllStructSetData($tPoint, "Y", $iY1) ; Update point destination dll data structure Y value.

        _WinAPI_UpdateLayeredWindow($hGui, $hWnd, $pPoint, $pSize, $hDC, $pSource, 0, $pBlend, $ULW_ALPHA)
        Sleep(10)
    Until _IsPressed("1B"); ESC key
    DllClose($dll)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_ReleaseDC(0, $hWnd)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hDC)
    _GDIPlus_Shutdown()
EndFunc   ;==>Main
Posted

Malkey this is excellent! I got my script working. Thank you very much for sharing this training piece. It's educational as well as entertaining......

Thanks again.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...