xref: /AOO41X/main/sal/workben/clipboardwben/testpaste/cbptest.cxx (revision 87d2adbc9cadf14644c3679b041b9226f7630199)
1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*87d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*87d2adbcSAndrew Rist  * distributed with this work for additional information
6*87d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*87d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*87d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*87d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist  * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*87d2adbcSAndrew Rist  * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*87d2adbcSAndrew Rist  *************************************************************/
21*87d2adbcSAndrew Rist 
22*87d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_sal.hxx"
27cdf0e10cSrcweir // TestWin32.cpp : Definiert den Einsprungpunkt f�r die Anwendung.
28cdf0e10cSrcweir //
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #define _WIN32_DCOM
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "stdafx.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <windows.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <ole2.h>
37cdf0e10cSrcweir #include <objidl.h>
38cdf0e10cSrcweir #include <objbase.h>
39cdf0e10cSrcweir #include <process.h>
40cdf0e10cSrcweir #include <olectl.h>
41cdf0e10cSrcweir #include <stdlib.h>
42cdf0e10cSrcweir #include <malloc.h>
43cdf0e10cSrcweir #include <..\..\inc\systools\win32\MtaOleClipb.h>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "resource.h"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #define MAX_LOADSTRING 100
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // Globale Variablen:
50cdf0e10cSrcweir HINSTANCE			hInst;						// aktuelle Instanz
51cdf0e10cSrcweir WCHAR				szTitle[MAX_LOADSTRING];			// Text der Titelzeile
52cdf0e10cSrcweir WCHAR				szWindowClass[MAX_LOADSTRING];	// Text der Titelzeile
53cdf0e10cSrcweir ATOM				MyRegisterClass( HINSTANCE hInstance );
54cdf0e10cSrcweir BOOL				InitInstance( HINSTANCE, int );
55cdf0e10cSrcweir LRESULT CALLBACK	WndProc( HWND, UINT, WPARAM, LPARAM );
56cdf0e10cSrcweir LRESULT CALLBACK	About( HWND, UINT, WPARAM, LPARAM );
57cdf0e10cSrcweir void				PasteClipboardData(HWND hwndParent);
58cdf0e10cSrcweir void				PasteClipboardData2(HWND hwndParent);
59cdf0e10cSrcweir 
60cdf0e10cSrcweir LPSTREAM			g_pStm    = NULL;
61cdf0e10cSrcweir char*				pTextBuff = NULL;
62cdf0e10cSrcweir DWORD				lData     = 0;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //----------------------------------------------------
65cdf0e10cSrcweir // a thread function
66cdf0e10cSrcweir //----------------------------------------------------
67cdf0e10cSrcweir 
ThreadProc(LPVOID pParam)68cdf0e10cSrcweir unsigned int _stdcall ThreadProc(LPVOID pParam)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	IDataObject* pIDataObj = NULL;
71cdf0e10cSrcweir 	FORMATETC    formatETC;
72cdf0e10cSrcweir 	STGMEDIUM	 stgMedium;
73cdf0e10cSrcweir 	LPVOID		 pGlobMem;
74cdf0e10cSrcweir 	HWND		 hwnd;
75cdf0e10cSrcweir 	DWORD		 sizeGlobBuff;
76cdf0e10cSrcweir 	HRESULT		 hr;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	hwnd = (HWND)pParam;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	OleInitialize( NULL );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	hr = OleGetClipboard( &pIDataObj );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	hr = CoGetInterfaceAndReleaseStream(
85cdf0e10cSrcweir 		g_pStm,
86cdf0e10cSrcweir 		__uuidof(IDataObject),
87cdf0e10cSrcweir 		reinterpret_cast<LPVOID*>(&pIDataObj));
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	formatETC.cfFormat = CF_TEXT;
90cdf0e10cSrcweir 	formatETC.ptd      = NULL;
91cdf0e10cSrcweir 	formatETC.dwAspect = DVASPECT_CONTENT;
92cdf0e10cSrcweir 	formatETC.lindex   = -1;
93cdf0e10cSrcweir 	formatETC.tymed    = TYMED_HGLOBAL;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	hr = pIDataObj->GetData( &formatETC, &stgMedium );
96cdf0e10cSrcweir 	pGlobMem = GlobalLock( stgMedium.hGlobal );
97cdf0e10cSrcweir 	if ( NULL != pGlobMem )
98cdf0e10cSrcweir 	{
99cdf0e10cSrcweir 		if ( NULL != pTextBuff )
100cdf0e10cSrcweir 		{
101cdf0e10cSrcweir 			free( pTextBuff );
102cdf0e10cSrcweir 		}
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		sizeGlobBuff = GlobalSize( stgMedium.hGlobal );
105cdf0e10cSrcweir 		pTextBuff = (char*)malloc( sizeGlobBuff + 1 );
106cdf0e10cSrcweir 		ZeroMemory( pTextBuff, sizeGlobBuff + 1 );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		memcpy( pTextBuff, pGlobMem, sizeGlobBuff );
109cdf0e10cSrcweir 		lData = sizeGlobBuff;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		InvalidateRect( hwnd, NULL, TRUE );
112cdf0e10cSrcweir 		UpdateWindow( hwnd );
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	GlobalUnlock( stgMedium.hGlobal );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	ReleaseStgMedium( &stgMedium );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	pIDataObj->Release();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	//CoUninitialize( );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	OleUninitialize( );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	return 0;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir //----------------------------------------------------
129cdf0e10cSrcweir // WinMain
130cdf0e10cSrcweir //----------------------------------------------------
131cdf0e10cSrcweir 
WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)132cdf0e10cSrcweir int APIENTRY WinMain(HINSTANCE hInstance,
133cdf0e10cSrcweir                      HINSTANCE hPrevInstance,
134cdf0e10cSrcweir                      LPSTR     lpCmdLine,
135cdf0e10cSrcweir                      int       nCmdShow )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir  	// ZU ERLEDIGEN: F�gen Sie hier den Code ein.
138cdf0e10cSrcweir 	MSG     msg;
139cdf0e10cSrcweir 	HACCEL  hAccelTable;
140cdf0e10cSrcweir 	HRESULT hr = E_FAIL;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	// it's important to initialize ole
143cdf0e10cSrcweir 	// in order to use the clipboard
144cdf0e10cSrcweir 	//hr = OleInitialize( NULL );
145cdf0e10cSrcweir 	hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );
146cdf0e10cSrcweir 	//hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	// Globale Zeichenfolgen initialisieren
149cdf0e10cSrcweir 	LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
150cdf0e10cSrcweir 	LoadStringW(hInstance, IDC_TESTWIN32, szWindowClass, MAX_LOADSTRING);
151cdf0e10cSrcweir 	MyRegisterClass(hInstance);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	// Initialisierung der Anwendung durchf�hren:
154cdf0e10cSrcweir 	if( !InitInstance( hInstance, nCmdShow ) )
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		return FALSE;
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TESTWIN32);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	// Hauptnachrichtenschleife:
162cdf0e10cSrcweir 	while( GetMessage(&msg, NULL, 0, 0) )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		if( !TranslateAccelerator (msg.hwnd, hAccelTable, &msg) )
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			TranslateMessage( &msg );
167cdf0e10cSrcweir 			DispatchMessage( &msg );
168cdf0e10cSrcweir 		}
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	// uninitializing the ole libraries
172cdf0e10cSrcweir 	//OleUninitialize( );
173cdf0e10cSrcweir 	CoUninitialize( );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	return msg.wParam;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //
181cdf0e10cSrcweir //  FUNKTION: MyRegisterClass()
182cdf0e10cSrcweir //
183cdf0e10cSrcweir //  AUFGABE: Registriert die Fensterklasse.
184cdf0e10cSrcweir //
185cdf0e10cSrcweir //  KOMMENTARE:
186cdf0e10cSrcweir //
187cdf0e10cSrcweir //    Diese Funktion und ihre Verwendung sind nur notwendig, wenn dieser Code
188cdf0e10cSrcweir //    mit Win32-Systemen vor der 'RegisterClassEx'-Funktion kompatibel sein soll,
189cdf0e10cSrcweir //    die zu Windows 95 hinzugef�gt wurde. Es ist wichtig diese Funktion aufzurufen,
190cdf0e10cSrcweir //    damit der Anwendung kleine Symbole mit den richtigen Proportionen zugewiesen
191cdf0e10cSrcweir //    werden.
192cdf0e10cSrcweir //
MyRegisterClass(HINSTANCE hInstance)193cdf0e10cSrcweir ATOM MyRegisterClass( HINSTANCE hInstance )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	WNDCLASSEXW wcex;
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	wcex.cbSize = sizeof(WNDCLASSEX);
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 	wcex.style			= CS_HREDRAW | CS_VREDRAW;
200cdf0e10cSrcweir 	wcex.lpfnWndProc	= (WNDPROC)WndProc;
201cdf0e10cSrcweir 	wcex.cbClsExtra		= 0;
202cdf0e10cSrcweir 	wcex.cbWndExtra		= 0;
203cdf0e10cSrcweir 	wcex.hInstance		= hInstance;
204cdf0e10cSrcweir 	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_TESTWIN32);
205cdf0e10cSrcweir 	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
206cdf0e10cSrcweir 	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
207cdf0e10cSrcweir 	wcex.lpszMenuName	= (LPCWSTR)IDC_TESTWIN32;
208cdf0e10cSrcweir 	wcex.lpszClassName	= szWindowClass;
209cdf0e10cSrcweir 	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	return RegisterClassExW(&wcex);
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir //
215cdf0e10cSrcweir //   FUNKTION: InitInstance(HANDLE, int)
216cdf0e10cSrcweir //
217cdf0e10cSrcweir //   AUFGABE: Speichert die Instanzzugriffsnummer und erstellt das Hauptfenster
218cdf0e10cSrcweir //
219cdf0e10cSrcweir //   KOMMENTARE:
220cdf0e10cSrcweir //
221cdf0e10cSrcweir //        In dieser Funktion wird die Instanzzugriffsnummer in einer globalen Variable
222cdf0e10cSrcweir //        gespeichert und das Hauptprogrammfenster erstellt und angezeigt.
223cdf0e10cSrcweir //
InitInstance(HINSTANCE hInstance,int nCmdShow)224cdf0e10cSrcweir BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir    HWND hWnd;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir    hInst = hInstance; // Instanzzugriffsnummer in unserer globalen Variable speichern
229cdf0e10cSrcweir 
230cdf0e10cSrcweir    hWnd = CreateWindowExW(0, szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
231cdf0e10cSrcweir       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir    if( !hWnd )
234cdf0e10cSrcweir    {
235cdf0e10cSrcweir       return FALSE;
236cdf0e10cSrcweir    }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir    ShowWindow( hWnd, nCmdShow );
239cdf0e10cSrcweir    UpdateWindow( hWnd );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir    return TRUE;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir //
245cdf0e10cSrcweir //  FUNKTION: WndProc(HWND, unsigned, WORD, LONG)
246cdf0e10cSrcweir //
247cdf0e10cSrcweir //  AUFGABE:  Verarbeitet Nachrichten f�r das Hauptfenster.
248cdf0e10cSrcweir //
249cdf0e10cSrcweir //  WM_COMMAND	- Anwendungsmen� verarbeiten
250cdf0e10cSrcweir //  WM_PAINT	- Hauptfenster darstellen
251cdf0e10cSrcweir //  WM_DESTROY	- Beendigungsnachricht ausgeben und zur�ckkehren
252cdf0e10cSrcweir //
253cdf0e10cSrcweir //
WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)254cdf0e10cSrcweir LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	int         wmId;
257cdf0e10cSrcweir 	int         wmEvent;
258cdf0e10cSrcweir 	PAINTSTRUCT ps;
259cdf0e10cSrcweir 	HDC         hdc;
260cdf0e10cSrcweir 	TCHAR       szHello[MAX_LOADSTRING];
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	switch( message )
266cdf0e10cSrcweir 	{
267cdf0e10cSrcweir 		case WM_COMMAND:
268cdf0e10cSrcweir 			wmId    = LOWORD(wParam);
269cdf0e10cSrcweir 			wmEvent = HIWORD(wParam);
270cdf0e10cSrcweir 			// Men�auswahlen analysieren:
271cdf0e10cSrcweir 			switch( wmId )
272cdf0e10cSrcweir 			{
273cdf0e10cSrcweir 				case IDD_PASTE:
274cdf0e10cSrcweir 					//PasteClipboardData(hWnd);
275cdf0e10cSrcweir 					PasteClipboardData2(hWnd);
276cdf0e10cSrcweir 					break;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 				case IDM_EXIT:
279cdf0e10cSrcweir 				   DestroyWindow( hWnd );
280cdf0e10cSrcweir 				   break;
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 				default:
283cdf0e10cSrcweir 				   return DefWindowProc( hWnd, message, wParam, lParam );
284cdf0e10cSrcweir 			}
285cdf0e10cSrcweir 			break;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 		case WM_PAINT:
288cdf0e10cSrcweir 			hdc = BeginPaint (hWnd, &ps);
289cdf0e10cSrcweir 			// ZU ERLEDIGEN: Hier beliebigen Code zum Zeichnen hinzuf�gen...
290cdf0e10cSrcweir 			RECT rt;
291cdf0e10cSrcweir 			GetClientRect( hWnd, &rt );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 			if ( NULL != pTextBuff )
294cdf0e10cSrcweir 			{
295cdf0e10cSrcweir 				DrawText( hdc, pTextBuff, lData, &rt, DT_CENTER );
296cdf0e10cSrcweir 			}
297cdf0e10cSrcweir 			else
298cdf0e10cSrcweir 			{
299cdf0e10cSrcweir 				DrawText( hdc, szHello, strlen(szHello), &rt, DT_CENTER );
300cdf0e10cSrcweir 			}
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 			EndPaint( hWnd, &ps );
303cdf0e10cSrcweir 			break;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 		case WM_DESTROY:
306cdf0e10cSrcweir 			PostQuitMessage( 0 );
307cdf0e10cSrcweir 			break;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 		default:
310cdf0e10cSrcweir 			return DefWindowProc( hWnd, message, wParam, lParam );
311cdf0e10cSrcweir    }
312cdf0e10cSrcweir    return 0;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
PasteClipboardData2(HWND hwndParent)315cdf0e10cSrcweir void PasteClipboardData2(HWND hwndParent)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	IDataObject* pIDataObject;
318cdf0e10cSrcweir 	HRESULT		 hr;
319cdf0e10cSrcweir 	FORMATETC    formatETC;
320cdf0e10cSrcweir 	STGMEDIUM	 stgMedium;
321cdf0e10cSrcweir 	LPVOID		 pGlobMem;
322cdf0e10cSrcweir 	HWND		 hwnd;
323cdf0e10cSrcweir 	DWORD		 sizeGlobBuff;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	hr = MTAGetClipboard( &pIDataObject );
326cdf0e10cSrcweir 	if ( SUCCEEDED( hr ) )
327cdf0e10cSrcweir 	{
328cdf0e10cSrcweir 		formatETC.cfFormat = CF_TEXT;
329cdf0e10cSrcweir 		formatETC.ptd      = NULL;
330cdf0e10cSrcweir 		formatETC.dwAspect = DVASPECT_CONTENT;
331cdf0e10cSrcweir 		formatETC.lindex   = -1;
332cdf0e10cSrcweir 		formatETC.tymed    = TYMED_HGLOBAL;
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 		hr = pIDataObject->GetData( &formatETC, &stgMedium );
335cdf0e10cSrcweir 		pGlobMem = GlobalLock( stgMedium.hGlobal );
336cdf0e10cSrcweir 		if ( NULL != pGlobMem )
337cdf0e10cSrcweir 		{
338cdf0e10cSrcweir 			if ( NULL != pTextBuff )
339cdf0e10cSrcweir 			{
340cdf0e10cSrcweir 				free( pTextBuff );
341cdf0e10cSrcweir 			}
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 			sizeGlobBuff = GlobalSize( stgMedium.hGlobal );
344cdf0e10cSrcweir 			pTextBuff = (char*)malloc( sizeGlobBuff + 1 );
345cdf0e10cSrcweir 			ZeroMemory( pTextBuff, sizeGlobBuff + 1 );
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 			memcpy( pTextBuff, pGlobMem, sizeGlobBuff );
348cdf0e10cSrcweir 			lData = sizeGlobBuff;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 			InvalidateRect( hwndParent, NULL, TRUE );
351cdf0e10cSrcweir 			UpdateWindow( hwndParent );
352cdf0e10cSrcweir 		}
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 		GlobalUnlock( stgMedium.hGlobal );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		ReleaseStgMedium( &stgMedium );
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		pIDataObject->Release();
359cdf0e10cSrcweir 	}
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir //----------------------------------------------------
363cdf0e10cSrcweir // clipboard handling
364cdf0e10cSrcweir //----------------------------------------------------
365cdf0e10cSrcweir 
366cdf0e10cSrcweir /*
367cdf0e10cSrcweir void PasteClipboardData(HWND hwndParent)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	IDataObject* pIDataObj = NULL;
370cdf0e10cSrcweir 	HRESULT      hr        = E_FAIL;
371cdf0e10cSrcweir 	unsigned int dwId;
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	hr = OleGetClipboard( &pIDataObj );
374cdf0e10cSrcweir 	if ( SUCCEEDED( hr ) )
375cdf0e10cSrcweir 	{
376cdf0e10cSrcweir 		HRESULT hr = CoMarshalInterThreadInterfaceInStream(
377cdf0e10cSrcweir 			__uuidof(IDataObject), //The IID of inteface to be marshaled
378cdf0e10cSrcweir 			pIDataObj,       //The interface pointer
379cdf0e10cSrcweir 			&g_pStm          //IStream pointer
380cdf0e10cSrcweir 			);
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 		HANDLE hThread = (HANDLE)_beginthreadex(
383cdf0e10cSrcweir 				NULL,		//Security
384cdf0e10cSrcweir 				0,			//Stack Size
385cdf0e10cSrcweir 				ThreadProc,	//Start Address
386cdf0e10cSrcweir 				NULL,	    //Parmeter
387cdf0e10cSrcweir 				(unsigned int)hwndParent,	//Creation Flag
388cdf0e10cSrcweir 				&dwId		//Thread Id
389cdf0e10cSrcweir 				);
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 		//Wait for the thread to finish execution
392cdf0e10cSrcweir 		//A thread handle is signaled is thread execution
393cdf0e10cSrcweir 		//is complete
394cdf0e10cSrcweir 		for(;;)
395cdf0e10cSrcweir 		{
396cdf0e10cSrcweir 			DWORD dwRet = ::MsgWaitForMultipleObjects(
397cdf0e10cSrcweir 									1,			//Count of objects
398cdf0e10cSrcweir 									&hThread,	//pointer to the array of objects
399cdf0e10cSrcweir 									FALSE,		//Wait for all objects?
400cdf0e10cSrcweir 									INFINITE,	//Wait How Long?
401cdf0e10cSrcweir 									QS_ALLINPUT //Wait for all messges
402cdf0e10cSrcweir 									);
403cdf0e10cSrcweir 
404cdf0e10cSrcweir 			//This means that the object is signaled
405cdf0e10cSrcweir 			if ( dwRet != WAIT_OBJECT_0 + 1 )
406cdf0e10cSrcweir 				break;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 			//Remove the messages from the queue
409cdf0e10cSrcweir 			MSG msg;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0)
412cdf0e10cSrcweir 			{
413cdf0e10cSrcweir 				//Not essential
414cdf0e10cSrcweir 				TranslateMessage(&msg);
415cdf0e10cSrcweir 				//Let the windowproc handle the message
416cdf0e10cSrcweir 				DispatchMessage(&msg);
417cdf0e10cSrcweir 			}
418cdf0e10cSrcweir 		}
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 		CloseHandle( hThread );
421cdf0e10cSrcweir 		pIDataObj->Release();
422cdf0e10cSrcweir 	}
423cdf0e10cSrcweir }
424cdf0e10cSrcweir */
425