Skip to content

Commit

Permalink
reorganize
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Nov 23, 2024
1 parent e4cc40a commit 2de7357
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
#include "enhanceddisplayswitch.h"
#include "EnhancedDisplaySwitch.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <shlobj.h>

void displayHelp() {
std::wcout << L"Usage: EnhancedDisplaySwitch.exe [option]\n";
std::wcout << L"Options:\n";
std::wcout << L" /internal or 1 Set display mode to internal\n";
std::wcout << L" /clone or 2 Set display mode to clone\n";
std::wcout << L" /external or 3 Set display mode to external\n";
std::wcout << L" /extend or 4 Set display mode to extend\n";
std::wcout << L" /lastmode or 5 Show the last used mode\n";
std::wcout << L" -h, --help, /? Display this help message\n";
}

void saveLastMode(const std::wstring& mode) {
HKEY hKey;
std::wstring subKey = L"SOFTWARE\\EnhancedDisplaySwitch";
Expand All @@ -25,7 +14,18 @@ void saveLastMode(const std::wstring& mode) {
}
}

std::wstring getLastMode() {
void EDS::displayHelp() {
std::wcout << L"Usage: EnhancedDisplaySwitch.exe [option]\n";
std::wcout << L"Options:\n";
std::wcout << L" /internal or 1 Set display mode to internal\n";
std::wcout << L" /clone or 2 Set display mode to clone\n";
std::wcout << L" /external or 3 Set display mode to external\n";
std::wcout << L" /extend or 4 Set display mode to extend\n";
std::wcout << L" /lastmode or 5 Show the last used mode\n";
std::wcout << L" -h, --help, /? Display this help message\n";
}

std::wstring EDS::getLastMode() {
HKEY hKey;
std::wstring subKey = L"SOFTWARE\\EnhancedDisplaySwitch";
std::wstring mode;
Expand All @@ -44,24 +44,28 @@ std::wstring getLastMode() {
return mode.empty() ? L"No last mode found." : mode;
}

void runDisplaySwitch(int mode) {
void EDS::runDisplaySwitch(int mode) {
LONG result = ERROR_SUCCESS;

switch (mode) {
case 1:
result = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_INTERNAL | SDC_APPLY);
saveLastMode(L"internal");
break;

case 2:
result = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_CLONE | SDC_APPLY);
saveLastMode(L"clone");
break;

case 3:
result = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTEND | SDC_APPLY);
saveLastMode(L"extend");
break;

case 4:
result = SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTERNAL | SDC_APPLY);
saveLastMode(L"external");
break;

default:
Expand Down
11 changes: 4 additions & 7 deletions EnhancedDisplaySwitch.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt

INCLUDEPATH += \
src/EnhancedDisplaySwitch

SOURCES += \
src/EnhancedDisplaySwitch/EnhancedDisplaySwitch.cpp \
src/main.cpp
EnhancedDisplaySwitch.cpp \
main.cpp

HEADERS += \
src/EnhancedDisplaySwitch/EnhancedDisplaySwitch.h
EnhancedDisplaySwitch.h

LIBS += -luser32
LIBS += -luser32 -ladvapi32

QMAKE_CXXFLAGS += -DUNICODE -D_UNICODE
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include <iostream>

void displayHelp();
void saveLastMode(const std::wstring& mode);
std::wstring getLastMode();
void runDisplaySwitch(int mode);
namespace EDS {
void displayHelp();
std::wstring getLastMode();
void runDisplaySwitch(int mode);
}

#endif // ENHANCED_DISPLAY_SWITCH_H
18 changes: 7 additions & 11 deletions src/main.cpp → main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "enhanceddisplayswitch.h"
#include "EnhancedDisplaySwitch.h"
#include <iostream>
#include <string>

Expand All @@ -12,21 +12,17 @@ int wmain(int argc, wchar_t* argv[])
std::wstring arg = argv[1];

if (arg == L"-h" || arg == L"--help" || arg == L"/?") {
displayHelp();
EDS::displayHelp();
} else if (arg == L"/internal" || arg == L"1") {
runDisplaySwitch(1);
saveLastMode(L"internal");
EDS::runDisplaySwitch(1);
} else if (arg == L"/clone" || arg == L"2") {
runDisplaySwitch(2);
saveLastMode(L"clone");
EDS::runDisplaySwitch(2);
} else if (arg == L"/extend" || arg == L"3") {
runDisplaySwitch(3);
saveLastMode(L"extend");
EDS:: runDisplaySwitch(3);
} else if (arg == L"/external" || arg == L"4") {
runDisplaySwitch(4);
saveLastMode(L"external");
EDS::runDisplaySwitch(4);
} else if (arg == L"/lastmode" || arg == L"5") {
std::wcout << getLastMode() << std::endl;
std::wcout << EDS::getLastMode() << std::endl;
} else {
std::wcerr << L"Invalid argument. Use /? -h or --help for usage information.\n";
return 1;
Expand Down

0 comments on commit 2de7357

Please sign in to comment.