Skip to content

Commit

Permalink
Add trial for pro features
Browse files Browse the repository at this point in the history
  • Loading branch information
chaohershi committed Oct 5, 2020
1 parent f612bbd commit 52b4c47
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 32 deletions.
124 changes: 114 additions & 10 deletions Advanced Settings.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ if WinExist()
}

; retrieve the title bar exception list
IniRead, exceptionList, %ConfigFile%, Advanced, TitleBarExceptionList, %A_Space%
exceptionList := TitleBarExceptionList
blackList := EscHotkeyBlackList

; create advanced settings GUI
Gui, 1:New, hwndhGui AlwaysOnTop
Gui, 1:Default

; settings tab
Gui, Add, Tab3, , %TEXT_TitleBarExceptionList%
Gui, Add, Tab3, , %TEXT_TitleBarExceptionList%|%TEXT_EscHotkeyBlackList%

; title bar exception list
Gui, Tab, 1

Gui, Add, Edit, Section w240 r4 ReadOnly -VScroll -Wrap vCtrl_Title
Gui, Add, Checkbox, w240 vCtrl_FollowMouse, %TEXT_FollowMouse%
Gui, Add, Checkbox, w240 vCtrl_FollowMouse gUpdateCheckBox, %TEXT_FollowMouse%
Gui, Add, Text, w240 r1 vCtrl_Freeze, %TEXT_NotFrozen%
Gui, Add, Button, ys w75 h23 vAddItem gAddItem, %TEXT_Add%

Expand All @@ -31,14 +32,29 @@ Gui, Add, Button, ys w75 h23 vDeleteItem gDeleteItem, %TEXT_Delete%

GBW2 := GroupBoxForTab3("GB2", TEXT_ExceptionList, 10, 10, "Ctrl_ListBox|DeleteItem")

; esc hotkey exception list
Gui, Tab, 2

Gui, Add, Edit, Section w240 r4 ReadOnly -VScroll -Wrap vCtrl_Title2
Gui, Add, Checkbox, w240 vCtrl_FollowMouse2 gUpdateCheckBox2, %TEXT_FollowMouse%
Gui, Add, Text, w240 r1 vCtrl_Freeze2, %TEXT_NotFrozen%
Gui, Add, Button, ys w75 h23 vAddItem2 gAddItem2, %TEXT_Add%

GBW3 := GroupBoxForTab3("GB3", TEXT_WindowInfo, 10, 10, "Ctrl_Title2|Ctrl_FollowMouse2|Ctrl_Freeze2|AddItem2")

Gui, Add, ListBox, Section xs AltSubmit r5 w240 vCtrl_ListBox2, %blackList%
Gui, Add, Button, ys w75 h23 vDeleteItem2 gDeleteItem2, %TEXT_Delete%

GBW4 := GroupBoxForTab3("GB4", TEXT_BlackList, 10, 10, "Ctrl_ListBox2|DeleteItem2")

; create hotkeys for suspending updates
Hotkey, ~*Ctrl, StopUpdate, On
Hotkey, ~*Shift, StopUpdate, On
Hotkey, ~*Ctrl up, StartUpdate, On
Hotkey, ~*Shift up, StartUpdate, On
Gosub, Update ; make the first execution to be immediate https://www.autohotkey.com/docs/commands/SetTimer.htm#Remarks
;Gosub, Update ; make the first execution to be immediate https://www.autohotkey.com/docs/commands/SetTimer.htm#Remarks
SetTimer, Update, 250
Gui, Show, NoActivate, %TEXT_AdvancedSettings%
Gui, Show, NoActivate, %TEXT_AdvancedSettingsTrial%
Return

; https://autohotkey.com/board/topic/71065-groupbox-addwrap-around-existing-controls/
Expand All @@ -59,6 +75,31 @@ GroupBoxForTab3(GBvName, Title, TitleH, Margin, Piped_CtrlvNames, FixedWidth :=
Return, GBW
}

; synchronize two check boxes
UpdateCheckBox:
GuiControlGet, Ctrl_FollowMouse
if Ctrl_FollowMouse
{
GuiControl, , Ctrl_FollowMouse2, 1
}
else
{
GuiControl, , Ctrl_FollowMouse2, 0
}
Return

UpdateCheckBox2:
GuiControlGet, Ctrl_FollowMouse2
if Ctrl_FollowMouse2
{
GuiControl, , Ctrl_FollowMouse, 1
}
else
{
GuiControl, , Ctrl_FollowMouse, 0
}
Return

