Skip to content

Commit

Permalink
Merge pull request #70 from idietmoran/iss42
Browse files Browse the repository at this point in the history
Iss42
  • Loading branch information
Stateford authored Oct 4, 2018
2 parents d297067 + b6c0fc1 commit cd98efe
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 24 deletions.
28 changes: 27 additions & 1 deletion Display-Lock/DisplayLock.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,27 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
CreateDialog(NULL, MAKEINTRESOURCE(IDD_MAIN_VIEW), hWnd, MainWindow);
invokeReadSettings(&settings);
notifyInit(hWnd, &sysTray);
initHotkey(hWnd, &settings);

menu = LoadMenu(NULL, MAKEINTRESOURCE(IDR_NOTIFY_MENU));
Shell_NotifyIcon(NIM_ADD, &sysTray);
Shell_NotifyIcon(NIM_SETVERSION, &sysTray);
break;

case WM_HOTKEY:
switch (wParam) {
// id of hotkey
case START_STOP:
if (running)
notifyChildWindows(hWnd, IDC_BUTTON_WINDOWS_STOP);
else
notifyChildWindows(hWnd, IDC_BUTTON_WINDOWS_START);
break;
default:
break;
}
break;

case NOTIFY_MSG:
switch (lParam)
{
Expand Down Expand Up @@ -217,6 +233,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_CLOSE:
Shell_NotifyIcon(NIM_DELETE, &sysTray);
cleanupHotkeys(hWnd, &settings);
shutDown(settings);
DestroyWindow(hWnd);
break;
Expand Down Expand Up @@ -285,12 +302,14 @@ INT_PTR CALLBACK windowViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM l
static WINDOW_VIEW_CONTROLS windowControls;
static MENU menu;
static ARGS args;


UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
initalizeWindowView(hDlg, &menu, &settings, &running, &windowControls, &args);

return (INT_PTR)TRUE;

case WM_COMMAND:
Expand Down Expand Up @@ -336,6 +355,7 @@ INT_PTR CALLBACK settingsViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
{
static SETTINGS_VIEW_CONTROLS settingsControls;
static SETTINGS previousSettings;
static HWND parent;

UNREFERENCED_PARAMETER(lParam);
switch (message)
Expand All @@ -354,6 +374,7 @@ INT_PTR CALLBACK settingsViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
break;
case WM_INITDIALOG:
initalizeSettings(hDlg, &settingsControls);
parent = GetParent(GetParent(GetParent(hDlg)));
return (INT_PTR)TRUE;
case WM_COMMAND:
{
Expand All @@ -380,9 +401,14 @@ INT_PTR CALLBACK settingsViewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM
settings.minimize = (BOOL)SendMessage(settingsControls.minimize, BM_GETCHECK, 0, 0);
break;

case IDC_HOTKEY:
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS_SAVE), TRUE);
settingsControls.settingsChanged = TRUE;
break;

case IDC_BUTTON_SETTINGS_SAVE:
EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_SETTINGS_SAVE), FALSE);
settingsSave(settingsControls, settings, &previousSettings);
settingsSave(parent, settingsControls, settings, &previousSettings);
break;

case IDC_BUTTON_SETTINGS_CANCEL:
Expand Down
Binary file modified Display-Lock/resources/resource.aps
Binary file not shown.
Binary file modified Display-Lock/resources/resource.h
Binary file not shown.
Binary file modified Display-Lock/resources/resource.rc
Binary file not shown.
28 changes: 13 additions & 15 deletions Display-Lock/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "win.h"
#include "menu.h"
#include "settings.h"
#include "hotkey.h"

