CVS: seamlessrdp/ServerExe clipper.rc,NONE,1.1 clipper.vcproj,NONE,1.1 icon.ico,NONE,1.1 main.cpp,NONE,1.1 resource.h,NONE,1.1

Peter Åstrand <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/seamlessrdp/ServerExe
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1824/ServerExe

Added Files:
	clipper.rc clipper.vcproj icon.ico main.cpp resource.h 
Log Message:
Imported CodeProject tswindowclipper source.

--- NEW FILE: clipper.rc ---
// Microsoft Visual C++ generated resource script.

//

#include "resource.h"



#define APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////

//

// Generated from the TEXTINCLUDE 2 resource.

//

#include "afxres.h"



/////////////////////////////////////////////////////////////////////////////

#undef APSTUDIO_READONLY_SYMBOLS



/////////////////////////////////////////////////////////////////////////////

// German (Germany) resources



#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)

#ifdef _WIN32

LANGUAGE LANG_GERMAN, SUBLANG_GERMAN

#pragma code_page(1252)

#endif //_WIN32



#ifdef APSTUDIO_INVOKED

/////////////////////////////////////////////////////////////////////////////

//

// TEXTINCLUDE

//



1 TEXTINCLUDE 

BEGIN

    "resource.h\0"

END



2 TEXTINCLUDE 

BEGIN

    "#include ""afxres.h""\r\n"

    "\0"

END



3 TEXTINCLUDE 

BEGIN

    "\r\n"

    "\0"

END



#endif    // APSTUDIO_INVOKED





/////////////////////////////////////////////////////////////////////////////

//

// Icon

//



// Icon with lowest ID value placed first to ensure application icon

// remains consistent on all systems.

IDI_TRAY                ICON                    "icon.ico"



/////////////////////////////////////////////////////////////////////////////

//

// Menu

//



IDR_TRAY MENU 

BEGIN

    POPUP "&Terminal Services Window Clipper"

    BEGIN

        MENUITEM "&About",                      ID_WMABOUT

        MENUITEM "&Exit",                       ID_WMEXIT

    END

END





/////////////////////////////////////////////////////////////////////////////

//

// Dialog

//



IDD_ABOUT DIALOGEX 0, 0, 125, 81

STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | 

    WS_SYSMENU

CAPTION "About"

FONT 8, "MS Sans Serif", 0, 0, 0x0

BEGIN

    ICON            IDI_TRAY,IDC_STATIC,50,4,21,20

    DEFPUSHBUTTON   "OK",IDOK,33,56,50,14

    GROUPBOX        "",IDC_STATIC,0,0,124,81

    CTEXT           " 0.1",IDC_STATIC,18,41,82,8

    CTEXT           "WTS Window Clipper",IDC_STATIC,19,27,82,8

END



#endif    // German (Germany) resources

/////////////////////////////////////////////////////////////////////////////







#ifndef APSTUDIO_INVOKED

/////////////////////////////////////////////////////////////////////////////

//

// Generated from the TEXTINCLUDE 3 resource.

//





/////////////////////////////////////////////////////////////////////////////

#endif    // not APSTUDIO_INVOKED




--- NEW FILE: clipper.vcproj ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: icon.ico ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: main.cpp ---
//*********************************************************************************

//

//Title: Terminal Services Window Clipper

//

//Author: Martin Wickett

//

//Date: 2004

//

//*********************************************************************************



#include <windows.h>



#include "resource.h"

#include "hookdll/hook.h"



//

// some global data

//

HWND				ghWnd;

NOTIFYICONDATA		nid;

HINSTANCE			hAppInstance;



static const UINT WM_TRAY_NOTIFY	= (WM_APP + 1000);

static const char szAppName[]		= "Terminal Services Window Clipper";



//

// spawn a message box

//

void Message(const char* message)

{

	MessageBox(GetDesktopWindow(),message,"TS Window Clipper", MB_OK);

}



//

// manage the tray icon

//

bool InitTrayIcon()

