Jump to content

Transparent window on draging


Alek
 Share

Recommended Posts

its kinda stupid way of checking if a window is being draged, it only works if you have enable 'show window contents while dragging'.

bugs

-i was unable to get any kind of error, so none <_<

#include <Misc.au3> ;For the _ispressed function

;Set options
Opt("TrayMenuMode",1)
Opt("WinTitleMatchMode",2)

;Create Tray Menu
$Tray_Menu_Setings = TrayCreateItem("Setings")
$Tray_Menu_Exit = TrayCreateItem("Exit")

#region Setings ---->
$Trans_percent = 70
$Fade_Steps = 20
#endregion Setings <----
#region Declear variables ---->
$Step = (100-$Trans_percent)/$Fade_Steps
$Trans = 100
$Title = ""
#endregion Declear variables <----
#region Setings GUI ---->
$Form1 = GUICreate("Window Drag Effect Setings",400,80)
$Label1 = GUICtrlCreateLabel("Fade %",5,15,40,20)
$Label2 = GUICtrlCreateLabel($Trans_percent & "%",355,15,40,20)
$Slider1 = GUICtrlCreateSlider(70,5,280,30)
GUICtrlSetLimit(-1,100,10)
GUICtrlSetData(-1,$Trans_percent)

$Label3 = GUICtrlCreateLabel("Fade Steps",5,50,60,20)
$Label4 = GUICtrlCreateLabel($Fade_Steps,355,50,40,20)
$Slider2 = GUICtrlCreateSlider(70,40,280,30)
GUICtrlSetLimit(-1,100,1)
GUICtrlSetData(-1,$Fade_Steps)
#endregion Setings GUI <----
GUISetState(@SW_HIDE)
While 1
    
    ;Get Tray message
    $Tray_Msg = TrayGetMsg()
    
    Switch $Tray_Msg
        Case $Tray_Menu_Exit
            ExitLoop
        Case $Tray_Menu_Setings
            GUISetState(@SW_SHOW,$Form1)
    EndSwitch
     
    ;Get Setings GUI message
    $Gui_Msg = GUIGetMsg()
    Switch $Gui_Msg
        Case -3 ;$GUI_EVENT_CLOSE
            GUISetState(@SW_HIDE,$Form1)
    EndSwitch
    
    ;Check and see if the sliders have changed
    If GUICtrlRead($Slider1) <> $Trans_percent Then
        $Trans_percent = GUICtrlRead($Slider1)
        GUICtrlSetData($Label2,$Trans_percent & "%")
        ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\windowdrageffect", "transpercent", "REG_SZ", $Trans_percent)
    ElseIf GUICtrlRead($Slider2) <> $Fade_Steps Then
        $Fade_Steps = GUICtrlRead($Slider2)
        GUICtrlSetData($Label4,$Fade_Steps)
        $Step = (100-$Trans_percent)/$Fade_Steps
        ;RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\windowdrageffect", "fadesteps", "REG_SZ", $Fade_Steps)
    EndIf

    ;check and see if the mouse button is pressed and 
    ;if the script thinks your draging a window
    If _IsPressed(01) And _IsDragingWindow() Then
        
        ;Get the title to make sure we are changeing the transparency of the same window
        $Title = WinGetTitle("")
        
        ;Fade out
        If $Fade_Steps > 1 Then
            Do
                WinSetTrans($Title,"",(255/100)*$Trans)
                $Trans -= $Step
                Sleep(1)
            Until $Trans < $Trans_percent-$Step
            WinSetTrans($Title,"",(255/100)*$Trans_percent)
        Else
            WinSetTrans($Title,"",(255/100)*$Trans_percent)
        EndIf
        
        ;wait for the user to relese the mouse button
        While _IsPressed(01)
            
            ;sleep to avoid massive cpu usage
            Sleep(10)
        WEnd
        
        ;Fade back in
        If $Fade_Steps > 1 Then
            Do
                WinSetTrans($Title,"",(255/100)*$Trans)
                $Trans += $Step
                Sleep(1)
            Until $Trans >= 100-$Step
        EndIf
        
        ;to make sure its 100% visible
        WinSetTrans($Title,"",255)
    EndIf
    
    ;sleep to avoid massive cpu usage
    Sleep(10)
WEnd
 WinSetTrans($Title,"",255)
 Exit

Func _IsDragingWindow()
    
    ;Get the title to make sure we get the position of the same window
    $Win_Title = WinGetTitle("")
    
    ;Get cursor and window position
    $1_Win_Pos = WinGetPos($Win_Title)
    $1_Mouse_Pos = MouseGetPos()
    
    ;wait for the window and cursor to move
    Sleep(1)
    
    ;Get new cursor and window position
    $2_Win_Pos = WinGetPos($Win_Title)
    $2_Mouse_Pos = MouseGetPos()
    
    ;to avoid array error, i hade some problems with it
    if UBound($1_Win_Pos) > 3 and UBound($2_Win_Pos) > 3 Then
        
        ;Check and see if the window has moved with the mouse
        if $1_Win_Pos[0] <> $2_Win_Pos[0] or $1_Win_Pos[1] <> $2_Win_Pos[1] Then
            if $1_Mouse_Pos[0]-$2_Mouse_Pos[0] = $1_Win_Pos[0]-$2_Win_Pos[0] or _
                $1_Mouse_Pos[1]-$2_Mouse_Pos[1] = $1_Win_Pos[1]-$2_Win_Pos[1] Then
                
                ;was a bug where it faded when you resized the window from the top or left,
                ;so i added so that it checks that window has not resized 
                If $1_Win_Pos[2] = $2_Win_Pos[2] And $1_Win_Pos[3] = $2_Win_Pos[3] Then 
                    Return 1
                EndIf
            EndIf
        EndIf
    EndIf
    Return 0
EndFunc
Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

its kinda stupid way of checking if a window is being draged, it only works if you have enable 'show window contents while dragging'.

bugs

-i was unable to get any kind of error, so none <_<

#include <Misc.au3> ;For the _ispressed function

#region Setings ---->
$Trans_percent = 70
$Fade_Steps = 20
#endregion Setings <----
#region Declear variables ---->
$Step = (100-$Trans_percent)/$Fade_Steps
$Trans = 100
#endregion Declear variables <----
While 1
    
    ;check and see if the mouse button is pressed and 
    ;if the script thinks your draging a window
    If _IsPressed(01) And _IsDragingWindow() Then
        
        ;Get the title to make sure we are changeing the transparency of the same window
        $Title = WinGetTitle("")
        
        ;Fade out
        Do
            WinSetTrans($Title,"",(255/100)*$Trans)
            $Trans -= $Step
            Sleep(1)
        Until $Trans = $Trans_percent
        
        ;wait for the user to relese the mouse button
        While _IsPressed(01)
            
            ;sleep to avoid massive cpu usage
            Sleep(10)
        WEnd
        
        ;Fade back in
        Do
            WinSetTrans($Title,"",(255/100)*$Trans)
            $Trans += $Step
            Sleep(1)
        Until $Trans = 100
        
        ;to make sure its 100% visible
        WinSetTrans($Title,"",255)
    EndIf
    
    ;sleep to avoid massive cpu usage
    Sleep(10)
WEnd

Func _IsDragingWindow()
    
    ;Get the title to make sure we get the position of the same window
    $Win_Title = WinGetTitle("")
    
    ;Get cursor and window position
    $1_Win_Pos = WinGetPos($Win_Title)
    $1_Mouse_Pos = MouseGetPos()
    
    ;wait for the window and cursor to move
    Sleep(1)
    
    ;Get new cursor and window position
    $2_Win_Pos = WinGetPos($Win_Title)
    $2_Mouse_Pos = MouseGetPos()
    
    ;to avoid array error, i hade some problems with it
    if UBound($1_Win_Pos) > 3 and UBound($2_Win_Pos) > 3 Then
        
        ;Check and see if the window has moved with the mouse
        if $1_Win_Pos[0] <> $2_Win_Pos[0] or $1_Win_Pos[1] <> $2_Win_Pos[1] Then
            if $1_Mouse_Pos[0]-$2_Mouse_Pos[0] = $1_Win_Pos[0]-$2_Win_Pos[0] or _
                $1_Mouse_Pos[1]-$2_Mouse_Pos[1] = $1_Win_Pos[1]-$2_Win_Pos[1] Then
                
                ;was a bug where it faded when you resized the window from the top or left,
                ;so i added so that it checks that window has not resized 
                If $1_Win_Pos[2] = $2_Win_Pos[2] And $1_Win_Pos[3] = $2_Win_Pos[3] Then 
                    Return 1
                EndIf
            EndIf
        EndIf
    EndIf
    Return 0
EndFunc

Nice idea and effect.

When I try it the window I'm moving flashes black at first, it wouldbe good if you could fix that.

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

Nice idea and effect.

When I try it the window I'm moving flashes black at first, it wouldbe good if you could fix that.

hmm, cant really figure out whats causing this problem :) i have so far never had that problem <_<

EDIT: i found the problem, was with the fade out/in effect, it check to see if the trans % was =, changed it to < and >

also i added a setings gui, you can open the gui by selecting setings in the tray menu

could use some help with the regwrite function i cant get it to work properly :P

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

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