Jump to content

[SOLVED] MouseClicks thru the GUI


Recommended Posts

Hi,

I have one little(?) task to do - I am trying to allow mouse clicks thru my GUI. Here is an example of what i have tried:

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
;

Global $aOld_Mouse_Pos = MouseGetPos()
Global $iMoveWithCursor = True

HotKeySet("^+m", "_MoveWithCursorToggle_Proc")

$hGUI = GUICreate("Test GUI", 500, 300, -1, -1, _
    BitOR($WS_POPUP, $WS_SIZEBOX), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

WinSetTrans($hGUI, "", 100)
GUISetBkColor(0xFF0000, $hGUI)
GUISetCursor(0, 1, $hGUI)
GUISetIcon("Shell32.dll", -35, $hGUI)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_SECONDARYUP
            _MouseClickInBkWnd($hGUI, "Secondary")
        Case $GUI_EVENT_PRIMARYUP
            _MouseClickInBkWnd($hGUI, "Main")
    EndSwitch
    
    If $iMoveWithCursor Then
        $aMouse_Pos = MouseGetPos()
        
        If $aMouse_Pos[0] <> $aOld_Mouse_Pos[0] Or $aMouse_Pos[1] <> $aOld_Mouse_Pos[1] Then
            $aGUI_Pos = WinGetPos($hGUI)
            
            Local $i_Left, $i_Top
            
            If $aMouse_Pos[0] > $aOld_Mouse_Pos[0] Then
                $i_Left = $aGUI_Pos[0] + ($aMouse_Pos[0] - $aOld_Mouse_Pos[0])
            Else
                $i_Left = $aGUI_Pos[0] - ($aOld_Mouse_Pos[0] - $aMouse_Pos[0])
            EndIf
            
            If $aMouse_Pos[1] > $aOld_Mouse_Pos[1] Then
                $i_Top = $aGUI_Pos[1] + ($aMouse_Pos[1] - $aOld_Mouse_Pos[1])
            Else
                $i_Top = $aGUI_Pos[1] - ($aOld_Mouse_Pos[1] - $aMouse_Pos[1])
            EndIf
            
            WinMove($hGUI, "", $i_Left, $i_Top)
            
            $aOld_Mouse_Pos = $aMouse_Pos
        EndIf
    EndIf
WEnd

Func _MoveWithCursorToggle_Proc()
    $iMoveWithCursor = Not $iMoveWithCursor
    $aOld_Mouse_Pos = MouseGetPos()
EndFunc

Func _MouseClickInBkWnd($sTitle, $sButton="Main", $iClicks=2)
    Local $iOld_MCM = Opt("MouseCoordMode", 1)
    Local $aMouse_Pos = MouseGetPos()
    
    WinSetState($sTitle, "", @SW_HIDE)
    
    Local $hBkWnd = DllCall("user32.dll", "int", "WindowFromPoint", "long", $aMouse_Pos[0], "long", $aMouse_Pos[1])
    $hBkWnd = _WinAPI_GetAncestor($hBkWnd[0], $GA_ROOT)
    
    Opt("MouseCoordMode", $iOld_MCM)
    
    Local $stPoint = DllStructCreate("int X;int Y")
    
    DllStructSetData($stPoint, "X", $aMouse_Pos[0])
    DllStructSetData($stPoint, "Y", $aMouse_Pos[1])
    
    _WinAPI_ScreenToClient($hBkWnd, $stPoint)
    
    Local $iX = DllStructGetData($stPoint, "X")
    Local $iY = DllStructGetData($stPoint, "Y")
    
    $iX += 2
    $iY -= 26
    
    If $sButton <> "Main" Then ControlClick($hBkWnd, "", "", "Main", $iClicks, $iX, $iY)
    ControlClick($hBkWnd, "", "", $sButton, $iClicks, $iX, $iY)
    
    WinSetState($sTitle, "", @SW_SHOWNOACTIVATE)
EndFunc

As you can see, in this example the GUI is following after mouse pointer, «Ctrl + Shift + M» hotkeys toggles this behaviour. But when the pointer inside GUI, i want it act like if there was no GUI, all clicks (and even dragging the mouse) must go thru the GUI and work for background window. I tried to build a function (_MouseClickInBkWnd()) that will do it - the idea here is to hide my GUI, get the background handle by WindowFromPoint, translate Mouse coords to client window coords, click in that coords and show back my GUI. But as you can see we have here lot of problems (blinking window, not always the clicks are passed to the bk window and few more bugs).

Any ideas of how this *can be done(?*) better?

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

is this it ?

Yes! It's was so simple :D . Thank you. Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Ok, and what if i need be able to click thru the GUI, but in the same time have the ability to resize my GUI (when $WS_SIZEBOX is used)?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Ok, and what if i need be able to click thru the GUI, but in the same time have the ability to resize my GUI (when $WS_SIZEBOX is used)?

I assume you don't want to be able to click through the sizing border.

I would make a window with the styles WS_POPUP and WS_SIZEBOX. You could make that window transparent as well but it would still be possible to resize it. Then apply a mask to make the client area transparent. Fit the transparent window in place of the client area, and use WM_NCCALCSIZE to know when the size has changed to adjust the size and position of the transparent window. You would also need to register WM_MOVE so that the border can be kept with the 'client' area.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Child (MDI?) gui inside a normal GUI so you have an active frame?

Thanks for the idea, i don't know about MDI childs, but using GUIHole it's can be done (not perfect, but it's a start) :D

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;

HotKeySet("^+e", "_Exit_Proc")

$hGUI = GUICreate("Resizing Transparent GUI Example", 500, 300, -1, -1, _
    $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_TRANSPARENT))

$hFrame_GUI = GUICreate("Frame", 500, 300, -1, -1, _
    BitOR($WS_POPUP, $WS_SIZEBOX), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

_GUICreateHole($hFrame_GUI, 4, 4, 497, 297)
_GUISetOptions_Proc()

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hFrame_GUI)

WM_SIZE()

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GUISetOptions_Proc()
    Local $aHWnds[2] = [$hGUI, $hFrame_GUI]
    
    For $i = 0 To 1
        WinSetTrans($aHWnds[$i], "", 100)
        GUISetBkColor(0xFF0000, $aHWnds[$i])
        GUISetCursor(0, 1, $aHWnds[$i])
    Next
EndFunc

Func _GUICreateHole($hWin, $i_X, $i_Y, $i_SizeW, $i_SizeH)
    Local $aWinPos, $aOuter_Rgn, $aInner_Rgn, $aCombined_Rgn
    
    Local Const $RGN_AND = 1
    Local Const $RGN_OR = 2
    Local Const $RGN_XOR = 3
    Local Const $RGN_DIFF = 4
    Local Const $RGN_COPY = 5
    
    $aWinPos = WinGetPos($hWin)
    
    $aOuter_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", $aWinPos[2], "long", $aWinPos[3])
    $aInner_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", _
        $i_X, "long", $i_Y, "long", $i_X + $i_SizeW, "long", $i_Y + $i_SizeH)
    
    $aCombined_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
    
    DllCall("gdi32.dll", "long", "CombineRgn", _
        "long", $aCombined_rgn[0], "long", $aOuter_Rgn[0], "long", $aInner_Rgn[0], "int", $RGN_DIFF)
    
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWin, "long", $aCombined_Rgn[0], "int", 1)
EndFunc

