1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "quickstarter.hxx"
25 #include <sfx2/qswin32.h>
26
EnumWindowsProc(HWND hWnd,LPARAM lParam)27 static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
28 {
29 MSIHANDLE hMSI = static_cast< MSIHANDLE >( lParam );
30 CHAR szClassName[sizeof(QUICKSTART_CLASSNAMEA) + 1];
31
32 int nCharsCopied = GetClassName( hWnd, szClassName, sizeof( szClassName ) );
33
34 if ( nCharsCopied && !stricmp( QUICKSTART_CLASSNAMEA, szClassName ) )
35 {
36 DWORD dwProcessId;
37
38 if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) )
39 {
40 std::string sImagePath = GetProcessImagePath( dwProcessId );
41 std::string sOfficeImageDir = GetOfficeInstallationPath( hMSI ) + "program\\";
42
43 if ( !strnicmp( sImagePath.c_str(), sOfficeImageDir.c_str(), sOfficeImageDir.length() ) )
44 {
45 UINT uMsgShutdownQuickstart = RegisterWindowMessageA( SHUTDOWN_QUICKSTART_MESSAGEA );
46
47 if ( uMsgShutdownQuickstart )
48 SendMessageA( hWnd, uMsgShutdownQuickstart, 0, 0 );
49
50
51 HANDLE hProcess = OpenProcess( SYNCHRONIZE, FALSE, dwProcessId );
52
53 if ( hProcess )
54 {
55 WaitForSingleObject( hProcess, 30000 ); // Wait at most 30 seconds for process to terminate
56 CloseHandle( hProcess );
57 }
58
59 return FALSE;
60 }
61
62 }
63 }
64
65 return TRUE;
66 }
67
68
ShutDownQuickstarter(MSIHANDLE hMSI)69 extern "C" UINT __stdcall ShutDownQuickstarter( MSIHANDLE hMSI )
70 {
71 EnumWindows( EnumWindowsProc, hMSI );
72
73 return ERROR_SUCCESS;
74 }
75
76