AddItem:
if (exeItem == "") ; don't add empty item
{
Expand Down Expand Up @@ -89,6 +130,36 @@ Gosub, Save
GuiControl, , Ctrl_ListBox, %exeItem%|| ; add the item to the ListBox and select it
Return

AddItem2:
if (exeItem == "") ; don't add empty item
{
Return
}
else
{
Loop, Parse, blackList, `|
{
if (exeItem == A_LoopField) ; if item already exists
{
GuiControl, Choose, Ctrl_ListBox2, %A_Index% ; select the existed item instead
Return
}
}
}
; add item
if (blackList == "")
{
blackList .= exeItem
}
else
{
blackList .= "|"
blackList .= exeItem
}
Gosub, Save
GuiControl, , Ctrl_ListBox2, %exeItem%|| ; add the item to the ListBox and select it
Return

DeleteItem:
Gui %hGui%:Submit, NoHide
newList := ""
Expand All @@ -108,10 +179,29 @@ GuiControl, , Ctrl_ListBox, |%exceptionList% ; construct new ListBox
GuiControl, Choose, Ctrl_ListBox, %Ctrl_ListBox% ; select the item below the deleted one
Return

DeleteItem2:
Gui %hGui%:Submit, NoHide
newList := ""
Loop, Parse, blackList, `|
{
if (A_Index == Ctrl_ListBox2)
{
Continue
}
newList := newList . A_LoopField . "|"

}
newList := SubStr(newList, 1, -1) ; remove the trailing delimiter
blackList := newList
Gosub, Save
GuiControl, , Ctrl_ListBox2, |%blackList% ; construct new ListBox
GuiControl, Choose, Ctrl_ListBox2, %Ctrl_ListBox2% ; select the item below the deleted one
Return

Save:
Gosub, EnsureConfigDirExists
IniWrite, %exceptionList%, %ConfigFile%, Advanced, TitleBarExceptionList ; update the exception list setting
TitleBarExceptionList := exceptionList
EscHotkeyBlackList := blackList
Return

GuiSize:
Expand All @@ -120,7 +210,7 @@ SetTimer, Update, % A_EventInfo == 1 ? "Off" : "On" ; suspend on minimize
Return

Update:
Gui %hGui%:Default
;Gui %hGui%:Default
GuiControlGet, Ctrl_FollowMouse
CoordMode, Mouse, Screen
MouseGetPos, msX, msY, msWin, msCtrl
Expand All @@ -138,17 +228,20 @@ else
}
WinGetTitle, t1
WinGetClass, t2
if (curWin == hGui || t2 == "MultitaskingViewFrame") ; our Gui || Alt-tab
if (curWin == hGui || t2 == "MultitaskingViewFrame") ; Our Gui || Alt-tab
{
UpdateText("Ctrl_Freeze", TEXT_Frozen)
UpdateText("Ctrl_Freeze2", TEXT_Frozen)
Return
}
UpdateText("Ctrl_Freeze", TEXT_NotFrozen)
UpdateText("Ctrl_Freeze2", TEXT_NotFrozen)
WinGet, t3, ProcessName
WinGet, t4, PID
;classItem := t2
exeItem := t3
UpdateText("Ctrl_Title", "Title " t1 "`nClass " t2 "`nEXE " t3 "`nPID " t4)
UpdateText("Ctrl_Title2", "Title " t1 "`nClass " t2 "`nEXE " t3 "`nPID " t4)
CoordMode, Mouse, Relative
CoordMode, Mouse, Client
Return
Expand All @@ -158,8 +251,19 @@ Hotkey, ~*Ctrl, Off
Hotkey, ~*Shift, Off
Hotkey, ~*Ctrl up, Off
Hotkey, ~*Shift up, Off
SetTimer, Update, Off
SetTimer, Update, Delete
Gui %hGui%:Destroy
Process, Exist
DetectHiddenWindows, On
if WinExist(TEXT_TrialNotice . " ahk_class #32770 ahk_pid " . ErrorLevel) ; if the trial message already exists
{
WinShow ; show the message window if it is hidden
WinActivate
}
else ; else display the trial message
{
MsgBox, 0, %TEXT_TrialNotice%, %TEXT_TrialMsg%
}
Return

WinGetTextFast(detect_hidden)
Expand Down Expand Up @@ -204,6 +308,7 @@ StopUpdate:
;}
SetTimer, Update, Off
UpdateText("Ctrl_Freeze", TEXT_Frozen)
UpdateText("Ctrl_Freeze2", TEXT_Frozen)
Return

