#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <Constants.au3>
#include <Misc.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
;Baisc Settings
Global $Class_Blacklist = "|BasicWindow|SideBar_AppBarWindow|SideBar_AppBarBullet|Progman|Button|ThunderRT6FormDC|ROCKETDOCK|"
Global $Num_Of_Desktop = IniRead(@ScriptDir & "\Data.ini", "Setings", "Num_Of_Desktop", "4")
Global $Gui_Size = IniRead(@ScriptDir & "\Data.ini", "Setings", "Gui_Size", "80")
Global $Slide_Trans = True
Global $Fade_Trans = False
Global $Debug = False
Global $Trans_Speed = 400
;Stuff that user should be able to control
Global $DesktopSize = WinGetClientSize("Program Manager")
Global Const $Ratio = $DesktopSize[0] / $DesktopSize[1]
Global $Desktop_Data[$Num_Of_Desktop][1]
Global $Desktop_Pic[$Num_Of_Desktop]
Global $Curent_Desktop = 0
Global $Sticky_Window
Global $Hover_Wait_Timer
Global $Form1, $Hover_Form
IniWrite(@ScriptDir & "\Data.ini", "Wallpaper", "Desktop_Default", _Wallpaper_Get())
For $x = 0 To $Num_Of_Desktop - 1
$Desktop_Data[$x][0] = IniRead(@ScriptDir & "\Data.ini", "Wallpaper", "Desktop_" & $x + 1, _Wallpaper_Get())
ConsoleWrite($Desktop_Data[$x][0] & @CRLF)
Next
Global $Form_Size_X = (($Gui_Size * $Ratio) * $Num_Of_Desktop) + ($Num_Of_Desktop * 5)
Global $Form_Size_Y = $Gui_Size + 10
Global $Default_Gui_Pos = IniRead(@ScriptDir & "\Data.ini", "Setings", "Default_Gui_Pos", $DesktopSize[0] - 25 & "," & $DesktopSize[1] - $Form_Size_Y - 32)
$Default_Gui_Pos = StringSplit($Default_Gui_Pos, ",")
$Form1 = GUICreate("", $Form_Size_X + 45, $Form_Size_Y, $Default_Gui_Pos[1], $Default_Gui_Pos[2], $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
GUISetBkColor(0xccccff)
$Slide_Button = GUICtrlCreateButton("<", 5, 20, 15, $Form_Size_Y - 25)
$Exit_Button = GUICtrlCreateButton("X", 5, 5, 15, 15)
$Slide_Button2 = GUICtrlCreateButton(">", $Form_Size_X + 25, 20, 15, $Form_Size_Y - 25)
$Exit_Button2 = GUICtrlCreateButton("X", $Form_Size_X + 25, 5, 15, 15)
;GUICtrlCreateLabel("", 0,0, $Form_Size_X + 25, $Form_Size_X, -1, $GUI_WS_EX_PARENTDRAG)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($Slide_Button, 0xaaaaff)
GUICtrlSetBkColor($Slide_Button2, 0xaaaaff)
GUICtrlSetBkColor($Exit_Button, 0xaaaaff)
GUICtrlSetBkColor($Exit_Button2, 0xaaaaff)
GUICtrlSetOnEvent($Slide_Button, "_Slide")
GUICtrlSetOnEvent($Exit_Button, "_Exit")
GUICtrlSetOnEvent($Slide_Button2, "_Slide")
GUICtrlSetOnEvent($Exit_Button2, "_Exit")
For $x = 0 To $Num_Of_Desktop - 1
$Desktop_Pic[$x] = GUICtrlCreatePic($Desktop_Data[$x][0], (($Gui_Size * $Ratio) * $x) + (5 * ($x)) + 25, 5, $Gui_Size * $Ratio, $Gui_Size)
Next
$Hover_Form = GUICreate("", $Gui_Size * $Ratio, $Gui_Size, 30, 5, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW + $WS_EX_MDICHILD, $Form1)
GUISetBkColor(0xFFFFFF)
$Fade_Form = GUICreate("", $DesktopSize[0], $DesktopSize[1], 0, 0, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
$Fade_Form_Pic = GUICtrlCreatePic("", 0, 0, 0, 0)
GUISetState(@SW_HIDE, $Fade_Form)
GUISetState(@SW_SHOW, $Form1)
GUISetState(@SW_SHOW, $Hover_Form)
WinSetTrans($Form1, "", 255)
WinSetTrans($Fade_Form, "", 255)
WinSetTrans($Hover_Form, "", 120)
WinSetOnTop($Form1, "", 1)
While 1
Sleep(10)
$Msg = _Effects()
If $Msg Then _ChangeDesktop($Msg)
_CheckWallpaper()
_CheckHotKeys()
WEnd
Func _CheckWallpaper()
If $Desktop_Data[$Curent_Desktop][0] <> _Wallpaper_Get() Then
If @OSVersion = "WIN_VISTA" Then
IniWrite(@ScriptDir & "\Data.ini", "Wallpaper", "Desktop_" & $Curent_Desktop + 1, _Wallpaper_Get())
$Desktop_Data[$Curent_Desktop][0] = _Wallpaper_Get()
Else
FileCopy(_Wallpaper_Get(), @ScriptDir & "\Desktop_" & $Curent_Desktop & ".bmp")
IniWrite(@ScriptDir & "\Data.ini", "Wallpaper", "Desktop_" & $Curent_Desktop + 1, @ScriptDir & "\Desktop_" & $Curent_Desktop & ".bmp")
$Desktop_Data[$Curent_Desktop][0] = @ScriptDir & "\Desktop_" & $Curent_Desktop & ".bmp"
EndIf
EndIf
EndFunc ;==>_CheckWallpaper
Func _CheckHotKeys()
If _IsPressed(27) And _IsPressed(11) And _IsPressed(12) Then
$Sticky_Window = WinGetHandle("")
If $Curent_Desktop = $Num_Of_Desktop - 1 Then
_ChangeDesktop(0)
Else
_ChangeDesktop($Curent_Desktop + 1)
EndIf
Do
Sleep(1)
Until _IsPressed(27) = 0 Or _IsPressed(11) = 0 Or _IsPressed(12) = 0
ElseIf _IsPressed(25) And _IsPressed(11) And _IsPressed(12) Then
$Sticky_Window = WinGetHandle("")
If $Curent_Desktop = 0 Then
_ChangeDesktop($Num_Of_Desktop - 1)
Else
_ChangeDesktop($Curent_Desktop - 1)
EndIf
Do
Sleep(1)
Until _IsPressed(25) = 0 Or _IsPressed(11) = 0 Or _IsPressed(12) = 0
EndIf
EndFunc ;==>_CheckHotKeys
Func _Effects()
Local $cur_desktop
$Ginfo = GUIGetCursorInfo($Form1)
If Not @error Then
For $x = 0 To $Num_Of_Desktop - 1
If $Ginfo[4] = $Desktop_Pic[$x] Then
$a_pos = ControlGetPos($Form1, "", $Desktop_Pic[$x])
$f_pos = WinGetPos($Form1)
WinMove($Hover_Form, "", $f_pos[0] + $a_pos[0] + 1, $f_pos[1] + $a_pos[1] + 1, $a_pos[2], $a_pos[3])
$Hover_Wait_Timer = 0
$cur_desktop = String($x)
ExitLoop
EndIf
Next
If $x = $Num_Of_Desktop And TimerDiff($Hover_Wait_Timer) > 500 And $Hover_Wait_Timer > 0 Then
$a_pos = ControlGetPos($Form1, "", $Desktop_Pic[$Curent_Desktop])
$f_pos = WinGetPos($Form1)
WinMove($Hover_Form, "", $f_pos[0] + $a_pos[0] + 1, $f_pos[1] + $a_pos[1] + 1, $a_pos[2], $a_pos[3])
$Hover_Wait_Timer = 0
ElseIf $x = $Num_Of_Desktop And $Hover_Wait_Timer = 0 Then
$Hover_Wait_Timer = TimerInit()
EndIf
If $Ginfo[2] And $Ginfo[4] = 0 And WinActive($Form1) Then
$a_pos = WinGetPos($Form1)
While _IsPressed(01)
If @error Then ExitLoop
$a_pos[1] = MouseGetPos(1) - $Ginfo[1]
If $a_pos[1] >= $DesktopSize[1] - $a_pos[3] Then $a_pos[1] = $DesktopSize[1] - $a_pos[3]
If $a_pos[1] <= 0 Then $a_pos[1] = 0
WinMove($Form1, "", $a_pos[0], $a_pos[1])
If MouseGetPos(0) > $DesktopSize[0] / 2 And $a_pos[0] <= 0 Then
$a_pos[0] = ($DesktopSize[0] - $a_pos[0]) - $a_pos[2]
ElseIf MouseGetPos(0) < $DesktopSize[0] / 2 And $a_pos[0] + $a_pos[2] >= $DesktopSize[0] Then
$a_pos[0] = ($DesktopSize[0] - $a_pos[0]) - $a_pos[2]
EndIf
Sleep(10)
WEnd
IniWrite(@ScriptDir & "\Data.ini", "Setings", "Default_Gui_Pos", $a_pos[0] & "," & $a_pos[1])
EndIf
EndIf
$Ginfo = GUIGetCursorInfo($Hover_Form)
If @error Then Return
If (WinActive($Form1) Or WinActive($Hover_Form)) And $Ginfo[0] > 0 And $Ginfo[0] < $Form_Size_X And $Ginfo[1] > 0 And $Ginfo[1] < $Form_Size_Y And $Ginfo[2] Then Return $cur_desktop
EndFunc ;==>_Effects
Func _Slide()
Local $i_dir, $s_dir = 0
Switch @GUI_CtrlId
Case $Slide_Button
If GUICtrlRead($Slide_Button) = "<" Then $i_dir = 1
$s_dir = "Right"
Case $Slide_Button2
If GUICtrlRead($Slide_Button2) = ">" Then $i_dir = 1
$s_dir = "Left"
EndSwitch
If $i_dir = 0 Then
_WinSlide($Form1, $s_dir, $i_dir, 15, 25)
Else
_WinSlide($Form1, $s_dir, $i_dir, 15, 20)
EndIf
If GUICtrlRead($Slide_Button) = ">" Then
GUICtrlSetData($Slide_Button, "<")
GUICtrlSetData($Slide_Button2, ">")
Else
GUICtrlSetData($Slide_Button, ">")
GUICtrlSetData($Slide_Button2, "<")
EndIf
Return
EndFunc ;==>_Slide
Func _WinSlide($s_hwnd, $s_dir, $i_dir, $i_speed = 10, $i_Stop = 0)
Local $a_pos = WinGetPos($Form1)
Local $i_sleeptime = 10
Local $i_step
Switch $i_dir
Case 0
Switch $s_dir
Case "Left"
For $x = $a_pos[2] - $i_Stop To $i_Stop Step -1 * _Sub($i_Stop, $a_pos[2]) / $i_speed
WinMove($s_hwnd, "", $x - $a_pos[2], $a_pos[1])
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $i_Stop - $a_pos[2], $a_pos[1])
Case "Right"
For $x = $DesktopSize[0] - ($a_pos[2] - $i_Stop) To $DesktopSize[0] - $i_Stop Step _Sub($DesktopSize[0] - ($a_pos[2] - $i_Stop), $DesktopSize[0] - $i_Stop) / $i_speed
WinMove($s_hwnd, "", $x, $a_pos[1])
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $DesktopSize[0] - $i_Stop, $a_pos[1])
Case "Up"
For $x = $a_pos[3] To $i_Stop Step -1 * _Sub($i_Stop, $a_pos[3]) / $i_speed
WinMove($s_hwnd, "", $a_pos[0], $x - $a_pos[3])
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $a_pos[0], $i_Stop - $a_pos[3])
Case "Down"
For $x = $DesktopSize[1] - $a_pos[3] To $DesktopSize[1] - $i_Stop Step _Sub($DesktopSize[1] - $a_pos[3], $DesktopSize[1] - $i_Stop) / $i_speed
WinMove($s_hwnd, "", $a_pos[0], $x)
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $a_pos[0], $DesktopSize[1] - $i_Stop)
EndSwitch
Case Else
Switch $s_dir
Case "Left"
For $x = $i_Stop To $a_pos[2] - $i_Stop Step _Sub($i_Stop, $a_pos[2]) / $i_speed
WinMove($s_hwnd, "", $x - $a_pos[2], $a_pos[1])
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", 0 - $i_Stop, $a_pos[1])
Case "Right"
For $x = $DesktopSize[0] - $i_Stop To $DesktopSize[0] - ($a_pos[2] + $i_Stop) Step -1 * _Sub($DesktopSize[0] - ($a_pos[2] + $i_Stop), $DesktopSize[0] - $i_Stop) / $i_speed
WinMove($s_hwnd, "", $x, $a_pos[1])
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $DesktopSize[0] - $a_pos[2] + $i_Stop, $a_pos[1])
Case "Up"
For $x = $i_Stop To $a_pos[3] Step _Sub($i_Stop, $a_pos[3]) / $i_speed
WinMove($s_hwnd, "", $a_pos[0], $x - $a_pos[3])
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $a_pos[0], 0 - $i_Stop)
Case "Down"
For $x = $DesktopSize[1] - $i_Stop To $DesktopSize[1] - $a_pos[3] + $i_Stop Step -1 * _Sub($DesktopSize[1] - $a_pos[3], $DesktopSize[1] - $i_Stop) / $i_speed
WinMove($s_hwnd, "", $a_pos[0], $x)
Sleep($i_sleeptime)
Next
WinMove($s_hwnd, "", $a_pos[0], $DesktopSize[1] - $a_pos[3])
EndSwitch
EndSwitch
Return
EndFunc ;==>_WinSlide
Func _Sub($s_Num1, $s_Num2)
If $s_Num1 > $s_Num2 Then Return $s_Num1 - $s_Num2
Return $s_Num2 - $s_Num1
EndFunc ;==>_Sub
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _Wallpaper_Change($s_BitmapImage, $l_params = 0)
Local $ai_Ret
$ai_Ret = DllCall('user32.dll', 'long', 'SystemParametersInfoA', 'long', 20, 'long', 0, 'str', $s_BitmapImage, 'long', $l_params)
RegWrite('HKEY_CURRENT_USER\Control Panel\Desktop', 'Wallpaper', 'REG_SZ', $s_BitmapImage)
Return $ai_Ret[0]
EndFunc ;==>_Wallpaper_Change
Func _Wallpaper_Get()
Return RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "WallPaper")
EndFunc ;==>_Wallpaper_Get
Func _ScreenShot()
Local $Reset_WinStyle = False
;_SetWinStat($Form1, 1)
;_SetWinStat($Hover_Form, 1)
If _IsPressed(10) Then
$Old_EX_STYLE = _WinAPI_GetWindowLong($Sticky_Window, $GWL_EXSTYLE) ;tnx komalo for this trick :P
WinSetTrans($Sticky_Window, "", 255)
Sleep(50)
$Reset_WinStyle = True
EndIf
_ScreenCapture_Capture(@TempDir & "\Desktop_" & $Curent_Desktop & ".bmp", 0, 0, $DesktopSize[0], $DesktopSize[1], False)
If $Reset_WinStyle Then _WinAPI_SetWindowLong($Sticky_Window, $GWL_EXSTYLE, $Old_EX_STYLE)
GUICtrlSetImage($Desktop_Pic[$Curent_Desktop], @TempDir & "\Desktop_" & $Curent_Desktop & ".bmp")
GUICtrlSetImage($Fade_Form_Pic, @TempDir & "\Desktop_" & $Curent_Desktop & ".bmp")
WinSetTrans($Hover_Form, "", 120)
;_SetWinStat($Form1, 2)
;_SetWinStat($Hover_Form, 2)
If $Fade_Trans Or $Slide_Trans Then DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Fade_Form, "int", 0, "long", 0x00080000)
EndFunc ;==>_ScreenShot
Func _ChangeDesktop($s_desktop)
Local $win, $x
If $s_desktop = $Curent_Desktop Then Return
$win = _GetWindows()
_ScreenShot()
If $win[0] > UBound($Desktop_Data, 2) - 1 Then ReDim $Desktop_Data[$Num_Of_Desktop][$win[0] + 1]
For $x = 1 To UBound($Desktop_Data, 2) - 1
$Desktop_Data[$Curent_Desktop][$x] = ""
Next
For $x = 1 To $win[0]
$Desktop_Data[$Curent_Desktop][$x] = $win[$x]
If $win[$x] = "" Then ContinueLoop
_SetWinStat($win[$x], 1)
Next
For $x = UBound($Desktop_Data, 2) - 1 To 1 Step -1
If $Desktop_Data[$s_desktop][$x] = "" Then ContinueLoop
_SetWinStat($Desktop_Data[$s_desktop][$x], 2)
Next
If _IsPressed(10) Then _SetWinStat($Sticky_Window, 2)
If $Desktop_Data[$s_desktop][0] <> _Wallpaper_Get() Then _Wallpaper_Change($Desktop_Data[$s_desktop][0], 3)
If $Fade_Trans Then
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Fade_Form, "int", $Trans_Speed, "long", 0x00090000)
ElseIf $Slide_Trans Then
If $s_desktop > $Curent_Desktop Then
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Fade_Form, "int", $Trans_Speed, "long", 0x00050002)
Else
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Fade_Form, "int", $Trans_Speed, "long", 0x00050001)
EndIf
EndIf
$Curent_Desktop = $s_desktop
EndFunc ;==>_ChangeDesktop
Func _SetWinStat($h_wnd, $i_stat)
Switch $i_stat
Case 1
_WinAPI_ShowWindow($h_wnd, @SW_HIDE)
Case 2
_WinAPI_ShowWindow($h_wnd, @SW_SHOW)
EndSwitch
EndFunc ;==>_SetWinStat
Func _GetWindows()
Local $aWindows, $i, $s_return, $i_count
$aWindows = WinList()
For $i = 1 To $aWindows[0][0]
If $aWindows[$i][0] = "" Then ContinueLoop
If Not _WinAPI_IsWindowVisible($aWindows[$i][1]) Then ContinueLoop
If StringInStr($Class_Blacklist, _WinAPI_GetClassName($aWindows[$i][1]) & "|") Then ContinueLoop
If _IsPressed(10) And $aWindows[$i][1] = $Sticky_Window Then ContinueLoop
$i_count += 1
If $Debug Then ConsoleWrite($i_count & ": " & $aWindows[$i][1] & " -> " & $aWindows[$i][0] & @CRLF)
$s_return &= $aWindows[$i][1] & Chr(1)
Next
Return StringSplit(StringTrimRight($s_return, 1), Chr(1))
EndFunc ;==>_GetWindows
Func OnAutoitExit()
For $y = 0 To UBound($Desktop_Data, 1) - 1
For $x = 0 To UBound($Desktop_Data, 2) - 1
If $Desktop_Data[$y][$x] = "" Then ContinueLoop
_SetWinStat($Desktop_Data[$y][$x], 2)
Next
Next
_Wallpaper_Change(IniRead(@ScriptDir & "\Data.ini", "Wallpaper", "Desktop_Default", _Wallpaper_Get()), 3)
EndFunc ;==>OnAutoitExit