OSDN Git Service

Switched the method of how the Designer UI file is used in the MainWindow class to...
[lamexp/LameXP.git] / src / WinMain.cpp
1 // ==========================================================================
2 // qtmain_win.cpp
3 // ==========================================================================
4 //
5 // This source file is included from Qt v4.8.4, because VS2012 won't link
6 // with the 'qtmain.lib' from the official Qt v4.8.4 (VS2010) release.
7 //
8 // ==========================================================================
9
10 /****************************************************************************
11 **
12 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
13 ** Contact: http://www.qt-project.org/legal
14 **
15 ** This file is part of the Windows main function of the Qt Toolkit.
16 **
17 ** $QT_BEGIN_LICENSE:BSD$
18 ** You may use this file under the terms of the BSD license as follows:
19 **
20 ** "Redistribution and use in source and binary forms, with or without
21 ** modification, are permitted provided that the following conditions are
22 ** met:
23 **   * Redistributions of source code must retain the above copyright
24 **     notice, this list of conditions and the following disclaimer.
25 **   * Redistributions in binary form must reproduce the above copyright
26 **     notice, this list of conditions and the following disclaimer in
27 **     the documentation and/or other materials provided with the
28 **     distribution.
29 **   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
30 **     of its contributors may be used to endorse or promote products derived
31 **     from this software without specific prior written permission.
32 **
33 **
34 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
45 **
46 ** $QT_END_LICENSE$
47 **
48 ****************************************************************************/
49
50 #include "qt_windows.h"
51 #include "qbytearray.h"
52 #include "qstring.h"
53 #include "qvector.h"
54
55 /*
56   This file contains the code in the qtmain library for Windows.
57   qtmain contains the Windows startup code and is required for
58   linking to the Qt DLL.
59
60   When a Windows application starts, the WinMain function is
61   invoked. WinMain calls qWinMain in the Qt DLL/library, which
62   initializes Qt.
63 */
64
65 QT_BEGIN_NAMESPACE
66
67 #if defined(Q_OS_WINCE)
68 extern void __cdecl qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector<char *> &);
69 #else
70 extern void qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector<char *> &);
71 #endif
72
73 QT_END_NAMESPACE
74
75 QT_USE_NAMESPACE
76
77
78 #if defined(QT_NEEDS_QMAIN)
79 int qMain(int, char **);
80 #define main qMain
81 #else
82 #ifdef Q_OS_WINCE
83 extern "C" int __cdecl main(int, char **);
84 #else
85 extern "C" int main(int, char **);
86 #endif
87 #endif
88
89 /*
90   WinMain() - Initializes Windows and calls user's startup function main().
91   NOTE: WinMain() won't be called if the application was linked as a "console"
92   application.
93 */
94
95 #ifdef Q_OS_WINCE
96 int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR /*wCmdParam*/, int cmdShow)
97 #else
98 extern "C"
99 int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /*cmdParamarg*/, int cmdShow)
100 #endif
101 {
102     QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit();
103
104 #if defined(Q_OS_WINCE)
105     wchar_t appName[MAX_PATH];
106     GetModuleFileName(0, appName, MAX_PATH);
107     cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit());
108 #endif
109
110     int argc = 0;
111     QVector<char *> argv(8);
112     qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv);
113
114 #if defined(Q_OS_WINCE)
115     wchar_t uniqueAppID[MAX_PATH];
116     GetModuleFileName(0, uniqueAppID, MAX_PATH);
117     QString uid = QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1String("\\"), QLatin1String("_"));
118
119     // If there exists an other instance of this application
120     // it will be the owner of a mutex with the unique ID.
121     HANDLE mutex = CreateMutex(NULL, TRUE, (LPCWSTR)uid.utf16());
122     if (mutex && ERROR_ALREADY_EXISTS == GetLastError()) {
123         CloseHandle(mutex);
124
125         // The app is already running, so we use the unique
126         // ID to create a unique messageNo, which is used
127         // as the registered class name for the windows
128         // created. Set the first instance's window to the
129         // foreground, else just terminate.
130         // Use bitwise 0x01 OR to reactivate window state if
131         // it was hidden
132         UINT msgNo = RegisterWindowMessage((LPCWSTR)uid.utf16());
133         HWND aHwnd = FindWindow((LPCWSTR)QString::number(msgNo).utf16(), 0);
134         if (aHwnd)
135             SetForegroundWindow((HWND)(((ULONG)aHwnd) | 0x01));
136         return 0;
137     }
138 #endif // Q_OS_WINCE
139
140     int result = main(argc, argv.data());
141 #if defined(Q_OS_WINCE)
142     CloseHandle(mutex);
143 #endif
144     return result;
145 }