StartUpdate:
Expand All @@ -214,4 +319,3 @@ StartUpdate:
;}
SetTimer, Update, On
Return

88 changes: 66 additions & 22 deletions CClose.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ LangFile := "lang.ini"
; set the script language
if (A_Language == "0804") ; https://autohotkey.com/docs/misc/Languages.htm
{
Language := "Chinese"
Language := "Chinese"
}
else ; use English by default
{
Language := "English"
Language := "English"
}

; set the script texts
Expand All @@ -30,6 +30,7 @@ IniRead, TEXT_Help, %LangFile%, %Language%, TEXT_Help, Help
IniRead, TEXT_About, %LangFile%, %Language%, TEXT_About, About
IniRead, TEXT_Exit, %LangFile%, %Language%, TEXT_Exit, Exit
IniRead, TEXT_Update, %LangFile%, %Language%, TEXT_Update, Update
IniRead, TEXT_Updater, %LangFile%, %Language%, TEXT_Updater, Updater
IniRead, TEXT_Close, %LangFile%, %Language%, TEXT_Close, Close
IniRead, TEXT_Checking_For_Updates, %LangFile%, %Language%, TEXT_Checking_For_Updates, Checking for updates...
IniRead, TEXT_Updater_Not_Found, %LangFile%, %Language%, TEXT_Updater_Not_Found, Updater not found!
Expand All @@ -41,19 +42,30 @@ IniRead, TEXT_MenuTitleBarRightClick, %LangFile%, %Language%, TEXT_MenuTitleBarR
IniRead, TEXT_MenuTitleBarHoldLeftClick, %LangFile%, %Language%, TEXT_MenuTitleBarHoldLeftClick, Hold left click on title bar to toggle window always on top
IniRead, TEXT_MenuEscKeyDoublePress, %LangFile%, %Language%, TEXT_MenuEscKeyDoublePress, Double press Esc key to close active window
IniRead, TEXT_MenuTaskbarButtonRightClick, %LangFile%, %Language%, TEXT_MenuTaskbarButtonRightClick, Right click on taskbar button to move pointer to "Close window"
IniRead, TEXT_HelpMsg1, %LangFile%, %Language%, TEXT_HelpMsg1, Middle click + title bar[1] = close window
IniRead, TEXT_HelpMsg2, %LangFile%, %Language%, TEXT_HelpMsg2, Right click + title bar[1] = minimize window[2]
IniRead, TEXT_HelpMsg3, %LangFile%, %Language%, TEXT_HelpMsg3, Hold left click + title bar[1] = toggle window always on top
IniRead, TEXT_HelpMsg4, %LangFile%, %Language%, TEXT_HelpMsg4, Double press + Esc key = close active window
IniRead, TEXT_HelpMsg5, %LangFile%, %Language%, TEXT_HelpMsg5, Right click + taskbar button = move pointer to "Close window"
IniRead, TEXT_HelpMsg6, %LangFile%, %Language%, TEXT_HelpMsg6, [1] Few programs don't have proper GUIs. Either there isn't a title bar, or the whole interface is technically a giant title bar. In such cases, title bar related functions will not work as expected. You can solve this issue by adding those programs to the exception list in advanced settings.
IniRead, TEXT_HelpMsg7, %LangFile%, %Language%, TEXT_HelpMsg7, [2] Hold right click for a normal right click.
TEXT_HelpMsg := TEXT_HelpMsg1 . "`n" . TEXT_HelpMsg2 . "`n" . TEXT_HelpMsg3 . "`n" . TEXT_HelpMsg4 . "`n" . TEXT_HelpMsg5 . "`n`n" . TEXT_HelpMsg6 . "`n`n" . TEXT_HelpMsg7
IniRead, TEXT_HelpMsg1, %LangFile%, %Language%, TEXT_HelpMsg1, Middle click + title bar[1][2] = close window
IniRead, TEXT_HelpMsg2, %LangFile%, %Language%, TEXT_HelpMsg2, Right click + title bar[1][2] = minimize window[3]
IniRead, TEXT_HelpMsg3, %LangFile%, %Language%, TEXT_HelpMsg3, Hold left click + title bar[1][2] = toggle window always on top
IniRead, TEXT_HelpMsg4, %LangFile%, %Language%, TEXT_HelpMsg4, Double press + Esc key = close active window
IniRead, TEXT_HelpMsg5, %LangFile%, %Language%, TEXT_HelpMsg5, Right click + taskbar button = move pointer to "Close window"
IniRead, TEXT_HelpMsg6, %LangFile%, %Language%, TEXT_HelpMsg6, [1] If CClose is installed outside the default directory Program Files, you need to run it as administrator to manipulate high-privileged windows, e.g. the Task Manager.
IniRead, TEXT_HelpMsg7, %LangFile%, %Language%, TEXT_HelpMsg7, [2] Few programs don't have proper GUIs. Either there isn't a title bar, or the whole interface is technically a giant title bar. In such cases, title bar related functions will not work as expected. You can solve this issue by adding those programs to the exception list in advanced settings (Pro version required).
IniRead, TEXT_HelpMsg8, %LangFile%, %Language%, TEXT_HelpMsg8, [3] Hold right click for a normal right click.
TEXT_HelpMsg := TEXT_HelpMsg1 . "`n" . TEXT_HelpMsg2 . "`n" . TEXT_HelpMsg3 . "`n" . TEXT_HelpMsg4 . "`n" . TEXT_HelpMsg5 . "`n`n" . TEXT_HelpMsg6 . "`n`n" . TEXT_HelpMsg7 . "`n`n" . TEXT_HelpMsg8
TEXT_AboutMsg := ScriptName . " " . ScriptVersion . "`n`n" . CopyrightNotice

