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: cbvtest.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>
55 #define MAX_LOADSTRING 100
58 HINSTANCE g_hInst
; // aktuelle Instanz
60 WCHAR szTitle
[MAX_LOADSTRING
]; // Text der Titelzeile
61 WCHAR szWindowClass
[MAX_LOADSTRING
]; // Text der Titelzeile
62 LPSTREAM g_pStm
= NULL
;
63 char* pTextBuff
= NULL
;
65 UINT g_nCBChanges
= 0;
67 // forward declaration
68 ATOM
MyRegisterClass( HINSTANCE hInstance
);
69 BOOL
InitInstance( HINSTANCE
, int );
70 HMENU
GetSubMenuHandle( HWND hwndParent
, UINT uiTopLevelIndex
);
71 BOOL
IsClipboardViewer( HWND hwndParent
);
72 void SwitchMenuState( HWND hwndParent
);
73 void RegisterClipboardViewer( BOOL bRegister
);
74 void ShowAvailableClipboardFormats( HWND hWnd
, HDC hdc
, PAINTSTRUCT ps
, RECT rcWnd
);
75 void ClearClipboardContent( HWND hWnd
);
77 void CALLBACK
OnClipboardContentChange( void );
78 LRESULT CALLBACK
WndProc( HWND
, UINT
, WPARAM
, LPARAM
);
79 LRESULT CALLBACK
About( HWND
, UINT
, WPARAM
, LPARAM
);
81 //----------------------------------------------------
83 //----------------------------------------------------
85 int APIENTRY
WinMain(HINSTANCE hInstance
,
86 HINSTANCE hPrevInstance
,
90 // ZU ERLEDIGEN: Fügen Sie hier den Code ein.
95 // it's important to initialize ole
96 // in order to use the clipboard
97 //hr = OleInitialize( NULL );
98 hr
= CoInitializeEx( NULL
, COINIT_MULTITHREADED
);
102 // Globale Zeichenfolgen initialisieren
103 LoadStringW(g_hInst
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
104 LoadStringW(g_hInst
, IDC_TESTWIN32
, szWindowClass
, MAX_LOADSTRING
);
105 MyRegisterClass(g_hInst
);
107 // Initialisierung der Anwendung durchführen:
108 if( !InitInstance( g_hInst
, nCmdShow
) )
113 hAccelTable
= LoadAccelerators(hInstance
, (LPCTSTR
)IDC_TESTWIN32
);
115 // Hauptnachrichtenschleife:
116 while( GetMessage(&msg
, NULL
, 0, 0) )
118 if( !TranslateAccelerator (msg
.hwnd
, hAccelTable
, &msg
) )
120 TranslateMessage( &msg
);
121 DispatchMessage( &msg
);
125 // uninitializing the ole libraries
126 //OleUninitialize( );
135 // FUNKTION: MyRegisterClass()
137 // AUFGABE: Registriert die Fensterklasse.
141 // Diese Funktion und ihre Verwendung sind nur notwendig, wenn dieser Code
142 // mit Win32-Systemen vor der 'RegisterClassEx'-Funktion kompatibel sein soll,
143 // die zu Windows 95 hinzugefügt wurde. Es ist wichtig diese Funktion aufzurufen,
144 // damit der Anwendung kleine Symbole mit den richtigen Proportionen zugewiesen
147 ATOM
MyRegisterClass( HINSTANCE hInstance
)
151 wcex
.cbSize
= sizeof(WNDCLASSEX
);
153 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
154 wcex
.lpfnWndProc
= (WNDPROC
)WndProc
;
157 wcex
.hInstance
= hInstance
;
158 wcex
.hIcon
= LoadIcon(hInstance
, (LPCTSTR
)IDI_TESTWIN32
);
159 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
160 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
161 wcex
.lpszMenuName
= (LPCWSTR
)IDC_TESTWIN32
;
162 wcex
.lpszClassName
= szWindowClass
;
163 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
165 return RegisterClassExW(&wcex
);
169 // FUNKTION: InitInstance(HANDLE, int)
171 // AUFGABE: Speichert die Instanzzugriffsnummer und erstellt das Hauptfenster
175 // In dieser Funktion wird die Instanzzugriffsnummer in einer globalen Variable
176 // gespeichert und das Hauptprogrammfenster erstellt und angezeigt.
178 BOOL
InitInstance( HINSTANCE hInstance
, int nCmdShow
)
180 g_hwndMain
= CreateWindowExW(0, szWindowClass
, szTitle
, WS_OVERLAPPEDWINDOW
,
181 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hInstance
, NULL
);
183 if( !IsWindow( g_hwndMain
) )
188 ShowWindow( g_hwndMain
, nCmdShow
);
189 UpdateWindow( g_hwndMain
);
195 // FUNKTION: WndProc(HWND, unsigned, WORD, LONG)
197 // AUFGABE: Verarbeitet Nachrichten für das Hauptfenster.
199 // WM_COMMAND - Anwendungsmenü verarbeiten
200 // WM_PAINT - Hauptfenster darstellen
201 // WM_DESTROY - Beendigungsnachricht ausgeben und zurückkehren
204 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
210 WCHAR szHello
[MAX_LOADSTRING
];
213 LoadStringW(g_hInst
, IDS_HELLO
, szHello
, MAX_LOADSTRING
);
218 ClearClipboardContent( hWnd
);
222 wmId
= LOWORD(wParam
);
223 wmEvent
= HIWORD(wParam
);
224 // Menüauswahlen analysieren:
228 SwitchMenuState( hWnd
);
229 RegisterClipboardViewer( IsClipboardViewer( hWnd
) );
233 DestroyWindow( hWnd
);
237 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
242 hdc
= BeginPaint (hWnd
, &ps
);
243 // ZU ERLEDIGEN: Hier beliebigen Code zum Zeichnen hinzufügen...
245 GetClientRect( hWnd
, &rt
);
247 if ( IsClipboardViewer( g_hwndMain
) )
249 ShowAvailableClipboardFormats( hWnd
, hdc
, ps
, rt
);
253 WCHAR wcString
[MAX_LOADSTRING
];
254 LoadStringW(g_hInst
, IDS_MSG_CBVIEWER_IS_OFF
, wcString
, MAX_LOADSTRING
);
255 DrawTextW( hdc
, wcString
, wcslen( wcString
), &rt
, DT_CENTER
);
258 EndPaint( hWnd
, &ps
);
262 PostQuitMessage( 0 );
266 return DefWindowProc( hWnd
, message
, wParam
, lParam
);
271 HMENU
GetSubMenuHandle( HWND hwndParent
, UINT uiTopLevelIndex
)
273 HMENU hMenuMain
= GetMenu( hwndParent
);
274 _ASSERT( IsMenu( hMenu
) );
276 HMENU hSubMenu
= GetSubMenu( hMenuMain
, uiTopLevelIndex
);
277 _ASSERT( IsMenu( hSubMenu
) );
282 BOOL
IsClipboardViewer( HWND hwndParent
)
284 HMENU hSubMenu
= GetSubMenuHandle( hwndParent
, 0 );
285 UINT uiMState
= GetMenuState( hSubMenu
, 0, MF_BYPOSITION
);
286 return ( MF_CHECKED
== uiMState
);
289 void SwitchMenuState( HWND hwndParent
)
291 HMENU hSubMenu
= GetSubMenuHandle( hwndParent
, 0 );
292 WCHAR wcMenuString
[MAX_LOADSTRING
];
294 if ( IsClipboardViewer( hwndParent
) )
296 LoadStringW(g_hInst
, IDS_CBVIEWER_OFF
, wcMenuString
, MAX_LOADSTRING
);
297 ModifyMenuW( hSubMenu
, 0, MF_BYPOSITION
| MF_STRING
, IDD_CBVIEWER
, wcMenuString
);
298 CheckMenuItem( hSubMenu
, 0, MF_BYPOSITION
| MF_UNCHECKED
);
302 LoadStringW(g_hInst
, IDS_CBVIEWER_ON
, wcMenuString
, MAX_LOADSTRING
);
303 ModifyMenuW( hSubMenu
, 0, MF_BYPOSITION
| MF_STRING
, IDD_CBVIEWER
, wcMenuString
);
304 CheckMenuItem( hSubMenu
, 0, MF_BYPOSITION
| MF_CHECKED
);
308 void RegisterClipboardViewer( BOOL bRegister
)
311 MTARegisterClipboardViewer( OnClipboardContentChange
);
313 MTARegisterClipboardViewer( NULL
);
315 InvalidateRect( g_hwndMain
, NULL
, TRUE
);
316 UpdateWindow( g_hwndMain
);
319 void ShowAvailableClipboardFormats( HWND hWnd
, HDC hdc
, PAINTSTRUCT ps
, RECT rcWnd
)
321 if ( !OpenClipboard( hWnd
) )
323 WCHAR szErrMsg
[] = { L
"Couldn't open the clipboard" };
324 DrawTextW( hdc
, szErrMsg
, wcslen( szErrMsg
), &rcWnd
, DT_CENTER
);
329 WCHAR szCBChangedMsg
[100];
331 wsprintfW( szCBChangedMsg
, L
"Clipboard content changed %d", g_nCBChanges
);
332 DrawTextW( hdc
, szCBChangedMsg
, wcslen( szCBChangedMsg
), &rcWnd
, DT_CENTER
);
338 void ClearClipboardContent( HWND hWnd
)
340 if ( OpenClipboard( hWnd
) )
347 // clipboard viewer callback function
348 void CALLBACK
OnClipboardContentChange( void )
351 InvalidateRect( g_hwndMain
, NULL
, TRUE
);
352 UpdateWindow( g_hwndMain
);