LibreOffice Module setup_native (master) 1
shutdown_quickstart.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "quickstarter.hxx"
21
22#include <systools/win32/qswin32.h>
23
24static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
25{
26 MSIHANDLE hMSI = static_cast< MSIHANDLE >( lParam );
27 WCHAR szClassName[sizeof(QUICKSTART_CLASSNAME)/sizeof(WCHAR) + 1];
28
29 int nCharsCopied = GetClassNameW( hWnd, szClassName, sizeof(szClassName)/sizeof(szClassName[0]) );
30
31 if ( nCharsCopied && !_wcsicmp( QUICKSTART_CLASSNAME, szClassName ) )
32 {
33 DWORD dwProcessId;
34
35 if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) )
36 {
37 std::wstring sImagePath = GetProcessImagePathW( dwProcessId );
38 std::wstring sOfficeImageDir = GetOfficeInstallationPathW( hMSI ) + L"program\\";
39
40 if ( !_wcsnicmp( sImagePath.c_str(), sOfficeImageDir.c_str(), sOfficeImageDir.length() ) )
41 {
42 UINT uMsgShutdownQuickstart = RegisterWindowMessageW( SHUTDOWN_QUICKSTART_MESSAGE );
43
44 if ( uMsgShutdownQuickstart )
45 SendMessageW( hWnd, uMsgShutdownQuickstart, 0, 0 );
46
47
48 HANDLE hProcess = OpenProcess( SYNCHRONIZE, FALSE, dwProcessId );
49
50 if ( hProcess )
51 {
52 WaitForSingleObject( hProcess, 30000 ); // Wait at most 30 seconds for process to terminate
53 CloseHandle( hProcess );
54 }
55
56 return FALSE;
57 }
58
59 }
60 }
61
62 return TRUE;
63}
64
65
66extern "C" __declspec(dllexport) UINT __stdcall ShutDownQuickstarter( MSIHANDLE hMSI )
67{
68 EnumWindows( EnumWindowsProc, hMSI );
69
70 return ERROR_SUCCESS;
71}
72
73/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define TRUE
#define FALSE
#define CALLBACK
std::wstring GetProcessImagePathW(DWORD dwProcessId)
std::wstring GetOfficeInstallationPathW(MSIHANDLE handle)
const wchar_t *typedef BOOL
Definition: regactivex.cxx:38
static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
__declspec(dllexport) UINT __stdcall ShutDownQuickstarter(MSIHANDLE hMSI)