BOOL getVersionString(wchar_t * buffer, int bufferSize)
{
Expand Down Expand Up @@ -49,31 +50,27 @@ void settingsShowWindow(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS * sett
SendMessage(settingsControls.fullScreen, BM_SETCHECK, settings->fullScreen, 0);
SendMessage(settingsControls.minimize, BM_SETCHECK, settings->minimize, 0);

if (running)
{
EnableWindow(settingsControls.borderless, FALSE);
EnableWindow(settingsControls.foreground, FALSE);
EnableWindow(settingsControls.fullScreen, FALSE);
EnableWindow(settingsControls.minimize, FALSE);
}
else
{
EnableWindow(settingsControls.borderless, TRUE);
EnableWindow(settingsControls.foreground, TRUE);
EnableWindow(settingsControls.fullScreen, TRUE);
EnableWindow(settingsControls.minimize, TRUE);
}
EnableWindow(settingsControls.borderless, !running);
EnableWindow(settingsControls.foreground, !running);
EnableWindow(settingsControls.fullScreen, !running);
EnableWindow(settingsControls.minimize, !running);
EnableWindow(settingsControls.hotkey, !running);


}


void settingsSave(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS settings, SETTINGS *previousSettings)
void settingsSave(HWND hWnd,SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS settings, SETTINGS *previousSettings)
{
settings.borderless = (BOOL)SendMessage(settingsControls.borderless, BM_GETCHECK, 0, 0);
settings.foreground = (BOOL)SendMessage(settingsControls.foreground, BM_GETCHECK, 0, 0);
settings.fullScreen = (BOOL)SendMessage(settingsControls.fullScreen, BM_GETCHECK, 0, 0);
settings.minimize = (BOOL)SendMessage(settingsControls.minimize, BM_GETCHECK, 0, 0);

WORD hotkey = (WORD)SendMessage(settingsControls.hotkey, HKM_GETHOTKEY, 0, 0);

addHotkey(hWnd, &settings, START_STOP, HIBYTE(hotkey), LOBYTE(hotkey));

*previousSettings = settings;
}

Expand All @@ -84,6 +81,7 @@ void settingsCancel(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS *settings,
SendMessage(settingsControls.foreground, BM_SETCHECK, settings->foreground, 0);
SendMessage(settingsControls.fullScreen, BM_SETCHECK, settings->fullScreen, 0);
SendMessage(settingsControls.minimize, BM_SETCHECK, settings->minimize, 0);
SendMessage(settingsControls.hotkey, HKM_SETHOTKEY, 0, 0);
}

void initalizeWindowView(HWND hDlg, MENU *menu, SETTINGS *settings, volatile BOOL *running, WINDOW_VIEW_CONTROLS *windowControls, ARGS *args)
Expand Down
2 changes: 1 addition & 1 deletion Display-Lock/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

BOOL getVersionString(wchar_t *buffer, int bufferSize);
void settingsShowWindow(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS *settings, SETTINGS *previousSettings, BOOL running);
void settingsSave(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS settings, SETTINGS *previousSettings);
void settingsSave(HWND hWnd, SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS settings, SETTINGS *previousSettings);
void settingsCancel(SETTINGS_VIEW_CONTROLS settingsControls, SETTINGS *settings, SETTINGS previousSettings);

void initalizeWindowView(HWND hDlg, MENU *menu, SETTINGS *settings, volatile BOOL *running, WINDOW_VIEW_CONTROLS *windowControls, ARGS *args);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Lightweight program that locks cursor in selected window, designed with performance in mind.

#### USES
-----------------
------------------
- Keeps cursor in a windowed game to prevent clicking outside
- Will stay active while the window is focused
- Keeps cursor in a fullscreen game while using a multi-monitor setup
Expand Down
2 changes: 2 additions & 0 deletions dispLib/dispLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@
<ItemGroup>
<ClInclude Include="include\common.h" />
<ClInclude Include="include\header.h" />
<ClInclude Include="include\hotkey.h" />
<ClInclude Include="include\menu.h" />
<ClInclude Include="include\settings.h" />
<ClInclude Include="include\win.h" />
<ClInclude Include="include\notify.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\hotkey.c" />
<ClCompile Include="src\menu.c" />
<ClCompile Include="src\notify.c" />
<ClCompile Include="src\settings.c" />
Expand Down
Binary file modified dispLib/include/common.h
Binary file not shown.
Binary file modified dispLib/include/header.h
Binary file not shown.
7 changes: 7 additions & 0 deletions dispLib/include/hotkey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "common.h"

void initHotkey(HWND hWnd, SETTINGS *settings);
BOOL addHotkey(HWND hWnd, SETTINGS *settings, int msgID, int modifier, unsigned int key);
BOOL removeHotkey(HWND hWnd, SETTINGS *settings, int index);
void cleanupHotkeys(HWND hWnd, SETTINGS *settings);
56 changes: 56 additions & 0 deletions dispLib/src/hotkey.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "hotkey.h"

void initHotkey(HWND hWnd, SETTINGS *settings)
{
for (int i = 0; i < settings->numOfHotkeys; i++)
{
RegisterHotKey(hWnd, settings->hotkeys[i].id, settings->hotkeys[i].modifiers, settings->hotkeys[i].key);
}
}


BOOL addHotkey(HWND hWnd, SETTINGS *settings, int msgID, int modifier, unsigned int key)
{
/*
if (settings->numOfHotkeys > 1)
return FALSE;
*/
UnregisterHotKey(hWnd, msgID);
BOOL result = RegisterHotKey(hWnd, msgID, modifier, key);

// store in setting
if (result)
{
settings->hotkeys[0] = (HOTKEY) { msgID, modifier, key };
//settings->numOfHotkeys++;
}

return result;
}


BOOL removeHotkey(HWND hWnd, SETTINGS *settings, int index)
{
if (index > settings->numOfHotkeys)
return FALSE;

// unregister the hotkey
BOOL result = UnregisterHotKey(hWnd, settings->hotkeys[index].id);

// remove hotkeys from settings
if (result)
{
settings->hotkeys[index] = (HOTKEY) { 0 };
//settings->numOfHotkeys--;
}

return result;
}

void cleanupHotkeys(HWND hWnd, SETTINGS *settings)
{
for (int i = 0; i < settings->numOfHotkeys; i++)
{
UnregisterHotKey(hWnd, settings->hotkeys[i].id);
}
}
4 changes: 4 additions & 0 deletions dispLib/src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void initalizeSettings(HWND hDlg, SETTINGS_VIEW_CONTROLS *settingsControls)
settingsControls->foreground = GetDlgItem(hDlg, IDC_CHECK_SETTINGS_FOREGROUND);
settingsControls->borderless = GetDlgItem(hDlg, IDC_CHECK_SETTINGS_BORDERLESS);
settingsControls->fullScreen = GetDlgItem(hDlg, IDC_CHECK_SETTINGS_FULL_SCREEN);
settingsControls->hotkey = GetDlgItem(hDlg, IDC_HOTKEY);
settingsControls->settingsChanged = FALSE;
}

