[..] Déplacer un GUI sur une fenêtre Windows pour récupérer son Handle
Posté : ven. 30 nov. 2018 13:39
Coucou
Comme le titre l'indique, je souhaiterais déplacer une GUI (interface minimaliste avec image avec fond transparent) sur une fenpetre windows, afin de récupérer son handle...
Comme le fait au3info (^^) mais en plus simple.
J'ai donc crée mon interface, avec une image avec fond transparent PNG...
Je me suis aidée de ce topic d'ailleurs : https://www.autoitscript.com/forum/topi ... nt-1311891
EN résumé, j'ai récupéré un "curseur", que j'ai mis dans l'interface.
Et je souhaite donc déplacer cette interface (donc le "curseur") sur la dite fenêtre...
Bien entendu, comme à mon habitude, la fin coince
Comment faire pour qu'il capte la bonne fenêtre ?
Voici le code :
Oui, le mouseclik est erroné, mais c'est surement une piste ^^
Disons que, si j'arrive à rendre la fenêtre "active", je pourrais aisément récupérer son handle.
++ et merci d'avance pour vos réponses.
Comme le titre l'indique, je souhaiterais déplacer une GUI (interface minimaliste avec image avec fond transparent) sur une fenpetre windows, afin de récupérer son handle...
Comme le fait au3info (^^) mais en plus simple.
J'ai donc crée mon interface, avec une image avec fond transparent PNG...
Je me suis aidée de ce topic d'ailleurs : https://www.autoitscript.com/forum/topi ... nt-1311891
EN résumé, j'ai récupéré un "curseur", que j'ai mis dans l'interface.
Et je souhaite donc déplacer cette interface (donc le "curseur") sur la dite fenêtre...
Bien entendu, comme à mon habitude, la fin coince
Comment faire pour qu'il capte la bonne fenêtre ?
Voici le code :
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI
$hImage = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\viseur\viseur (14).png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Global $hGUI = GUICreate("Form1", 32,32, 192, 124, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOPMOST)
GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
GUISetState(@SW_SHOW)
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
Local $tDim = DllStructCreate($tagBITMAP)
If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
$tSize.X = $tDim.bmWidth
$tSize.Y = $tDim.bmHeight
$tBlend.Alpha = $iOpacity
$tBlend.Format = 1
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteDC($hMemDC)
If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
Return True
EndFunc
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
_SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc ;==>_WM_LBUTTONDOWN
Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
Local $iX = BitAND($ilParam, 0xFFFF), $iY = BitShift($ilParam, 16)
;~ $fDblClk = True
ConsoleWrite("!Double click on: [" & $iX & "," & $iY & "]" & @CRLF)
MouseClick("left")
Return $GUI_RUNDEFMSG
EndFunc
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
_GDIPlus_Startup()
Global Const $SC_DRAGMOVE = 0xF012
Global $iW, $iH, $hImage, $hBitmap, $hGUI
$hImage = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\viseur\viseur (14).png")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
Global $hGUI = GUICreate("Form1", 32,32, 192, 124, $WS_POPUP, $WS_EX_LAYERED+$WS_EX_TOPMOST)
GUIRegisterMsg($WM_LBUTTONDBLCLK, "_WM_LBUTTONDBLCLK")
GUISetState(@SW_SHOW)
_WinAPI_BitmapDisplayTransparentInGUI($hBitmap, $hGUI)
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True)
If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0)
Local $tDim = DllStructCreate($tagBITMAP)
If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0)
Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION)
Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap)
$tSize.X = $tDim.bmWidth
$tSize.Y = $tDim.bmHeight
$tBlend.Alpha = $iOpacity
$tBlend.Format = 1
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteDC($hMemDC)
If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap)
Return True
EndFunc
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
_SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
EndFunc ;==>_WM_LBUTTONDOWN
Func _WM_LBUTTONDBLCLK($hWnd, $iMsg, $iwParam, $ilParam)
Local $iX = BitAND($ilParam, 0xFFFF), $iY = BitShift($ilParam, 16)
;~ $fDblClk = True
ConsoleWrite("!Double click on: [" & $iX & "," & $iY & "]" & @CRLF)
MouseClick("left")
Return $GUI_RUNDEFMSG
EndFunc
Disons que, si j'arrive à rendre la fenêtre "active", je pourrais aisément récupérer son handle.
++ et merci d'avance pour vos réponses.