Jump to content

Coordinate Variable update needed


Drifter
 Share

Recommended Posts

I was wondering if anyone could help me with a script i am trying to write in AutoItv3. It involves moving a GUI with WM_NCHITTEST. My script is here:

http://pastebin.com/m8c4afe7

Basically the script works and all, but i need it to update the variables $x and $y when the user drags the window. any ideas? Thank you for your time!

Link to comment
Share on other sites

Hi, you could use another register msg for a WM_MOVE and use WinGetPos to fill the X, Y, W, H variables

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

Opt("MustDeclareVars", 1)

; Global constants
Global Const $AC_SRC_ALPHA = 1


; Global variables
Global $hGUI1, $alpha, $x1, $y1, $w1, $h1, $x2, $y2, $w2, $h2, $WGP

$alpha = 250

$x1 = 300
$y1 = 300
$w1 = 200
$h1 = 500

$x2 = 300
$y2 = 300
$w2 = 200
$h2 = 500

; Create layered child window
$hGUI1 = GUICreate("Box 1", $w1, $h1, $x1, $y1, -1, $WS_EX_LAYERED)
ShowBoxes()

Func ShowBoxes()

    Local $hImage1

    ; Load layered image
    _GDIPlus_Startup()
    $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Torus.png")
    SetBitMap($hGUI1, $hImage1, $alpha)
    GUISetState()

    ; Register notification messages
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUIRegisterMsg($WM_MOVE, "WM_MOVE")

    ; Let user move image, report its new position.

    While GUIGetMsg() <> -3 ; Esc to exit loop
        Sleep(10)
        ToolTip("x =" & $x1 & " and y = " & $y1, $x1 , $y1)
    WEnd
    ; Release resources
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_Shutdown()

EndFunc


Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam)
    if ($hWnd = $hGUI1) then
        $WGP = WinGetPos($hWnd)
        $x1 = $WGP[0]
        $y1 = $WGP[1]
        $w1 = $WGP[2]
        $h1 = $WGP[3]
    EndIf
EndFunc

; ===============================================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $hGUI1) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
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

Cheers

Edited by smashly
Link to comment
Share on other sites

Okay your system works, but now im trying to have multiple different boxes (just 2) that you can drag around.... so far its not working lol, one last bit of help please? >_<

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

Opt("MustDeclareVars", 1)

; Global constants
Global Const $AC_SRC_ALPHA = 1


; Global variables
Global $hGUI1, $hGUI2, $alpha, $x1, $y1, $w1, $h1, $x2, $y2, $w2, $h2, $WGP

$alpha = 250

$x1 = 300
$y1 = 300
$w1 = 200
$h1 = 500

$x2 = 400
$y2 = 300
$w2 = 200
$h2 = 500

; Create layered child window
$hGUI1 = GUICreate("Box 1", $w1, $h1, $x1, $y1, -1, $WS_EX_LAYERED)
$hGUI2 = GUICreate("Box 2", $w2, $h2, $x2, $y2, -1, $WS_EX_LAYERED)
ShowBoxes(1)

Func ShowBoxes($ImageIDENT)
    
    Local $hImage1
    
    ; Load layered image
    _GDIPlus_Startup()
    $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Torus.png")
    
    If $ImageIDENT == 1 Then
        SetBitMap($hGUI1, $hImage1, $alpha)
    ElseIf $ImageIDENT == 2 Then
        SetBitMap($hGUI2, $hImage1, $alpha)
    EndIf
    
    GUISetState()
    
    ; Register notification messages
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUIRegisterMsg($WM_MOVE, "WM_MOVE")

    
    ; Loop until user exits
    Sleep(3000)
    ToolTip("x =" & $x1 & " and y = " & $y1,200,200)
    Sleep(3000)
    ; Release resources
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_Shutdown()
    
EndFunc

Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam)
    if ($hWnd = $hGUI1) then
        $WGP = WinGetPos($hWnd)
        $x1 = $WGP[0]
        $y1 = $WGP[1]
        $w1 = $WGP[2]
        $h1 = $WGP[3]
    ElseIf ($hWnd = $hGUI2) Then
        WGP = WinGetPos($hWnd)
        $x2 = $WGP[0]
        $y2 = $WGP[1]
        $w2 = $WGP[2]
        $h2 = $WGP[3]
    EndIf
    
EndFunc



; ===============================================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
  if ($hWnd = $hGUI1) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
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
Edited by Drifter
Link to comment
Share on other sites

So if i understand correctly, we still need WM_NCHITTEST to allow the user to move the window, but WM_MOVE allows the capture of the XY coords, correct?

