Jump to content

traygetmsg


Recommended Posts

Hi,

I was researching on how to identify click on baloon popup caused by TrayTip(), but no solution. TrayGetMsg returns value only if a click event occurs on the tray icon. Is there any way to get the mouse click on the message baloon poped by the function TrayTip()

Thanks in advance

Roshith

Link to comment
Share on other sites

Thanks Wakillon, That almost serves the purpose. But is there anyway to differentiate the click on the message and on the X (close) mark? Sorry if I'm a headache.. :unsure:

In the rover example, if you click on traytip, console give a !NIN_BALLOONUSERCLICK

and if you click on the X, console give -NIN_BALLOONTIMEOUT.

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • 2 weeks later...

Hi Wakillon,

I modified Rover's script removing the GUI. Its working well. But even after the script exits, the AutoIt process still runs without exiting. I think there there is some dll issue. Can you please help me. I'm attaching the code

Thanks in advance

Roshith

#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>
Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4
Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5
Global $wProcNew = 0, $wProcOld = 0, $iMsg, $iError = 0
Global $hGUI1 = _AutoItWinGetHandle()
$hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam")
$hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", $hGUI1, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew))
$hProcOld = $hProcOld[0]

TrayTip("I'm a title", "I'm the message", 5, 1)
$iTimer = TimerInit()
While TimerDiff($iTimer) < 5000
  Sleep(10)
WEnd





Func _SubclassWin($hWnd, ByRef $hProcNew, ByRef $hProcOld)
      If $hProcNew <> 0 Or $hProcOld <> 0 Then Return SetError(1, 0, 0)
      $hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam")
      If @error Or $hProcNew = 0 Then Return SetError(2, 0, 0)
      $hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", _
              $hWnd, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew))
      If @error Or $hProcOld[0] = 0 Then
          $hProcOld = 0
          Return SetError(3, 0, 0)
      EndIf
      $hProcOld = $hProcOld[0]
      Return SetError(0, 0, 1)
  EndFunc;==>_SubclassWin

  Func _RestoreWndProc($hWnd, ByRef $hProcNew, ByRef $hProcOld)
      If $hProcOld <> 0 Then _WinAPI_SetWindowLong($hWnd, $GWL_WNDPROC, $hProcOld)
      DllCallbackFree($hProcNew)
      $hProcNew = 0
      $hProcOld = 0
  EndFunc;==>_RestoreWndProc

  Func OnAutoItExit()
      _RestoreWndProc($hGUI1, $wProcNew, $wProcOld)
  EndFunc;==>OnAutoItExit

  Func _AutoItWndProc($hWnd, $iMsg, $iwParam, $ilParam)
      #forceref $hWnd, $iMsg, $iwParam, $ilParam
      Switch $iMsg
          Case $WM_USER + 1;AutoIt callback message value for tray icon (1025), can be retrieved with ReadProcessMemory and TRAYDATA struct
              Switch $ilParam
                  Case $NIN_BALLOONTIMEOUT; timeout and by tooltip close icon
                      MsgBox(0,"","close")
                  Case $NIN_BALLOONUSERCLICK
                      MsgBox(0,"","click")
              EndSwitch
      EndSwitch
   ; pass the unhandled messages to default WindowProc
      Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $iwParam, $ilParam)
  EndFunc;==>_AutoItWndProc

;===============================================================================
;
; Function Name:   _AutoItWinGetHandle
; Description:: Returns the Windowhandle of AutoIT-Window
; Parameter(s): --
; Requirement(s):  --
; Return Value(s): Autoitwindow Handle
; Author(s):       Prog@ndy
;
;===============================================================================
;
  Func _AutoItWinGetHandle()
      Local $oldTitle = AutoItWinGetTitle()
      Local $x = Random(1248578, 1249780)
      AutoItWinSetTitle("qwrzu" & $x)
      Local $x = WinGetHandle("qwrzu" & $x)
      AutoItWinSetTitle($oldTitle)
      Return $x
  EndFunc;==>_AutoItWinGetHandle
Link to comment
Share on other sites

Add this:

OnAutoItExitRegister("OnAutoItExit")

You have the function, but I don't see you registering it with OnAutoItExitRegister().

:unsure:

P.S. I don't see where the script ever exits either.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Oops, missed the timer exiting your only main loop.