{

	nid.cbSize				= sizeof(NOTIFYICONDATA) ;

	nid.hWnd				= ghWnd;

	nid.uID					= 0 ;

	nid.uFlags				= NIF_MESSAGE | NIF_ICON | NIF_TIP ;	

	nid.uCallbackMessage	= WM_TRAY_NOTIFY;  

	strcpy(nid.szTip,szAppName);

	nid.hIcon				= ::LoadIcon(hAppInstance,MAKEINTRESOURCE(IDI_TRAY)); 

	

	if (Shell_NotifyIcon (NIM_ADD,&nid) != TRUE)

	{

		Message("Unable to create tray icon.");

		return false;

	}



	return true;

}



//

// Remove tray icon

//

bool RemoveTrayIcon()

{

	if (Shell_NotifyIcon (NIM_DELETE,&nid) != TRUE)

	{

		Message("Unable to remove tray icon.");

		return false;

	}



	return true;



}



//

// manage the about dialog box

//

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )

{

	if (uMsg == WM_COMMAND)

	{

		WORD wID		 = LOWORD(wParam);

		if (wID == IDOK) DestroyWindow(hwndDlg);

	}



	return 0;

}



void AboutDlg()

{

	DialogBox(hAppInstance,MAKEINTRESOURCE(IDD_ABOUT),NULL,DialogProc);

}



//

// manage the context menu

//

void DoContextMenu()

{

	HMENU hMenu =LoadMenu(hAppInstance,MAKEINTRESOURCE(IDR_TRAY));

	if (hMenu == NULL)

	{

		Message("Unable to load menu ressource.");

		return;

	}



	HMENU hSubMenu = GetSubMenu(hMenu,0);

	if (hSubMenu == NULL)

	{

		Message("Unable to find popup mennu.");

		return;

	}



	// get the cursor position

	POINT pt;

	GetCursorPos (&pt) ;



	SetForegroundWindow(ghWnd);

	int cmd = TrackPopupMenu(hSubMenu,TPM_RETURNCMD|TPM_LEFTALIGN|TPM_RIGHTBUTTON,

							pt.x,pt.y,0,ghWnd,NULL);				

	DeleteObject(hMenu);



	switch (cmd)

	{

		case ID_WMEXIT :

		{

			PostQuitMessage(0);

			break;						

		}

		case ID_WMABOUT :

		{

			AboutDlg();

			break;

		}

	}

}



//

// manage the main window

//

LONG WINAPI MainWndProc ( HWND    hWnd, UINT    uMsg, WPARAM  wParam, LPARAM  lParam) 

{ 

	switch (uMsg)

	{

		case WM_DESTROY :

		{

			PostQuitMessage (0);

			return 0;

		}

		case WM_TRAY_NOTIFY :

		{

			if (lParam == WM_RBUTTONDOWN) 

				DoContextMenu();

			return 0;

		}

	}

	

	return DefWindowProc (hWnd, uMsg, wParam, lParam); 

} 



//

//Init window

//

bool InitWindow()

{

	// register the frame class

	WNDCLASS wndclass;

    wndclass.style         = 0; 

    wndclass.lpfnWndProc   = (WNDPROC)MainWndProc; 

    wndclass.cbClsExtra    = 0; 

    wndclass.cbWndExtra    = 0; 

    wndclass.hInstance     = hAppInstance; 

    wndclass.hIcon         = 0; 

    wndclass.hCursor       = LoadCursor (NULL,IDC_ARROW); 

    wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 

    wndclass.lpszMenuName  = NULL; 

    wndclass.lpszClassName = szAppName;

 

    if (!RegisterClass (&wndclass))

	{

		Message("Unable to register the window class.");

		return false;

	}

 

    // create the frame 

    ghWnd = CreateWindow (szAppName, szAppName, 

         WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 

             CW_USEDEFAULT, 

             CW_USEDEFAULT, 

             640, 

             480, 

             NULL, 

             NULL, 

             hAppInstance, 

             NULL); 

 

    // make sure window was created

    if (!ghWnd) 

	{

		Message("Unable to create the window.");

		return false; 

	}



	return true;

}



//

// init

//

bool Init(LPSTR lpCmdLine)

