1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cbcpytest.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 // TestWin32.cpp : Definiert den Einsprungpunkt für die Anwendung.
51 #include <..\..\inc\systools\win32\MtaOleClipb.h>
52 #include "XTDataObject.hxx"
56 #define MAX_LOADSTRING 100
59 #define MSG_FLUSHCLIPBOARD WM_USER + 1
62 HINSTANCE hInst
; // aktuelle Instanz
63 TCHAR szTitle
[MAX_LOADSTRING
]; // Text der Titelzeile
64 TCHAR szWindowClass
[MAX_LOADSTRING
]; // Text der Titelzeile
65 ATOM
MyRegisterClass( HINSTANCE hInstance
);
66 BOOL
InitInstance( HINSTANCE
, int );
67 LRESULT CALLBACK
WndProc( HWND
, UINT
, WPARAM
, LPARAM
);
68 LRESULT CALLBACK
About( HWND
, UINT
, WPARAM
, LPARAM
);
69 void CopyClipboardData(HWND hwndParent
);
70 void FlushClipboard( );
71 void PasteData( HWND hWnd
);
75 LPSTREAM g_pStm
= NULL
;
76 char* pTextBuff
= NULL
;
78 CXTDataObject
* g_xtDo
= NULL
;
83 //----------------------------------------------------
85 //----------------------------------------------------
87 unsigned int _stdcall
ThreadProc(LPVOID pParam
)
91 WaitForSingleObject( g_hEvent
, INFINITE
);
92 SendMessage( g_hWnd
, MSG_FLUSHCLIPBOARD
, WPARAM(0), LPARAM(0) );
98 //----------------------------------------------------
100 //----------------------------------------------------
102 int APIENTRY
WinMain(HINSTANCE hInstance
,
103 HINSTANCE hPrevInstance
,
107 // ZU ERLEDIGEN: Fügen Sie hier den Code ein.
113 g_hEvent = CreateEvent( 0,
121 _beginthreadex( ThreadProc,
129 // it's important to initialize ole
130 // in order to use the clipboard
132 hr
= CoInitializeEx( NULL
, COINIT_MULTITHREADED
);
134 hr
= OleInitialize( NULL
);
138 // Globale Zeichenfolgen initialisieren
139 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
140 LoadString(hInstance
, IDC_TESTWIN32
, szWindowClass
, MAX_LOADSTRING
);
141 MyRegisterClass(hInstance
);
143 // Initialisierung der Anwendung durchführen:
144 if( !InitInstance( hInstance
, nCmdShow
) )
149 hAccelTable
= LoadAccelerators(hInstance
, (LPCTSTR
)IDC_TESTWIN32
);
151 // Hauptnachrichtenschleife:
152 while( GetMessage(&msg
, NULL
, 0, 0) )
154 if( !TranslateAccelerator (msg
.hwnd
, hAccelTable
, &msg
) )
156 TranslateMessage( &msg
);
157 DispatchMessage( &msg
);
161 // uninitializing the ole libraries
168 CloseHandle( g_hEvent
);
175 //----------------------------------------------------------------
176 // FUNKTION: MyRegisterClass()
178 // AUFGABE: Registriert die Fensterklasse.
182 // Diese Funktion und ihre Verwendung sind nur notwendig, wenn dieser Code
183 // mit Win32-Systemen vor der 'RegisterClassEx'-Funktion kompatibel sein soll,
184 // die zu Windows 95 hinzugefügt wurde. Es ist wichtig diese Funktion aufzurufen,
185 // damit der Anwendung kleine Symbole mit den richtigen Proportionen zugewiesen
187 //----------------------------------------------------------------
189 ATOM
MyRegisterClass( HINSTANCE hInstance
)
193 wcex
.cbSize
= sizeof(WNDCLASSEX
);
195 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
196 wcex
.lpfnWndProc
= (WNDPROC
)WndProc
;
199 wcex
.hInstance
= hInstance
;
200 wcex
.hIcon
= LoadIcon(hInstance
, (LPCTSTR
)IDI_TESTWIN32
);
201 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
202 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
203 wcex
.lpszMenuName
= (LPCTSTR
)IDC_TESTWIN32
;
204 wcex
.lpszClassName
= _T(szWindowClass
);
205 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
207 return RegisterClassEx(&wcex
);
210 //----------------------------------------------------------------
211 // FUNKTION: InitInstance(HANDLE, int)
213 // AUFGABE: Speichert die Instanzzugriffsnummer und erstellt das Hauptfenster
217 // In dieser Funktion wird die Instanzzugriffsnummer in einer globalen Variable
218 // gespeichert und das Hauptprogrammfenster erstellt und angezeigt.
219 //----------------------------------------------------------------
221 BOOL
InitInstance( HINSTANCE hInstance
, int nCmdShow
)
223 hInst
= hInstance
; // Instanzzugriffsnummer in unserer globalen Variable speichern
225 g_hWnd
= CreateWindowEx(0, szWindowClass
, szTitle
, WS_OVERLAPPEDWINDOW
,
226 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hInstance
, NULL
);
233 ShowWindow( g_hWnd
, nCmdShow
);
234 UpdateWindow( g_hWnd
);
239 //----------------------------------------------------------------
240 // FUNKTION: WndProc(HWND, unsigned, WORD, LONG)
242 // AUFGABE: Verarbeitet Nachrichten für das Hauptfenster.
244 // WM_COMMAND - Anwendungsmenü verarbeiten
245 // WM_PAINT - Hauptfenster darstellen
246 // WM_DESTROY - Beendigungsnachricht ausgeben und zurückkehren
247 //----------------------------------------------------------------
249 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
255 TCHAR szHello
[MAX_LOADSTRING
];
258 LoadString(hInst
, IDS_HELLO
, szHello
, MAX_LOADSTRING
);
263 wmId
= LOWORD(wParam
);
264 wmEvent
= HIWORD(wParam
);
265 // Menüauswahlen analysieren:
269 CopyClipboardData(hWnd
);
278 DestroyWindow( hWnd
);
282 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
287 hdc
= BeginPaint (hWnd
, &ps
);
288 // ZU ERLEDIGEN: Hier beliebigen Code zum Zeichnen hinzufügen...
290 GetClientRect( hWnd
, &rt
);
292 if ( NULL
!= pTextBuff
)
294 DrawText( hdc
, pTextBuff
, lData
, &rt
, DT_CENTER
);
298 DrawText( hdc
, szHello
, strlen(szHello
), &rt
, DT_CENTER
);
301 EndPaint( hWnd
, &ps
);
306 SetEvent( g_hEvent
);
308 PostQuitMessage( 0 );
312 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
317 //----------------------------------------------
318 // copy data into the clipboard
319 //----------------------------------------------
321 void CopyClipboardData( HWND hWnd
)
323 g_xtDo
= new CXTDataObject( 1 );
325 MTASetClipboard( static_cast< IDataObject
* >( g_xtDo
) );
327 OleSetClipboard( static_cast< IDataObject
* >( g_xtDo
) );
331 //----------------------------------------------
332 // flush the content into the clipboard
333 //----------------------------------------------
335 void FlushClipboard( )
337 if ( NULL
!= g_xtDo
)
340 HRESULT hr
= MTAIsCurrentClipboard( static_cast< IDataObject
* >( g_xtDo
) );
342 MTAFlushClipboard( );
344 HRESULT hr
= OleIsCurrentClipboard( static_cast< IDataObject
* >( g_xtDo
) );
346 OleFlushClipboard( );
349 static_cast< IDataObject
* >( g_xtDo
)->Release( );
354 void PasteData(HWND hWnd
)
356 IDataObject
* pDataObj
;
360 HRESULT hr
= OleGetClipboard( &pDataObj
);
361 if ( SUCCEEDED( hr
) )
366 fetc
.cfFormat
= CF_LOCALE
;
368 fetc
.dwAspect
= DVASPECT_CONTENT
;
370 fetc
.tymed
= TYMED_HGLOBAL
;
372 hr
= pDataObj
->GetData( &fetc
, &stgmedium
);
373 if ( SUCCEEDED( hr
) )
375 LPVOID lpData
= GlobalLock( stgmedium
.hGlobal
);
377 if ( NULL
!= lpData
)
379 LCID lcid
= *( (WORD
*)lpData
);
381 WORD langID
= LANGIDFROMLCID( lcid
);
382 WORD sublangID
= SUBLANGID( langID
);
385 int cbWritten
= GetLocaleInfo( lcid
, LOCALE_IDEFAULTANSICODEPAGE
, buff
, sizeof( buff
) );
386 cbWritten
= GetLocaleInfo( lcid
, LOCALE_IDEFAULTCODEPAGE
, buff
, sizeof( buff
) );
388 GlobalUnlock( stgmedium
.hGlobal
);
392 DWORD dwLastError
= GetLastError( );
395 ReleaseStgMedium( &stgmedium
);
403 LCID threadLcid
= GetThreadLocale();