Qt 4.8
Functions
qtmain_win.cpp File Reference
#include "qt_windows.h"
#include "qbytearray.h"
#include "qstring.h"
#include "qvector.h"

Go to the source code of this file.

Functions

int __cdecl main (int, char **)
 
void __cdecl qWinMain (HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector< char *> &)
 
int WINAPI WinMain (HINSTANCE instance, HINSTANCE prevInstance, LPWSTR, int cmdShow)
 

Function Documentation

◆ main()

int __cdecl main ( int  ,
char **   
)

Definition at line 46 of file qaxmain.cpp.

Referenced by WinMain().

47 {
50  QApplication app(argc, argv);
51  app.setQuitOnLastWindowClosed(false);
52 
53  return app.exec();
54 }
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
static bool startServer(ServerType type=MultipleInstances)
Starts the COM server with type and returns true if successful, otherwise returns false...
Definition: qaxfactory.h:115
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88

◆ qWinMain()

void __cdecl qWinMain ( HINSTANCE  ,
HINSTANCE  ,
LPSTR  ,
int  ,
int &  ,
QVector< char *> &   
)

Definition at line 170 of file qcoreapplication_win.cpp.

Referenced by WinMain().

177 {
178  static bool already_called = false;
179 
180  if (already_called) {
181  qWarning("Qt: Internal error: qWinMain should be called only once");
182  return;
183  }
184  already_called = true;
185  usingWinMain = true;
186 
187  // Install default debug handler
189 
190  // Create command line
191  argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
192 
193  appCmdShow = cmdShow;
194 
195  // Ignore Windows parameters
196  Q_UNUSED(instance);
197  Q_UNUSED(prevInstance);
198 }
Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str)
int appCmdShow
bool usingWinMain
Q_CORE_EXPORT void qWarning(const char *,...)
QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
Definition: qglobal.cpp:2698
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ WinMain()

int WINAPI WinMain ( HINSTANCE  instance,
HINSTANCE  prevInstance,
LPWSTR  ,
int  cmdShow 
)

Definition at line 87 of file qtmain_win.cpp.

92 {
93  QByteArray cmdParam = QString::fromWCharArray(GetCommandLine()).toLocal8Bit();
94 
95 #if defined(Q_OS_WINCE)
96  wchar_t appName[MAX_PATH];
97  GetModuleFileName(0, appName, MAX_PATH);
98  cmdParam.prepend(QString(QLatin1String("\"%1\" ")).arg(QString::fromWCharArray(appName)).toLocal8Bit());
99 #endif
100 
101  int argc = 0;
102  QVector<char *> argv(8);
103  qWinMain(instance, prevInstance, cmdParam.data(), cmdShow, argc, argv);
104 
105 #if defined(Q_OS_WINCE)
106  wchar_t uniqueAppID[MAX_PATH];
107  GetModuleFileName(0, uniqueAppID, MAX_PATH);
108  QString uid = QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1String("\\"), QLatin1String("_"));
109 
110  // If there exists an other instance of this application
111  // it will be the owner of a mutex with the unique ID.
112  HANDLE mutex = CreateMutex(NULL, TRUE, (LPCWSTR)uid.utf16());
113  if (mutex && ERROR_ALREADY_EXISTS == GetLastError()) {
114  CloseHandle(mutex);
115 
116  // The app is already running, so we use the unique
117  // ID to create a unique messageNo, which is used
118  // as the registered class name for the windows
119  // created. Set the first instance's window to the
120  // foreground, else just terminate.
121  // Use bitwise 0x01 OR to reactivate window state if
122  // it was hidden
123  UINT msgNo = RegisterWindowMessage((LPCWSTR)uid.utf16());
124  HWND aHwnd = FindWindow((LPCWSTR)QString::number(msgNo).utf16(), 0);
125  if (aHwnd)
126  SetForegroundWindow((HWND)(((ULONG)aHwnd) | 0x01));
127  return 0;
128  }
129 #endif // Q_OS_WINCE
130 
131  int result = main(argc, argv.data());
132 #if defined(Q_OS_WINCE)
133  CloseHandle(mutex);
134 #endif
135  return result;
136 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void __cdecl qWinMain(HINSTANCE, HINSTANCE, LPSTR, int, int &, QVector< char *> &)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QByteArray & prepend(char c)
Prepends the character ch to this byte array.
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
int __cdecl main(int, char **)
Definition: qaxmain.cpp:46
void * HANDLE
Definition: qnamespace.h:1671
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
#define TRUE
Synonym for true.
Definition: qglobal.h:1018
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
static QString appName
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290