Jump to content

window slider Script - issues with closing


nadigo
 Share

Recommended Posts

Hi,

I modified a window slider Script that was fond here on one of the posts to have a "slide" in and out of a small window from above the task bar.

I wanted to have a 1px line on the right side of the screen right above the task bar, once the mouse is hovered on it, a slider window is to move to the right and show.

What i also wanted is when the user moves the mouse away from the slider window, it will slide in (aka close) back again.

I manged to reach the first part, but when I add the option to slide out once the mouse is away of the GUI, for some reason i can no longer activate the slider window from its closed position to its open one, on some cases it stopped sliding out and is not operational well.

Do you know how to solve this such window ?

#include <GUIConstants.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include "Misc.au3"
#Include <SliderConstants.au3>
#include <Constants.au3>
#Include <WinAPI.au3>
#Include <GuiMenu.au3>
#include <GuiReBar.au3>

Opt("TrayIconHide", 1)  


Global Const $tagNMCUSTOMDRAW = 'hwnd hWndFrom;uint_ptr IDFrom;int Code;dword DrawStage;hwnd hDC;' & $tagRECT & ';dword_ptr ItemSpec;uint ItemState;lparam ItemlParam'
Global Const $STM_GETIMAGE = 0x0173
;Global Const $WM_SYSCOMMAND = 0x0112

Local $hTaskBar = _WinAPI_FindWindow("Shell_TrayWnd", "")
Local $hRebar =  ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "ReBarWindow321")
local $Rehighet = _GUICtrlRebar_GetBarHeight($hReBar)
local $Vposition = @DesktopHeight - $Rehighet - 200

#Region Global
Global Const $SM_VIRTUALWIDTH = 78
$VirtualDesktopWidth = DLLCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH)
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
Global $Auto_appear = 1
Global $hide_state = 0, $btn_state = 0, $pass = 0, $active_window, $side = "left"
; hide the window almost completely as the mouse over will slidein the window, no button needs to be shown
Global $left_hwnd = -505
Global $right_hwnd = ($VirtualDesktopWidth -6)
#EndRegion Global

#Region config window $hwnd2
$hwnd = GUICreate("", 503, 170, $left_hwnd, $Vposition, -1,  BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES))

#Region Perforated Image
; Perforated Image
# ==> Start
Local $_Left_pos, $_Top_pos, $_GUI_NAME
$_Left_pos = 342 ; Replace with correct position
$_Top_pos = 139 ; Replace with correct position
_GuiImageHole($hwnd, $_Left_pos, $_Top_pos, 136, 41)
# <== End
#EndRegion Perforated Image


#Region main window $hwnd2

$hwnd2 = GUICreate("", 503, 170, 1, $Vposition, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW ))
GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND")
GUISetBkColor(0xFFFFFF)
GUISetState()
_ReduceMemory() 

#EndRegion main window $hwnd2


#Region While

While 1
    $msg1 = GUIGetMsg()
    Select
        Case $msg1 =  $GUI_EVENT_CLOSE
        Slide_out()
        _ReduceMemory() 
    EndSelect
    
    If GetHoveredHwnd() = $hwnd Then 
        Slide_in()
        _ReduceMemory() 
    EndIf
    
    ; once i add this i lose the ability to have the slide our working well on some windwos 
    ;##############################################
;   If GetHoveredHwnd() <> $hwnd2 Then 
;       Slide_out()
;       _ReduceMemory() 
;   EndIf
    
    
    If  $hide_state = 0 Then 
        Slide_out()
        _ReduceMemory() 
    EndIf

     
WEnd
#EndRegion While



#FUNCTION# ==============================================================
Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If BitAND($wParam, 0xFFF0) = $SC_MOVE Then Return False
        

    Return $GUI_RUNDEFMSG
EndFunc
#FUNCTION# ==============================================================
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    If IsArray($iRet) Then Return HWnd($iRet[0])
    Return SetError(1, 0, 0)
EndFunc ;==>GetHoveredHwnd
#FUNCTION# ==============================================================
Func Slide_in()
    ; the window will appear from left to right
    ;$hide_state = 1
   
    If $side = "left" Then 
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 100, "long", 0x00040001);slide in from left
    Else
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 100, "long", 0x00040002);slide in from right
    EndIf
    
    GUISetState(@SW_HIDE, $hwnd)
    WinActivate($hwnd2)
    WinWaitActive($hwnd2)
    _ReduceMemory() 
