Repository navigation
Expand file tree
/
Copy pathWindowLayoutManager.ahk
More file actions
202 lines (176 loc) · 5.38 KB
/
Copy pathWindowLayoutManager.ahk
File metadata and controls
202 lines (176 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#NoEnv
#SingleInstance, Force
SetWorkingDir, %A_ScriptDir%
global targetProgram := ""
global targetWindow := ""
global restoreFile := ""
global isCliMode := false
; 명령줄 인수 처리
if (A_Args.Length() = 3) {
targetProgram := A_Args[1]
targetWindow := A_Args[2]
restoreFile := A_Args[3]
isCliMode := true
GoSub, AutoRestore
} else if (A_Args.Length() >= 2) {
targetWindow := A_Args[1]
restoreFile := A_Args[2]
isCliMode := true
GoSub, AutoRestore
} else {
GoSub, ShowGUI
}
return
AutoRestore:
if (FindAndSelectWindow(targetWindow)) {
RestoreWindowInfo(restoreFile)
} else {
MsgBox, 지정된 창을 찾을 수 없습니다: %targetWindow%
}
ExitApp
ShowGUI:
Gui, Add, Text,, 대상 프로그램:
Gui, Add, DropDownList, vSelectedProgram gUpdateSelected
Gui, Add, Button, gSaveWindowInfo, 위치/크기 저장
Gui, Add, Button, gRestoreWindowInfo, 위치/크기 복원
Gui, Add, Button, gRefreshList, 프로그램 목록 새로고침
Gui, Show,, 창 위치/크기 관리자
GoSub, RefreshList
return
UpdateSelected:
Gui, Submit, NoHide
targetProgram := SelectedProgram
return
SaveWindowInfo:
if (targetProgram = "") {
MsgBox, 프로그램을 선택하세요.
return
}
WinGetPos, x, y, w, h, %targetProgram%
FileSelectFile, file, S16,, 창 정보 저장, INI (*.ini)
if (file = "")
return
IniWrite, %x%, %file%, MainWindow, X
IniWrite, %y%, %file%, MainWindow, Y
IniWrite, %w%, %file%, MainWindow, Width
IniWrite, %h%, %file%, MainWindow, Height
SaveUIElements(targetProgram, file)
MsgBox, 창 정보와 내부 UI 요소 정보가 저장되었습니다.
return
RestoreWindowInfo:
if (!isCliMode) {
if (targetProgram = "") {
MsgBox, 프로그램을 선택하세요.
return
}
FileSelectFile, file, 3,, 창 정보 불러오기, INI (*.ini)
if (file = "")
return
} else {
file := restoreFile
}
RestoreWindowInfo(file)
return
RestoreWindowInfo(file) {
if (!WinExist(targetProgram)) {
MsgBox, 지정된 창을 찾을 수 없습니다: %targetProgram%
return
}
IniRead, x, %file%, MainWindow, X, ERROR
IniRead, y, %file%, MainWindow, Y, ERROR
IniRead, w, %file%, MainWindow, Width, ERROR
IniRead, h, %file%, MainWindow, Height, ERROR
if ((x = "ERROR" or y = "ERROR" or w = "ERROR" or h = "ERROR") and !isCliMode) {
MsgBox, 파일에서 창 정보를 읽을 수 없습니다.
return
}
; 현재 창 크기 확인
WinGetPos, currentX, currentY, currentW, currentH, %targetProgram%
; 최소 크기 설정 (예: 100x100)
w := (w < 100) ? 100 : w
h := (h < 100) ? 100 : h
WinMove, %targetProgram%,, %x%, %y%, %w%, %h%
RestoreUIElements(targetProgram, file)
if (isCliMode) {
FileAppend, 창 위치/크기 복원 완료 - X: %x%, Y: %y%, W: %w%, H: %h%`n, *
} else {
MsgBox, 창 위치와 내부 UI 요소 위치가 복원되었습니다.
}
}
RefreshList:
WinGet, id, List,,, Program Manager
GuiControl,, SelectedProgram, |
Loop, %id%
{
this_id := id%A_Index%
WinGetTitle, title, ahk_id %this_id%
if (title != "")
GuiControl,, SelectedProgram, %title%
}
; 명령줄 인수로 받은 창 자동 선택
if (targetWindow != "") {
if (FindAndSelectWindow(targetWindow)) {
GuiControl, Choose, SelectedProgram, %targetProgram%
}
}
return
FindAndSelectWindow(windowName) {
WinGet, id, List,,, Program Manager
bestMatch := ""
bestMatchScore := 0
Loop, %id%
{
this_id := id%A_Index%
WinGetTitle, title, ahk_id %this_id%
if (title != "") {
matchScore := CalculateMatchScore(title, windowName)
if (matchScore > bestMatchScore) {
bestMatch := title
bestMatchScore := matchScore
}
}
}
if (bestMatch != "") {
targetProgram := bestMatch
if (isCliMode) {
FileAppend, 선택된 창: %targetProgram%`n, *
}
return true
}
return false
}
CalculateMatchScore(str1, str2) {
score := 0
Loop, Parse, str2, %A_Space%
{
if (InStr(str1, A_LoopField))
score += StrLen(A_LoopField)
}
return score
}
SaveUIElements(winTitle, file) {
WinGet, controlList, ControlList, %winTitle%
Loop, Parse, controlList, `n
{
ControlGetPos, cx, cy, cw, ch, %A_LoopField%, %winTitle%
IniWrite, %cx%, %file%, UIElements, %A_LoopField%_X
IniWrite, %cy%, %file%, UIElements, %A_LoopField%_Y
IniWrite, %cw%, %file%, UIElements, %A_LoopField%_Width
IniWrite, %ch%, %file%, UIElements, %A_LoopField%_Height
}
}
RestoreUIElements(winTitle, file) {
WinGet, controlList, ControlList, %winTitle%
Loop, Parse, controlList, `n
{
IniRead, cx, %file%, UIElements, %A_LoopField%_X, ERROR
IniRead, cy, %file%, UIElements, %A_LoopField%_Y, ERROR
IniRead, cw, %file%, UIElements, %A_LoopField%_Width, ERROR
IniRead, ch, %file%, UIElements, %A_LoopField%_Height, ERROR
if (cx != "ERROR" and cy != "ERROR" and cw != "ERROR" and ch != "ERROR") {
ControlMove, %A_LoopField%, %cx%, %cy%, %cw%, %ch%, %winTitle%
}
}
}
GuiClose:
ExitApp