Compare commits

...

5 Commits

Author SHA1 Message Date
cf310dc71c
Setup UI fonts 2026-06-04 20:20:51 -05:00
2d6a972e85
Change background color 2026-06-04 20:11:49 -05:00
35b0d02af5
Add tray icon 2026-06-04 19:41:31 -05:00
1d3e58587d
Add base dialog 2026-06-04 18:08:26 -05:00
fdbe1a07bb
Add precompiled header 2026-06-04 11:22:42 -05:00
8 changed files with 322 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.vs/
build/
*.aps

View File

@ -1,5 +1,5 @@
# Watchful Eye app CMakeLists.txt
add_executable(WatchfulEye WIN32 "src/main.cpp")
add_executable(WatchfulEye WIN32 "src/main.cpp" "src/pch.h" "src/Application.h" "src/Application.cpp" "resource.rc" "src/resource.h")
set_property(TARGET WatchfulEye PROPERTY CXX_STANDARD 20)
@ -9,6 +9,8 @@ if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set_property(TARGET WatchfulEye PROPERTY WIN32_EXECUTABLE FALSE)
endif()
target_precompile_headers(WatchfulEye PUBLIC "src/pch.h")
find_package(Git)
execute_process(COMMAND ${GIT_EXECUTABLE} describe OUTPUT_VARIABLE APPVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
configure_file(src/version.h.in version.h)

105
WatchfulEye/resource.rc Normal file
View File

@ -0,0 +1,105 @@
// Microsoft Visual C++ generated resource script.
//
#include "src/resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <winres.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"src/resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include <winres.h>\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOGMAIN DIALOGEX 0, 0, 300, 114
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOPMOST
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CTEXT "00:00",IDC_STATICTIME,17,35,266,60,SS_CENTERIMAGE,WS_EX_TRANSPARENT
CTEXT "Time left on tester:",IDC_STATICUPPER,7,4,286,22,SS_CENTERIMAGE,WS_EX_TRANSPARENT
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOGMAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 293
TOPMARGIN, 7
BOTTOMMARGIN, 107
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//
IDD_DIALOGMAIN AFX_DIALOG_LAYOUT
BEGIN
0
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,151 @@
// Application class implementation
#include "pch.h"
#include "Application.h"
#include "resource.h"
#define WM_TRAYICON WM_USER
#define IDM_EXIT 1001
namespace watchfuleye {
Application::Application(const char* appName, const char* appVersion)
: m_appName(appName)
, m_appVersion(appVersion)
, m_mainDlg(nullptr)
{
std::cout << std::format("{} {}\n", m_appName, m_appVersion);
}
void Application::run() {
// Create dialog
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
m_mainDlg = CreateDialogParam(nullptr, MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, reinterpret_cast<DLGPROC>(mainDlgProc), reinterpret_cast<LPARAM>(this));
// Create tray icon
createTrayIcon();
ShowWindow(m_mainDlg, SW_SHOW);
MSG msg = {};
while (GetMessage(&msg, nullptr, 0, 0))
IsDialogMessage(m_mainDlg, &msg);
}
BOOL CALLBACK Application::mainDlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) {
static Application* app = nullptr;
static UINT taskbarCreatedMessage = 0;
switch (msg) {
case WM_INITDIALOG: {
app = reinterpret_cast<Application*>(lParam);
SetWindowText(dlg, app->m_appName.c_str());
SendMessage(dlg, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION))));
// Spawn in the lower right corner of the virtual screen (might be problematic in some cases)
int cornerX = GetSystemMetrics(SM_XVIRTUALSCREEN) + GetSystemMetrics(SM_CXVIRTUALSCREEN);
int cornerY = GetSystemMetrics(SM_YVIRTUALSCREEN) + GetSystemMetrics(SM_CYVIRTUALSCREEN);
SetWindowPos(dlg, nullptr, cornerX - 550, cornerY - 340, NULL, NULL, SWP_NOZORDER | SWP_NOSIZE);
taskbarCreatedMessage = RegisterWindowMessage("TaskbarCreated");
// Set up UI
LOGFONT lFont = {};
strcpy(lFont.lfFaceName, "Consolas");
lFont.lfHeight = 50;
HFONT upperFont = CreateFontIndirect(&lFont);
SendMessage(GetDlgItem(dlg, IDC_STATICUPPER), WM_SETFONT, reinterpret_cast<WPARAM>(upperFont), NULL);
lFont.lfHeight = 200;
HFONT timeFont = CreateFontIndirect(&lFont);
SendMessage(GetDlgItem(dlg, IDC_STATICTIME), WM_SETFONT, reinterpret_cast<WPARAM>(timeFont), NULL);
return TRUE;
}
case WM_TRAYICON: {
if (LOWORD(lParam) == WM_RBUTTONDOWN) {
SetForegroundWindow(dlg);
POINT cursor = {};
GetCursorPos(&cursor);
HMENU popupMenu = CreatePopupMenu();
AppendMenu(popupMenu, MF_STRING, IDM_EXIT, "Exit");
TrackPopupMenu(popupMenu, NULL, cursor.x, cursor.y, NULL, dlg, nullptr); // Will block here. Might be problematic.
DestroyMenu(popupMenu);
}
return TRUE;
}
case WM_COMMAND: {
if (HIWORD(wParam) == 0 && LOWORD(wParam) == IDM_EXIT)
DestroyWindow(dlg);
return TRUE;
}
case WM_ERASEBKGND: {
HDC hDC = reinterpret_cast<HDC>(wParam);
HBRUSH backgroundBrush = CreateSolidBrush(RGB(255, 150, 150));
RECT clientRect = {};
GetClientRect(dlg, &clientRect);
FillRect(hDC, &clientRect, backgroundBrush);
DeleteObject(backgroundBrush);
return TRUE;
}
case WM_CTLCOLORSTATIC: {
if (GetWindowLongPtr(reinterpret_cast<HWND>(lParam), GWL_EXSTYLE) & WS_EX_TRANSPARENT) {
std::cout << "Test\n";
SetBkMode(reinterpret_cast<HDC>(wParam), TRANSPARENT);
return reinterpret_cast<INT_PTR>(GetStockObject(NULL_BRUSH));
}
return FALSE;
}
case WM_CLOSE: {
// Do nothing
return TRUE;
}
case WM_DESTROY: {
PostQuitMessage(0);
return TRUE;
}
}
if (msg == taskbarCreatedMessage)
app->createTrayIcon();
return FALSE;
}
void Application::createTrayIcon() {
NOTIFYICONDATA iconData = {};
iconData.cbSize = sizeof(iconData);
iconData.uVersion = NOTIFYICON_VERSION_4;
iconData.hWnd = m_mainDlg;
iconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
iconData.uCallbackMessage = WM_TRAYICON;
iconData.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
strcpy(iconData.szTip, m_appName.c_str());
Shell_NotifyIcon(NIM_ADD, &iconData);
}
Application::~Application() {
}
}