EndFunc  ;==>Slide_in
#FUNCTION# ==============================================================
Func Slide_out()
    ; the window will disappear from right to left
    $hide_state = 1
    If $side = "left" Then 
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 100, "long", 0x00050002);slide out to left
    Else
        DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd2, "int", 100, "long", 0x00050001);slide out to right    
    EndIf
    GUISetState(@SW_SHOW, $hwnd)
    WinActivate($hwnd)
    WinWaitActive($hwnd)
    _ReduceMemory() 
EndFunc  ;==>Slide_out
#FUNCTION# ==============================================================
#FUNCTION# ==============================================================
Func Function(ByRef $b)
    Slide_out()
    _ReduceMemory()
EndFunc  ;==>Function
#FUNCTION# ==============================================================
Func Set_Exit()
    GUIDelete($hwnd2)   
    GUIDelete($hwnd)    
    Exit
EndFunc  ;==>Set_Exit
#FUNCTION# ==============================================================

Func _ReduceMemory()
    Local $dll_mem = DllOpen(@SystemDir & "\psapi.dll")
    Local $ai_Return = DllCall($dll_mem, 'int', 'EmptyWorkingSet', 'long', -1)
    If @error Then Return SetError(@error, @error, 1)
    Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory
#FUNCTION# ==============================================================
#Region Perforated Image
#comments-start
    The lines below will generate the perforated image (bewteen start and end)
    Move these lines into your GUI code, usually just before GUISetState()
    Don't forget to fill in the correct coordinates for $Left_pos, $Top_pos
    and enter the GUI Window Handle in the last line

# ==> Start
Local $_Left_pos, $_Top_pos, $_GUI_NAME
$_Left_pos = 10 ; Replace with correct position
$_Top_pos = 10 ; Replace with correct position
$_GUI_NAME = 'The name of your GUI window'
_GuiImageHole($_GUI_NAME, $_Left_pos, $_Top_pos, 136, 45)
# <== End

#comments-end

#FUNCTION# ==============================================================
Func _GuiImageHole($window_handle, $pos_x, $pos_y,$Image_Width ,$Image_Height)
    Local $aClassList, $aM_Mask, $aMask