{

	// try to load WTSWinClipper.dll

	if (!WTSWinClipper::Init())

	{

		Message("Application not installed correctly: Unable to init hookdll.dll.");

		return false;

	}



	// check number of instances

	if (WTSWinClipper::GetInstanceCount() == 1)

	{

		// hook in

		WTSWinClipper::SetCbtHook();	

		return true;

	} else 

	{

		// already hooked

		return false;

	}

}



// 

// our main loop

//

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 

{

	hAppInstance = hInstance;

	if (!Init(lpCmdLine)) 

	{

		return 0;

	}



	// if we have been specified an app to launch, we will wait until the app has closed and use that for

	// our cue to exit

	if (strlen(lpCmdLine)> 0)

	{

		// Because we do not have a explorer.exe we need to make this application the replacement

		// shell. We do this by calling SystemParametersInfo. If we don't do this, we won't get the WH_SHELL notifications.

		

		// From MSDN:

		// Note that custom shell applications do not receive WH_SHELL messages. Therefore, any application that 

		// registers itself as the default shell must call the SystemParametersInfo function with SPI_SETMINIMIZEDMETRICS 

		// before it (or any other application) can receive WH_SHELL messages.



		MINIMIZEDMETRICS mmm;

		mmm.cbSize = sizeof( MINIMIZEDMETRICS);

		SystemParametersInfo(SPI_SETMINIMIZEDMETRICS ,sizeof( MINIMIZEDMETRICS),&mmm,0);



		//set the current directory to that of the requested app .exe location

		//tokenise lpCmdLine. first is the exe path. second (if exists) is the current directory to set.

		//SetCurrentDirectory ();



		//start process specified from command line arg.

		PROCESS_INFORMATION procInfo;

		STARTUPINFO startupInfo = {0}; 

		startupInfo.cb = sizeof(STARTUPINFO);

		char attr[] = "";

		LPTSTR process= lpCmdLine;

		DWORD dwExitCode;



		BOOL m_create  = CreateProcess( NULL,process,NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &procInfo);

		

		if (m_create != false)

		{		 

			// A loop to watch the process. 

			GetExitCodeProcess(procInfo.hProcess, &dwExitCode);



			while (dwExitCode == STILL_ACTIVE )

			{

				GetExitCodeProcess(procInfo.hProcess, &dwExitCode);

				Sleep(1000);

			}



			// Release handles

			CloseHandle(procInfo.hProcess);

			CloseHandle(procInfo.hThread);

		}

		else

		{

			// CreateProcess failed.

			Message("Unable to launch the requested application");

		}

	}

	else

	// we are launching without an app, therefore we will show the system tray app and wait for the user to close it

	{

		// create a dummy window to receive WM_QUIT message

		InitWindow();



		// create the tray icon

		InitTrayIcon();



		// just get and dispatch messages until we're killed

		MSG msg;

		while (GetMessage(&msg,0,0,0))

		{

			TranslateMessage(&msg);

			DispatchMessage(&msg);

		};



		// remove our tray icon

		RemoveTrayIcon();

	}





	// remove hook before saying goodbye

	WTSWinClipper::RemoveCbtHook();

	

	WTSWinClipper::Done();



	return 1;

}
--- NEW FILE: resource.h ---
//*********************************************************************************

//

//Title: Terminal Services Window Clipper

//

//Author: Martin Wickett

//

//Date: 2004

//

//*********************************************************************************



//{{NO_DEPENDENCIES}}

// Microsoft Developer Studio generated include file.

// Used by clipper.rc

//

#define IDC_CURSOR1                     101

#define IDI_TRAY                        102

#define IDD_DIALOG1                     103

#define IDD_ABOUT                       103

#define IDR_TRAY                        130

#define ID_WMEXIT                       40002

#define ID_WMABOUT                      40003

#define ID_WMEXEC                       50000



// Next default values for new objects

// 

#ifdef APSTUDIO_INVOKED

#ifndef APSTUDIO_READONLY_SYMBOLS

#define _APS_NEXT_RESOURCE_VALUE        105

#define _APS_NEXT_COMMAND_VALUE         40004

#define _APS_NEXT_CONTROL_VALUE         1000

#define _APS_NEXT_SYMED_VALUE           101

#endif

#endif




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.