-
Notifications
You must be signed in to change notification settings - Fork 41
/
WPXA.ahk
1534 lines (1292 loc) · 46.5 KB
/
WPXA.ahk
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Title: WindowPadX-Actions library
Implementation of different useful actions for handling windows in general and within a multi-monitor setup in special.
Functions starting with the prefix *WPXA* are designed to be used as user-actions within *WindowPadX*, whereas functions starting with the prefix *wp* are internal helper functions.
Author:
hoppfrosch
License:
WTFPL (http://sam.zoy.org/wtfpl/)
Credits:
Lexikos - for his great work and his Original *WindowPad - multi-monitor window-moving tool* (http://www.autohotkey.com/forum/topic21703.html)
ShinyWong - for his *GetMonitorIndexFromWindow* function (http://www.autohotkey.com/forum/viewtopic.php?p=462080#462080) - used in <wp_GetMonitorFromWindow>
Skrommel - for his *MouseMark* function (http://www.donationcoder.com/Software/Skrommel/MouseMark/MouseMark.ahk) - used in <WPXA_MouseLocator>
x97animal - for his *clipCursor* Function (http://www.autohotkey.com/forum/viewtopic.php?p=409537#409537) - used in <wp_ClipCursor>
ipstone today - for his initial implementation (http://www.autohotkey.com/forum/viewtopic.php?p=521482#521482) for <WPXA_TileLast2Windows>
Sean - for his *WinTrayMin* functionality (http://http://www.autohotkey.com/community/viewtopic.php?f=2&t=33263) - used in <wp_WinTrayMin>
gwarble - for his great *Notify* function (http://www.autohotkey.com/community/viewtopic.php?f=2&t=48668)
Changelog:
0.2.0 - [-] Removed <wp_RollWindow>
[-] Removed <wp_UnrollWindow>
[+] <wp_RollWindowToggle>: Toggles Roll/Unroll State of window. (Corrected behaviour after manually resizing a previously rolled window)
[*] Adapted <WPXA_RollToggle> to use wp_RollWindowToggle
0.1.12 - [*] Internal Changes: Update to Notify 0.499 (http://www.autohotkey.com/community/viewtopic.php?f=2&t=48668), Introduced Global variables for easier configuration ...
0.1.11 - [+] <wp_WinTraymin> : Minimize a window to a tray icon (see: http://http://www.autohotkey.com/community/viewtopic.php?f=2&t=33263 - thanks to Sean)
{+] <WPXA_TrayMinWindow>: Mininmize a window to a tray icon (see <wp_TrayMin>)
0.1.10 - [+] <wp_GetMonitorFromMouse>: Determines monitor from current mouseposition.
[*] <WPXA_MinimizeWindowsOnMonitor>: added minimization of all windows on screen where mouse is.
0.1.9 - [+] <WPXA_TileLast2Windows>: Tile active and last window (see: http://www.autohotkey.com/forum/viewtopic.php?p=521482#521482 - thanks to ipstone today).
0.1.8 - [*] <WPXA_MaximizeToggle>: Bugfix to actually toggle Maximization (see: http://www.autohotkey.com/forum/post-508122.html#508122 - thanks to sjkeegs).
0.1.7 - [+] <WPXA_RollToggle>: Toggles Roll/Unroll State of window.
[+] <wp_RollWindow>: Rolls up a window to its titlebar.
[+] <wp_UnRollWindow>: Unrolls a previously rolled up window (restores original height).
0.1.6 - [*] <WPXA_TopToggle>: Reanimated Notification (removed Parameter ShowNotification).
[*] Extended Debug-Logging via OutputDebug. (Unified Output format, Created posibillity to remove debug information (via Tag _DBG_)).
0.1.5 - [-] <WPXA_MouseLocator>: Using integer coordinates for Gui Show.
*/
; ****** HINT: Documentation can be extracted to HTML using NaturalDocs ************** */
; Global Varibles
Version := "0.2.0"
NotifyOptions := "GC=303030 TC=FFFFFF TS=8 TF=Verdana MC=FFFFFF MF=Verdana SI=200 ST=200 SC=200 BK=White IW=16 IH=16 Image="
NotifyDuration := 3
Ico_Dir := A_ScriptDir "/icons"
Ico_Minus := Ico_Dir "/minus.png"
Ico_Plus := Ico_Dir "/plus.png"
/*
===============================================================================
Function: WPXA_version
Returns the current version of WPXA
Versioning scheme according to http://semver.org
Returns:
current version number of the module
Author(s):
20110713 - hoppfrosch - Original
===============================================================================
*/
#include %A_ScriptDir%/WinGetPosEx.ahk
WPXA_version()
{
Global Version
return Version
}
/*
===============================================================================
Function: wp_ClipCursor
Clips (restricts/confines) the mouse to a given area
Parameters:
Confine - Toogle for Clipping
x1,y1,x2,y2 - Bounding coordinates (upper left, lower right) of confined area
Returns:
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Author(s):
Original - x79animal - http://www.autohotkey.com/forum/viewtopic.php?p=409537#409537
20110127 - hoppfrosch - Modifications
===============================================================================
*/
wp_ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 )
{
VarSetCapacity(R,16,0), NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}
/*
===============================================================================
Function: wp_GetMonitorAt
Get the index of the monitor containing the specified x and y coordinates.
Parameters:
x,y - Coordinates
default - Default monitor
Returns:
Index of the monitor at specified coordinates
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_GetMonitorAt(x, y, default=1)
{
SysGet, m, MonitorCount
; Iterate through all monitors.
Loop, %m%
{ ; Check if the window is on this monitor.
SysGet, Mon, Monitor, %A_Index%
if (x >= MonLeft && x <= MonRight && y >= MonTop && y <= MonBottom)
return A_Index
}
return default
}
/*
===============================================================================
Function: wp_GetMonitorFromMouse
Get the index of the monitor where the mouse is
Parameters:
default - Default monitor
Returns:
Index of the monitor where the mouse is
Author(s):
20120322- hoppfrosch: Initial
===============================================================================
*/
wp_GetMonitorFromMouse(default=1)
{
MouseGetPos,x,y
return wp_GetMonitorAt(x,y,default)
}
/*
===============================================================================
Function: wp_GetMonitorFromWindow
Get the index of the monitor containing the specified window.
Parameters:
hWnd - Window handle
Returns:
Index of the monitor of specified window
Author(s):
Original - ShinyWong - http://www.autohotkey.com/forum/viewtopic.php?p=462080#462080
===============================================================================
*/
wp_GetMonitorFromWindow(hWnd)
{
; Starts with 1.
monitorIndex := 1
VarSetCapacity(monitorInfo, 40)
NumPut(40, monitorInfo)
if (monitorHandle := DllCall("MonitorFromWindow", "uint", hWnd, "uint", 0x2))
&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
{
monitorLeft := NumGet(monitorInfo, 4, "Int")
monitorTop := NumGet(monitorInfo, 8, "Int")
monitorRight := NumGet(monitorInfo, 12, "Int")
monitorBottom := NumGet(monitorInfo, 16, "Int")
workLeft := NumGet(monitorInfo, 20, "Int")
workTop := NumGet(monitorInfo, 24, "Int")
workRight := NumGet(monitorInfo, 28, "Int")
workBottom := NumGet(monitorInfo, 32, "Int")
isPrimary := NumGet(monitorInfo, 36, "Int") & 1
SysGet, monitorCount, MonitorCount
Loop, %monitorCount%
{
SysGet, tempMon, Monitor, %A_Index%
; Compare location to determine the monitor index.
if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
{
monitorIndex := A_Index
break
}
}
}
return %monitorIndex%
}
/*
===============================================================================
Function: wp_GetProp
Get window property.
Parameters:
hwnd - Window handle
property_name - Name of the property
type - Type of the property - should be int, uint or float.
Returns:
Value of the property, otherwise NULL if property does not exist
See also:
<wp_SetProp>, <wp_RemoveProp>
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
Reference - MSDN - http://msdn.microsoft.com/en-us/library/ms633564%28v=vs.85%29.aspx
===============================================================================
*/
wp_GetProp(hwnd, property_name, type="int") {
return DllCall("GetProp", "uint", hwnd, "str", property_name, type)
}
/*
===============================================================================
Function: wp_IsAlwaysOnTop
Determine whether fiven window is set to always on top
Parameters:
WinTitle - Title of the window
IsSetByWP - Checks whether "AlwaysOnTop" was set with WindowPadX (needed to restore state ...)
Returns:
True or False
Author(s):
20110811 - hoppfrosch - Initial
===============================================================================
*/
wp_IsAlwaysOnTop(WinTitle,IsSetByWP=0)
{
WinGet, CurrExStyle, ExStyle, %WinTitle%
if hwnd := wp_WinExist(WinTitle) {
if (IsSetByWP=1)
{
if wp_GetProp(hwnd,"wpAlwaysOnTop")
{
return (CurrExStyle & 0x08) ; WS_EX_TOPMOST
}
else
{
return 0
}
}
return (CurrExStyle & 0x08) ; WS_EX_TOPMOST
}
return
}
/*
===============================================================================
Function: wp_IsResizable
Determine if we should attempt to resize the last found window.
Returns:
True or False
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_IsResizable()
{
WinGetClass, Class
if Class in Chrome_XPFrame,MozillaUIWindowClass
return true
WinGet, CurrStyle, Style
return (CurrStyle & 0x40000) ; WS_SIZEBOX
}
/*
===============================================================================
Function: wp_IsWhereWePutIt
Restores windows position and size previously stored with <wp_RememberPos>
Parameters:
hwnd - Window handle
Returns:
x,y,w,h - last position and size
See also:
<wp_RememberPos>
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_IsWhereWePutIt(hwnd, x, y, w, h)
{
if wp_GetProp(hwnd,"wpHasRestorePos")
{ ; Window has restore info. Check if it is where we last put it.
last_x := wp_GetProp(hwnd,"wpLastX")
last_y := wp_GetProp(hwnd,"wpLastY")
last_w := wp_GetProp(hwnd,"wpLastW")
last_h := wp_GetProp(hwnd,"wpLastH")
return (last_x = x && last_y = y && last_w = w && last_h = h)
}
return false
}
/*
===============================================================================
Function: wp_RememberPos
Helper function for detection of window movement by user. Stores the current position. The stored position can be recovered by <wp_IsWhereWePutIt>
Parameters:
hwnd - Window handle
See also:
<wp_SetProp>, <wp_IsWhereWePutIt>
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_RememberPos(hwnd)
{
WinGetPos, x, y, w, h, ahk_id %hwnd%
; Remember where we put it, to detect if the user moves it.
wp_SetProp(hwnd,"wpLastX",x)
wp_SetProp(hwnd,"wpLastY",y)
wp_SetProp(hwnd,"wpLastW",w)
wp_SetProp(hwnd,"wpLastH",h)
}
/*
===============================================================================
Function: wp_RemoveProp
Remove window property.
Parameters:
hwnd - Window handle
property_name - Name of the property
Returns:
Handle - The return value identifies the specified data. If the data cannot be found in the specified property list, the return value is NULL.
See also:
<wp_GetProp>, <wp_SetProp>
Author(s):
Reference - MSDN (http://msdn.microsoft.com/en-us/library/ms633567%28v=vs.85%29.aspx)
20110713 - hoppfrosch - AutoHotkey-Implementation
===============================================================================
*/
wp_RemoveProp(hwnd, property_name) {
_DBG_FName := A_ScriptName "-[wp_RemoveProp] - " ; _DBG_
WinGetClass, WinClass, ahk_id %hwnd% ; _DBG_
WinGetTitle, WinTitle, ahk_id %hwnd% ; _DBG_
OutputDebug % _DBG_FName "Remove Property <" property_name "> for hwnd: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
return DllCall("RemoveProp", "uint", hwnd, "str", property_name)
}
/*
===============================================================================
Function: wp_Restore
Restores windows to state according properties
Following states are restored:
* AlwaysOnTop
* RolledWindow
Author(s):
20110713 - hoppfrosch - AutoHotkey-Implementation
===============================================================================
*/
wp_Restore() {
;MsgBox % "wp_Restore(): Vollstaendige Implementierung"
_DBG_FName := A_ScriptName "-[wp_Restore] - " ; _DBG_
WinGet, id, list, , , Program Manager
Loop, %id%
{
; Aktionen rückhängig ...
hwnd := id%A_Index%
WinGetTitle, WinTitle, ahk_id %hwnd%
WinGetClass, WinClass, ahk_id %hwnd% ; _DBG_
OutputDebug % _DBG_FName "Besuche Fenster <" a_index "/" id ">: ahk_id: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
if wp_GetProp(hwnd,"wpAlwaysOnTop") {
OutputDebug % _DBG_FName "Window <" WinTitle "> has property <AlwaysOnTop!>" ; _DBG_
if wp_IsAlwaysOnTop(WinTitle,1) {
OutputDebug % _DBG_FName "Disable AlwaysOnTop since it was set by WindowPadX" ; _DBG_
WPXA_TopToggle(WinTitle)
OutputDebug % _DBG_FName "Current State of AlwaysOnTop: " wp_IsAlwaysOnTop(WinTitle) ; _DBG_
}
}
else if (wp_GetProp(hwnd,"wpHasRestorePos")) {
OutputDebug % _DBG_FName "Window <" WinTitle "> has property <HasRestorePos!>" ; _DBG_
}
else if (wp_GetProp(hwnd,"wpRolledUp") = 1)
{
OutputDebug % _DBG_FName "RollWindow disabled for hwnd: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
wp_RollWindowToggle(hwnd)
}
}
}
/*
===============================================================================
Function: wp_RollWindowToggle
Toggles Rollup of a window (Rollup to caption bar)
Parameters:
hWnd - Window handle
Author(s):
20120620 - hoppfrosch - Original
===============================================================================
*/
wp_RollWindowToggle(hwnd)
{
_DBG_FName := A_ScriptName "-[wp_RollWindowToggle] - " ; _DBG_
WinGetClass, WinClass, ahk_id %hwnd% ; _DBG_
WinGetTitle, WinTitle, ahk_id %hwnd% ; _DBG_
; Determine the minmal height of a window
SysGet, MinWinHeight, 29
; Get size of current window
WinGetPos, x, y, width, height, ahk_id %hwnd%
OutputDebug % _DBG_FName "MinWinHeight: " MinWinHeight " - win_height: " height " - wpRolledUp: " wp_GetProp(hwnd,"wpRolledUp") ; _DBG_
if (wp_GetProp(hwnd,"wpRolledUp") = 1)
{
if (height = MinWinHeight)
{
; The window is still rolled up
heightUnrolled := wp_GetProp(hwnd,"wpUnrolledHeight")
WinMove, ahk_id %hwnd%, , , , ,%heightUnrolled%
wp_SetProp(hwnd,"wpRolledUp", 0)
wp_RemoveProp(hwnd,"wpUnrolledHeight")
OutputDebug % _DBG_FName "RollWindow disabled for hwnd: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
}
else
{
; the previously rolled-up window was unrolled manually - so rollup it again
wp_SetProp(hwnd,"wpRolledUp",1)
wp_SetProp(hwnd,"wpUnrolledHeight",height)
WinMove, ahk_id %hwnd%, , , , ,%MinWinHeight%
OutputDebug % _DBG_FName "RollWindow enabled for hwnd: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
}
}
else
{
if (height > MinWinHeight)
{
wp_SetProp(hwnd,"wpRolledUp",1)
wp_SetProp(hwnd,"wpUnrolledHeight",height)
WinMove, ahk_id %hwnd%, , , , ,%MinWinHeight%
OutputDebug % _DBG_FName "RollWindow enabled for hwnd: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
}
}
return wp_GetProp(hwnd,"wpRolledUp")
}
/*
===============================================================================
Function: wp_SetProp
Set window property.
Parameters:
hwnd - Window handle
property_name - Name of the property
data - Value of the property
type - Type of the property - should be int, uint or float
Returns:
True or False
See also:
<wp_GetProp>, <wp_RemoveProp>
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_SetProp(hwnd, property_name, data, type="int") {
_DBG_FName := A_ScriptName "-[wp_SetProp] - " ; _DBG_
WinGetClass, WinClass, ahk_id %hwnd% ; _DBG_
WinGetTitle, WinTitle, ahk_id %hwnd% ; _DBG_
OutputDebug % _DBG_FName "Set Property <" property_name "> to data <" data "> for hwnd: " hwnd " - win_class: " WinClass " - win_title: " WinTitle ; _DBG_
return DllCall("SetProp", "uint", hwnd, "str", property_name, type, data)
}
/*
===============================================================================
Function: wp_SetRestorePos
Stores windows position for restoring it later
Parameters:
hwnd - Window handle
x,y,w,h - Next time user requests the window be "restored" use this position and size.
See also:
<wp_SetProp>
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_SetRestorePos(hwnd, x, y, w, h)
{
; Next time user requests the window be "restored" use this position and size.
wp_SetProp(hwnd,"wpHasRestorePos",true)
wp_SetProp(hwnd,"wpRestoreX",x)
wp_SetProp(hwnd,"wpRestoreY",y)
wp_SetProp(hwnd,"wpRestoreW",w)
wp_SetProp(hwnd,"wpRestoreH",h)
}
/*
===============================================================================
Function: wp_WinExist
Custom WinExist() for implementing a couple extra "special" values.
Parameters:
WinTitle - Title of the window
Returns:
Windowshandle
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_WinExist(WinTitle)
{
if WinTitle = P
return wp_WinPreviouslyActive()
if WinTitle = M
{
MouseGetPos,,, win
return WinExist("ahk_id " win)
}
if WinTitle = _
return wp_WinLastMinimized()
return WinExist(WinTitle!="" ? WinTitle : "A")
}
/*
===============================================================================
Function: wp_WinGetTitle
Custom WinGetTitle() for getting either title of "last found" window or window given by title
Parameters:
WinTitle - Title of the window
Returns:
WinTitle - Title of the window
Author(s):
20110607 - hoppfrosch - Original
===============================================================================
*/
wp_WinGetTitle(WinTitle)
{
if WinTitle =
WinGetTitle, CurrWinTitle,
else
WinGetTitle, CurrWinTitle,WinTitle
return CurrWinTitle
}
/*
===============================================================================
Function: wp_WinLastMinimized
Get most recently minimized window.
Returns:
True or false
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_WinLastMinimized()
{
WinGet, w, List
Loop %w%
{
wi := w%A_Index%
WinGet, m, MinMax, ahk_id %wi%
if m = -1 ; minimized
{
lastFound := wi
break
}
}
return WinExist("ahk_id " . (lastFound ? lastFound : 0))
}
/*
===============================================================================
Function: wp_WinPreviouslyActive
Get next window beneath the active one in the z-order.
Returns:
Windowshandle
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
wp_WinPreviouslyActive()
{
active := WinActive("A")
WinGet, win, List
; Find the active window.
; (Might not be win1 if there are always-on-top windows?)
Loop, %win%
if (win%A_Index% = active)
{
if (A_Index < win)
N := A_Index+1
; hack for PSPad: +1 seems to get the document (child!) window, so do +2
ifWinActive, ahk_class TfPSPad
N += 1
break
}
; Use WinExist to set Last Found Window (for consistency with WinActive())
return WinExist("ahk_id " . win%N%)
}
/*
===============================================================================
Function: wp_WinTraymin
Minimizes a window to a tray icon.
Parameters:
hWnd - Windows-Handle
nFlags - Flag to allow manipulate properites:
wp_WinTraymin(hWnd,0), where 0 can be omitted.
Removing all trayminned trayicons: wp_WinTraymin(0,-1).
Other values than 0 & -1 are reserved for internal use.
Author(s):
Original - Sean - http://http://www.autohotkey.com/community/viewtopic.php?f=2&t=33263
===============================================================================
*/
wp_WinTraymin(hWnd = "", nFlags = "")
{
Static
If Not hAHK&&hAHK:=WinExist("ahk_class AutoHotkey ahk_pid " DllCall("GetCurrentProcessId"))
ShellHook:=DllCall("RegisterWindowMessage","Str","SHELLHOOK"), nIcons:=0
, DllCall("RegisterShellHookWindow","Uint",hAHK)
, OnMessage(nMsg:=1028,"WM_SHELLHOOKMESSAGE")
If Not nFlags
{
If Not ((hWnd+=0)||hWnd:=DllCall("GetForegroundWindow"))||((h:=DllCall("GetWindow","Uint",hWnd,"Uint",4))&&DllCall("IsWindowVisible","Uint",h)&&!hWnd:=h)||
!(VarSetCapacity(sClass,32),DllCall("GetClassName","Uint",hWnd,"Str",sClass,"Uint",VarSetCapacity(sClass)//2))||sClass=="Shell_TrayWnd"||sClass=="Progman"
{
Return
}
OnMessage(ShellHook,"")
WinMinimize, ahk_id %hWnd%
WinHide, ahk_id %hWnd%
Sleep, 100
OnMessage(ShellHook,"WM_SHELLHOOKMESSAGE")
uID:=uID_%hWnd%, uID ? "" : (uID_%hWnd%:=uID:=++nIcons=nMsg ? ++nIcons : nIcons)
SendMessage, 0x7F, 2, 0,, ahk_id %hWnd%
If Not hIcon:=ErrorLevel
{
hIcon:=DllCall("GetClassLong","Uint",hWnd,"Int",-34)
}
DllCall("GetWindowTextA","Uint",hWnd,"Uint",NumPut(hIcon,NumPut(nMsg,NumPut(1|2|4,NumPut(uID,NumPut(hAHK,NumPut(VarSetCapacity(ni,152),ni)))))),"int",128)
Return hWnd_%uID%:=DllCall("shell32\Shell_NotifyIcon","Uint",hWnd_%uID% ? 1 : 0,"Uint",&ni) ? hWnd : DllCall("ShowWindow","Uint",hWnd,"int",5)*0, DllCall("DestroyIcon","Uint",hIcon)
}
Else If nFlags > 0
{
If (nFlags=3&&uID:=hWnd)
If WinExist("ahk_id " . hWnd:=hWnd_%uID%)
{
WinShow, ahk_id %hWnd%
WinRestore, ahk_id %hWnd%
}
Else nFlags:=2
Else uID:=uID_%hWnd%
Return uID&&hWnd_%uID% ? (DllCall("shell32\Shell_NotifyIcon","Uint",2,"Uint",NumPut(uID,NumPut(hAHK,NumPut(VarSetCapacity(ni,152),ni)))-12),hWnd_%uID%:="") : ""
}
Else
Loop, % nIcons+0*DllCall("DeregisterShellHookWindow","Uint",hAHK)
hWnd_%A_Index% ? (DllCall("shell32\Shell_NotifyIcon","Uint",2,"Uint",NumPut(A_Index,NumPut(hAHK,NumPut(VarSetCapacity(ni,152),ni)))-12),DllCall("ShowWindow","Uint",hWnd_%A_Index%,"int",5),hWnd_%A_Index%:="") : ""
}
/*
===============================================================================
Function: wp_RecenterMouse
Move cursor to the center of the active window
Author(s):
Original - artemisart
===============================================================================
*/
wp_RecenterMouse()
{
global RecenterMouse, RecenterOnlyIfOutside
if (RecenterMouse=0)
return
MouseGetPos, , , mID
WinGet, wID, ID
if (RecenterOnlyIfOutside and mID=wID)
return
CoordMode, Mouse, Window
WinGetPos, , , w, h
MouseMove, w / 2, h / 2
}
/*
===============================================================================
Function: WPXA_ClipCursorToMonitor
Clips (Restricts) mouse to given monitor
Parameters:
md - monitor-id
Author(s):
20110126 - hoppfrosch - Initial
===============================================================================
*/
WPXA_ClipCursorToMonitor(md)
{
SysGet, mc, MonitorCount
if (md<0 or md>mc)
return
if (md=0)
{
wp_ClipCursor( False,0,0,1,1) ; Turn clipping off
return
}
Loop, %mc%
SysGet, mon%A_Index%, MonitorWorkArea, %A_Index%
; Destination monitor
mdx1 := mon%md%Left
mdy1 := mon%md%Top
mdx2 := mon%md%Right
mdy2 := mon%md%Bottom
wp_ClipCursor(True,mdx1,mdy1,mdx2,mdy2)
}
/*
===============================================================================
Function: WPXA_ClipCursorToCurrentMonitorToggle
Toogles clipping mouse to current monitor
Author(s):
20110126 - hoppfrosch - Initial
===============================================================================
*/
WPXA_ClipCursorToCurrentMonitorToggle()
{
Static IsLocked
if (IsLocked=True)
{
wp_ClipCursor( False ) ; Turn clipping off
IsLocked:=False
}
else
{
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
md := wp_GetMonitorAt(xpos, ypos, 0)
SysGet, mc, MonitorCount
Loop, %mc%
SysGet, mon%A_Index%, MonitorWorkArea, %A_Index%
; Destination monitor
mdx1 := mon%md%Left
mdy1 := mon%md%Top
mdx2 := mon%md%Right
mdy2 := mon%md%Bottom
wp_ClipCursor(True,mdx1,mdy1,mdx2,mdy2)
IsLocked := True
}
}
/*
===============================================================================
Function: WPXA_FillVirtualScreen
Expand the window to fill the virtual screen (all monitors).
Parameters:
winTitle - windows title
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
WPXA_FillVirtualScreen(winTitle)
{
if hwnd := wp_WinExist(winTitle)
{
WinGetPos, x, y, w, h
if !wp_IsWhereWePutIt(hwnd, x, y, w, h)
wp_SetRestorePos(hwnd, x, y, w, h)
; Get position and size of virtual screen.
SysGet, x, 76
SysGet, y, 77
SysGet, w, 78
SysGet, h, 79
; Resize window to fill all...
WinMove,,, x, y, w, h
wp_RememberPos(hwnd)
}
}
/*
===============================================================================
Function: WPXA_GatherWindowsOnMonitor
"Gather" windows on a specific screen.
Parameters:
md - monitor id
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
WPXA_GatherWindowsOnMonitor(md)
{
global ProcessGatherExcludeList
SetWinDelay, 0
; List all visible windows.
WinGet, win, List
; Copy bounds of all monitors to an array.
SysGet, mc, MonitorCount
Loop, %mc%
SysGet, mon%A_Index%, MonitorWorkArea, %A_Index%
if md = M
{ ; Special exception for 'M', since the desktop window
; spreads across all screens.
CoordMode, Mouse, Screen
MouseGetPos, x, y
md := wp_GetMonitorAt(x, y, 0)
}
else if md is not integer
{ ; Support A, P and WinTitle.
; (Gather at screen containing specified window.)
wp_WinExist(md)
WinGetPos, x, y, w, h
md := wp_GetMonitorAt(x+w/2, y+h/2, 0)
}
if (md<1 or md>mc)
return
; Destination monitor
mdx := mon%md%Left
mdy := mon%md%Top
mdw := mon%md%Right - mdx
mdh := mon%md%Bottom - mdy
Loop, %win%
{
; If this window matches the GatherExclude group, don't touch it.
if (WinExist("ahk_group GatherExclude ahk_id " . win%A_Index%))
continue
; Set Last Found Window.
if (!WinExist("ahk_id " . win%A_Index%))
continue
WinGet, procname, ProcessName
; Check process (program) exclusion list.
if procname in %ProcessGatherExcludeList%
continue
WinGetPos, x, y, w, h
; Determine which monitor this window is on.
xc := x+w/2, yc := y+h/2
ms := 0
Loop, %mc%
if (xc >= mon%A_Index%Left && xc <= mon%A_Index%Right
&& yc >= mon%A_Index%Top && yc <= mon%A_Index%Bottom)
{
ms := A_Index
break
}
; If already on destination monitor, skip this window.
if (ms = md)
continue
WinGet, state, MinMax
if (state = 1) {
WinRestore
WinGetPos, x, y, w, h
}
if ms
{
; Source monitor
msx := mon%ms%Left
msy := mon%ms%Top
msw := mon%ms%Right - msx
msh := mon%ms%Bottom - msy
; If the window is resizable, scale it by the monitors' resolution difference.
if (wp_IsResizable()) {
w *= (mdw/msw)
h *= (mdh/msh)
}
; Move window, using resolution difference to scale co-ordinates.
WinMove,,, mdx + (x-msx)*(mdw/msw), mdy + (y-msy)*(mdh/msh), w, h
}
else
{ ; Window not on any monitor, move it to center.
WinMove,,, mdx + (mdw-w)/2, mdy + (mdh-h)/2
}
if state = 1
WinMaximize
}
}
/*
===============================================================================
Function: WPXA_MaximizeToggle
Maximize or restore the window.
Parameters:
winTitle - windows title
Author(s):
Original - Lexikos - http://www.autohotkey.com/forum/topic21703.html
===============================================================================
*/
WPXA_MaximizeToggle(winTitle)
{
if hwnd := wp_WinExist(winTitle)
{
WinGetPos, x, y, w, h
if !wp_IsWhereWePutIt(hwnd, x, y, w, h)
{
; WindowPadX didn't put that window here, so save this position before moving.
wp_SetRestorePos(hwnd, x, y, w, h)
}
WinGet, state, MinMax
if state
WinRestore
else
WinMaximize
wp_RememberPos(hwnd)
wp_RecenterMouse()
}
}
/*
===============================================================================
Function: WPXA_MinimizeWindowsOnMonitor
Minimize all windows on the given Screen or all windows on screen where where the mouse currently lives