added session_notification module

git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@32 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
joshholtrop 2009-07-29 17:10:35 +00:00
parent 017bf47501
commit f0fa9956af
3 changed files with 91 additions and 1 deletions

View File

@ -1,6 +1,6 @@
TARGET := pppc.exe
OBJS := pppc.o
OBJS := pppc.o session_notification.o
CXXFLAGS := -O2 -Wall
all: $(TARGET)

70
session_notification.cc Normal file
View File

@ -0,0 +1,70 @@
#include <windows.h>
#include <stdlib.h>
#include <iostream>
#include "session_notification.h"
using namespace std;
static BOOL WINAPI (*WTSRegisterSessionNotification)(HWND, DWORD) = NULL;
static BOOL WINAPI (*WTSUnRegisterSessionNotification)(HWND) = NULL;
static HMODULE wtsapi = NULL;
void session_notification_enable(HWND hWnd)
{
if (wtsapi == NULL)
{
wtsapi = LoadLibrary("wtsapi32.dll");
if (wtsapi == NULL)
{
cerr << "Could not load wtsapi32.dll!" << endl;
exit(2);
}
}
if (WTSRegisterSessionNotification == NULL)
{
WTSRegisterSessionNotification = (BOOL WINAPI (*)(HWND, DWORD))
GetProcAddress(wtsapi, "WTSRegisterSessionNotification");
if (WTSRegisterSessionNotification == NULL)
{
cerr << "Could not obtain WTSRegisterSessionNotification address!"
<< endl;
exit(3);
}
}
if (WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_ALL_SESSIONS)
!= TRUE)
{
cerr << "WTSRegisterSessionNotification() error: "
<< GetLastError() << endl;
}
}
void session_notification_disable(HWND hWnd)
{
if (wtsapi == NULL)
{
wtsapi = LoadLibrary("wtsapi32.dll");
if (wtsapi == NULL)
{
cerr << "Could not load wtsapi32.dll!" << endl;
exit(2);
}
}
if (WTSUnRegisterSessionNotification == NULL)
{
WTSUnRegisterSessionNotification = (BOOL WINAPI (*)(HWND))
GetProcAddress(wtsapi, "WTSUnRegisterSessionNotification");
if (WTSUnRegisterSessionNotification == NULL)
{
cerr << "Could not obtain WTSUnRegisterSessionNotification address!"
<< endl;
exit(3);
}
}
if (WTSUnRegisterSessionNotification(hWnd) != TRUE)
{
cerr << "WTSUnRegisterSessionNotification() error: "
<< GetLastError() << endl;
}
}

20
session_notification.h Normal file
View File

@ -0,0 +1,20 @@
#include <windows.h>
#define NOTIFY_FOR_THIS_SESSION 0
#define NOTIFY_FOR_ALL_SESSIONS 1
#define WM_WTSSESSION_CHANGE 0x02B1
#define WTS_CONSOLE_CONNECT 0x1
#define WTS_CONSOLE_DISCONNECT 0x2
#define WTS_REMOTE_CONNECT 0x3
#define WTS_REMOTE_DISCONNECT 0x4
#define WTS_SESSION_LOGON 0x5
#define WTS_SESSION_LOGOFF 0x6
#define WTS_SESSION_LOCK 0x7
#define WTS_SESSION_UNLOCK 0x8
#define WTS_SESSION_REMOTE_CONTROL 0x9
void session_notification_enable(HWND hWnd);
void session_notification_disable(HWND hWnd);