#Region picture array
Local $PictArray[248]
$PictArray[0] = '1,1,2,1'
$PictArray[1] = '5,1,24,1'
$PictArray[2] = '29,1,44,1'
$PictArray[3] = '48,1,91,1'
$PictArray[4] = '95,1,136,1'
$PictArray[5] = '1,2,3,2'
$PictArray[6] = '6,2,23,2'
$PictArray[7] = '30,2,44,2'
$PictArray[8] = '47,2,91,2'
$PictArray[9] = '96,2,136,2'
$PictArray[10] = '1,3,4,3'
$PictArray[11] = '7,3,8,3'
$PictArray[12] = '10,3,22,3'
$PictArray[13] = '30,3,37,3'
$PictArray[14] = '42,3,43,3'
$PictArray[15] = '46,3,92,3'
$PictArray[16] = '96,3,136,3'
$PictArray[17] = '1,4,5,4'
$PictArray[18] = '11,4,23,4'
$PictArray[19] = '29,4,36,4'
$PictArray[20] = '45,4,65,4'
$PictArray[21] = '68,4,92,4'
$PictArray[22] = '96,4,136,4'
$PictArray[23] = '1,5,5,5'
$PictArray[24] = '13,5,23,5'
$PictArray[25] = '30,5,35,5'
$PictArray[26] = '44,5,65,5'
$PictArray[27] = '69,5,86,5'
$PictArray[28] = '91,5,92,5'
$PictArray[29] = '97,5,136,5'
$PictArray[30] = '1,6,5,6'
$PictArray[31] = '13,6,22,6'
$PictArray[32] = '31,6,36,6'
$PictArray[33] = '43,6,64,6'
$PictArray[34] = '71,6,85,6'
$PictArray[35] = '92,6,92,6'
$PictArray[36] = '97,6,136,6'
$PictArray[37] = '1,7,5,7'
$PictArray[38] = '12,7,21,7'
$PictArray[39] = '32,7,34,7'
$PictArray[40] = '42,7,64,7'
$PictArray[41] = '71,7,85,7'
$PictArray[42] = '92,7,92,7'
$PictArray[43] = '97,7,136,7'
$PictArray[44] = '1,8,5,8'
$PictArray[45] = '15,8,21,8'
$PictArray[46] = '32,8,33,8'
$PictArray[47] = '43,8,49,8'
$PictArray[48] = '54,8,64,8'
$PictArray[49] = '70,8,85,8'
$PictArray[50] = '97,8,136,8'
$PictArray[51] = '1,9,4,9'
$PictArray[52] = '18,9,20,9'
$PictArray[53] = '32,9,32,9'
$PictArray[54] = '44,9,48,9'
$PictArray[55] = '55,9,64,9'
$PictArray[56] = '72,9,85,9'
$PictArray[57] = '96,9,136,9'
$PictArray[58] = '1,10,4,10'
$PictArray[59] = '15,10,15,10'
$PictArray[60] = '44,10,47,10'
$PictArray[61] = '55,10,63,10'
$PictArray[62] = '73,10,85,10'
$PictArray[63] = '96,10,136,10'
$PictArray[64] = '1,11,3,11'
$PictArray[65] = '15,11,19,11'
$PictArray[66] = '45,11,47,11'
$PictArray[67] = '54,11,63,11'
$PictArray[68] = '74,11,84,11'
$PictArray[69] = '96,11,136,11'
$PictArray[70] = '1,12,3,12'
$PictArray[71] = '17,12,18,12'
$PictArray[72] = '46,12,47,12'
$PictArray[73] = '55,12,62,12'
$PictArray[74] = '75,12,83,12'
$PictArray[75] = '96,12,136,12'
$PictArray[76] = '1,13,4,13'
$PictArray[77] = '17,13,17,13'
$PictArray[78] = '46,13,46,13'
$PictArray[79] = '56,13,62,13'
$PictArray[80] = '76,13,83,13'
$PictArray[81] = '97,13,136,13'
$PictArray[82] = '1,14,4,14'
$PictArray[83] = '17,14,17,14'
$PictArray[84] = '46,14,46,14'
$PictArray[85] = '56,14,62,14'
$PictArray[86] = '77,14,83,14'
$PictArray[87] = '97,14,136,14'
$PictArray[88] = '1,15,5,15'
$PictArray[89] = '16,15,17,15'
$PictArray[90] = '33,15,33,15'
$PictArray[91] = '57,15,62,15'
$PictArray[92] = '77,15,83,15'
$PictArray[93] = '98,15,136,15'
$PictArray[94] = '1,16,5,16'
$PictArray[95] = '16,16,16,16'
$PictArray[96] = '32,16,33,16'
$PictArray[97] = '58,16,62,16'
$PictArray[98] = '77,16,83,16'
$PictArray[99] = '98,16,136,16'
$PictArray[100] = '1,17,5,17'
$PictArray[101] = '16,17,16,17'
$PictArray[102] = '32,17,33,17'
$PictArray[103] = '58,17,62,17'
$PictArray[104] = '78,17,82,17'
$PictArray[105] = '98,17,136,17'
$PictArray[106] = '1,18,5,18'
$PictArray[107] = '32,18,33,18'
$PictArray[108] = '58,18,62,18'
$PictArray[109] = '78,18,82,18'
$PictArray[110] = '98,18,136,18'
$PictArray[111] = '1,19,5,19'
$PictArray[112] = '57,19,63,19'
$PictArray[113] = '78,19,81,19'
$PictArray[114] = '98,19,136,19'
$PictArray[115] = '1,20,5,20'
$PictArray[116] = '57,20,64,20'
$PictArray[117] = '78,20,81,20'
$PictArray[118] = '98,20,136,20'
$PictArray[119] = '1,21,5,21'
$PictArray[120] = '58,21,64,21'
$PictArray[121] = '77,21,81,21'
$PictArray[122] = '99,21,136,21'
$PictArray[123] = '1,22,5,22'
$PictArray[124] = '58,22,63,22'
$PictArray[125] = '76,22,82,22'
$PictArray[126] = '99,22,136,22'
$PictArray[127] = '1,23,6,23'
$PictArray[128] = '32,23,32,23'
$PictArray[129] = '46,23,46,23'
$PictArray[130] = '58,23,63,23'
$PictArray[131] = '77,23,82,23'
$PictArray[132] = '100,23,136,23'
$PictArray[133] = '1,24,6,24'
$PictArray[134] = '31,24,32,24'
$PictArray[135] = '46,24,46,24'
$PictArray[136] = '58,24,64,24'
$PictArray[137] = '77,24,82,24'
$PictArray[138] = '99,24,136,24'
$PictArray[139] = '2,25,6,25'
$PictArray[140] = '31,25,32,25'
$PictArray[141] = '59,25,64,25'
$PictArray[142] = '78,25,83,25'
$PictArray[143] = '98,25,136,25'
$PictArray[144] = '7,26,7,26'
$PictArray[145] = '16,26,17,26'
$PictArray[146] = '31,26,32,26'
$PictArray[147] = '46,26,46,26'
$PictArray[148] = '59,26,64,26'
$PictArray[149] = '79,26,83,26'
$PictArray[150] = '96,26,136,26'
$PictArray[151] = '8,27,9,27'
$PictArray[152] = '15,27,17,27'
$PictArray[153] = '25,27,25,27'
$PictArray[154] = '31,27,33,27'
$PictArray[155] = '45,27,46,27'
$PictArray[156] = '60,27,61,27'
$PictArray[157] = '79,27,84,27'
$PictArray[158] = '95,27,136,27'
$PictArray[159] = '3,28,5,28'
$PictArray[160] = '8,28,9,28'
$PictArray[161] = '15,28,20,28'
$PictArray[162] = '25,28,25,28'
$PictArray[163] = '33,28,33,28'
$PictArray[164] = '42,28,47,28'
$PictArray[165] = '60,28,61,28'
$PictArray[166] = '78,28,84,28'
$PictArray[167] = '95,28,136,28'
$PictArray[168] = '34,29,34,29'
$PictArray[169] = '39,29,39,29'
$PictArray[170] = '42,29,48,29'
$PictArray[171] = '60,29,61,29'
$PictArray[172] = '76,29,85,29'
$PictArray[173] = '95,29,119,29'
$PictArray[174] = '125,29,129,29'
$PictArray[175] = '135,29,136,29'
$PictArray[176] = '38,30,38,30'
$PictArray[177] = '44,30,50,30'
$PictArray[178] = '76,30,87,30'
$PictArray[179] = '95,30,121,30'
$PictArray[180] = '125,30,128,30'
$PictArray[181] = '131,30,133,30'
$PictArray[182] = '135,30,136,30'
$PictArray[183] = '47,31,50,31'
$PictArray[184] = '55,31,59,31'
$PictArray[185] = '64,31,64,31'
$PictArray[186] = '76,31,87,31'
$PictArray[187] = '95,31,120,31'
$PictArray[188] = '123,31,123,31'
$PictArray[189] = '126,31,127,31'
$PictArray[190] = '130,31,133,31'
$PictArray[191] = '135,31,136,31'
$PictArray[192] = '49,32,50,32'
$PictArray[193] = '56,32,61,32'
$PictArray[194] = '65,32,65,32'
$PictArray[195] = '69,32,69,32'
$PictArray[196] = '76,32,80,32'
$PictArray[197] = '83,32,87,32'
$PictArray[198] = '95,32,119,32'
$PictArray[199] = '122,32,123,32'
$PictArray[200] = '126,32,126,32'
$PictArray[201] = '129,32,136,32'
$PictArray[202] = '56,33,57,33'
$PictArray[203] = '66,33,69,33'
$PictArray[204] = '76,33,77,33'
$PictArray[205] = '84,33,87,33'
$PictArray[206] = '95,33,119,33'
$PictArray[207] = '122,33,123,33'
$PictArray[208] = '126,33,126,33'
$PictArray[209] = '129,33,130,33'
$PictArray[210] = '135,33,136,33'
$PictArray[211] = '67,34,70,34'
$PictArray[212] = '77,34,78,34'
$PictArray[213] = '84,34,88,34'
$PictArray[214] = '95,34,118,34'
$PictArray[215] = '126,34,126,34'
$PictArray[216] = '129,34,131,34'
$PictArray[217] = '134,34,136,34'
$PictArray[218] = '32,35,32,35'
$PictArray[219] = '85,35,88,35'
$PictArray[220] = '95,35,117,35'
$PictArray[221] = '120,35,123,35'
$PictArray[222] = '126,35,126,35'
$PictArray[223] = '129,35,131,35'
$PictArray[224] = '134,35,136,35'
$PictArray[225] = '18,36,23,36'
$PictArray[226] = '26,36,40,36'
$PictArray[227] = '86,36,88,36'
$PictArray[228] = '95,36,116,36'
$PictArray[229] = '121,36,122,36'
$PictArray[230] = '127,36,127,36'
$PictArray[231] = '134,36,136,36'
$PictArray[232] = '14,37,45,37'
$PictArray[233] = '85,37,88,37'
$PictArray[234] = '95,37,136,37'
$PictArray[235] = '9,38,51,38'
$PictArray[236] = '88,38,88,38'
$PictArray[237] = '97,38,136,38'
$PictArray[238] = '7,39,54,39'
$PictArray[239] = '57,39,58,39'
$PictArray[240] = '62,39,64,39'
$PictArray[241] = '67,39,68,39'
$PictArray[242] = '70,39,72,39'
$PictArray[243] = '100,39,136,39'
$PictArray[244] = '6,40,78,40'
$PictArray[245] = '100,40,136,40'
$PictArray[246] = '4,41,80,41'
$PictArray[247] = '100,41,136,41'

