- Code: Select all Expand view RUN
- #include "FiveWin.ch"
#define WM_WTSSESSION_CHANGE 0x02B1
#define WTS_CONSOLE_CONNECT 0x1 // The session identified by lParam was connected to the console terminal or RemoteFX session.
#define WTS_CONSOLE_DISCONNECT 0x2 // The session identified by lParam was disconnected from the console terminal or RemoteFX session.
#define WTS_REMOTE_CONNECT 0x3 // The session identified by lParam was connected to the remote terminal.
#define WTS_REMOTE_DISCONNECT 0x4 // The session identified by lParam was disconnected from the remote terminal.
#define WTS_SESSION_LOGON 0x5 // A user has logged on to the session identified by lParam.
#define WTS_SESSION_LOGOFF 0x6 // A user has logged off the session identified by lParam.
#define WTS_SESSION_LOCK 0x7 // The session identified by lParam has been locked.
#define WTS_SESSION_UNLOCK 0x8 // The session identified by lParam has been unlocked.
#define WTS_SESSION_REMOTE_CONTROL 0x9 // The session identified by lParam has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric.
#define WTS_SESSION_CREATE 0xA // Reserved for future use.
#define WTS_SESSION_TERMINATE 0xB // Reserved for future use.
#define NOTIFY_FOR_ALL_SESSIONS 1
#define NOTIFY_FOR_THIS_SESSION 0
function Main()
local oWnd := TMyWindow():New()
WTSRegisterSessionNotification( oWnd:hWnd, NOTIFY_FOR_ALL_SESSIONS )
ACTIVATE WINDOW oWnd VALID ( WTSUnRegisterSessionNotification( oWnd:hWnd ), .T. )
return nil
CLASS TMyWindow FROM TWindow
METHOD HandleEvent( nMsg, nWParam, nLParam )
ENDCLASS
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyWindow
if nMsg == WM_WTSSESSION_CHANGE
switch nWParam
case WTS_CONSOLE_CONNECT
MsgInfo( "WTS_CONSOLE_CONNECT", "console ID:" + AllTrim( Str( nLParam ) ) )
case WTS_CONSOLE_DISCONNECT
MsgInfo( "WTS_CONSOLE_DISCONNECT", "console ID:" + AllTrim( Str( nLParam ) ) )
end
endif
return ::Super:HandleEvent( nMsg, nWParam, nLParam )
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <wtsapi32.h>
HB_FUNC( WTSREGISTERSESSIONNOTIFICATION )
{
hb_retl( WTSRegisterSessionNotification( ( HWND ) hb_parnll( 1 ), hb_parnl( 2 ) ) );
}
HB_FUNC( WTSUNREGISTERSESSIONNOTIFICATION )
{
hb_retl( WTSUnRegisterSessionNotification( ( HWND ) hb_parnll( 1 ) ) );
}
#pragma ENDDUMP