Func WM_SIZE($hWnd=0, $MsgID=0, $wParam=0, $lParam=0)
    Local $aGUI_Pos = WinGetPos($hGUI)
    Local $aFrameGUI_Pos = WinGetPos($hFrame_GUI)
    
    GUIRegisterMsg($WM_SIZE, "")
    
    If $hWnd = $hGUI Then
        WinMove($hFrame_GUI, "", $aGUI_Pos[0], $aGUI_Pos[1], $aGUI_Pos[2], $aGUI_Pos[3])
    Else
        WinMove($hGUI, "", $aFrameGUI_Pos[0], $aFrameGUI_Pos[1], $aFrameGUI_Pos[2], $aFrameGUI_Pos[3])
    EndIf
    
    If IsHWnd($hWnd) Then _GUICreateHole($hFrame_GUI, 4, 4, $aGUI_Pos[2]-10, $aGUI_Pos[3]-10)
    
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
EndFunc

Func _Exit_Proc()
    Exit
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

This is with an MDI child. I think it's really close (except the window frame changes after the create hole function).

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;

HotKeySet("^+e", "_Exit_Proc")



$hFrame_GUI = GUICreate("Frame", 500, 300, -1, -1, _
    BitOR($WS_POPUP, $WS_SIZEBOX), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

$hGUI = GUICreate("Resizing Transparent GUI Example", 500, 300, 4, 4, _
    $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW, $WS_EX_TRANSPARENT), $hFrame_GUI)

_GUICreateHole($hFrame_GUI, 4, 4, 497, 297)
_GUISetOptions_Proc()

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hFrame_GUI)

WM_SIZE($hFrame_GUI)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GUISetOptions_Proc()
    Local $aHWnds[2] = [$hGUI, $hFrame_GUI]

    For $i = 0 To 1
        WinSetTrans($aHWnds[$i], "", 100)
        GUISetBkColor(0xFF0000, $aHWnds[$i])
        GUISetCursor(0, 1, $aHWnds[$i])
    Next
EndFunc

Func _GUICreateHole($hWin, $i_X, $i_Y, $i_SizeW, $i_SizeH)
    Local $aWinPos, $aOuter_Rgn, $aInner_Rgn, $aCombined_Rgn

    Local Const $RGN_AND = 1
    Local Const $RGN_OR = 2
    Local Const $RGN_XOR = 3
    Local Const $RGN_DIFF = 4
    Local Const $RGN_COPY = 5

    $aWinPos = WinGetPos($hWin)

    $aOuter_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", $aWinPos[2], "long", $aWinPos[3])
    $aInner_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", _
        $i_X, "long", $i_Y, "long", $i_X + $i_SizeW, "long", $i_Y + $i_SizeH)

    $aCombined_Rgn = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)

    DllCall("gdi32.dll", "long", "CombineRgn", _
        "long", $aCombined_rgn[0], "long", $aOuter_Rgn[0], "long", $aInner_Rgn[0], "int", $RGN_DIFF)

    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWin, "long", $aCombined_Rgn[0], "int", 1)
EndFunc

Func WM_SIZE($hWnd=0, $MsgID=0, $wParam=0, $lParam=0)
    Switch $hWnd
        Case $hFrame_GUI
            Local $aFrameGUI_Pos = WinGetPos($hFrame_GUI)
            _GUICreateHole($hFrame_GUI, 4, 4, $aFrameGUI_Pos[2]-8, $aFrameGUI_Pos[3]-8)
            WinMove($hGUI, "", $aFrameGUI_Pos[0] + 4, $aFrameGUI_Pos[1] + 4, $aFrameGUI_Pos[2] - 8, $aFrameGUI_Pos[3] - 8)
    EndSwitch
EndFunc

Func _Exit_Proc()
    Exit
EndFunc
Edited by wraithdu
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...