#EndRegion picture array

    ; get the size of the active window
    $size = WinGetClientSize($window_handle)
    $Window_width = $size[0]
    $Window_height = $size[1]+33 ; including the title bar
    ; First hide the window
    $aClassList = StringSplit(_WinGetClassListEx($window_handle), @LF)
    $aM_Mask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', 0, 'long', 0, 'long', 0)
    ; rectangle A - left side
    $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', 0, 'long', $pos_x, 'long', $Window_height)
    DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
    ; rectangle B - Top
    $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0, 'long', 0, 'long', $Window_width, 'long', $pos_y)
    DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
    ; rectangle C - Right side
    $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', $pos_x  + $Image_Width , 'long', 0 , 'long', $Window_width + 30, 'long', $Window_height)
    DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
    ; rectangle D - Bottom
    $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', 0 , 'long', $pos_y + $Image_Height, 'long', $Window_width, 'long', $Window_height)
    DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
    ; now unhide all regions as defined  in array $PictArray
    For $i = 0 To (UBound($PictArray) - 1)
        $Block_value = StringSplit($PictArray[$i],',')
        $aMask = DllCall('gdi32.dll', 'long', 'CreateRectRgn', 'long', $pos_x + $Block_value[1] - 1 , 'long', $pos_y + $Block_value[2], 'long', $pos_x + $Block_value[3], 'long', $pos_y + $Block_value[4] -1)
        DllCall('gdi32.dll', 'long', 'CombineRgn', 'long', $aM_Mask[0], 'long', $aMask[0], 'long', $aM_Mask[0], 'int', 2)
    Next
    DllCall('user32.dll', 'long', 'SetWindowRgn', 'hwnd', $window_handle, 'long', $aM_Mask[0], 'int', 1)
    $PictArray='' ; empty array
