Skip to content

Commit

Permalink
Merge pull request #19 from idietmoran/dev-win32
Browse files Browse the repository at this point in the history
Added settings and config saving
  • Loading branch information
Stateford authored Apr 13, 2018
2 parents 948cacd + cdad791 commit 069af80
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/x64/
*.vcxproj.*
.vs/
*.DLOCK
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog
All notable changes to this project will be documented in this file.
## [1.1.0]
All notable changes to this project will be documented in this file

## [1.0.4]
### Added
- Added Settings Menu
- Added Config File
- Config File saves to appdata/roaming/DisplayLock/settings.DLOCK

### Fixed
- Fixed issue when using alt+tab to switch windows would change the currently selected window in the drop down list

### Removed
- Unessecary symbols that would use more RAM

## [1.0.3]
### Added
- Added meta tags for windows

Expand Down
21 changes: 17 additions & 4 deletions Display Lock.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_WINDOWS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Expand All @@ -89,11 +89,13 @@
<TargetMachine>MachineX86</TargetMachine>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_WINDOWS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
Expand All @@ -105,6 +107,8 @@
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -115,10 +119,12 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -129,16 +135,19 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\bin\menu.c" />
<ClCompile Include="src\bin\win.c" />
<ClCompile Include="src\displayLock-win32.c" />
<ClCompile Include="src\settings.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\bin\menu.h">
Expand All @@ -156,6 +165,9 @@
<ClInclude Include="src\resource.h">
<FileType>CppCode</FileType>
</ClInclude>
<ClInclude Include="src\settings.h">
<FileType>CppCode</FileType>
</ClInclude>
<ClInclude Include="src\targetver.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -174,6 +186,7 @@
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<SubType>Designer</SubType>
</Manifest>
</ItemGroup>
<ItemGroup>
Expand Down
13 changes: 1 addition & 12 deletions src/bin/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@ void initMenu(Menu *menu)
menu->currentSelection = 0;
menu->active = FALSE;
menu->live = TRUE;

menu->mainMenu.maxSelections = 3;

strcpy_s(menu->mainMenu.options[0], 30, "Select Window");
strcpy_s(menu->mainMenu.options[1], 30, "Start");
strcpy_s(menu->mainMenu.options[2], 30, "Quit");

menu->hstdin = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(menu->hstdin, &menu->mode);
SetConsoleMode(menu->hstdin, 0);
menu->hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
}

void updateComboBoxT(Args *arguments)
void updateComboBox(Args *arguments)
{
openWindows(&arguments->menu->windows); // open open windows
}
Expand Down
4 changes: 1 addition & 3 deletions src/bin/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ typedef struct winArgs
} winArgs;

void initMenu(Menu*);
void updateComboBoxT(Args*);
void updateComboBox(void*);
int __stdcall updateComboBoxEx(void *arguments);
void updateComboBox(Args*);
WINDOW *sortWindow(Args*, char*, int);

#endif
10 changes: 0 additions & 10 deletions src/bin/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,16 @@ typedef struct WINDOWLIST
} WINDOWLIST;


typedef struct Main
{
int maxSelections;
char options[5][30];
} Main;

typedef struct Menu
{
Main mainMenu;
WINDOWLIST windows;
WINDOW selectedWindow;
BOOL active;
int currentMenu;
int currentSelection;
BOOL live;
BOOL consoleWindowIsFocused;
DWORD mode;
INPUT_RECORD event;
HANDLE hstdin;
HANDLE hConsole;
} Menu;

typedef enum MAINMENU
Expand Down
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.h
Binary file not shown.
Binary file modified src/displayLock-win32.rc
Binary file not shown.
Binary file modified src/header.h
Binary file not shown.
Binary file modified src/resource.h
Binary file not shown.
74 changes: 74 additions & 0 deletions src/settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "settings.h"
#include <stdio.h>
#include <ShlObj.h>
#include <shtypes.h>
#include "Shlwapi.h"


// initalizes settings window on startup
void initalizeSettings(HWND hDlg, SETTINGS* settings)
{
// get the checkbox
HWND checkbox = GetDlgItem(hDlg, IDC_SETTINGS_MINIMIZE);

// 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);
}

// 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);
}

// TODO: This should probably save to a temp folder instead of a local folder to make the program more portable
void writeSettings(SETTINGS settings)
{
PWSTR path = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, 0, &path);

// create directory
PathAppend(path, TEXT("DisplayLock"));
CreateDirectory(path, NULL);
// create file
PathAppend(path, TEXT("\\settings.DLOCK"));
FILE *file = _wfopen(path, TEXT("w"));

fwrite(&settings, sizeof(settings), 1, file);
fclose(file);

// free the memory
CoTaskMemFree(path);
}

// TODO: read from new folder
void readSettings(SETTINGS *settings)
{
PWSTR path = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, 0, &path);

PathAppend(path, TEXT("DisplayLock\\settings.DLOCK"));

FILE *file = _wfopen(path, TEXT("r"));
if(file != NULL)
{
fread(settings, sizeof(settings), 1, file);
fclose(file);
}
else
{
strcpy(settings->header, "DLOCK");
settings->minimize = 1;
}
// free memory
CoTaskMemFree(path);
}
17 changes: 17 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "header.h"

// pack the struct to easily read from file
#pragma pack(push, 1)
typedef struct SETTINGS
{
char header[5];
BOOL minimize;
} SETTINGS;
#pragma pack(pop)

void initalizeSettings(HWND hDlg, SETTINGS* settings);
void updateSettings(HWND hDlg, SETTINGS *settings);

void writeSettings(SETTINGS settings);
void readSettings(SETTINGS *settings);

0 comments on commit 069af80

Please sign in to comment.