diff --git a/pppc.cc b/pppc.cc index 46b1ce2..71ceddb 100644 --- a/pppc.cc +++ b/pppc.cc @@ -76,9 +76,13 @@ int WinMain( cerr << "Warning: Shell_NotifyIcon(): " << GetLastError() << endl; } + /* begin capturing session notifications */ + session_notification_enable(hWnd); + BOOL bRet; MSG msg; - for (;;) + bool running = true; + while(running) { bRet = GetMessage(&msg, NULL, 0, 0); if (bRet == -1 || bRet == 0) @@ -93,21 +97,48 @@ int WinMain( case WM_COMMAND: cerr << "WM_COMMAND" << endl; break; + case WM_CLOSE: + case WM_DESTROY: + case WM_QUIT: + running = false; + break; + case WM_WTSSESSION_CHANGE: + if (msg.wParam == WTS_SESSION_LOGON + || msg.wParam == WTS_SESSION_UNLOCK) + { + pport_write(0xFF); + } + if (msg.wParam == WTS_SESSION_LOGOFF + || msg.wParam == WTS_SESSION_LOCK) + { + pport_write(0x0); + } + break; } } + /* stop listening for session notifications */ + session_notification_disable(hWnd); + 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; + case WM_CLOSE: + DestroyWindow(hWnd); + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + case WM_ICON_NOTIFY: + cerr << "WM_ICON_NOTIFY" << endl; break; } return 0;