This is simple plugin for moving, resize, hiding and applying a few different styles to a window. Originally it was meant to complement the
that was added to the plugin instead.
Code: Select all
class WindowStyler extends _UCR.Classes.Plugin
{
; Author: Helgef
; Date: 2016-11-30
; Version 1.
; Instructions at: https://autohotkey.com/boards/viewtopic.php?f=19&t=24538
; Credits to evilC for making UCR (https://github.com/evilC/UCR)
; Plugin variables
type:="WindowStyler"
description:="Edit a windows style and dimensions."
static linkTypes:={"Zoom":0, "WindowStyler":0, "CodeThread":0} ; List of plugin types that can be linked to.
init()
{
WinShow, % "ahk_id " this.sId
; Misc
this.WinTitle:="" ; Source wintitle
this.ucrHWND:=UCR.hwnd ; UCR hwnd, used in pickGame()
this.doNothingFunc:=ObjBindMethod(this,"doNothing")
; Gui
; Rows for gui placement
; Most controls are placed at rowX, colY, defined here:
row1:=" y35 ", row1_:=" y32 "
row2:=" y65 ", row2_:=" y62 "
row3:=" y95 ", row3_:=" y92 "
row4:=" y125 ", row4_:=" y123 "
row5:=" y155 ", row5_:=" y153 "
row6:=" y185 ", row6_:=" y183 "
row7:=" y215 ", row7_:=" y213 "
; Columns for gui placement
col1:=" x15 ", col2:=" x200 ", col3:=" x335 ", col4:=" x455 "
Gui, Add, Tab2, w650 h245, % "Window|Styles|Link|Help"
; Window tab
Gui, Tab, 1
; Pick game button.
; Button to initialise quick source pick routine.
this.AddControl("Edit","exe", 0, row1_ col2 " w125 h25")
Gui, Add, Text, % row2 " x32 ", % "and window title (optional):"
this.AddControl("Edit","title",0, row2_ col2 " w125 h25")
this.AddControl("Edit","hwndEdit",0, row3_ col2 " w125 h25")
Gui, Add, Radio, % row1 col1 "hwndsourceRadio1", % "Specify application name (exe):"
Gui, Add, Radio, % row3 col1 "hwndsourceRadio2", % "Use hwnd"
Gui, Add, Radio, % row4 col1 "hwndsourceRadio3", % "Use active window (Not recommended)"
this.sourceRadio1:=sourceRadio1
this.sourceRadio2:=sourceRadio2
this.sourceRadio3:=sourceRadio3
this.AddControl("Edit", "SourceRadioEdit", this.checkSourceRadio.Bind(this), "hidden disabled ReadOnly", 1) ; Hidden edit to hold radio choise
gFunc:=this.SourceRadioChanged.Bind(this)
GuiControl, +g, % this.sourceRadio1, % gFunc
GuiControl, +g, % this.sourceRadio2, % gFunc
GuiControl, +g, % this.sourceRadio3, % gFunc
Gui, Add, Button, % row1_ col3 " w125 hwndpickButton", % "Get source"
this.pickButton:=pickButton
gFunc := this.pickGame.Bind(this)
GuiControl +g, % this.pickButton, % gFunc
Gui, Add, Text, % row5 col1 , % "Hotkey to apply settings:"
this.AddControl("InputButton","hotkeyApply", 0, this.updateStyle.Bind(this), row5_ col2 " w125 h25")
; Styles tab.
col4:=" x485 " ; Modify column 4 for this tab
Gui, Tab, 2
; Custom window placment and size
Gui, Add, Text, % row1 col1, % "Position and dimension:"
this.AddControl("Checkbox", "useCustomWinPlacement", this.winBoxChanged.Bind(this), row2 col1, " Move to specified location")
Gui, Add, Button, % row2_ col2 "w110 hwndSelectRectButton disabled", % "Select area"
this.SelectRectButton:=SelectRectButton
gFunc := this.selectRect.Bind(this)
GuiControl +g, % this.SelectRectButton, % gFunc
Gui, Add, Text, % row3 col1 " hwndCWBText1 disabled", % "Position (x,y):"
this.CWBText1:=CWBText1
this.AddControl("Edit", "cwb_x1", 0, row3_ col2 " w50 Number Center Disabled")
this.AddControl( "Edit", "cwb_y1", 0, row3_ " x+10 w50 Number Center Disabled")
Gui, Add, Text, % row4 col1 " hwndCWBText2 disabled", % "Size (w,h):"
this.CWBText2:=CWBText2
this.AddControl("Edit", "cwb_w", 0, row4_ col2 " w50 Number Center Disabled")
this.AddControl( "Edit", "cwb_h", 0, row4_ " x+10 w50 Number Center Disabled")
this.AddControl("Checkbox", "offScreen", this.offScreen.Bind(this), row5 col1, "Move off screen")
this.AddControl("Checkbox", "fullscreen", this.fullscreen.Bind(this), row6 col1, "Resize to fullscreen")
; Styles
Gui, Add, Text, % row1 col3, % "Styles:"
this.AddControl("Checkbox", "noResize", 0, row2 col3 "Check3 checked-1", "No thick border")
this.AddControl("Checkbox", "noThinBorder", 0, row3 col3 "Check3 checked-1", "No thin border")
this.AddControl("Checkbox", "noCaption", 0, row4 col3 "Check3 checked-1", "No caption")
this.AddControl("Checkbox", "alwaysOnTop", 0, row5 col3 "Check3 checked-1", "Make always on top")
this.AddControl("Checkbox", "disableTransition", 0, row6 col3 "Check3 checked-1", "No transition animation")
this.AddControl("Checkbox", "info", this.infoCB.bind(this), row7 col3 "Check3 checked-1", "Info: Filled check means don't change")
this.AddControl("Checkbox", "transCB", this.transCB.Bind(this), row4 col4 "Check3 checked-1", "Trans level:") ; Enable tranparency
this.AddControl("edit", "transEdit", this.transEdit.Bind(this), row4_ "x+10 w55 center number limit3 disabled", 255)
this.AddControl("Checkbox", "clickThroughCB", 0, row5 col4 "Check3 checked-1", "Enable click-through") ; Enable click-through
this.AddControl("Checkbox", "transColorCB", this.transColorCB.Bind(this), row6 col4 "Check3 checked-1", "Trans color:") ; Enable transColor
this.AddControl("edit", "transColorEdit", this.transColorEdit.Bind(this), row6_ "x+9 w55 center limit6 disabled", "FFFFFF")
; DropDownLists
Gui, Add, Text, % row1 col4, % "Misc:"
this.AddControl("DropDownList", "topDDL", 0, row2 col4, "No choise made||Activate|Send to bottom|Maximise|Minimise")
this.AddControl("DropDownList", "hideDDL", 0, row3 col4, "No choise made||Hide|Un-hide")
Gui, Add, Button, % row7 col1 " w75 hwndApply", % "Apply"
this.ApplyButton:=Apply
gFunc := this.apply.Bind(this)
GuiControl +g, % this.ApplyButton, % gFunc
; Link tab
Gui, Tab, 3
col4:=" x455 " ; restore col
; Plugin lists.
caseOptions:="Never||Apply"
this.didNotRefreshPluginList:=1 ; Listboxes are disabled until lists has been refreshed once, then this is set to zero, until forever.
Gui, Add, Text, % row1 col1, % "Select plugin to run for case:"
this.AddControl("DropDownList", "DDLcase1", 0, row1_ "x+10 w105", caseOptions)
this.AddControl("ListBox", "lb_case1", this.selectLbItem.bind(this,1), row2 col1 " w250 r6 disabled","Please refresh")
Gui, Add, Text, % row5 col1, % "Delay call with: (ms)"
this.AddControl("Edit","case1Delay",0,row5_ " x215 w50 center number",0)
this.AddControl("Edit","lb_case1_selected_edit",0,"disabled hidden ReadOnly")
/*
; Currently, it makes no sens to have this, since this plugin only has one case, i.e., apply.
; But the code is "ready" for other cases, hence this is left for future convenience, should it be extended.
; There is also "check" for a second case in the code, these have not been commented out.
Gui, Add, Text, % row1 col3, % "Select plugin to run for case:"
this.AddControl("DropDownList", "DDLcase2", 0, row1_ "x+10 w105", caseOptions)
this.AddControl("ListBox", "lb_case2", this.selectLbItem.bind(this,2), row2 col3 " w250 r6 disabled","Please refresh")
this.AddControl("Edit","lb_case2_selected_edit",0,"disabled hidden ReadOnly")
Gui, Add, Text, % row5 col3, % "Delay call with: (ms)"
this.AddControl("Edit","case2Delay",0,row5_ " x535 w50 center number",0)
*/
Gui, Add, Button, % row6 col1 " w125 hwndRefreshButton", % "Refresh lists"
this.RefreshButton:=RefreshButton
gFunc := this.refreshPluginList.Bind(this)
GuiControl +g, % this.RefreshButton, % gFunc
Gui, Add, Text, % row6 col3 , % "Hotkey to stop all:"
this.AddControl("InputButton","HotkeyStop", 0, this.forceAllOff.Bind(this), row6_ col4 " w130 h25")
linkedToOptionsSame:="Apply||Ignore"
Gui, Add, Text, % row7 col1 , % "When linked to by same type:"
this.AddControl("DropDownList", "DDLlinkedToSame", 0, row7_ "x+10 w105", linkedToOptionsSame)
linkedToOptionsOther:="Apply||Ignore"
Gui, Add, Text, % row7 col3 , % "When linked to by other type:"
this.AddControl("DropDownList", "DDLlinkedToOther", 0, row7_ "x+10 w105", linkedToOptionsOther)
; Help tab
Gui, Tab, 4
Gui, add, text, % row1 col1, % "Author: Helgef"
Gui, add, text, % row2 col1, % "Date: 2016-11-30"
Gui, add, Link, % row3 col1, % "Instructions are available at: <a href=""https://autohotkey.com/boards/viewtopic.php?f=19&t=24538"">AutoHotkey.com forum.</a>"
Gui, add, Link, % col1 " y+5", % "Credits to evilC for making <a href=""https://github.com/evilC/UCR"">UCR.</a>"
Gui, add, text, % col1 "y+5 w500 +wrap" , % "Note:`nThis is a user plugin made for UCR. Neither the author of UCR nor the author of this plugin, is responsible for any outcome this piece of code yields."
}
onClose()
{
WinShow, % "ahk_id " this.sId ; Show window when closing UCR. For safety
GuiControl, -g, % this.pickButton
GuiControl, -g, % this.sourceRadio1
GuiControl, -g, % this.sourceRadio2
GuiControl, -g, % this.sourceRadio3
GuiControl, -g, % this.SelectRectButton
GuiControl, -g, % this.ApplyButton
this.extTimer:=""
GuiControl, -g, % this.RefreshButton
this.doNothingFunc:=""
base.onClose() ;?
return
}
; Gui functions.
; Transparency gui handling.
transCB(state)
{
GuiControl, % state=1?"Enable":"Disable", % this.GuiControls.transEdit.hwnd
return
}
transColorCB(state)
{
GuiControl, % state=1?"Enable":"Disable", % this.GuiControls.transColorEdit.hwnd
return
}
transEdit(val)
{
if (val>255)
this.GuiControls.transEdit.Set(255)
return
}
transColorEdit(val)
{
return ; Seems to trigger inf loop ?
if val is not xdigit
this.GuiControls.transColorEdit.Set("FFFFFF")
if (val<0)
this.GuiControls.transColorEdit.Set("000000")
else if (val>0xFFFFFF)
this.GuiControls.transColorEdit.Set("FFFFFF")
return
}
infoCB(state) ; Check box example, info.
{
if (state=-1)
this.GuiControls.info.Set("Info: Filled or gray means don't change this style")
else if (state=1)
this.GuiControls.info.Set("Info: Checked means set this style")
else if (state=0)
this.GuiControls.info.Set("Info: Empty means disable this style")
return
}
; DropDownList functions
topDDL(state)
{
; State is 1 if called from updateStyle, 0 if called from restoreStyles
; Options: No choise made||Activate|Send to bottom|Maximise|Minimise
selection:=this.GuiControls.topDDL.Get()
if (selection="No choise made")
return
else if (selection="Activate" && state)
WinActivate, % "ahk_id " this.sId
else if (selection="Send to bottom" && state)
WinSet, Bottom,, % "ahk_id " this.sId
else if (selection="Maximise" && state)
WinMaximize, % "ahk_id " this.sId
else if (selection="Maximise" && !state)
WinRestore, % "ahk_id " this.sId
else if (selection="Minimise" && state)
WinMinimize, % "ahk_id " this.sId
else if (selection="Minimise" && !state)
WinRestore, % "ahk_id " this.sId
return
}
hideDDL(state)
{
; State is 1 if called from updateStyle, 0 if called from restoreStyles
; Options No choise made||Hide
; NOTE: Option removed, still using ddl
selection:=this.GuiControls.hideDDL.Get()
if (selection="Un-hide")
WinShow, % "ahk_id " this.sId
else if (selection="Hide" && state)
WinHide, % "ahk_id " this.sId
else if (selection="Hide" && !state)
WinShow, % "ahk_id " this.sId
return
}
winBoxChanged(state)
{
; Enable / disable custom window coords depending on useCustomWinPlacement checkbox.
GuiControl, % state?"Enable":"Disable", % this.GuiControls.cwb_x1.hwnd
GuiControl, % state?"Enable":"Disable", % this.GuiControls.cwb_y1.hwnd
GuiControl, % state?"Enable":"Disable", % this.GuiControls.cwb_w.hwnd
GuiControl, % state?"Enable":"Disable", % this.GuiControls.cwb_h.hwnd
GuiControl, % state?"Enable":"Disable", % this.SelectRectButton
GuiControl, % state?"Enable":"Disable", % this.CWBText1
GuiControl, % state?"Enable":"Disable", % this.CWBText2
GuiControl, % !state?"Enable":"Disable", % this.GuiControls.fullscreen.hwnd
GuiControl, % !state?"Enable":"Disable", % this.GuiControls.offScreen.hwnd
return
}
; Select rect functions
; Select custom window rectangle
selectRect()
{
; this is called by the "Select area"-button. this.SelectRectButton
KeyWait, LButton ; Wait for LButton to be released.
fn:=this.doNothingFunc ; Hotkey function
Hotkey, If, 1
Hotkey, LButton, % fn, On
TrayTip,, % "Left click and drag over the area you want to zoom.",15,1
KeyWait, LButton, d ; Wait for LButton to be held down
CoordMode, Mouse, Screen
MouseGetPos,x,y,wum
WinActivate, % "ahk_id " wum
guiID:=this.makeDragBoxGui(x,y) ; Create the gui drag box.
timerFunc:=ObjBindMethod(this, "dragRect", x,y,guiID) ; Timer routine for resizing the gui drag box.
SetTimer, % timerFunc, 20
; Wait for LButton to be released.
KeyWait, LButton
; Delete the timer.
SetTimer, % timerFunc, Delete
this.setDragBoxCoords(wum, guiID) ; Set up the correct coords.
Hotkey, LButton, % fn, Off ; Turn off the LButton suppress
Hotkey, If
TrayTip,, % "Selection done!",10,1 ; Show tray tip and do some fancy fade out.
WinActivate, % "ahk_id " this.ucrHWND
Loop,30 ; Fancy fade out
{
WinSet, Transparent, % 125-A_Index*5, % "ahk_id " guiID
Sleep,10
}
Gui, %guiID%: Destroy ; Destroy drag box gui
CoordMode, Mouse, Window ; This doesn't really seem to be needed.
return
}
doNothing() ; for suppress LButton in selectRect().
{
return
}
setDragBoxCoords(wum,guiID)
{
; Sets up the custom win rectangle edit boxes after a drag box has been completed.
WinGetPos,dX,dY,dW,dH, % "ahk_id " guiID ; Get drag box gui pos and dimensions.
; Update edit boxes
this.GuiControls.cwb_x1.Set(dX)
this.GuiControls.cwb_y1.Set(dY)
this.GuiControls.cwb_w.Set(dW)
this.GuiControls.cwb_h.Set(dH)
return
}
makeDragBoxGui(x,y)
{
; Make the drag box gui, pop-up at location x,y
; return hwnd to the new gui.
Gui, new
Gui, +HWNDguiID +ToolWindow +AlwaysOnTop -Caption
Gui, %guiID%: Color, 7777FF ; UCR purple.
Gui, %guiID%: Show, x%x% y%y%
WinSet, Transparent, 125, % "ahk_id " guiID ; Make drag box transparent.
return guiID
}
dragRect(refX,refY,guiID)
{
; Function for resizing the drag box gui.
; This is only called via timer, no need to reset WinDelay and CoordMode.
CoordMode, Mouse, Screen
MouseGetPos,x,y
if (x<refX)
this.swapVar(x,refX)
if (y<refY)
this.swapVar(y,refY)
w:=abs(refX-x)
h:=abs(refY-y)
SetWinDelay,-1
WinMove, ahk_id %guiID%,,refX,refY,w,h
return
}
swapVar(ByRef a,ByRef b) ; Standard swap variable value function
{
c:=b, b:=a, a:=c
return
}
; For source radio buttons
checkSourceRadio()
{
; Check the correct radio button, according to saved value in hidden edit box
num:=this.GuiControls.SourceRadioEdit.Get()
GuiControl,, % this.sourceRadio1, % num=1
GuiControl,, % this.sourceRadio2, % num=2
GuiControl,, % this.sourceRadio3, % num=3
return
}
SourceRadioChanged()
{
; Saves radio button selection to hidden edit
GuiControlGet,num1,, % this.sourceRadio1
GuiControlGet,num2,, % this.sourceRadio2
GuiControlGet,num3,, % this.sourceRadio3
Loop, 3
if (num%A_Index% && (num:=A_Index))
break
this.GuiControls.SourceRadioEdit.Set(num) ; Hidden edit
return
}
pickGame()
{
; Point and click routine to set up exe, title and hwnd for window to style.
TrayTip,, % "Left-Click the game window`, click on UCR to abort.",30,1
KeyWait, LButton
KeyWait, LButton,D
MouseGetPos,,,wum
if (wum=this.ucrHWND) ; User clicked UCR, abort.
{
TrayTip,, % "Aborted.",10,1
return
}
WinActivate, % "ahk_id " this.ucrHWND ; Activate UCR again.
; Get window info
WinGetTitle, title, ahk_id %wum% ; Get window title
WinGet,exe, ProcessName, ahk_id %wum%
; Set edit fields
this.GuiControls.exe.Set(exe)
this.GuiControls.title.Set(title)
this.GuiControls.hwndEdit.Set(wum)
TrayTip,, % "Done!`nSelected:`n" exe "`n" title,10,1
this.settingChanged()
return
}
fullscreen(state)
{
if state
this.GuiControls.offScreen.Set(0)
return
}
offScreen(state)
{
if state
this.GuiControls.fullscreen.Set(0)
return
}
; Apply and button functions.
apply()
{
this.updateStyle(1)
return
}
updateStyle(state)
{
if !state
return
DHW_Setting:=A_DetectHiddenWindows
DetectHiddenWindows, On
this.sId:=WinExist(this.GetGameTitle()) ; Get source hWnd.
if !this.sId ; If source doesn't exist, return
{
DetectHiddenWindows, % DHW_Setting
return
}
if (this.GuiControls.noCaption.Get()!=-1)
WinSet, Style, % this.GuiControls.noCaption.Get()? "-0xC00000":"+0xC00000", % "ahk_id " this.sId
if (this.GuiControls.noThinBorder.Get()!=-1)
WinSet, Style, % this.GuiControls.noThinBorder.Get()?"-0x800000":"+0x800000", % "ahk_id " this.sId
if (this.GuiControls.noResize.Get()!=-1)
WinSet, Style, % this.GuiControls.noResize.Get()? "-0x40000":"+0x40000", % "ahk_id " this.sId
; Set desired position and dimension
if this.GuiControls.useCustomWinPlacement.Get()
{
; Set window to custom position and size.
x:=this.GuiControls.cwb_x1.Get(), y:=this.GuiControls.cwb_y1.Get()
w:=this.GuiControls.cwb_w.Get(), h:=this.GuiControls.cwb_h.Get()
WinMove, % "ahk_id " this.sId,,x,y,w,h
}
else if this.GuiControls.fullscreen.Get()
{
; Move window to 0,0 and resize to fit screen.
WinMove, % "ahk_id " this.sId,,0,0,A_ScreenWidth,A_ScreenHeight
}
else if this.GuiControls.offScreen.Get()
{
; Set window y position to 10000, off screen, probably
WinMove, % "ahk_id " this.sId,,,10000
}
if (this.GuiControls.alwaysOnTop.Get()!=-1)
WinSet,AlwaysOnTop, % this.GuiControls.alwaysOnTop.Get()?"On":"Off", % "ahk_id " this.sId
if (this.GuiControls.disableTransition.Get()!=-1)
this.Dwm_SetWindowAttributeTransistionDisable(this.sId,this.GuiControls.disableTransition.Get())
; Handle tranparency and trans color
; Only transColor or tranparency allowed.
if (this.GuiControls.clickThroughCB.Get()!=-1)
WinSet, ExStyle, % this.GuiControls.clickThroughCB.Get()=1?"+0x20":"-0x20", % "ahk_id " this.sId
if (this.GuiControls.transColorCB.Get()!=-1)
{
WinSet, Transparent, Off, % "ahk_id " this.sId
WinSet, TransColor, % this.GuiControls.transColorCB.Get()=1?this.GuiControls.transColorEdit.Get():"Off", % "ahk_id " this.sId
}
else if (this.GuiControls.transCB.Get()!=-1)
{
WinSet, TransColor, Off, % "ahk_id " this.sId
WinSet, Transparent, % this.GuiControls.transCB.Get()=1? this.GuiControls.transEdit.Get():"Off", % "ahk_id " this.sId
}
this.topDDL(1)
this.hideDDL(1)
WinSet, Redraw,, % "ahk_id " this.sId
DetectHiddenWindows, % DHW_Setting
; == Link ==
case:="Apply"
this.linkTrigger(case)
return
}
GetGameTitle()
{
; Source radio buttons
GuiControlGet,button1,, % this.sourceRadio1 ; Use game exe and title
GuiControlGet,button2,, % this.sourceRadio2 ; Use hwnd
GuiControlGet,button3,, % this.sourceRadio3 ; Use active window
; If using active window and window is hidden or moved, restore
if (button3 && this.sId!=WinActive("A"))
{
if this.wasMoved
WinMove, % "ahk_id " this.sId,, this.x, this.y, this.w, this.h
if this.wasHidden
WinShow, % "ahk_id " this.sId
this.wasMoved:=0
this.wasHidden:=0
}
if button1
{
exe:=this.GuiControls.exe.Get()
exe:= RegExMatch(exe,".exe$")?exe:exe ".exe" ; Append .exe if needed
wintitle:=this.GuiControls.title.Get()
return wintitle " ahk_exe " exe
}
if (button2 && (hwnd:=this.GuiControls.hwndEdit.Get()))
return "ahk_id " hwnd
if (button3 && (hwnd:=WinActive("A")))
return "ahk_id " hwnd
Msgbox, 16, Error, Couldn't determine source.,1
return 0
}
; DWM functions
Dwm_SetWindowAttributeTransistionDisable(hwnd,onOff)
{
;
; DWMWA_TRANSITIONS_FORCEDISABLED=3
; Use with DwmSetWindowAttribute. Enables or forcibly disables DWM transitions.
; The pvAttribute parameter points to a value of TRUE to disable transitions or FALSE to enable transitions.
;
dwAttribute:=3
cbAttribute:=4
VarSetCapacity(pvAttribute,4,0)
NumPut(onOff,pvAttribute,0,"Int")
hr:=DllCall("Dwmapi.dll\DwmSetWindowAttribute", "Uint", hwnd, "Uint", dwAttribute, "Uint", &pvAttribute, "Uint", cbAttribute)
return hr
}
; Link code.
selectLbItem(num,val)
{
; Set hidden edit field to hold selected items in plugin lists.
if (num=1)
this.GuiControls.lb_case1_selected_edit.set(val)
else if (num=2)
this.GuiControls.lb_case2_selected_edit.set(val)
return
}
refreshPluginList()
{
if this.didNotRefreshPluginList
{
this.didNotRefreshPluginList:=0
GuiControl, % "Enable", % this.GuiControls.lb_case1.hwnd
GuiControl, % "Enable", % this.GuiControls.lb_case2.hwnd
}
; Build list.
pluginList:=" - None - |"
for k, v in this.ParentProfile.Plugins
pluginList.=this.linkTypes.HasKey(v.type)?"|" v.name:""
this.pluginList:=pluginList
; Empty lists.
GuiControl,, % this.GuiControls.lb_case1.hwnd, % "|"
GuiControl,, % this.GuiControls.lb_case2.hwnd, % "|"
; Update.
GuiControl,, % this.GuiControls.lb_case1.hwnd, % this.pluginList
GuiControl,, % this.GuiControls.lb_case2.hwnd, % this.pluginList
; Restore selection.
this.GuiControls.lb_case1.Set(this.GuiControls.lb_case1_selected_edit.Get())
this.GuiControls.lb_case2.Set(this.GuiControls.lb_case2_selected_edit.Get())
return
}
externalCall(vars*)
{
; For now, only call with plugins preset settings. I.e., vars* is empty.
if this.foff ; Forced off, return
return
; Possible "actions" are: "Apply||Ignore"
if (vars[1].type=this.type)
action:=this.GuiControls.DDLlinkedToSame.Get() ; Match DDLlinkedToSame
else
action:=this.GuiControls.DDLlinkedToOther.Get() ; Match DDLlinkedToOther
if (action="Ignore")
return
else if (action="Apply")
this.apply()
return
}
forceOff()
{
; Force the plugin off. Depending on what the plugin does, this might not need to do anything.
extTimer:=this.extTimer
try
SetTimer, % extTimer, Delete ; Delete timer if it exists.
this.toggleState:=0 ; ensure correct toggle state.
this.restoreStyles()
return
}
forceAllOff(state)
{
; Shuts down all (linkTypes) plugins in current profile.
; When all has been forced off, call this function again to re-enable all.
if !state
return
if this.foff
{
for k, v in this.ParentProfile.Plugins
if this.linkTypes.HasKey(v.type)
v.foff:=0
return
}
for k, v in this.ParentProfile.Plugins
if this.linkTypes.HasKey(v.type)
v.foff:=1,v.forceOff()
return
}
linkTrigger(case)
{
; Call another plugin depending on 'case'
; 'case' is one of the options in the DDLcase1 or DDLcase2 DropDownLists. I.e., a string.
if !(case:=this.confirmCase(case))
return
; Case confirmed and converted to numeric, 1 or 2.
plugin:=this.getExternalPlugin(case)
if plugin
{
extParams:=this.getCaseParams(case)
extTimer:=ObjBindMethod(plugin,"externalCall",extParams*)
this.extTimer:=extTimer ; Needed to shut down chain.
if (case=1)
SetTimer, % extTimer, % (del:=this.GuiControls.case1Delay.Get())?-del:-1
else if (case=2)
SetTimer, % extTimer, % (del:=this.GuiControls.case2Delay.Get())?-del:-1
}
return
}
getCaseParams(case)
{
; Create an array of params to be passed to the external plugin.
; params[1] should contain a reference to the caller.
params:=[]
params[1]:=this
return params
}
confirmCase(case)
{
; Function to confirm the current event is selected as one case that will trigger another plugin.
if (case=this.GuiControls.DDLcase1.Get())
return 1
else if (case=this.GuiControls.DDLcase2.Get())
return 2
return 0 ; Case not confirmed, no external plugin should be called
}
getExternalPlugin(case)
{
; Check if an external plugin call should be made.
; If, return a reference to that plugin.
; case indicates which case occured, fetch correct plugin.
if (case=1)
pluginName:=this.GuiControls.lb_case1_selected_edit.Get()
else if (case=2)
pluginName:=this.GuiControls.lb_case2_selected_edit.Get()
if (pluginName=" - None - " || pluginName="") ; No plugin should be called
return
for k, plugin in this.ParentProfile.Plugins ; Search for plugin in the current profile.
if (plugin.name=pluginName)
return plugin
return 0 ; The plugin wasn't found.
}
; Used by the hotkey command in selectRect()
#If, 1
#If
}