1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// QuickStart.cpp : Defines the entry point for the application.
#include <sal/config.h>
#if defined _MSC_VER
#pragma warning(push, 1)
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <shellapi.h>
#if defined _MSC_VER
#pragma warning(pop)
#endif
#include "resource.h"
#include <systools/win32/uwinapi.h>
#include <systools/win32/qswin32.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
bool SofficeRuns()
{
// check for soffice by searching the communication window
return FindWindowExW( nullptr, nullptr, QUICKSTART_CLASSNAME, nullptr ) != nullptr;
}
bool launchSoffice( )
{
if ( !SofficeRuns() )
{
wchar_t filename[_MAX_PATH + 1];
filename[_MAX_PATH] = 0;
GetModuleFileNameW( nullptr, filename, _MAX_PATH ); // soffice resides in the same dir
wchar_t *p = wcsrchr( filename, L'\\' );
if ( !p )
return false;
wcsncpy( p+1, L"soffice.exe", _MAX_PATH - (p+1 - filename) );
wchar_t imagename[_MAX_PATH + 1];
imagename[_MAX_PATH] = 0;
_snwprintf(imagename, _MAX_PATH, L"\"%s\" --quickstart", filename );
STARTUPINFOW aStartupInfo;
ZeroMemory(&aStartupInfo, sizeof(aStartupInfo));
aStartupInfo.cb = sizeof(aStartupInfo);
aStartupInfo.wShowWindow = SW_SHOW;
PROCESS_INFORMATION aProcessInfo;
BOOL bSuccess = CreateProcessW(filename, imagename, nullptr, nullptr, TRUE, 0, nullptr, nullptr, &aStartupInfo, &aProcessInfo);
if ( !bSuccess )
return false;
return true;
}
else
return true;
}
int APIENTRY wWinMain(HINSTANCE /*hInstance*/,
HINSTANCE /*hPrevInstance*/,
LPWSTR /*lpCmdLine*/,
int /*nCmdShow*/)
{
// Look for --killtray argument
for ( int i = 1; i < __argc; i++ )
{
if ( 0 == strcmp( __argv[i], "--killtray" ) )
{
HWND hwndTray = FindWindowW( QUICKSTART_CLASSNAME, nullptr );
if ( hwndTray )
{
UINT uMsgKillTray = RegisterWindowMessageW( SHUTDOWN_QUICKSTART_MESSAGE );
SendMessageW( hwndTray, uMsgKillTray, 0, 0 );
}
return 0;
}
}
launchSoffice();
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|