IniRead, TEXT_AdvancedSettings, %LangFile%, %Language%, TEXT_AdvancedSettings, Advanced Settings
IniRead, TEXT_GetPro, %LangFile%, %Language%, TEXT_GetPro, Upgrade to Pro
IniRead, TEXT_GetProMsg1, %LangFile%, %Language%, TEXT_GetProMsg1, Upgrade to CClose Pro to unlock extra features, including:
IniRead, TEXT_GetProMsg2, %LangFile%, %Language%, TEXT_GetProMsg2, - Support windows without proper title bar
IniRead, TEXT_GetProMsg3, %LangFile%, %Language%, TEXT_GetProMsg3, - Blacklist for Esc key feature
IniRead, TEXT_GetProMsg4, %LangFile%, %Language%, TEXT_GetProMsg4, - Support the developer and future updates
IniRead, TEXT_GetProMsg5, %LangFile%, %Language%, TEXT_GetProMsg5, Proceed to upgrade?
TEXT_GetProMsg := TEXT_GetProMsg1 . "`n`n" . TEXT_GetProMsg2 . "`n" . TEXT_GetProMsg3 . "`n" . TEXT_GetProMsg4 . "`n`n" . TEXT_GetProMsg5

IniRead, TEXT_AdvancedSettingsTrial, %LangFile%, %Language%, TEXT_AdvancedSettingsTrial, Advanced Settings (Trial)
IniRead, TEXT_TrialNotice, %LangFile%, %Language%, TEXT_TrialNotice, Trial Notice
IniRead, TEXT_TrialMsg, %LangFile%, %Language%, TEXT_TrialMsg, The trial version allows you to test out some selected Pro features. However, the settings you made will not be saved beyond the current session. If you enjoy using CClose, please consider upgrading to Pro for a small fee to support the developer and future updates, thank you!

