From dde23b5594cfc9c4bb4ed23fc836fc99f86db9a9 Mon Sep 17 00:00:00 2001 From: joshholtrop Date: Wed, 29 Jul 2009 21:28:39 +0000 Subject: [PATCH] added skeleton window creation, tray icon creation, and message handling code git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@36 8131a0b2-b21c-1c47-bd6a-f003126495bd --- pppc.cc | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/pppc.cc b/pppc.cc index aa45be0..46b1ce2 100644 --- a/pppc.cc +++ b/pppc.cc @@ -1,16 +1,115 @@ #include +#include #include #include "session_notification.h" #include "pport.h" +#include "resources.h" using namespace std; +#define APP_NAME "Parallel Port Power Controller" +#define WM_ICON_NOTIFY (WM_APP + 42) + +LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + +static HINSTANCE m_hInstance; + int WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - cerr << "Hi there" << endl; + m_hInstance = hInstance; + + /* Load the application icon */ + HICON icon = ::LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); + if (icon == 0) + { + cerr << "Warning: LoadIcon(): " << GetLastError() << endl; + } + + /* Create the TrayIconClass class */ + WNDCLASSEX wcex; + memset(&wcex, 0, sizeof(wcex)); + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; + wcex.lpfnWndProc = (WNDPROC)WindowProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = icon; + wcex.hCursor = 0; + wcex.hbrBackground = 0; + wcex.lpszMenuName = 0; + wcex.lpszClassName = "TrayIconClass"; + wcex.hIconSm = 0; + + RegisterClassEx(&wcex); + + + /* Create the tray icon window */ + HWND hWnd = ::CreateWindow("TrayIconClass", "", WS_POPUP, + CW_USEDEFAULT,CW_USEDEFAULT, + CW_USEDEFAULT,CW_USEDEFAULT, + NULL, 0, + hInstance, 0); + if (hWnd == NULL) + { + cerr << "Warning: CreateWindow(): " << GetLastError() << endl; + } + + /* Create the notify icon data */ + NOTIFYICONDATA nid; + memset(&nid, 0, sizeof(nid)); + nid.cbSize = sizeof(NOTIFYICONDATA); + nid.hWnd = hWnd; + nid.uID = 0; + nid.hIcon = icon; + nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; + nid.uCallbackMessage = WM_ICON_NOTIFY; + strncpy(nid.szTip, APP_NAME, sizeof(nid.szTip)); + + BOOL bResult = Shell_NotifyIcon(NIM_ADD, &nid); + if (bResult == 0) + { + cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl; + } + + BOOL bRet; + MSG msg; + for (;;) + { + bRet = GetMessage(&msg, NULL, 0, 0); + if (bRet == -1 || bRet == 0) + { + break; + } + switch (msg.message) + { + case WM_PAINT: + cerr << "WM_PAINT" << endl; + break; + case WM_COMMAND: + cerr << "WM_COMMAND" << endl; + break; + } + } + + return bRet; +} + +LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + cerr << "WindowProc()" << endl; + switch (message) + { + case WM_NCCREATE: + return 1; + case WM_CREATE: + cerr << "WindowProc(): WM_CREATE" << endl; + break; + } return 0; } +