Yep that's correct.

You can use a transparent label with the extended style $GUI_WS_EX_PARENTDRAG on the gui to allow moving the gui instead..

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

Opt("MustDeclareVars", 1)

; Global constants
Global Const $AC_SRC_ALPHA = 1


; Global variables
Global $hGUI1, $alpha, $x1, $y1, $w1, $h1, $x2, $y2, $w2, $h2, $WGP

$alpha = 250

$x1 = 300
$y1 = 300
$w1 = 200
$h1 = 500

$x2 = 300
$y2 = 300
$w2 = 200
$h2 = 500

; Create layered child window
$hGUI1 = GUICreate("Box 1", $w1, $h1, $x1, $y1, -1, $WS_EX_LAYERED)
GUICtrlCreateLabel("", 0, 0, $w1, $h1, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
ShowBoxes()

Func ShowBoxes()

    Local $hImage1

    ; Load layered image
    _GDIPlus_Startup()
    $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Images\Torus.png")
    SetBitMap($hGUI1, $hImage1, $alpha)
    GUISetState()

    ; Register notification messages
    GUIRegisterMsg($WM_MOVE, "WM_MOVE")

    ; Let user move image, report its new position.

    While GUIGetMsg() <> -3 ; Esc to exit loop
        Sleep(10)
        ToolTip("x =" & $x1 & " and y = " & $y1, $x1, $y1)
    WEnd
    ; Release resources
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_Shutdown()

EndFunc   ;==>ShowBoxes


Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI1) Then
        $WGP = WinGetPos($hWnd)
        $x1 = $WGP[0]
        $y1 = $WGP[1]
        $w1 = $WGP[2]
        $h1 = $WGP[3]
    EndIf
EndFunc   ;==>WM_MOVE

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
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
Link to comment
Share on other sites

Im inclined to use the first way that works as long as theres nothing i can gain from the other method. I looked into commenting things out, and it seems if i comment out:

$hGUI2 = GUICreate("Box 2", $w2, $h2, $x2, $y2, -1, $WS_EX_LAYERED)

From my code it works, so there must be something about having multiple GUIs? Maybe i can have one be the parent or something? Its best to have them both show and be draggable at once, but i can do the "ShowBoxes(1)" method too.

(please note: my earlier post was edited)

Edited by Drifter
Link to comment
Share on other sites

Im inclined to use the first way that works as long as theres nothing i can gain from the other method. I looked into commenting things out, and it seems if i comment out:

$hGUI2 = GUICreate("Box 2", $w2, $h2, $x2, $y2, -1, $WS_EX_LAYERED)

From my code it works, so there must be something about having multiple GUIs? Maybe i can have one be the parent or something? Its best to have them both show and be draggable at once, but i can do the "ShowBoxes(1)" method too.

(please note: my earlier post was edited)

Hi again,

Check your code, slow down and take a deep breath and look at your code again..

Did you use GUISetState(@SW_SHOW, $hGUI1) or GUISetState(@SW_SHOW, $hGUI2) in that prior code you posted?

In the WM_MOVE you left a $ off the $WGP variable..

When showing your tooltip are you rembering to show the correct $x1, $y1 or $x2, $y2 values?

In your WM_NCHITTEST did you allow for $hGUI2?

Edited by smashly
Link to comment
Share on other sites

haha, right, fixed and works! thanks alot for your help! >_<

Good to hear and your welcome :(

Here's what I was going to post if you still had probs, I'll still post it anyway..lol

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

Opt("MustDeclareVars", 1)


; Global variables
Global $hGUI1, $hGUI2, $alpha, $x1, $y1, $w1, $h1, $x2, $y2, $w2, $h2

$alpha = 250

$x1 = 300
$y1 = 300
$w1 = 200
$h1 = 500

$x2 = 400
$y2 = 300
$w2 = 200
$h2 = 500

; Create layered child windows
$hGUI1 = GUICreate("Box 1", $w1, $h1, $x1, $y1, $WS_POPUP, $WS_EX_LAYERED)
$hGUI2 = GUICreate("Box 2", $w2, $h2, $x2, $y2, $WS_POPUP, $WS_EX_LAYERED)

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_MOVE, "WM_MOVE")

ShowBoxes($hGUI1, @ScriptDir & "\Untitled.png", $alpha)
ShowBoxes($hGUI2, @ScriptDir & "\Untitled.png", $alpha)


While GUIGetMsg() <> -3 And GUIGetMsg(1) <> -3 ; Esc to exit loop
    Sleep(50)
    If BitAND(WinGetState($hGUI1), 8) Then
        ToolTip("x1 =" & $x1 & " and y1 = " & $y1, $x1, $y1)
    ElseIf BitAND(WinGetState($hGUI2), 8) Then
        ToolTip("x2 =" & $x2 & " and y2 = " & $y2, $x2, $y2)
    EndIf
WEnd


Func ShowBoxes($hWnd, $sImagePath, $iAlpha = 255)
    Local $hImage1

    ; Load layered image
    _GDIPlus_Startup()
    $hImage1 = _GDIPlus_ImageLoadFromFile($sImagePath)
    SetBitMap($hWnd, $hImage1, $iAlpha)
    GUISetState(@SW_SHOW, $hWnd)

    ; Release resources
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_Shutdown()
EndFunc   ;==>ShowBoxes

Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam)
    Local $WGP = WinGetPos($hWnd)
    Switch $hWnd
        Case $hGUI1
            $x1 = $WGP[0]
            $y1 = $WGP[1]
            $w1 = $WGP[2]
            $h1 = $WGP[3]
        Case $hGUI2
            $x2 = $WGP[0]
            $y2 = $WGP[1]
            $w2 = $WGP[2]
            $h2 = $WGP[3]
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOVE

; ===============================================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI1) Or ($hWnd = $hGUI2) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
Func SetBitmap($hGUI, $hImage, $iOpacity)
    Local Const $AC_SRC_ALPHA = 1
    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

Cheers

Link to comment
Share on other sites

we did it differently than eachother but mine still works rofl. Question though.... i now put the code in its final context with image w,h set to 30. the images are still big. why is this? shouldnt it shrink? if you want the code context i will provide.

Link to comment
Share on other sites

we did it differently than eachother but mine still works rofl. Question though.... i now put the code in its final context with image w,h set to 30. the images are still big. why is this? shouldnt it shrink? if you want the code context i will provide.

You'll need to scale the images to the size you want before calling the SetBitmap() function.

It's pretty easy to do with GDIPlus (once you know how).

It's more a question how you want the image scaled..

If you hard set the GUI size and you display an image thats bigger or smaller then the GUI how do you want the image scaled...

eg:

If the image is bigger then the Gui then Keep the Aspect Ratio of the image and make it fit inside the GUI area?

If the image is bigger then the Gui Don't worry about the Aspect Ratio of the image, just make it fill(stretch/shrink) to the whole GUI size?

If the image is bigger then the Gui then Keep the Aspect Ratio and Size just show part of the image in the GUI?

If the image is smaller then the Gui then Keep the Aspect Ratio of the image and make it fit inside the GUI area?

If the image is smaller then the Gui Don't worry about the Aspect Ratio of the image, just make it fill to the whole GUI size?

If the image is smaller then the Gui Keep the Aspect Ratio and Image Size

Edited by smashly
Link to comment
Share on other sites

Okay basically i want it like ms paints "stretch/shrink". Show the whole image fitting the area given exactly. I dont want aspect ratio fixed.

$hGUI1 = GUICreate("Box 1", $wide, $tall, $x1, $y1, -1, $WS_EX_LAYERED)

should give me a small picture if $wide = 30 and $tall = 30 for instance. i thought that was automatic to be honest.

Link to comment
Share on other sites

Okay basically i want it like ms paints "stretch/shrink". Show the whole image fitting the area given exactly. I dont want aspect ratio fixed.

$hGUI1 = GUICreate("Box 1", $wide, $tall, $x1, $y1, -1, $WS_EX_LAYERED)

should give me a small picture if $wide = 30 and $tall = 30 for instance. i thought that was automatic to be honest.

Hi,

Nope it's not automatich, but try this

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

Opt("MustDeclareVars", 1)


; Global variables
Global $hGUI1, $hGUI2, $alpha, $x1, $y1, $w1, $h1, $x2, $y2, $w2, $h2

$alpha = 250

$x1 = 300
$y1 = 300
$w1 = 30
$h1 = 30

$x2 = 400
$y2 = 300
$w2 = 100
$h2 = 200

; Create layered child windows
$hGUI1 = GUICreate("Box 1", $w1, $h1, $x1, $y1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_TOPMOST))
$hGUI2 = GUICreate("Box 2", $w2, $h2, $x2, $y2, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_TOPMOST))

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg($WM_MOVE, "WM_MOVE")

ShowBoxes($hGUI1, @ScriptDir & "\Images\Torus.png", $w1, $h1, $alpha)
ShowBoxes($hGUI2, @ScriptDir & "\Images\Torus.png", $w2, $h2, $alpha)


While GUIGetMsg() <> -3 And GUIGetMsg(1) <> -3 ; Esc to exit loop
    Sleep(50)
    If BitAND(WinGetState($hGUI1), 8) Then
        ToolTip("x1 =" & $x1 & " and y1 = " & $y1, $x1 + $w1, $y1)
    ElseIf BitAND(WinGetState($hGUI2), 8) Then
        ToolTip("x2 =" & $x2 & " and y2 = " & $y2, $x2 + $w2, $y2)
    EndIf
WEnd




Func ShowBoxes($hWnd, $sImagePath, $iW, $iH, $iAlpha = 255)
    Local $hImage, $aResult

    ; Load layered image
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($sImagePath)
    ; Get a Thumbnail of the image
    $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageThumbnail", "hwnd", $hImage, "int", $iW, "int", $iH, "int*", 0, "ptr", 0, "ptr", 0)
    SetBitMap($hWnd, $aResult[4], $iAlpha)
    GUISetState(@SW_SHOW, $hWnd)

    ; Release resources
    _GDIPlus_ImageDispose($aResult[4])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
EndFunc   ;==>ShowBoxes

Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam)
    Local $WGP = WinGetPos($hWnd)
    Switch $hWnd
        Case $hGUI1
            $x1 = $WGP[0]
            $y1 = $WGP[1]
            $w1 = $WGP[2]
            $h1 = $WGP[3]
        Case $hGUI2
            $x2 = $WGP[0]
            $y2 = $WGP[1]
            $w2 = $WGP[2]
            $h2 = $WGP[3]
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOVE

; ===============================================================================================================================
; Handle the WM_NCHITTEST for the layered window so it can be dragged by clicking anywhere on the image.
; ===============================================================================================================================
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $hGUI1) Or ($hWnd = $hGUI2) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

; ===============================================================================================================================
; SetBitMap
; ===============================================================================================================================
Func SetBitmap($hGUI, $hImage, $iOpacity)
    Local Const $AC_SRC_ALPHA = 1
    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

Can do keep aspect ratio as well if you like?

Cheers

Edited by smashly
Link to comment
Share on other sites

okay so im going to point out the change i see since our scripts are so different now lol....

$hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Torus.png")
    
SetBitMap($hGUI1, $hImage1, $alpha)
SetBitMap($hGUI2, $hImage1, $alpha)

is replaced by:

$aResult = DllCall($ghGDIPDll, "int", "GdipGetImageThumbnail", "hwnd", $hImage, "int", $iW, "int", $iH, "int*", 0, "ptr", 0, "ptr", 0)
SetBitMap($hGUI1, $aResult[4], $iAlpha)
SetBitMap($hGUI2, $aResult[4], $iAlpha)

(note that i still use my old $hGUI codes):

$hGUI1 = GUICreate("Box 1", $wide, $tall, $x1, $y1, -1, $WS_EX_LAYERED)
$hGUI2 = GUICreate("Box 2", $wide, $tall, $x2, $y2, -1, $WS_EX_LAYERED)

Am i correct?

Link to comment
Share on other sites

okay so im going to point out the change i see since our scripts are so different now lol....

$hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Torus.png")
    
SetBitMap($hGUI1, $hImage1, $alpha)
SetBitMap($hGUI2, $hImage1, $alpha)

is replaced by:

$aResult = DllCall($ghGDIPDll, "int", "GdipGetImageThumbnail", "hwnd", $hImage, "int", $iW, "int", $iH, "int*", 0, "ptr", 0, "ptr", 0)
SetBitMap($hGUI1, $aResult[4], $iAlpha)
SetBitMap($hGUI2, $aResult[4], $iAlpha)

(note that i still use my old $hGUI codes):

$hGUI1 = GUICreate("Box 1", $wide, $tall, $x1, $y1, -1, $WS_EX_LAYERED)
$hGUI2 = GUICreate("Box 2", $wide, $tall, $x2, $y2, -1, $WS_EX_LAYERED)

Am i correct?

Hand the $hImage1 and $wide and $tall to the dllcall

$aResult = DllCall($ghGDIPDll, "int", "GdipGetImageThumbnail", "hwnd", $hImage1, "int", $wide, "int", $tall, "int*", 0, "ptr", 0, "ptr", 0)
$aResult[4] is the handle to the new image at the size you want

Don't forget the free the resource when finished with it >_<

_GDIPlus_ImageDispose($aResult[4])
Edited by smashly
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...