IniRead, TEXT_TitleBarExceptionList, %LangFile%, %Language%, TEXT_TitleBarExceptionList, Title Bar Exception List
IniRead, TEXT_EscHotkeyBlackList , %LangFile%, %Language%, TEXT_EscHotkeyBlackList, Esc Hotkey Blacklist
IniRead, TEXT_WindowInfo, %LangFile%, %Language%, TEXT_WindowInfo, Window Info
IniRead, TEXT_Title, %LangFile%, %Language%, TEXT_Title, Title
IniRead, TEXT_Class, %LangFile%, %Language%, TEXT_Class, Class
Expand All @@ -64,7 +76,7 @@ IniRead, TEXT_NotFrozen, %LangFile%, %Language%, TEXT_NotFrozen, (Hold Ctrl or S
IniRead, TEXT_Frozen, %LangFile%, %Language%, TEXT_Frozen, (Updates suspended)
IniRead, TEXT_BlackList, %LangFile%, %Language%, TEXT_BlackList, Blacklist
IniRead, TEXT_ExceptionList, %LangFile%, %Language%, TEXT_ExceptionList, Exception List
IniRead, TEXT_Add, %LangFile%, %Language%, TEXT_AddClass, Add
IniRead, TEXT_Add, %LangFile%, %Language%, TEXT_Add, Add
IniRead, TEXT_Delete, %LangFile%, %Language%, TEXT_Delete, Delete

; add the tray menu
Expand All @@ -80,11 +92,12 @@ Menu, SettingMenu, Add, %TEXT_MenuTitleBarHoldLeftClick%, ConfigSetting
Menu, SettingMenu, Add, %TEXT_MenuEscKeyDoublePress%, ConfigSetting
Menu, SettingMenu, Add, %TEXT_MenuTaskbarButtonRightClick%, ConfigSetting
Menu, SettingMenu, Add
Menu, SettingMenu, Add, %TEXT_AdvancedSettings%, ConfigAdvSetting
Menu, SettingMenu, Add, %TEXT_AdvancedSettingsTrial%, ConfigAdvSetting
Menu, Tray, Add, %TEXT_Settings%, :SettingMenu
Menu, Tray, Add
Menu, Tray, Add, %TEXT_Help%, ShowHelpMsg
Menu, Tray, Add, %TEXT_About%, ShowAboutMsg
Menu, Tray, Add, %TEXT_GetPro%, ShowGetProMsg
Menu, Tray, Add
Menu, Tray, Add, %TEXT_Exit%, ExitProgram
Menu, Tray, Tip, %ScriptName% ; change the tray icon's tooltip
Expand Down Expand Up @@ -170,8 +183,9 @@ else ; else update the autostart setting
IniWrite, %IsAutostart%, %ConfigFile%, Autostart, EnableAutostart ; update the autostart setting
}

; retrieve the list of apps that have no title bars or entire GUI as title bars
IniRead, TitleBarExceptionList, %ConfigFile%, Advanced, TitleBarExceptionList, %A_Space%
; retrieve the advanced settings
TitleBarExceptionList := ""
EscHotkeyBlackList := ""

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Return ; end of the auto-execute section
Expand Down Expand Up @@ -286,11 +300,15 @@ else ; else display the about message
{
if FileExist("Updater.exe")
{
TrayTip, %ScriptName%, %TEXT_Checking_For_Updates%
Run %A_ScriptDir%\Updater.exe /A
Sleep, 1000
WinWait, ahk_exe Updater.exe, , 20
HideTrayTip() ; https://autohotkey.com/docs/commands/TrayTip.htm#Remarks
if WinExist(ScriptName . " ahk_exe Updater.exe") ; if the updater already exists
{
WinShow ; show the message window if it is hidden
WinActivate
}
else
{
Run, %A_ScriptDir%\Updater.exe
}
}
else
{
Expand All @@ -300,6 +318,24 @@ else ; else display the about message
}
Return

ShowGetProMsg:
Process, Exist
DetectHiddenWindows, On
if WinExist(TEXT_GetPro . " ahk_class #32770 ahk_pid " . ErrorLevel) ; if the get pro message already exists
{
WinShow ; show the message window if it is hidden
WinActivate
}
else ; else display the get pro message
{
MsgBox, 1, %TEXT_GetPro%, %TEXT_GetProMsg%
IfMsgBox, OK
{
Run, https://chaohershi.github.io/cclose/
}
}
Return

ExitProgram:
ExitApp

Expand All @@ -317,7 +353,7 @@ WM_COMMNOTIFY(wParam)
DetectHiddenWindows, On
if WinExist(TEXT_About . " ahk_class #32770 ahk_pid " . ErrorLevel)
{
ControlSetText, Button1, &%TEXT_Update%
ControlSetText, Button1, &%TEXT_Updater%
ControlSetText, Button2, &%TEXT_Close%
}
}
Expand Down Expand Up @@ -440,6 +476,14 @@ Return
#If, true ; apply the following hotkey with no conditions
~Esc::
WinGet, idOld, ID, A ; get the window id
WinGet, exeName, ProcessName, A ; get the EXE name
Loop, Parse, EscHotkeyBlackList, `|
{
if (exeName == A_LoopField) ; if item already exists
{
Return
}
}
KeyWait, Esc ; wait for the Esc key to be released
KeyWait, Esc, D, T0.4 ; wait for the Esc key to be pressed again
if (ErrorLevel == 0)
Expand Down
Binary file modified lang.ini
Binary file not shown.

0 comments on commit 52b4c47

Please sign in to comment.