Compare commits

..

6 Commits

Author SHA1 Message Date
cedb800012 Fix annotations for WinMain
Fix "C28251 Inconsistent annotation for function" compiler warning by correctly defining WinMain.
2025-08-15 11:44:51 -07:00
5911ca0100 Update README.md
Update the readme to reflect the current state of the project. The program is much more complete now, and has been tested and works flawlessly on both Windows Vista and 7.
2025-08-14 23:20:15 -07:00
e4157e70b3 Fix 32-bit profiles 2025-08-12 12:40:59 -04:00
a5555b4ee1 Guarantee Vista support
Define NT version headers so that Windows Vista support should reasonably be guaranteed, since we will not be using any newer APIs.
2025-08-12 09:16:34 -04:00
01727c04f0 Remove the battery warning
The battery warning could be annoying, and the option to disable it is confusing to somebody who may never see it.
2025-08-11 15:33:32 -04:00
e5dbac5879 Fix Debug and Release profiles for both x86 and x64
Application now builds with debug and release profiles on both x86 and x64.
2025-08-11 12:55:04 -04:00
5 changed files with 29 additions and 23 deletions

View File

@ -2,16 +2,15 @@
A utility for switching the resolution of your laptop's display based on the current power state.
Currently a work in progress. Not very useful yet since it doesn't save your preferences. It doesn't even have an icon.
Currently a work in progress. It works reasonably well for a standard single display configuration, but other scenarios have not been extensively tested, and there are some edge cases that may need to be worked out.
This is a simple C program written using Visual Studio 2022 that has no external dependencies. It should support Windows Vista or higher, but this hasn't been tested yet.
This is a simple C program written using Visual Studio 2022 that has no external dependencies. It supports Windows Vista or higher.
## TODO
- [x] Save preferences to the Windows registry.
- [x] Add a checkbox to preferences for starting at login.
- [x] Add an icon.
- [ ] Add behavior for when multiple displays are connected.
- [x] Warn the user when the system has no battery.
- [x] Make the default display mode the current one instead of the highest resolution if there are no preferences set.
- [ ] Make an actual about dialog.
- [ ] Support dark mode.

View File

