Skip to content

Commit

Permalink
Merge pull request #23 from idietmoran/dev-win32
Browse files Browse the repository at this point in the history
Added Boarderless Windowed and Fullscreen
  • Loading branch information
Stateford authored Apr 14, 2018
2 parents 4bc9385 + 6aa4ed1 commit c68df98
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
All notable changes to this project will be documented in this file

## [1.0.5]
### Added
- Added option for borderless windowed mode
- Added option for fullscreen mode
### Fixed
- Fixed issue where window could be resized when locked in the window
- This could create an issue with programs running in elevated permissions
### Removed
- Removed the ability for display lock to select the itself

## [1.0.4]
### Added
Expand Down
1 change: 0 additions & 1 deletion src/bin/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

void initMenu(Menu *menu)
{
menu->currentMenu = MAIN;
menu->windows.count = 0;
menu->currentSelection = 0;
menu->active = FALSE;
Expand Down
3 changes: 3 additions & 0 deletions src/bin/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "win.h"

typedef struct SETTINGS SETTINGS;

typedef struct Args
{
Menu *menu;
Expand All @@ -15,6 +17,7 @@ typedef struct winArgs
{
HANDLE *mutex;
WINDOW *window;
SETTINGS *settings;
BOOL *active;
} winArgs;

Expand Down
53 changes: 49 additions & 4 deletions src/bin/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
void openWindows(WINDOWLIST *windows)
{
//mutex = CreateMutex(NULL, FALSE, NULL);

windows->count = 0;

EnumWindows(&EnumWindowsProc, (LPARAM)windows);

}

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

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

void borderlessWindow(HWND activeWindow)
{
SetWindowLongPtr(activeWindow, GWL_STYLE, GetWindowLongPtr(activeWindow, GWL_STYLE)^WS_OVERLAPPED^WS_THICKFRAME^WS_SYSMENU^WS_CAPTION);
SetWindowLongPtr(activeWindow, GWL_EXSTYLE, GetWindowLongPtr(activeWindow, GWL_EXSTYLE)^WS_EX_WINDOWEDGE);
}

void fullScreen(WINDOW activeWindow, PREVIOUSRECT *prev)
{
GetClientRect(activeWindow.hWnd, &activeWindow.size);
ClientToScreen(activeWindow.hWnd, &activeWindow.size.left);
ClientToScreen(activeWindow.hWnd, &activeWindow.size.right);

prev->width = activeWindow.size.right - activeWindow.size.left;
prev->height = activeWindow.size.bottom - activeWindow.size.top;
prev->x = activeWindow.size.left;
prev->y = activeWindow.size.top;

SetWindowPos(activeWindow.hWnd, NULL, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL);
}

void disableFullScreen(WINDOW activeWindow, PREVIOUSRECT *prev)
{
SetWindowPos(activeWindow.hWnd, NULL, prev->x, prev->y, prev->width, prev->height, NULL);
}


// threaded function to lock the cursor to specified window
int __stdcall cursorLockEx(void* arguments)
{
HANDLE hMessageStop = CreateEvent(NULL, FALSE, FALSE, _T("STOP"));
HANDLE hMessageEmpty = CreateEvent(NULL, FALSE, TRUE, _T("EMPTY"));
winArgs *args = (winArgs*)arguments;
WINDOW activeWindow = *args->window;
HWND const currentWindow = activeWindow.hWnd;

const HWND currentWindow = activeWindow.hWnd;

POINT cursorPos;

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

SETTINGS *settings = (SETTINGS*)args->settings;

PREVIOUSRECT previousrect;

if(settings->borderlessWindow)
borderlessWindow(currentWindow);

if(settings->fullScreen)
fullScreen(activeWindow, &previousrect);

// TODO: bring to foreground
// TODO: keep on top (WS_EX_TOP???)

// if window style has WS_SIZEBOX, remove it with EXCLUSIVE OR (^)
if(checkResizeStyle(activeWindow.hWnd))
{
Expand Down Expand Up @@ -112,6 +151,12 @@ int __stdcall cursorLockEx(void* arguments)
if(styleChanged)
SetWindowLongPtr(currentWindow, GWL_STYLE, GetWindowLongPtr(currentWindow, GWL_STYLE)|WS_SIZEBOX);

if(settings->borderlessWindow)
borderlessWindow(currentWindow);

if (settings->fullScreen)
disableFullScreen(activeWindow, &previousrect);

ClipCursor(NULL); // release the cursor clip
_endthreadex(1); // end thread_ex
return 1;
Expand Down
25 changes: 11 additions & 14 deletions src/bin/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
#include <Windows.h>
//#include "menu.h"


typedef struct PREVIOUSRECT
{
int width;
int height;
int x;
int y;
} PREVIOUSRECT;

typedef struct WINDOW
{
Expand All @@ -28,35 +34,26 @@ typedef struct Menu
WINDOWLIST windows;
WINDOW selectedWindow;
BOOL active;
int currentMenu;
int currentSelection;
BOOL live;
DWORD mode;
INPUT_RECORD event;
} Menu;

typedef enum MAINMENU
{
MAIN,
WINDOWS,
DEFAULT,
ACTIVE
} MAINMENU;

BOOL CALLBACK EnumWindowsProc(HWND, LPARAM);

void openWindows(WINDOWLIST*);
void clearWindows(WINDOWLIST*);
void getCurrentMousePos(POINT*);

void lockFocused(WINDOW*);

void cursorLock(void*);

BOOL checkClientArea(POINT*, RECT*);

BOOL checkResizeStyle(HWND);

void borderlessWindow(HWND);
void undoborderlessWindow(HWND);
void fullScreen(WINDOW, PREVIOUSRECT*);
void disableFullScreen(WINDOW, PREVIOUSRECT*);
int __stdcall cursorLockEx(void* arguments);

#endif
Binary file modified src/displayLock-win32.aps
Binary file not shown.
Binary file modified src/displayLock-win32.c
Binary file not shown.
Binary file modified src/displayLock-win32.rc
Binary file not shown.
Binary file modified src/resource.h
Binary file not shown.
35 changes: 24 additions & 11 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,36 @@
void initalizeSettings(HWND hDlg, SETTINGS* settings)
{
// get the checkbox
HWND checkbox = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
HWND minimize = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
HWND borderless = GetDlgItem(hDlg, IDC_SETTINGS_BORDERLESS);
HWND fullScreen = GetDlgItem(hDlg, IDC_SETTINGS_FULLSCREEN);


// check the current setting
int checkState;
if (!settings->minimize)
checkState = BST_UNCHECKED;
else
checkState = BST_CHECKED;

// update the dialog window
SendMessage(checkbox, BM_SETCHECK, checkState, 0);
SendMessage(minimize, BM_SETCHECK, settings->minimize, 0);
SendMessage(borderless, BM_SETCHECK, settings->borderlessWindow, 0);
SendMessage(fullScreen, BM_SETCHECK, settings->fullScreen, 0);
}

// update settings
void updateSettings(HWND hDlg, SETTINGS* settings)
{
// check the checkbox
HWND checkbox = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
settings->minimize = SendMessage(checkbox, BM_GETCHECK, 0, 0);
HWND minimize = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);
HWND borderless = GetDlgItem(hDlg, IDC_SETTINGS_BORDERLESS);
HWND fullScreen = GetDlgItem(hDlg, IDC_SETTINGS_FULLSCREEN);


//WORD wHotKey = LOWORD(SendMessage(GetDlgItem(hDlg, IDC_SETTINGS_HOTKEY), HKM_GETHOTKEY, 0, 0));
//settings->hotKeyCount = 0;

settings->minimize = SendMessage(minimize, BM_GETCHECK, 0, 0);
settings->borderlessWindow = SendMessage(borderless, BM_GETCHECK, 0, 0);
settings->fullScreen = SendMessage(fullScreen, BM_GETCHECK, 0, 0);
//settings->HOTKEY = LOBYTE(wHotKey);
//settings->HOTKEY_MODIFIERS[0] = HIBYTE(wHotKey);
//settings->hotKeyCount;
}

void writeSettings(SETTINGS settings)
Expand Down Expand Up @@ -61,13 +72,15 @@ void readSettings(SETTINGS *settings)
FILE *file = _wfopen(path, TEXT("r"));
if(file != NULL)
{
fread(settings, sizeof(settings), 1, file);
fread(settings, sizeof(*settings), 1, file);
fclose(file);
}
else
{
strcpy(settings->header, "DLOCK");
settings->minimize = 1;
settings->borderlessWindow = 0;
settings->fullScreen = 0;
}
// free memory
CoTaskMemFree(path);
Expand Down
5 changes: 5 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ typedef struct SETTINGS
{
char header[5];
BOOL minimize;
BOOL borderlessWindow;
BOOL fullScreen;
//BYTE HOTKEY;
//UINT8 hotKeyCount;
//BYTE HOTKEY_MODIFIERS[3];
} SETTINGS;
#pragma pack(pop)

Expand Down

0 comments on commit c68df98

Please sign in to comment.