Skip to content

Commit c68df98

Browse files
authored
Merge pull request #23 from idietmoran/dev-win32
Added Boarderless Windowed and Fullscreen
2 parents 4bc9385 + 6aa4ed1 commit c68df98

File tree

11 files changed

+97
-30
lines changed

11 files changed

+97
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
All notable changes to this project will be documented in this file
33

44
## [1.0.5]
5+
### Added
6+
- Added option for borderless windowed mode
7+
- Added option for fullscreen mode
58
### Fixed
69
- Fixed issue where window could be resized when locked in the window
710
- This could create an issue with programs running in elevated permissions
11+
### Removed
12+
- Removed the ability for display lock to select the itself
813

914
## [1.0.4]
1015
### Added

src/bin/menu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
void initMenu(Menu *menu)
88
{
9-
menu->currentMenu = MAIN;
109
menu->windows.count = 0;
1110
menu->currentSelection = 0;
1211
menu->active = FALSE;

src/bin/menu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "win.h"
55

6+
typedef struct SETTINGS SETTINGS;
7+
68
typedef struct Args
79
{
810
Menu *menu;
@@ -15,6 +17,7 @@ typedef struct winArgs
1517
{
1618
HANDLE *mutex;
1719
WINDOW *window;
20+
SETTINGS *settings;
1821
BOOL *active;
1922
} winArgs;
2023

src/bin/win.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
void openWindows(WINDOWLIST *windows)
88
{
99
//mutex = CreateMutex(NULL, FALSE, NULL);
10-
1110
windows->count = 0;
1211

1312
EnumWindows(&EnumWindowsProc, (LPARAM)windows);
14-
1513
}
1614

1715
// enumerate windows and get current window list
@@ -29,7 +27,7 @@ BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
2927
GetWindowTextA(hwnd, title, sizeof(title));
3028

3129
// if title contains more than 1 character
32-
if (strlen(title) != 0)
30+
if (strlen(title) != 0 && strcmp(title, "Display Lock") != 0)
3331
{
3432
// get rectangle
3533
//GetWindowRect(hwnd, &win->windows[win->count].size);
@@ -62,19 +60,60 @@ BOOL checkResizeStyle(HWND activeWindow)
6260
return (GetWindowLongPtr(activeWindow, GWL_STYLE)&WS_SIZEBOX);
6361
}
6462

63+
void borderlessWindow(HWND activeWindow)
64+
{
65+
SetWindowLongPtr(activeWindow, GWL_STYLE, GetWindowLongPtr(activeWindow, GWL_STYLE)^WS_OVERLAPPED^WS_THICKFRAME^WS_SYSMENU^WS_CAPTION);
66+
SetWindowLongPtr(activeWindow, GWL_EXSTYLE, GetWindowLongPtr(activeWindow, GWL_EXSTYLE)^WS_EX_WINDOWEDGE);
67+
}
68+
69+
void fullScreen(WINDOW activeWindow, PREVIOUSRECT *prev)
70+
{
71+
GetClientRect(activeWindow.hWnd, &activeWindow.size);
72+
ClientToScreen(activeWindow.hWnd, &activeWindow.size.left);
73+
ClientToScreen(activeWindow.hWnd, &activeWindow.size.right);
74+
75+
prev->width = activeWindow.size.right - activeWindow.size.left;
76+
prev->height = activeWindow.size.bottom - activeWindow.size.top;
77+
prev->x = activeWindow.size.left;
78+
prev->y = activeWindow.size.top;
79+
80+
SetWindowPos(activeWindow.hWnd, NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL);
81+
}
82+
83+
void disableFullScreen(WINDOW activeWindow, PREVIOUSRECT *prev)
84+
{
85+
SetWindowPos(activeWindow.hWnd, NULL, prev->x, prev->y, prev->width, prev->height, NULL);
86+
}
87+
88+
6589
// threaded function to lock the cursor to specified window
6690
int __stdcall cursorLockEx(void* arguments)
6791
{
6892
HANDLE hMessageStop = CreateEvent(NULL, FALSE, FALSE, _T("STOP"));
6993
HANDLE hMessageEmpty = CreateEvent(NULL, FALSE, TRUE, _T("EMPTY"));
7094
winArgs *args = (winArgs*)arguments;
7195
WINDOW activeWindow = *args->window;
72-
HWND const currentWindow = activeWindow.hWnd;
96+
97+
const HWND currentWindow = activeWindow.hWnd;
98+
7399
POINT cursorPos;
74100

75101
// keeps track if style was changed
76102
BOOL styleChanged = FALSE;
77103

104+
SETTINGS *settings = (SETTINGS*)args->settings;
105+
106+
PREVIOUSRECT previousrect;
107+
108+
if(settings->borderlessWindow)
109+
borderlessWindow(currentWindow);
110+
111+
if(settings->fullScreen)
112+
fullScreen(activeWindow, &previousrect);
113+
114+
// TODO: bring to foreground
115+
// TODO: keep on top (WS_EX_TOP???)
116+
78117
// if window style has WS_SIZEBOX, remove it with EXCLUSIVE OR (^)
79118
if(checkResizeStyle(activeWindow.hWnd))
80119
{
@@ -112,6 +151,12 @@ int __stdcall cursorLockEx(void* arguments)
112151
if(styleChanged)
113152
SetWindowLongPtr(currentWindow, GWL_STYLE, GetWindowLongPtr(currentWindow, GWL_STYLE)|WS_SIZEBOX);
114153

154+
if(settings->borderlessWindow)
155+
borderlessWindow(currentWindow);
156+
157+
if (settings->fullScreen)
158+
disableFullScreen(activeWindow, &previousrect);
159+
115160
ClipCursor(NULL); // release the cursor clip
116161
_endthreadex(1); // end thread_ex
117162
return 1;

src/bin/win.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
#include <Windows.h>
55
//#include "menu.h"
66

7-
7+
typedef struct PREVIOUSRECT
8+
{
9+
int width;
10+
int height;
11+
int x;
12+
int y;
13+
} PREVIOUSRECT;
814

915
typedef struct WINDOW
1016
{
@@ -28,35 +34,26 @@ typedef struct Menu
2834
WINDOWLIST windows;
2935
WINDOW selectedWindow;
3036
BOOL active;
31-
int currentMenu;
3237
int currentSelection;
3338
BOOL live;
3439
DWORD mode;
3540
INPUT_RECORD event;
3641
} Menu;
3742

38-
typedef enum MAINMENU
39-
{
40-
MAIN,
41-
WINDOWS,
42-
DEFAULT,
43-
ACTIVE
44-
} MAINMENU;
4543

4644
BOOL CALLBACK EnumWindowsProc(HWND, LPARAM);
4745

4846
void openWindows(WINDOWLIST*);
4947
void clearWindows(WINDOWLIST*);
5048
void getCurrentMousePos(POINT*);
51-
5249
void lockFocused(WINDOW*);
53-
5450
void cursorLock(void*);
55-
5651
BOOL checkClientArea(POINT*, RECT*);
57-
5852
BOOL checkResizeStyle(HWND);
59-
53+
void borderlessWindow(HWND);
54+
void undoborderlessWindow(HWND);
55+
void fullScreen(WINDOW, PREVIOUSRECT*);
56+
void disableFullScreen(WINDOW, PREVIOUSRECT*);
6057
int __stdcall cursorLockEx(void* arguments);
6158

6259
#endif

src/displayLock-win32.aps

604 Bytes
Binary file not shown.

src/displayLock-win32.c

578 Bytes
Binary file not shown.

src/displayLock-win32.rc

316 Bytes
Binary file not shown.

src/resource.h

184 Bytes
Binary file not shown.

src/settings.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,36 @@
99
void initalizeSettings(HWND hDlg, SETTINGS* settings)
1010
{
1111
// get the checkbox
12-
HWND checkbox = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
12+
HWND minimize = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
13+
HWND borderless = GetDlgItem(hDlg, IDC_SETTINGS_BORDERLESS);
14+
HWND fullScreen = GetDlgItem(hDlg, IDC_SETTINGS_FULLSCREEN);
15+
1316

14-
// check the current setting
15-
int checkState;
16-
if (!settings->minimize)
17-
checkState = BST_UNCHECKED;
18-
else
19-
checkState = BST_CHECKED;
2017

2118
// update the dialog window
22-
SendMessage(checkbox, BM_SETCHECK, checkState, 0);
19+
SendMessage(minimize, BM_SETCHECK, settings->minimize, 0);
20+
SendMessage(borderless, BM_SETCHECK, settings->borderlessWindow, 0);
21+
SendMessage(fullScreen, BM_SETCHECK, settings->fullScreen, 0);
2322
}
2423

2524
// update settings
2625
void updateSettings(HWND hDlg, SETTINGS* settings)
2726
{
2827
// check the checkbox
29-
HWND checkbox = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
30-
settings->minimize = SendMessage(checkbox, BM_GETCHECK, 0, 0);
28+
HWND minimize = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
29+
HWND borderless = GetDlgItem(hDlg, IDC_SETTINGS_BORDERLESS);
30+
HWND fullScreen = GetDlgItem(hDlg, IDC_SETTINGS_FULLSCREEN);
31+
32+
33+
//WORD wHotKey = LOWORD(SendMessage(GetDlgItem(hDlg, IDC_SETTINGS_HOTKEY), HKM_GETHOTKEY, 0, 0));
34+
//settings->hotKeyCount = 0;
35+
36+
settings->minimize = SendMessage(minimize, BM_GETCHECK, 0, 0);
37+
settings->borderlessWindow = SendMessage(borderless, BM_GETCHECK, 0, 0);
38+
settings->fullScreen = SendMessage(fullScreen, BM_GETCHECK, 0, 0);
39+
//settings->HOTKEY = LOBYTE(wHotKey);
40+
//settings->HOTKEY_MODIFIERS[0] = HIBYTE(wHotKey);
41+
//settings->hotKeyCount;
3142
}
3243

3344
void writeSettings(SETTINGS settings)
@@ -61,13 +72,15 @@ void readSettings(SETTINGS *settings)
6172
FILE *file = _wfopen(path, TEXT("r"));
6273
if(file != NULL)
6374
{
64-
fread(settings, sizeof(settings), 1, file);
75+
fread(settings, sizeof(*settings), 1, file);
6576
fclose(file);
6677
}
6778
else
6879
{
6980
strcpy(settings->header, "DLOCK");
7081
settings->minimize = 1;
82+
settings->borderlessWindow = 0;
83+
settings->fullScreen = 0;
7184
}
7285
// free memory
7386
CoTaskMemFree(path);

0 commit comments

Comments
 (0)