@ -1,3 +1,7 @@
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#define NTDDI_VERSION NTDDI_VISTA
#include <stdio.h>
#include <windows.h>
#include <shellapi.h>
@ -124,7 +128,6 @@ static void TestDisplayMode(HWND hDlg, DISPLAY_MODE* mode) {
typedef struct {
DISPLAY_MODE modeBatt;
DISPLAY_MODE modeAC;
DWORD disableBatteryWarning;
BOOL runAtStartup;
} WINPOWERDMS_PREFS;
@ -145,7 +148,6 @@ static BOOL SavePrefs(void) {
RegSetKeyValue(regKey, L"AC Power", L"Width", REG_DWORD, &userPrefs.modeAC.width, sizeof(userPrefs.modeAC.width));
RegSetKeyValue(regKey, L"AC Power", L"Height", REG_DWORD, &userPrefs.modeAC.height, sizeof(userPrefs.modeAC.height));
RegSetKeyValue(regKey, L"AC Power", L"Refresh Rate", REG_DWORD, &userPrefs.modeAC.refresh, sizeof(userPrefs.modeAC.refresh));
RegSetValueEx(regKey, L"Disable Battery Warning", 0, REG_DWORD, &userPrefs.disableBatteryWarning, sizeof(userPrefs.disableBatteryWarning));
RegCloseKey(regKey);
saved = TRUE;
}
@ -180,8 +182,6 @@ static BOOL LoadPrefs(void) {
RegGetValue(regKey, L"AC Power", L"Height", RRF_RT_REG_DWORD, NULL, &userPrefs.modeAC.height, &keySize);
keySize = sizeof(userPrefs.modeAC.refresh);
RegGetValue(regKey, L"AC Power", L"Refresh Rate", RRF_RT_REG_DWORD, NULL, &userPrefs.modeAC.refresh, &keySize);
keySize = sizeof(userPrefs.disableBatteryWarning);
RegGetValue(regKey, NULL, L"Disable Battery Warning", RRF_RT_REG_DWORD, NULL, &userPrefs.disableBatteryWarning, &keySize);
RegCloseKey(regKey);
loaded = TRUE;
}
@ -206,8 +206,7 @@ static DISPLAY_MODE GetCurrentDisplayMode(void) {
static INT_PTR CALLBACK PrefsDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
HWND hComboBatt = GetDlgItem(hDlg, IDC_COMBO_BATT);
HWND hComboAC = GetDlgItem(hDlg, IDC_COMBO_AC);
HWND hCheckBattWarning = GetDlgItem(hDlg, IDC_CHECK_BATT_WARNING);
HWND hCheckStartup = GetDlgItem(hCheckBattWarning, IDC_CHECK_STARTUP);
HWND hCheckStartup = GetDlgItem(hDlg, IDC_CHECK_STARTUP);
switch (uMsg) {
case WM_INITDIALOG: {
@ -246,7 +245,6 @@ static INT_PTR CALLBACK PrefsDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPA
}
}
SendMessage(hCheckBattWarning, BM_SETCHECK, userPrefs.disableBatteryWarning ? BST_CHECKED : BST_UNCHECKED, 0);
SendMessage(hCheckStartup, BM_SETCHECK, userPrefs.runAtStartup ? BST_CHECKED : BST_UNCHECKED, 0);
return TRUE;
}
@ -257,7 +255,6 @@ static INT_PTR CALLBACK PrefsDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPA
case IDOK: {
userPrefs.modeBatt = GetModeFromCB(hComboBatt);
userPrefs.modeAC = GetModeFromCB(hComboAC);
userPrefs.disableBatteryWarning = SendMessage(hCheckBattWarning, BM_GETCHECK, 0, 0) == BST_CHECKED;
userPrefs.runAtStartup = SendMessage(hCheckStartup, BM_GETCHECK, 0, 0) == BST_CHECKED;
SavePrefs();
if (LOWORD(wParam) == IDC_BUTTON_APPLY) return TRUE;
@ -340,7 +337,7 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) {
if (!LoadPrefs()) { // set both battery and AC to current display mode if there are no preferences set
DISPLAY_MODE currentMode = GetCurrentDisplayMode();
userPrefs.modeAC = currentMode;
@ -359,11 +356,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
HWND hWnd = CreateWindowEx(0, L"TrayAppClass", NULL, 0, 0, 0, 0, 0,
HWND_MESSAGE, NULL, hInstance, NULL);
RegisterPowerSettingNotification(hWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE);
// Check if there is a battery in the system and display a warning message if there isn't one.
SYSTEM_POWER_STATUS powerStatus;
if (!userPrefs.disableBatteryWarning && GetSystemPowerStatus(&powerStatus) && powerStatus.BatteryFlag == 128)
MessageBox(hWnd, L"There is no battery present in the system. The program will start and set your display mode to what you have set for AC power, but do nothing else afterwards.", L"WinPowerDMS", MB_OK | MB_ICONWARNING);
// Create context menu
hMenu = CreatePopupMenu();

Binary file not shown.

View File

@ -79,9 +79,14 @@
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ComCtl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
@ -93,9 +98,14 @@
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ComCtl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@ -108,9 +118,10 @@
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ComCtl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
</Link>
<Manifest>
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
<EnableDpiAwareness>true</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -123,9 +134,14 @@
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ComCtl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<MinimumRequiredVersion>6.0</MinimumRequiredVersion>
</Link>
<Manifest>
<EnableDpiAwareness>true</EnableDpiAwareness>
</Manifest>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="WinPowerDMS.c" />

View File

@ -10,8 +10,7 @@
#define IDC_BUTTON_TEST_AC 1004
#define IDC_BUTTON_APPLY 1005
#define IDC_LIST1 1006
#define IDC_CHECK_BATT_WARNING 1007
#define IDC_CHECK_STARTUP 1008
#define IDC_CHECK_STARTUP 1007
// Next default values for new objects
//