Expand All @@ -34,6 +35,9 @@ void defaultSettings(SETTINGS *settings, wchar_t *versionStr)
settings->foreground = FALSE;
settings->fullScreen = FALSE;
settings->minimize = TRUE;
settings->numOfHotkeys = 0;
settings->hotkeys[0] = (HOTKEY){ 0 };
settings->hotkeys[1] = (HOTKEY){ 0 };
}

BOOL checkVersion(SETTINGS *settings, wchar_t *versionStr)
Expand Down
1 change: 1 addition & 0 deletions scripts/buildInc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import os


def writeHeader(filePath, config, version, build):
print("Writing to path: %s\n" % filePath)
versSplit = version.split('.')
Expand Down
14 changes: 12 additions & 2 deletions scripts/parseConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Reads binary from a DLOCK config file and prints it in a human readable format

import struct
import sys

# config for config version 5
class ConfigV5:
# constructor, takes a string path as an argument
def __init__(self, path):
def __init__(self, path: str):
self.path = path
self.header = None
self.version = None
Expand Down Expand Up @@ -51,4 +52,13 @@ def start(self):
self.openFile()
self.parse()
self.printResults()


def main():
print(sys.argv)
if(len(sys.argv) < 2):
raise Exception("Pass an argument in")
output = ConfigV5(sys.argv[1])
output.start()


main()
8 changes: 4 additions & 4 deletions tests/tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>false</LinkIncremental>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>false</LinkIncremental>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand Down

0 comments on commit cd98efe

Please sign in to comment.