This works fine:

OnAutoItExitRegister("OnAutoItExit")

TrayTip("I'm a title", "I'm the message", 5, 1)
$iTimer = TimerInit()
While TimerDiff($iTimer) < 5000
  Sleep(10)
WEnd

Func OnAutoItExit()
    ConsoleWrite("OnAutoItExit()  @ExitCode = " & @exitCode & "  @ExitMethod = " & @exitMethod & @LF )
EndFunc

So the call to OnAutoItExit() should be made. Since you are messing with the AutoIt script's own window processing I guess you might be in a loop of callbacks. Add a ConsoleWrite() to each of your handler functions so you can see when they are called. For example:

Func _AutoItWndProc($hWnd, $iMsg, $iwParam, $ilParam)
     ConsoleWrite("Debug:  _AutoItWndProc(" & $hWnd & ", " & $iMsg & ", " & $iwParam & ", " & $ilParam & ")" & @LF)

     ; ...

EndFunc

:unsure:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You need to use DllCallbackFree, else script do not exit ! Posted Image

#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>

Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4
Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5
Global $wProcNew = 0, $wProcOld = 0, $iMsg, $iError = 0
Global $hGUI1 = _AutoItWinGetHandle()
$hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam")
$hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", $hGUI1, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew))
$hProcOld = $hProcOld[0]

TrayTip("I'm a title", "I'm the message", 5, 1)
$iTimer = TimerInit()

While 1
    If TimerDiff($iTimer) > 5000 Then
        DllCallbackFree ( $hProcNew )
        Exit
    EndIf
    Sleep ( 10 )
WEnd

Func _SubclassWin($hWnd, ByRef $hProcNew, ByRef $hProcOld)
      If $hProcNew <> 0 Or $hProcOld <> 0 Then Return SetError(1, 0, 0)
      $hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam")
      If @error Or $hProcNew = 0 Then Return SetError(2, 0, 0)
      $hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", _
              $hWnd, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew))
      If @error Or $hProcOld[0] = 0 Then
          $hProcOld = 0
          Return SetError(3, 0, 0)
      EndIf
      $hProcOld = $hProcOld[0]
      Return SetError(0, 0, 1)
  EndFunc;==>_SubclassWin

  Func _RestoreWndProc($hWnd, ByRef $hProcNew, ByRef $hProcOld)
      If $hProcOld <> 0 Then _WinAPI_SetWindowLong($hWnd, $GWL_WNDPROC, $hProcOld)
      DllCallbackFree($hProcNew)
      $hProcNew = 0
      $hProcOld = 0
  EndFunc;==>_RestoreWndProc

  Func OnAutoItExit()
      _RestoreWndProc($hGUI1, $wProcNew, $wProcOld)
  EndFunc;==>OnAutoItExit

  Func _AutoItWndProc($hWnd, $iMsg, $iwParam, $ilParam)
      #forceref $hWnd, $iMsg, $iwParam, $ilParam
      Switch $iMsg
          Case $WM_USER + 1;AutoIt callback message value for tray icon (1025), can be retrieved with ReadProcessMemory and TRAYDATA struct
              Switch $ilParam
                  Case $NIN_BALLOONTIMEOUT; timeout and by tooltip close icon
                      MsgBox(0,"","close")
                  Case $NIN_BALLOONUSERCLICK
                      MsgBox(0,"","click")
              EndSwitch
      EndSwitch
   ; pass the unhandled messages to default WindowProc
      Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $iwParam, $ilParam)
  EndFunc;==>_AutoItWndProc

;===============================================================================
;
; Function Name:   _AutoItWinGetHandle
; Description:: Returns the Windowhandle of AutoIT-Window
; Parameter(s): --
; Requirement(s):  --
; Return Value(s): Autoitwindow Handle
; Author(s):       Prog@ndy
;
;===============================================================================
;
  Func _AutoItWinGetHandle()
      Local $oldTitle = AutoItWinGetTitle()
      Local $x = Random(1248578, 1249780)
      AutoItWinSetTitle("qwrzu" & $x)
      Local $x = WinGetHandle("qwrzu" & $x)
      AutoItWinSetTitle($oldTitle)
      Return $x
  EndFunc;==>_AutoItWinGetHandle

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

