forked from leonid-shevtsov/gvimfullscreen_win32
-
Notifications
You must be signed in to change notification settings - Fork 9
/
gvimfullscreen.c
executable file
·118 lines (96 loc) · 3.78 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
115
116
117
118
/*
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];
HBRUSH b;
UNREFERENCED_PARAMETER(lParam);
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);
b = CreateSolidBrush(RGB(0,0,0));
SetClassLongPtr (hwnd, GCLP_HBRBACKGROUND, (LONG_PTR) b);
}
return TRUE;
}