Sign in to follow this  
Followers 0
olympus

[SOLVED]Sliding Notification Not Working in XP Classic

6 posts in this topic

#1 ·  Posted (edited)

I'm using this code:

#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; hotkey pause function
HotKeySet("!p", "pause")

Global $Paused ;Default is unpaused (0=off 1=on)
Global $Paused = 0 ; Default is unpaused (0=off 1=on)
Local $GUIToaster, $text1 = "the"
Local $GUIToaster, $text2 = "slider"
Local $Pos, $i

While 1
    Sleep(50)
WEnd

; hotkey pause function
Func pause()
    Opt("WinTitleMatchMode", 4)
    $Paused = Not $Paused ;changes $Paused from 0 to 1 or from 1 to 0
    If $Paused And Not WinExists("slider", "") Then
        _HorzToaster()
        While $Paused ; while $Paused = 1
            Sleep(10); idle around (pause)
        WEnd
        For $i = 100 To 1 Step -1
            WinSetTrans($GUIToaster, "", $i * 1.5)
            WinMove("slider", "", $Pos[2] - $i, $Pos[3] - 30)
            Sleep(0) ; fast slide-out to right
        Next
        GUIDelete($GUIToaster)

    EndIf
EndFunc   ;==>TogglePause

Func _HorzToaster() ; incorporating code from Danny35d
    Opt("WinTitleMatchMode", 4)
    $Pos = WinGetPos("classname=Shell_TrayWnd")
    If $Pos[2] <> @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]
    If $Pos[3] <> @DesktopHeight Then
        $Pos[3] = @DesktopHeight - ($Pos[3] + 11)
    Else
        $Pos[3] -= 32
    EndIf
    $GUIToaster = GUICreate("slider", 100, 40, $Pos[2] - 100, $Pos[3], _
            $WS_POPUP, BitOR($WS_EX_TRANSPARENT, $WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    GUISetBkColor(0xFFFFFF, $GUIToaster)
    $label1 = GUICtrlCreateLabel($text1, 0, 0, 100, 15, $SS_CENTER)
    GUICtrlSetFont(-1, 11, 800, 1, "Arial")
    GUICtrlSetColor($label1, 0x000000)
    $label2 = GUICtrlCreateLabel($text2, 0, 17, 100, 30, $SS_CENTER)
    GUICtrlSetFont(-1, 11, 800, 1, "Arial")
    GUICtrlSetColor($label2, 0x000000)
    WinSetTrans($GUIToaster, "", 0)
    Sleep(20)
    GUISetState(@SW_SHOW, $GUIToaster)
    For $i = 1 To 100
        WinSetTrans($GUIToaster, "", 1.5 * $i)
        WinMove("slider", "", $Pos[2] - $i, $Pos[3] - 30)
        Sleep(0) ; fast slide-in from right
    Next
EndFunc   ;==>_HorzToaster

It works great on the default theme of Windows XP whereby when you press 'Alt+p', a notification slides-in above the system tray(clock). But on the Classic theme, I can only see a quick flash on the left bottom side of my screen.

Turns out that the WinGetPos("classname=Shell_TrayWnd") doesn't return the same value and it depends on the theme used. Can anyone suggest a more reliable method? Thank you!

Edited by olympus

Share this post


Link to post
Share on other sites

Any help here please...?

I've tried this but toast did not appear in either themes:

#include <StaticConstants.au3>
#include <WindowsConstants.au3>

; hotkey pause function
HotKeySet("!p", "pause")

Global $Paused ;Default is unpaused (0=off 1=on)
Global $Paused = 0 ; Default is unpaused (0=off 1=on)
Local $GUIToaster, $text1 = "the"
Local $GUIToaster, $text2 = "slider"
Local $Pos, $i

While 1
    Sleep(50)
WEnd

; hotkey pause function
Func pause()
    Opt("WinTitleMatchMode", 4)
    $Paused = Not $Paused ;changes $Paused from 0 to 1 or from 1 to 0
    If $Paused And Not WinExists("slider", "") Then
        _HorzToaster(100,40)
        While $Paused ; while $Paused = 1
            Sleep(10); idle around (pause)
        WEnd
        _TrayPopup_SlideOut($GUIToaster)
        GUIDelete($GUIToaster)

    EndIf
EndFunc   ;==>TogglePause

Func _HorzToaster($nWidth, $nHeight, $nOffset = 4)
    Opt("WinTitleMatchMode", 4)
    Local $aPos = WinGetPos("[class:Shell_TrayWnd]"), $y, $x
    Switch _TaskBarGetSide()
        Case "Bottom"
            $y = $aPos[1] - $nHeight - $nOffset
            $x = @DesktopWidth - $nWidth - $nOffset
        Case "Left"
            $y = @DesktopHeight - $nHeight - $nOffset
            $x = $aPos[2] + $nOffset
        Case "Top"
            $y = $aPos[3] + $nOffset
            $x = @DesktopWidth - $nWidth - $nOffset
        Case "Right"
            $y = @DesktopHeight - $nHeight - $nOffset
            $x = $aPos[0] - $nWidth - $nOffset
    EndSwitch
    ConsoleWrite($x & ", " & $y & @CRLF & _TaskBarGetSide() & @CRLF)
    $GUIToaster = GUICreate("slider", $nWidth, $nHeight, $x, $y, _
            $WS_POPUP, BitOR($WS_EX_TRANSPARENT, $WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
    GUISetBkColor(0xFFFFFF, $GUIToaster)
    $label1 = GUICtrlCreateLabel($text1, 0, 0, 100, 15, $SS_CENTER)
    GUICtrlSetFont(-1, 11, 800, 1, "Arial")
    GUICtrlSetColor($label1, 0x000000)
    $label2 = GUICtrlCreateLabel($text2, 0, 17, 100, 30, $SS_CENTER)
    GUICtrlSetFont(-1, 11, 800, 1, "Arial")
    GUICtrlSetColor($label2, 0x000000)
    WinSetTrans($GUIToaster, "", 0)
    Sleep(20)
    GUISetState(@SW_SHOW, $GUIToaster)
    _TrayPopup_SlideIn($GUIToaster)
EndFunc   ;==>_HorzToaster



Func _TaskBarGetSide()
    Local $aPos = WinGetPos("[class:Shell_TrayWnd]")
    If $aPos[0] < 10 Then
        If $aPos[2] > 200 Then Return "Bottom"
        Return "Right"
    EndIf
    If $aPos[3] > 200 Then Return "Left"
    Return "Top"
EndFunc   ;==>_TaskBarGetSide

; Gary Frost's WinAnimate function
; 0x00040001 ; slide in from left
; 0x00050002 ; slide out to left
; 0x00040002 ; slide in from right
; 0x00050001 ; slide out to right
; 0x00040004 ; slide-in from top
; 0x00050008 ; slide-out to top
; 0x00040008 ; slide-in from bottom
; 0x00050004 ; slide-out to bottom

Func _TrayPopup_SlideIn($GUIToaster, $i_duration = 1000)
    Local $i_mode
    Switch _TaskBarGetSide()
        Case "Bottom"
            $i_mode = 0x00040008
        Case "Left"
            $i_mode = 0x00040001
        Case "Top"
            $i_mode = 0x00040004
        Case "Right"
            $i_mode = 0x00040002
    EndSwitch
    If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_2000" Or @OSVersion = "WIN_VISTA" Then
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUIToaster, "int", $i_duration, "long", $i_mode)

        Local $ai_gle = DllCall('kernel32.dll', 'int', 'GetLastError')
        If $ai_gle[0] <> 0 Then
            Return SetError(1, 0, 0)
        EndIf
        Return 1
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc   ;==>_TrayPopup_SlideIn

Func _TrayPopup_SlideOut($GUIToaster, $i_duration = 1000)
    Local $i_mode
    Switch _TaskBarGetSide()
        Case "Bottom"
            $i_mode = 0x00050004
        Case "Left"
            $i_mode = 0x00050002
        Case "Top"
            $i_mode = 0x00050008
        Case "Right"
            $i_mode = 0x00050001
    EndSwitch
    If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_2000" Or @OSVersion = "WIN_VISTA" Then
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUIToaster, "int", $i_duration, "long", $i_mode)

        Local $ai_gle = DllCall('kernel32.dll', 'int', 'GetLastError')
        If $ai_gle[0] <> 0 Then
            Return SetError(1, 0, 0)
        EndIf
        Return 1
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc   ;==>_TrayPopup_SlideOut

I just can't figure out what's wrong. Any help is appreciated. Thank you.

Share this post


Link to post
Share on other sites

Try this

If $Pos[2] < @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]

instead of this

If $Pos[2] <> @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

Try this

If $Pos[2] < @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]

instead of this

If $Pos[2] <> @DesktopWidth Then $Pos[2] = @DesktopWidth - $Pos[2]

It worked! Thank you, thank you, thank you!

Can you explain a bit more about the solution you gave? It's like magic...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

$Pos[2] for the classic theme is for me @DesktopWidth + 4 (1284)

$Pos[2] for the XP theme is for me exactly @DesktopWidth (1280)

So I changed the comparator.

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

Ah I see. Thank you for your help!

Share this post


Link to post
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
Sign in to follow this  
Followers 0