I've already tried adding dllcallbackfree(). But that time, once the it comes out of the loop, I get the attached error.

Then I tried removing Dllcallbackfree(), then the script does not exit once it comes out of the loop (icon goes of from the tray, but 'AutoIt' process runs in the background)

Roshith

Link to comment
Share on other sites

Found the solution. Below code works well

;Author: rover 07/04/09
;MSDN reference:
;Shell_NotifyIcon Function
;http://msdn.microsoft.com/en-us/library/bb762159(VS.85).aspx
#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>

Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4
Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5
;Global Const $GWLP_WNDPROC = -4; for SetWindowLongPtr

Global $wProcNew = 0, $wProcOld = 0, $iMsg, $iError = 0

;get handle to AutoIt v3 hidden gui
Global $hGUI1 = _AutoItWinGetHandle()
;$hGUI1 = WinGetHandle(AutoItWinGetTitle())

;will work without GUICreate but global vars must be set in WndProc instead of GUICtrlCreateDummy/GUICtrlSendToDummy

;NOTE: _WinAPI_SetWindowLong() in WinAPI.au3 consistently returns 'The specified procedure could not be found' error 127
;error is due to the call being SetWindowLong instead of SetWindowLongW,
;using SetWindowLongW the error message is 'The operation completed successfully.

Global $cTooltipClose = GUICtrlCreateDummy()
Global $cTooltipClick = GUICtrlCreateDummy()


TrayTip("Clear", "", 1)
TrayTip("I'm a title", "I'm the message", 5, 1)
GUISwitch($hGUI1)
_SubclassWin($hGUI1, $wProcNew, $wProcOld)
$iTimer = TimerInit()
While TimerDiff($iTimer) < 5000
    Sleep(10)
WEnd

Func _SubclassWin($hWnd, ByRef $hProcNew, ByRef $hProcOld)
    If $hProcNew <> 0 Or $hProcOld <> 0 Then Return SetError(1, 0, 0)
    $hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam")
    If @error Or $hProcNew = 0 Then Return SetError(2, 0, 0)
    $hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", _
            $hWnd, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew))
    If @error Or $hProcOld[0] = 0 Then
        $hProcOld = 0
        Return SetError(3, 0, 0)
    EndIf
    $hProcOld = $hProcOld[0]
    Return SetError(0, 0, 1)
EndFunc   ;==>_SubclassWin

Func _RestoreWndProc($hWnd, ByRef $hProcNew, ByRef $hProcOld)
    If $hProcOld <> 0 Then _WinAPI_SetWindowLong($hWnd, $GWL_WNDPROC, $hProcOld)
    If $hProcNew <> 0 Then DllCallbackFree($hProcNew)
    $hProcNew = 0
    $hProcOld = 0
EndFunc   ;==>_RestoreWndProc

Func OnAutoItExit()
    _RestoreWndProc($hGUI1, $wProcNew, $wProcOld)
EndFunc   ;==>OnAutoItExit

Func _AutoItWndProc($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Switch $iMsg
        Case $WM_USER + 1;AutoIt callback message value for tray icon (1025), can be retrieved with ReadProcessMemory and TRAYDATA struct
            Switch $ilParam
                Case $NIN_BALLOONTIMEOUT; timeout and by tooltip close icon
                    MsgBox(0,$NIN_BALLOONTIMEOUT,"close")
                    ;GUICtrlSendToDummy($cTooltipClose)
                Case $NIN_BALLOONUSERCLICK
                    MsgBox(0,$NIN_BALLOONUSERCLICK,"clicked")
                    ;GUICtrlSendToDummy($cTooltipClick)
            EndSwitch
    EndSwitch
    ; pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc   ;==>_AutoItWndProc

;===============================================================================
;
; Function Name:   _AutoItWinGetHandle
; Description:: Returns the Windowhandle of AutoIT-Window
; Parameter(s): --
; Requirement(s):  --
; Return Value(s): Autoitwindow Handle
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _AutoItWinGetHandle()
    Local $oldTitle = AutoItWinGetTitle()
    Local $x = Random(1248578, 1249780)
    AutoItWinSetTitle("qwrzu" & $x)
    Local $x = WinGetHandle("qwrzu" & $x)
    AutoItWinSetTitle($oldTitle)
    Return $x
EndFunc   ;==>_AutoItWinGetHandle
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...