-
Notifications
You must be signed in to change notification settings - Fork 18
/
gvimfullscreen.c
114 lines (93 loc) · 3.57 KB
/
gvimfullscreen.c
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
/*
cl /LD gvimfullscreen.c user32.lib
------------------------------
:call libcallnr("gvimfullscreen.dll", "EnableFullScreen", 1)
*/
#include <windows.h>
int g_x, g_y, g_dx, g_dy;
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
BOOL CALLBACK FindWindowProc(HWND hwnd, LPARAM lParam)
{
HWND* pphWnd = (HWND*)lParam;
if (GetParent(hwnd))
{
*pphWnd = NULL;
return TRUE;
}
*pphWnd = hwnd;
return FALSE;
}
LONG _declspec(dllexport) ToggleFullScreen()
{
HWND hTop = NULL;
DWORD dwThreadID;
dwThreadID = GetCurrentThreadId();
EnumThreadWindows(dwThreadID, FindWindowProc, (LPARAM)&hTop);
if (hTop)
{
/* Determine the current state of the window */
if ( GetWindowLong(hTop, GWL_STYLE) & WS_CAPTION )
{
/* Has a caption, so isn't maximised */
MONITORINFO mi;
RECT rc;
HMONITOR hMonitor;
GetWindowRect(hTop, &rc);
hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST);
//
// get the work area or entire monitor rect.
//
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
g_x = mi.rcMonitor.left;
g_y = mi.rcMonitor.top;
g_dx = mi.rcMonitor.right - g_x;
g_dy = mi.rcMonitor.bottom - g_y;
//cx = GetSystemMetrics(SM_CXSCREEN);
//cy = GetSystemMetrics(SM_CYSCREEN);
/* Remove border, caption, and edges */
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_EXSTYLE) & ~WS_BORDER);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) & ~WS_CAPTION);
SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_STYLE) & ~WS_EX_CLIENTEDGE);
SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_STYLE) & ~WS_EX_WINDOWEDGE);
SetWindowPos(hTop, HWND_TOP, g_x, g_y, g_dx, g_dy, SWP_SHOWWINDOW);
/* Now need to find the child text area window
* and set it's size accordingly
*/
EnumChildWindows(hTop, EnumChildProc, 0);
}
else
{
/* Already full screen, so restore all the previous styles */
SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_EXSTYLE) | WS_BORDER);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_CAPTION);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_SYSMENU);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_MINIMIZEBOX);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_MAXIMIZEBOX);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_SYSMENU);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_EX_CLIENTEDGE);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_EX_WINDOWEDGE);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_THICKFRAME);
SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_DLGFRAME);
SendMessage(hTop, WM_SYSCOMMAND, SC_RESTORE, 0);
SendMessage(hTop, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
return GetLastError();
}
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
char lpszClassName[100];
GetClassName(hwnd, lpszClassName, 100);
if ( strcmp(lpszClassName, "VimTextArea") == 0 )
{
//int cx, cy;
//cx = GetSystemMetrics(SM_CXSCREEN);
//cy = GetSystemMetrics(SM_CYSCREEN);
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_EX_CLIENTEDGE);
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_EX_WINDOWEDGE);
SetWindowPos(hwnd, HWND_TOP, 0, 0, g_dx, g_dy, SWP_SHOWWINDOW);
SetClassLong(hwnd, GCL_HBRBACKGROUND, CreateSolidBrush(RGB(0,0,0)));
}
return TRUE;
}