EndFunc  ;==>_GuiImageHole
#FUNCTION# ==============================================================
Func _WinGetClassListEx($sTitle)
    Local $sClassList = WinGetClassList($sTitle)
    Local $aClassList = StringSplit($sClassList, @LF)
    Local $sRetClassList = '', $sHold_List = '|'
    Local $aiInHold, $iInHold
    For $i = 1 To UBound($aClassList) - 1
        If $aClassList[$i] = '' Then ContinueLoop
        If StringRegExp($sHold_List, '\|' & $aClassList[$i] & '~(\d+)\|') Then
            $aiInHold = StringRegExp($sHold_List, '.*\|' & $aClassList[$i] & '~(\d+)\|.*', 1)
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])
            If $iInHold = 0 Then $iInHold += 1
            $aClassList[$i] &= '~' & $iInHold + 1
            $sHold_List &= $aClassList[$i] & '|'
            $sRetClassList &= $aClassList[$i] & @LF
        Else
            $aClassList[$i] &= '~1'
            $sHold_List &= $aClassList[$i] & '|'
            $sRetClassList &= $aClassList[$i] & @LF
        EndIf
    Next
    Return StringReplace(StringStripWS($sRetClassList, 3), '~', '')
EndFunc ;==>_WinGetClassListEx
#FUNCTION# ==============================================================
#EndRegion Perforated Image
#EndRegion Functions
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...