-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmodalizer.ahk
134 lines (120 loc) · 4.6 KB
/
unmodalizer.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
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
OnExit("ExitFunc")
HiddenWindow := 0
HelpMessage := "Modal dialog under mouse cursor -> Ctrl+Alt+M`nPress again to hide/show pointed window."
Menu, Tray, Tip, unmodalizer`n`n%HelpMessage%
TrayTip unmodalizer, %HelpMessage%
OnMessage(0x404, "AHK_NOTIFYICON") ; Registers a callback for the WM_NOTIFYICON message
AHK_NOTIFYICON(wParam, lParam, uMsg, hWnd) {
Global HelpMessage
if (lParam = 0x201) ; WM_LBUTTONDOWN
{
TrayTip unmodalizer, %HelpMessage%
}
}
^!m::
MouseGetPos,,, WindowUnderMouse
hOwner := DllCall("user32\GetWindow", Ptr, WindowUnderMouse, UInt, 4, Ptr) ; GW_OWNER = 4
if (HiddenWindow)
{
WinShow, ahk_id %HiddenWindow%
WinActivate, ahk_id %HiddenWindow%
HiddenWindow := 0
}
else
{
if (!hOwner)
{
WinHide, ahk_id %WindowUnderMouse%
HiddenWindow := WindowUnderMouse
}
else
{
; remove modality: unlock disabled owner window
WinSet, Style, -0x08000000, ahk_id %hOwner% ; WS_DISABLED 0x08000000L
; make former modal dialog the proper independent window shown on taskbar
SetOwner(WindowUnderMouse, 0)
WinSet, Style, -0x80000000, ahk_id %WindowUnderMouse% ; WS_POPUP 0x80000000L
WinSet, ExStyle, -0x00000080, ahk_id %WindowUnderMouse% ; WS_EX_TOOLWINDOW 0x00000080L
WinSet, ExStyle, -0x08000000, ahk_id %WindowUnderMouse% ; WS_EX_NOACTIVATE 0x08000000L
WinSet, ExStyle, +0x00040000, ahk_id %WindowUnderMouse% ; WS_EX_APPWINDOW 0x00040000L
WinSet, Style, +0x00cf0000, ahk_id %WindowUnderMouse% ; WS_OVERLAPPEDWINDOW 0x00cf0000
AddSystemMenuItems(WindowUnderMouse)
; disable minimize for IrfanView (erasing dialog contents)
WinGetClass, OwnerClass, ahk_id %hOwner%
if (OwnerClass == "IrfanView")
WinSet, Style, -0x00020000, ahk_id %WindowUnderMouse% ; WS_MINIMIZEBOX 0x00020000L
;WinSet, Style, -0x00010000, ahk_id %WindowUnderMouse% ; WS_MAXIMIZEBOX 0x00010000L
; refresh window to apply changes
DllCall("SetWindowPos", "UInt", WindowUnderMouse, "UInt", 0, "Int", 0, "Int", 0, "Int", 0, "Int", 0, "UInt", 0x27)
; update window's taskbar button
WinActivate, ahk_id %hOwner%
WinActivate, ahk_id %WindowUnderMouse%
SoundBeep, 750, 200
}
}
return
SetOwner(hwnd, newOwner) {
static GWL_HWNDPARENT := -8
if A_PtrSize = 8
DllCall("SetWindowLongPtr", "ptr", hwnd, "int", GWL_HWNDPARENT, "ptr", newOwner)
else
DllCall("SetWindowLong", "int", hwnd, "int", GWL_HWNDPARENT, "int", newOwner)
}
IsWindowVisible(hwnd) {
static WS_VISIBLE := 0x10000000 ; WS_VISIBLE
WinGet, Style, Style, ahk_id %hwnd%
if (Style & WS_VISIBLE)
return true
return false
}
ExitFunc(ExitReason, ExitCode) {
Global HiddenWindow
if ExitReason not in Logoff,Shutdown
{
if (HiddenWindow)
{
WinShow, ahk_id %HiddenWindow%
}
}
; Do not call ExitApp -- that would prevent other OnExit functions from being called.
}
AddSystemMenuItems(hwnd) {
hMenu := DllCall("GetSystemMenu", "UInt", hwnd, "UInt", False)
if (hMenu) {
DllCall("AppendMenu", "UInt", hMenu, "UInt", 0x800, "UInt", 0, "Str", "") ; separator
if (!MenuItemExist(hMenu, 0xF120)) {
DllCall("AppendMenu", "UInt", hMenu, "UInt", 0x0000 | 0x0000, "UInt", 0xF120, "Str", "Restore")
}
if (!MenuItemExist(hMenu, 0xF010)) {
DllCall("AppendMenu", "UInt", hMenu, "UInt", 0x0000 | 0x0000, "UInt", 0xF010, "Str", "Move")
}
if (!MenuItemExist(hMenu, 0xF000)) {
DllCall("AppendMenu", "UInt", hMenu, "UInt", 0x0000 | 0x0000, "UInt", 0xF000, "Str", "Size")
}
if (!MenuItemExist(hMenu, 0xF020)) {
DllCall("AppendMenu", "UInt", hMenu, "UInt", 0x0000 | 0x0000, "UInt", 0xF020, "Str", "Minimize")
}
if (!MenuItemExist(hMenu, 0xF030)) {
DllCall("AppendMenu", "UInt", hMenu, "UInt", 0x0000 | 0x0000, "UInt", 0xF030, "Str", "Maximize")
}
DllCall("DrawMenuBar", "UInt", hwnd)
}
}
MenuItemExist(hMenu, uIDNewItem) {
VarSetCapacity(MENUITEMINFO, size := 80, 0)
NumPut(size, MENUITEMINFO, 0, "UInt") ; cbSize = 80
NumPut(0x00000002, MENUITEMINFO, 4, "UInt") ; fMask = MIIM_ID (0x00000002)
itemCount := DllCall("GetMenuItemCount", "Ptr", hMenu)
Loop, %itemCount% {
DllCall("GetMenuItemInfo", "Ptr", hMenu, "UInt", A_Index-1, "UInt", true, "Ptr", &MENUITEMINFO)
if (NumGet(MENUITEMINFO, 4*4, "UInt") = uIDNewItem) { ; compare wID
return true
}
}
return false
}