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