View File

@ -0,0 +1,19 @@
// Application class header
namespace watchfuleye {
class Application {
public:
Application(const char* appName, const char* appVersion);
void run();
~Application();
private:
static BOOL CALLBACK mainDlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam);
void createTrayIcon();
std::string m_appName, m_appVersion;
HWND m_mainDlg;
};
}

View File

@ -1,11 +1,21 @@
// Watchful Eye main file
#include <iostream>
#include "pch.h"
#include "version.h"
#include "Application.h"
// Enable visual styles
#pragma comment(linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define APPNAME "Watchful Eye"
int main(int argc, char* argv[]) {
std::cout << "Watchful Eye " APPVERSION "\n";
{
watchfuleye::Application app(APPNAME, APPVERSION);
app.run();
}
std::cin.get();
return EXIT_SUCCESS;
}

12
WatchfulEye/src/pch.h Normal file
View File

@ -0,0 +1,12 @@
// Watchful Eye precompiled header
// STD
#include <iostream>
#include <string>
#include <format>
#include <chrono>
// Windows
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <shellapi.h>

View File

@ -0,0 +1,18 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by C:\Users\Grayson\Documents\Visual Studio 18\Solutions\watchful-eye\WatchfulEye\resource.rc
//
#define IDD_DIALOGMAIN 101
#define IDC_STATICTIME 1000
#define IDC_STATICUPPER 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif