Jump to content

[solved] flash child on parent click


Recommended Posts

$Gui = GuiCreate("Test", 500, 150)
GUISetState()

; so I disable the gui
GUISetState(@SW_DISABLE)

; the msgbox is to fake a child gui
MsgBox(0,"Clicking parent title flash msgbox","clicking parent client area does not fash msgbox",60,$Gui)

; re-enable the gui
GUISetState(@SW_ENABLE)

While 1
    Switch GUIGetMsg()
        Case -3
            GUIDelete()
            Exit
    EndSwitch
WEnd

I'd like to have the child form flash, as it does, when the title of the parent is clicked, but when I click any part of it and not just the title.
I don't know how to do it.

Thanks

Edited by argumentum
Solved

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Look likes it could be working using this :

#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Global Const $tagMSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
OnAutoItExitRegister("Cleanup")

_Main()

Func _Main()

  Global $g_hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
  Local $hMod = _WinAPI_GetModuleHandle(0)
  Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_MouseProc), $hMod)

  Global $Gui = GUICreate("Test", 500, 150)
  Global $Label = GUICtrlCreateLabel ("", 0, 0, 500, 150)
  GUISetState()

  GUISetState(@SW_DISABLE)

  MsgBox(0, "Clicking parent title flash msgbox", "clicking parent client area does not fash msgbox", 60, $Gui)

  GUISetState(@SW_ENABLE)

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

EndFunc   ;==>_Main


Func _MouseProc($nCode, $wParam, $lParam)
  Local $xevent

  If $nCode < 0 Then
    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
  EndIf

  Local $tMouseHOOKS = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)

  Local $ptx = DllStructGetData($tMouseHOOKS, "X")
  Local $pty = DllStructGetData($tMouseHOOKS, "Y")
  Local $mouseData = DllStructGetData($tMouseHOOKS, "mousedata")
  Local $flags = DllStructGetData($tMouseHOOKS, "flags")

  Select
    Case $wParam = $WM_LBUTTONDOWN
      ; return 1 ; (will block)
      $xevent = "Left Down"
    Case $wParam = $WM_LBUTTONUP
      $xevent = "Left Up"
      ConsoleWrite($xevent & " = " & $ptx & "/" & $pty & @CRLF)
      If WinExists ("Clicking") Then
        If GUIGetCursorInfo ($Gui)[4] then _WinAPI_FlashWindowEX (WinGetHandle ("Clicking"),3,3,100)
      EndIf
  EndSelect

  Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)

EndFunc   ;==>_MouseProc

; ===========================================================

Func Cleanup()
  GUIDelete()
  _WinAPI_UnhookWindowsHookEx($g_hHook)
  DllCallbackFree($g_hStub_MouseProc)
EndFunc   ;==>Cleanup

Needs some cleaning, but you will get the idea...lmk how it goes

Edited by Nine
Link to comment
Share on other sites

8 hours ago, Nine said:

lmk how it goes

#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Global Const $tagMSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
OnAutoItExitRegister("Cleanup")

Global $_If_DISABLED = 0 ; useless idea of mine, but, gotta try something :)
Global $g_hStub_MouseProc, $hMod, $g_hHook
Global $Gui, $Label, $Button

_Main()

Func _Main()

    $g_hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    $hMod = _WinAPI_GetModuleHandle(0)
    $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_MouseProc), $hMod)

    $Gui = GUICreate("Test", 500, 150)
    $Label = GUICtrlCreateLabel("", 0, 0, 500, 150)
    GUICtrlSetState($Label, $GUI_HIDE)
    $Button = GUICtrlCreateButton("MsgBox", 30, 60, 120)
    GUICtrlCreateCheckbox("a Checkbox", 30, 30)
    GUISetState()

    Opt("GUIOnEventMode", 1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_FormClose")
    GUICtrlSetOnEvent($Button, "On_Button")

;~  On_Button() ; MsgBox(0, "Clicking parent title flash msgbox", "clicking parent client area does not fash msgbox", 60, $Gui)

    While 1
        Sleep(100)
    WEnd

EndFunc   ;==>_Main


Func _MouseProc($nCode, $wParam, $lParam)
    Local $xevent

    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf

    Local $tMouseHOOKS = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)

    Local $ptx = DllStructGetData($tMouseHOOKS, "X")
    Local $pty = DllStructGetData($tMouseHOOKS, "Y")
    Local $mouseData = DllStructGetData($tMouseHOOKS, "mousedata")
    Local $flags = DllStructGetData($tMouseHOOKS, "flags")

    If $_If_DISABLED Then
        Switch $wParam
            Case $WM_LBUTTONDOWN
                ; return 1 ; (will block)
                $xevent = "Left Down"
            Case $WM_LBUTTONUP, $WM_RBUTTONUP
                $xevent = "Left Up"
                ConsoleWrite($xevent & " = " & $ptx & "/" & $pty & @TAB & $nCode & @TAB & $wParam & @TAB & $lParam & @CRLF)
                If WinExists("Clicking") Then
                    If GUIGetCursorInfo($Gui)[4] Then _WinAPI_FlashWindowEx(WinGetHandle("Clicking"), 3, 7, 70)
                EndIf
        EndSwitch
    EndIf

    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)

EndFunc   ;==>_MouseProc

; ===========================================================

Func Cleanup()
    GUIDelete()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_MouseProc)
EndFunc   ;==>Cleanup

Func On_FormClose()
    Exit
EndFunc

Func On_Button()
    GUISetState(@SW_DISABLE)
    GUICtrlSetState($Label, $GUI_SHOW)
;~  GUICtrlSendMsg($Gui, 11, 0, 0);$WM_SETREDRAW
    $_If_DISABLED = 1
    MsgBox(0, "Clicking parent title flash msgbox", "clicking parent client area does not fash msgbox", 60, $Gui)
    $_If_DISABLED = 0
;~  GUICtrlSendMsg($Gui, 11, 1, 0);$WM_SETREDRAW
    GUICtrlSetState($Label, $GUI_HIDE)
    GUISetState(@SW_ENABLE)
EndFunc

..if you click anything, it flashes, anything. And when I close the MsgBox(), there is no response. Try the mod. above. Controls don't receive the clicking 😕 

Edit: hiding the $Label, solved the clicking non-responsive. Didn't see that :(

 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

Let me get a better version

#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <WinAPIError.au3>

Global Const $tagMSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
OnAutoItExitRegister("Cleanup")

_Main()

Func _Main()

  Global $g_hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
  Local $hMod = _WinAPI_GetModuleHandle(0)
  Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_MouseProc), $hMod)

  Global $Gui = GUICreate("Test", 500, 150)
  Local $Button = GUICtrlCreateButton("OK", 220, 100, 60)
  GUISetState()

  GUISetState(@SW_DISABLE)

  MsgBox($MB_SYSTEMMODAL, "Clicking parent title flash", "clicking parent client area NOW does flash !", 60, $Gui)

  GUISetState(@SW_ENABLE)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $Button
        ExitLoop
    EndSwitch
  WEnd

EndFunc   ;==>_Main

Func _MouseProc($nCode, $wParam, $lParam)

  If $nCode < 0 Or $wParam <> $WM_LBUTTONDOWN Then Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)

  Local $tStruct = DllStructCreate($tagPOINT)
  Local $tMouseHOOKS = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)

  Local $ptx = DllStructGetData($tMouseHOOKS, "X")
  Local $pty = DllStructGetData($tMouseHOOKS, "Y")

  DllStructSetData($tStruct, "x", $ptx)
  DllStructSetData($tStruct, "y", $pty)
  If WinExists("Clicking") And _WinAPI_WindowFromPoint($tStruct) = $Gui Then
    _WinAPI_MessageBeep(1)
    _WinAPI_FlashWindowEx(WinGetHandle("Clicking"), 3, 5, 100)
  EndIf

  Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)

EndFunc   ;==>_MouseProc

Func Cleanup()
  GUIDelete()
  _WinAPI_UnhookWindowsHookEx($g_hHook)
  DllCallbackFree($g_hStub_MouseProc)
EndFunc   ;==>Cleanup

 

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <WinAPIError.au3>

Global Const $tagMSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo"
OnAutoItExitRegister("Cleanup")

_Main()

Func _Main()

    Global $Gui = GUICreate("Test", 500, 150)
    Local $Button = GUICtrlCreateButton("OK", 220, 100, 60)

    GUISetState()

    MsgBoxEr()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $Button
                MsgBoxEr()

        EndSwitch
    WEnd

EndFunc   ;==>_Main

Func MsgBoxEr() ; moving the mouse over the area, goes from 0.10~0.20 w/o hook, to 0.60~0.70 with the hook
    Global $g_hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam")
    Local $hMod = _WinAPI_GetModuleHandle(0)
    Global $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_MouseProc), $hMod)

    GUISetState(@SW_DISABLE)
    MsgBox($MB_SYSTEMMODAL, "Clicking parent title flash", "clicking parent client area NOW does flash !", 60, $Gui)
    GUISetState(@SW_ENABLE)

    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_MouseProc)
EndFunc


Func _MouseProc($nCode, $wParam, $lParam)

    If $nCode < 0 Or ( $wParam <> $WM_LBUTTONDOWN And $wParam <> $WM_RBUTTONDOWN ) Then Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)

    Local $tStruct = DllStructCreate($tagPOINT)
    Local $tMouseHOOKS = DllStructCreate($tagMSLLHOOKSTRUCT, $lParam)

    Local $ptx = DllStructGetData($tMouseHOOKS, "X")
    Local $pty = DllStructGetData($tMouseHOOKS, "Y")

    DllStructSetData($tStruct, "x", $ptx)
    DllStructSetData($tStruct, "y", $pty)
    If WinExists("Clicking") And _WinAPI_WindowFromPoint($tStruct) = $Gui Then
        _WinAPI_MessageBeep(1)
        _WinAPI_FlashWindowEx(WinGetHandle("Clicking"), 3, 6, 100)
    EndIf

    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)

EndFunc   ;==>_MouseProc

Func Cleanup()
    GUIDelete()
;~  _WinAPI_UnhookWindowsHookEx($g_hHook)
;~  DllCallbackFree($g_hStub_MouseProc)
EndFunc   ;==>Cleanup

I believe this is better, as it uses an extra 0.60 of CPU from a base of 0.10 ( as seen in "Process Explorer" ), while I move the mouse around in circles around the GUI.
Let me know if this ON/OFF is flawed, thanks

Edit: it does leak some memory but is barely notable.

Edited by argumentum
mistake in the code I poted

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

The hook captures every single action of the mouse.  That is why you get a higher proc usage when moving the mouse.  But hooking and unhooking is not what I would do...To save few CPU cycles.

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...