-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from idietmoran/dev-win32
Added settings and config saving
- Loading branch information
Showing
14 changed files
with
126 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/x64/ | ||
*.vcxproj.* | ||
.vs/ | ||
*.DLOCK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |