Skip to content

Commit

Permalink
Winmain: Remove Windows CE.
Browse files Browse the repository at this point in the history
Remove #ifdef sections for Q_OS_WINCE and wince .pro file clauses in library.

Task-number: QTBUG-51673
Change-Id: I473f215066db819a273f293940dcce9fe03152c3
Reviewed-by: Joerg Bornemann <[email protected]>
  • Loading branch information
Friedemann Kleint authored and Friedemann Kleint committed Mar 10, 2016
1 parent 8042c52 commit 390598c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 61 deletions.
59 changes: 1 addition & 58 deletions src/winmain/qtmain_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
#include "qstring.h"
#include "qvector.h"

#ifndef Q_OS_WINCE
# include <shlobj.h>
#endif
#include <shlobj.h>

/*
This file contains the code in the qtmain library for Windows.
Expand All @@ -59,11 +57,7 @@

QT_BEGIN_NAMESPACE

#if defined(Q_OS_WINCE)
extern void __cdecl qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector<char *> &);
#else
extern void qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector<char *> &);
#endif

QT_END_NAMESPACE

Expand All @@ -74,21 +68,15 @@ QT_USE_NAMESPACE
int qMain(int, char **);
#define main qMain
#else
#ifdef Q_OS_WINCE
extern "C" int __cdecl main(int, char **);
#else
extern "C" int main(int, char **);
#endif
#endif

/*
WinMain() - Initializes Windows and calls user's startup function main().
NOTE: WinMain() won't be called if the application was linked as a "console"
application.
*/

#ifndef Q_OS_WINCE

// Convert a wchar_t to char string, equivalent to QString::toLocal8Bit()
// when passed CP_ACP.
static inline char *wideToMulti(int codePage, const wchar_t *aw)
Expand Down Expand Up @@ -116,48 +104,3 @@ extern "C" int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR /*cmdParamarg*/, int
delete [] argv;
return exitCode;
}

#else // !Q_OS_WINCE

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR /*wCmdParam*/, int cmdShow)
{
QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit();

wchar_t appName[MAX_PATH];
GetModuleFileName(0, appName, MAX_PATH);
cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit());

int argc = 0;
QVector<char *> argv(8);
qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv);

wchar_t uniqueAppID[MAX_PATH];
GetModuleFileName(0, uniqueAppID, MAX_PATH);
QString uid = QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1String("\\"), QLatin1String("_"));

// If there exists an other instance of this application
// it will be the owner of a mutex with the unique ID.
HANDLE mutex = CreateMutex(NULL, TRUE, (LPCWSTR)uid.utf16());
if (mutex && ERROR_ALREADY_EXISTS == GetLastError()) {
CloseHandle(mutex);

// The app is already running, so we use the unique
// ID to create a unique messageNo, which is used
// as the registered class name for the windows
// created. Set the first instance's window to the
// foreground, else just terminate.
// Use bitwise 0x01 OR to reactivate window state if
// it was hidden
UINT msgNo = RegisterWindowMessage((LPCWSTR)uid.utf16());
HWND aHwnd = FindWindow((LPCWSTR)QString::number(msgNo).utf16(), 0);
if (aHwnd)
SetForegroundWindow((HWND)(((ULONG)aHwnd) | 0x01));
return 0;
}

int result = main(argc, argv.data());
CloseHandle(mutex);
return result;
}

#endif // Q_OS_WINCE
4 changes: 1 addition & 3 deletions src/winmain/winmain.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ winrt {
} else {
SOURCES = qtmain_win.cpp

!wince: LIBS += -lshell32
LIBS += -lshell32
}

load(qt_installs)
Expand All @@ -31,5 +31,3 @@ TARGET = $$qtLibraryTarget($$TARGET$$QT_LIBINFIX) #do this towards the end
load(qt_targets)
load(qt_build_paths)
load(qt_common)

wince: QMAKE_POST_LINK =

0 comments on commit 390598c

Please sign in to comment.