1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtCore module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include "qcoreapplication.h"
43
#include "qcoreapplication_p.h"
44
#include "qstringlist.h"
47
#include "qfileinfo.h"
48
#include "qcorecmdlineargs_p.h"
49
#include <private/qthread_p.h>
51
#include <qt_windows.h>
55
bool usingWinMain = false; // whether the qWinMain() is used or not
58
Q_CORE_EXPORT HINSTANCE qWinAppInst() // get Windows app handle
60
return GetModuleHandle(0);
63
Q_CORE_EXPORT HINSTANCE qWinAppPrevInst() // get Windows prev app handle
68
Q_CORE_EXPORT int qWinAppCmdShow() // get main window show command
70
#if defined(Q_OS_WINCE)
73
STARTUPINFO startupInfo;
74
GetStartupInfo(&startupInfo);
76
return (startupInfo.dwFlags & STARTF_USESHOWWINDOW)
77
? startupInfo.wShowWindow
82
Q_CORE_EXPORT QString qAppFileName() // get application file name
84
// We do MAX_PATH + 2 here, and request with MAX_PATH + 1, so we can handle all paths
85
// up to, and including MAX_PATH size perfectly fine with string termination, as well
86
// as easily detect if the file path is indeed larger than MAX_PATH, in which case we
87
// need to use the heap instead. This is a work-around, since contrary to what the
88
// MSDN documentation states, GetModuleFileName sometimes doesn't set the
89
// ERROR_INSUFFICIENT_BUFFER error number, and we thus cannot rely on this value if
90
// GetModuleFileName(0, buffer, MAX_PATH) == MAX_PATH.
91
// GetModuleFileName(0, buffer, MAX_PATH + 1) == MAX_PATH just means we hit the normal
92
// file path limit, and we handle it normally, if the result is MAX_PATH + 1, we use
93
// heap (even if the result _might_ be exactly MAX_PATH + 1, but that's ok).
94
wchar_t buffer[MAX_PATH + 2];
95
DWORD v = GetModuleFileName(0, buffer, MAX_PATH + 1);
96
buffer[MAX_PATH + 1] = 0;
100
else if (v <= MAX_PATH)
101
return QString::fromWCharArray(buffer);
103
// MAX_PATH sized buffer wasn't large enough to contain the full path, use heap
110
b = reinterpret_cast<wchar_t *>(realloc(b, (size + 1) * sizeof(wchar_t)));
112
v = GetModuleFileName(NULL, b, DWORD(size));
113
} while (b && v == size);
117
QString res = QString::fromWCharArray(b);
123
QString QCoreApplicationPrivate::appName() const
125
return QFileInfo(qAppFileName()).baseName();
128
/*****************************************************************************
129
qWinMain() - Initializes Windows. Called from WinMain() in qtmain_win.cpp
130
*****************************************************************************/
132
#if defined(Q_OS_WINCE)
133
Q_CORE_EXPORT void __cdecl qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
134
int cmdShow, int &argc, QVector<char *> &argv)
137
void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
138
int cmdShow, int &argc, QVector<char *> &argv)
141
static bool already_called = false;
143
if (already_called) {
144
qWarning("Qt: Internal error: qWinMain should be called only once");
147
already_called = true;
150
// Create command line
151
argv = qWinCmdLine<char>(cmdParam, int(strlen(cmdParam)), argc);
153
appCmdShow = cmdShow;
155
// Ignore Windows parameters
157
Q_UNUSED(prevInstance);
160
void QCoreApplicationPrivate::removePostedTimerEvent(QObject *object, int timerId)
162
QThreadData *data = object->d_func()->threadData;
164
QMutexLocker locker(&data->postEventList.mutex);
165
if (data->postEventList.size() == 0)
167
for (int i = 0; i < data->postEventList.size(); ++i) {
168
const QPostEvent & pe = data->postEventList.at(i);
169
if (pe.receiver == object
171
&& (pe.event->type() == QEvent::Timer || pe.event->type() == QEvent::ZeroTimerEvent)
172
&& static_cast<QTimerEvent *>(pe.event)->timerId() == timerId) {
173
--pe.receiver->d_func()->postedEvents;
174
pe.event->posted = false;
176
const_cast<QPostEvent &>(pe).event = 0;
182
#if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
183
/*****************************************************************************
184
Convenience functions for convert WM_* messages into human readable strings,
185
including a nifty QDebug operator<< for simpel QDebug() << msg output.
186
*****************************************************************************/
187
QT_BEGIN_INCLUDE_NAMESPACE
188
#include <windowsx.h>
190
QT_END_INCLUDE_NAMESPACE
192
#if !defined(GET_X_LPARAM)
193
# define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
194
# define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
197
# ifndef WM_NCACTIVATE
198
# define WM_NCACTIVATE 0x86
202
// The values below should never change. Note that none of the usual
203
// WM_...FIRST & WM_...LAST values are in the list, as they normally have other
204
// WM_... representations
209
{{ 0x0000, "WM_NULL" },
210
{ 0x0001, "WM_CREATE" },
211
{ 0x0002, "WM_DESTROY" },
212
{ 0x0003, "WM_MOVE" },
213
{ 0x0005, "WM_SIZE" },
214
{ 0x0006, "WM_ACTIVATE" },
215
{ 0x0007, "WM_SETFOCUS" },
216
{ 0x0008, "WM_KILLFOCUS" },
217
{ 0x000A, "WM_ENABLE" },
218
{ 0x000B, "WM_SETREDRAW" },
219
{ 0x000C, "WM_SETTEXT" },
220
{ 0x000D, "WM_GETTEXT" },
221
{ 0x000E, "WM_GETTEXTLENGTH" },
222
{ 0x000F, "WM_PAINT" },
223
{ 0x0010, "WM_CLOSE" },
224
{ 0x0011, "WM_QUERYENDSESSION" },
225
{ 0x0013, "WM_QUERYOPEN" },
226
{ 0x0016, "WM_ENDSESSION" },
227
{ 0x0012, "WM_QUIT" },
228
{ 0x0014, "WM_ERASEBKGND" },
229
{ 0x0015, "WM_SYSCOLORCHANGE" },
230
{ 0x0018, "WM_SHOWWINDOW" },
231
{ 0x001A, "WM_WININICHANGE" },
232
{ 0x001B, "WM_DEVMODECHANGE" },
233
{ 0x001C, "WM_ACTIVATEAPP" },
234
{ 0x001D, "WM_FONTCHANGE" },
235
{ 0x001E, "WM_TIMECHANGE" },
236
{ 0x001F, "WM_CANCELMODE" },
237
{ 0x0020, "WM_SETCURSOR" },
238
{ 0x0021, "WM_MOUSEACTIVATE" },
239
{ 0x0022, "WM_CHILDACTIVATE" },
240
{ 0x0023, "WM_QUEUESYNC" },
241
{ 0x0024, "WM_GETMINMAXINFO" },
242
{ 0x0026, "WM_PAINTICON" },
243
{ 0x0027, "WM_ICONERASEBKGND" },
244
{ 0x0028, "WM_NEXTDLGCTL" },
245
{ 0x002A, "WM_SPOOLERSTATUS" },
246
{ 0x002B, "WM_DRAWITEM" },
247
{ 0x002C, "WM_MEASUREITEM" },
248
{ 0x002D, "WM_DELETEITEM" },
249
{ 0x002E, "WM_VKEYTOITEM" },
250
{ 0x002F, "WM_CHARTOITEM" },
251
{ 0x0030, "WM_SETFONT" },
252
{ 0x0031, "WM_GETFONT" },
253
{ 0x0032, "WM_SETHOTKEY" },
254
{ 0x0033, "WM_GETHOTKEY" },
255
{ 0x0037, "WM_QUERYDRAGICON" },
256
{ 0x0039, "WM_COMPAREITEM" },
257
{ 0x003D, "WM_GETOBJECT" },
258
{ 0x0041, "WM_COMPACTING" },
259
{ 0x0044, "WM_COMMNOTIFY" },
260
{ 0x0046, "WM_WINDOWPOSCHANGING" },
261
{ 0x0047, "WM_WINDOWPOSCHANGED" },
262
{ 0x0048, "WM_POWER" },
263
{ 0x004A, "WM_COPYDATA" },
264
{ 0x004B, "WM_CANCELJOURNAL" },
265
{ 0x004E, "WM_NOTIFY" },
266
{ 0x0050, "WM_INPUTLANGCHANGEREQUEST" },
267
{ 0x0051, "WM_INPUTLANGCHANGE" },
268
{ 0x0052, "WM_TCARD" },
269
{ 0x0053, "WM_HELP" },
270
{ 0x0054, "WM_USERCHANGED" },
271
{ 0x0055, "WM_NOTIFYFORMAT" },
272
{ 0x007B, "WM_CONTEXTMENU" },
273
{ 0x007C, "WM_STYLECHANGING" },
274
{ 0x007D, "WM_STYLECHANGED" },
275
{ 0x007E, "WM_DISPLAYCHANGE" },
276
{ 0x007F, "WM_GETICON" },
277
{ 0x0080, "WM_SETICON" },
278
{ 0x0081, "WM_NCCREATE" },
279
{ 0x0082, "WM_NCDESTROY" },
280
{ 0x0083, "WM_NCCALCSIZE" },
281
{ 0x0084, "WM_NCHITTEST" },
282
{ 0x0085, "WM_NCPAINT" },
283
{ 0x0086, "WM_NCACTIVATE" },
284
{ 0x0087, "WM_GETDLGCODE" },
285
{ 0x0088, "WM_SYNCPAINT" },
286
{ 0x00A0, "WM_NCMOUSEMOVE" },
287
{ 0x00A1, "WM_NCLBUTTONDOWN" },
288
{ 0x00A2, "WM_NCLBUTTONUP" },
289
{ 0x00A3, "WM_NCLBUTTONDBLCLK" },
290
{ 0x00A4, "WM_NCRBUTTONDOWN" },
291
{ 0x00A5, "WM_NCRBUTTONUP" },
292
{ 0x00A6, "WM_NCRBUTTONDBLCLK" },
293
{ 0x00A7, "WM_NCMBUTTONDOWN" },
294
{ 0x00A8, "WM_NCMBUTTONUP" },
295
{ 0x00A9, "WM_NCMBUTTONDBLCLK" },
296
{ 0x00AB, "WM_NCXBUTTONDOWN" },
297
{ 0x00AC, "WM_NCXBUTTONUP" },
298
{ 0x00AD, "WM_NCXBUTTONDBLCLK" },
299
{ 0x00FF, "WM_INPUT" },
300
{ 0x0100, "WM_KEYDOWN" },
301
{ 0x0101, "WM_KEYUP" },
302
{ 0x0102, "WM_CHAR" },
303
{ 0x0103, "WM_DEADCHAR" },
304
{ 0x0104, "WM_SYSKEYDOWN" },
305
{ 0x0105, "WM_SYSKEYUP" },
306
{ 0x0106, "WM_SYSCHAR" },
307
{ 0x0107, "WM_SYSDEADCHAR" },
308
{ 0x0109, "WM_UNICHAR" },
309
{ 0x010D, "WM_IME_STARTCOMPOSITION" },
310
{ 0x010E, "WM_IME_ENDCOMPOSITION" },
311
{ 0x010F, "WM_IME_COMPOSITION" },
312
{ 0x0110, "WM_INITDIALOG" },
313
{ 0x0111, "WM_COMMAND" },
314
{ 0x0112, "WM_SYSCOMMAND" },
315
{ 0x0113, "WM_TIMER" },
316
{ 0x0114, "WM_HSCROLL" },
317
{ 0x0115, "WM_VSCROLL" },
318
{ 0x0116, "WM_INITMENU" },
319
{ 0x0117, "WM_INITMENUPOPUP" },
320
{ 0x011F, "WM_MENUSELECT" },
321
{ 0x0120, "WM_MENUCHAR" },
322
{ 0x0121, "WM_ENTERIDLE" },
323
{ 0x0122, "WM_MENURBUTTONUP" },
324
{ 0x0123, "WM_MENUDRAG" },
325
{ 0x0124, "WM_MENUGETOBJECT" },
326
{ 0x0125, "WM_UNINITMENUPOPUP" },
327
{ 0x0126, "WM_MENUCOMMAND" },
328
{ 0x0127, "WM_CHANGEUISTATE" },
329
{ 0x0128, "WM_UPDATEUISTATE" },
330
{ 0x0129, "WM_QUERYUISTATE" },
331
{ 0x0132, "WM_CTLCOLORMSGBOX" },
332
{ 0x0133, "WM_CTLCOLOREDIT" },
333
{ 0x0134, "WM_CTLCOLORLISTBOX" },
334
{ 0x0135, "WM_CTLCOLORBTN" },
335
{ 0x0136, "WM_CTLCOLORDLG" },
336
{ 0x0137, "WM_CTLCOLORSCROLLBAR" },
337
{ 0x0138, "WM_CTLCOLORSTATIC" },
338
{ 0x0200, "WM_MOUSEMOVE" },
339
{ 0x0201, "WM_LBUTTONDOWN" },
340
{ 0x0202, "WM_LBUTTONUP" },
341
{ 0x0203, "WM_LBUTTONDBLCLK" },
342
{ 0x0204, "WM_RBUTTONDOWN" },
343
{ 0x0205, "WM_RBUTTONUP" },
344
{ 0x0206, "WM_RBUTTONDBLCLK" },
345
{ 0x0207, "WM_MBUTTONDOWN" },
346
{ 0x0208, "WM_MBUTTONUP" },
347
{ 0x0209, "WM_MBUTTONDBLCLK" },
348
{ 0x020A, "WM_MOUSEWHEEL" },
349
{ 0x020B, "WM_XBUTTONDOWN" },
350
{ 0x020C, "WM_XBUTTONUP" },
351
{ 0x020D, "WM_XBUTTONDBLCLK" },
352
{ 0x020E, "WM_MOUSEHWHEEL" },
353
{ 0x0210, "WM_PARENTNOTIFY" },
354
{ 0x0211, "WM_ENTERMENULOOP" },
355
{ 0x0212, "WM_EXITMENULOOP" },
356
{ 0x0213, "WM_NEXTMENU" },
357
{ 0x0214, "WM_SIZING" },
358
{ 0x0215, "WM_CAPTURECHANGED" },
359
{ 0x0216, "WM_MOVING" },
360
{ 0x0218, "WM_POWERBROADCAST" },
361
{ 0x0219, "WM_DEVICECHANGE" },
362
{ 0x0220, "WM_MDICREATE" },
363
{ 0x0221, "WM_MDIDESTROY" },
364
{ 0x0222, "WM_MDIACTIVATE" },
365
{ 0x0223, "WM_MDIRESTORE" },
366
{ 0x0224, "WM_MDINEXT" },
367
{ 0x0225, "WM_MDIMAXIMIZE" },
368
{ 0x0226, "WM_MDITILE" },
369
{ 0x0227, "WM_MDICASCADE" },
370
{ 0x0228, "WM_MDIICONARRANGE" },
371
{ 0x0229, "WM_MDIGETACTIVE" },
372
{ 0x0230, "WM_MDISETMENU" },
373
{ 0x0231, "WM_ENTERSIZEMOVE" },
374
{ 0x0232, "WM_EXITSIZEMOVE" },
375
{ 0x0233, "WM_DROPFILES" },
376
{ 0x0234, "WM_MDIREFRESHMENU" },
377
{ 0x0281, "WM_IME_SETCONTEXT" },
378
{ 0x0282, "WM_IME_NOTIFY" },
379
{ 0x0283, "WM_IME_CONTROL" },
380
{ 0x0284, "WM_IME_COMPOSITIONFULL" },
381
{ 0x0285, "WM_IME_SELECT" },
382
{ 0x0286, "WM_IME_CHAR" },
383
{ 0x0288, "WM_IME_REQUEST" },
384
{ 0x0290, "WM_IME_KEYDOWN" },
385
{ 0x0291, "WM_IME_KEYUP" },
386
{ 0x02A0, "WM_NCMOUSEHOVER" },
387
{ 0x02A1, "WM_MOUSEHOVER" },
388
{ 0x02A2, "WM_NCMOUSELEAVE" },
389
{ 0x02A3, "WM_MOUSELEAVE" },
390
{ 0x02B1, "WM_WTSSESSION_CHANGE" },
391
{ 0x02C0, "WM_TABLET_FIRST" },
392
{ 0x02C1, "WM_TABLET_FIRST + 1" },
393
{ 0x02C2, "WM_TABLET_FIRST + 2" },
394
{ 0x02C3, "WM_TABLET_FIRST + 3" },
395
{ 0x02C4, "WM_TABLET_FIRST + 4" },
396
{ 0x02C5, "WM_TABLET_FIRST + 5" },
397
{ 0x02C6, "WM_TABLET_FIRST + 6" },
398
{ 0x02C7, "WM_TABLET_FIRST + 7" },
399
{ 0x02C8, "WM_TABLET_FIRST + 8" },
400
{ 0x02C9, "WM_TABLET_FIRST + 9" },
401
{ 0x02CA, "WM_TABLET_FIRST + 10" },
402
{ 0x02CB, "WM_TABLET_FIRST + 11" },
403
{ 0x02CC, "WM_TABLET_FIRST + 12" },
404
{ 0x02CD, "WM_TABLET_FIRST + 13" },
405
{ 0x02CE, "WM_TABLET_FIRST + 14" },
406
{ 0x02CF, "WM_TABLET_FIRST + 15" },
407
{ 0x02D0, "WM_TABLET_FIRST + 16" },
408
{ 0x02D1, "WM_TABLET_FIRST + 17" },
409
{ 0x02D2, "WM_TABLET_FIRST + 18" },
410
{ 0x02D3, "WM_TABLET_FIRST + 19" },
411
{ 0x02D4, "WM_TABLET_FIRST + 20" },
412
{ 0x02D5, "WM_TABLET_FIRST + 21" },
413
{ 0x02D6, "WM_TABLET_FIRST + 22" },
414
{ 0x02D7, "WM_TABLET_FIRST + 23" },
415
{ 0x02D8, "WM_TABLET_FIRST + 24" },
416
{ 0x02D9, "WM_TABLET_FIRST + 25" },
417
{ 0x02DA, "WM_TABLET_FIRST + 26" },
418
{ 0x02DB, "WM_TABLET_FIRST + 27" },
419
{ 0x02DC, "WM_TABLET_FIRST + 28" },
420
{ 0x02DD, "WM_TABLET_FIRST + 29" },
421
{ 0x02DE, "WM_TABLET_FIRST + 30" },
422
{ 0x02DF, "WM_TABLET_LAST" },
423
{ 0x0300, "WM_CUT" },
424
{ 0x0301, "WM_COPY" },
425
{ 0x0302, "WM_PASTE" },
426
{ 0x0303, "WM_CLEAR" },
427
{ 0x0304, "WM_UNDO" },
428
{ 0x0305, "WM_RENDERFORMAT" },
429
{ 0x0306, "WM_RENDERALLFORMATS" },
430
{ 0x0307, "WM_DESTROYCLIPBOARD" },
431
{ 0x0308, "WM_DRAWCLIPBOARD" },
432
{ 0x0309, "WM_PAINTCLIPBOARD" },
433
{ 0x030A, "WM_VSCROLLCLIPBOARD" },
434
{ 0x030B, "WM_SIZECLIPBOARD" },
435
{ 0x030C, "WM_ASKCBFORMATNAME" },
436
{ 0x030D, "WM_CHANGECBCHAIN" },
437
{ 0x030E, "WM_HSCROLLCLIPBOARD" },
438
{ 0x030F, "WM_QUERYNEWPALETTE" },
439
{ 0x0310, "WM_PALETTEISCHANGING" },
440
{ 0x0311, "WM_PALETTECHANGED" },
441
{ 0x0312, "WM_HOTKEY" },
442
{ 0x0317, "WM_PRINT" },
443
{ 0x0318, "WM_PRINTCLIENT" },
444
{ 0x0319, "WM_APPCOMMAND" },
445
{ 0x031A, "WM_THEMECHANGED" },
446
{ 0x0358, "WM_HANDHELDFIRST" },
447
{ 0x0359, "WM_HANDHELDFIRST + 1" },
448
{ 0x035A, "WM_HANDHELDFIRST + 2" },
449
{ 0x035B, "WM_HANDHELDFIRST + 3" },
450
{ 0x035C, "WM_HANDHELDFIRST + 4" },
451
{ 0x035D, "WM_HANDHELDFIRST + 5" },
452
{ 0x035E, "WM_HANDHELDFIRST + 6" },
453
{ 0x035F, "WM_HANDHELDLAST" },
454
{ 0x0360, "WM_AFXFIRST" },
455
{ 0x0361, "WM_AFXFIRST + 1" },
456
{ 0x0362, "WM_AFXFIRST + 2" },
457
{ 0x0363, "WM_AFXFIRST + 3" },
458
{ 0x0364, "WM_AFXFIRST + 4" },
459
{ 0x0365, "WM_AFXFIRST + 5" },
460
{ 0x0366, "WM_AFXFIRST + 6" },
461
{ 0x0367, "WM_AFXFIRST + 7" },
462
{ 0x0368, "WM_AFXFIRST + 8" },
463
{ 0x0369, "WM_AFXFIRST + 9" },
464
{ 0x036A, "WM_AFXFIRST + 10" },
465
{ 0x036B, "WM_AFXFIRST + 11" },
466
{ 0x036C, "WM_AFXFIRST + 12" },
467
{ 0x036D, "WM_AFXFIRST + 13" },
468
{ 0x036E, "WM_AFXFIRST + 14" },
469
{ 0x036F, "WM_AFXFIRST + 15" },
470
{ 0x0370, "WM_AFXFIRST + 16" },
471
{ 0x0371, "WM_AFXFIRST + 17" },
472
{ 0x0372, "WM_AFXFIRST + 18" },
473
{ 0x0373, "WM_AFXFIRST + 19" },
474
{ 0x0374, "WM_AFXFIRST + 20" },
475
{ 0x0375, "WM_AFXFIRST + 21" },
476
{ 0x0376, "WM_AFXFIRST + 22" },
477
{ 0x0377, "WM_AFXFIRST + 23" },
478
{ 0x0378, "WM_AFXFIRST + 24" },
479
{ 0x0379, "WM_AFXFIRST + 25" },
480
{ 0x037A, "WM_AFXFIRST + 26" },
481
{ 0x037B, "WM_AFXFIRST + 27" },
482
{ 0x037C, "WM_AFXFIRST + 28" },
483
{ 0x037D, "WM_AFXFIRST + 29" },
484
{ 0x037E, "WM_AFXFIRST + 30" },
485
{ 0x037F, "WM_AFXLAST" },
486
{ 0x0380, "WM_PENWINFIRST" },
487
{ 0x0381, "WM_PENWINFIRST + 1" },
488
{ 0x0382, "WM_PENWINFIRST + 2" },
489
{ 0x0383, "WM_PENWINFIRST + 3" },
490
{ 0x0384, "WM_PENWINFIRST + 4" },
491
{ 0x0385, "WM_PENWINFIRST + 5" },
492
{ 0x0386, "WM_PENWINFIRST + 6" },
493
{ 0x0387, "WM_PENWINFIRST + 7" },
494
{ 0x0388, "WM_PENWINFIRST + 8" },
495
{ 0x0389, "WM_PENWINFIRST + 9" },
496
{ 0x038A, "WM_PENWINFIRST + 10" },
497
{ 0x038B, "WM_PENWINFIRST + 11" },
498
{ 0x038C, "WM_PENWINFIRST + 12" },
499
{ 0x038D, "WM_PENWINFIRST + 13" },
500
{ 0x038E, "WM_PENWINFIRST + 14" },
501
{ 0x038F, "WM_PENWINLAST" },
502
{ 0x0400, "WM_USER" },
503
{ 0x8000, "WM_APP" },
504
{ 0,0 }}; // End of known messages
506
// Looks up the WM_ message in the table above
507
static const char* findWMstr(uint msg)
510
const char* result = 0;
512
while (knownWM[i].str && (knownWM[i].WM != msg))
514
result = knownWM[i].str;
518
// Convenience function for converting flags and values into readable strings
519
struct FLAG_STRING_STRUCT
525
FLAG_STRING_STRUCT FLAG_STRING(uint value = 0, const char *c = 0)
527
FLAG_STRING_STRUCT s = {value, c};
531
#define FLGSTR(x) FLAG_STRING(x, #x)
533
// Returns an ORed (" | ") together string for the flags active in the actual
534
// value. (...) must consist of FLAG_STRING, with a FLAG_STRING() as the last
535
// value in the list passed to the function
536
QString flagCheck(uint actual, ...)
539
va_start(ap, actual);
543
FLAG_STRING_STRUCT v;
544
while((v=va_arg(ap,FLAG_STRING_STRUCT)).str) {
545
if ((actual & v.value) == v.value) {
547
result += QLatin1String(" | ");
548
result += QString::fromLatin1(v.str);
555
// Returns the string representation of the value in 'actual'. (...) must
556
// consist of FLAG_STRING, with a FLAG_STRING() as the last value in the list
557
// passed to the function
558
QString valueCheck(uint actual, ...)
561
va_start(ap, actual);
564
FLAG_STRING_STRUCT v;
565
while((v=va_arg(ap,FLAG_STRING_STRUCT)).str && (actual != v.value))
567
result = QString::fromLatin1(v.str);
575
QString decodeMSG(const MSG& msg)
577
return QString::fromLatin1("THis is not supported on Borland");
582
// Returns a "human readable" string representation of the MSG and the
583
// information it points to
584
QString decodeMSG(const MSG& msg)
586
const WPARAM wParam = msg.wParam;
587
const LPARAM lParam = msg.lParam;
588
QString wmmsg = QString::fromLatin1(findWMstr(msg.message));
589
// Unknown WM_, so use number
591
wmmsg = QString::fromLatin1("WM_(%1)").arg(msg.message);
593
QString rawParameters;
594
rawParameters.sprintf("hwnd(0x%p) ", (void *)msg.hwnd);
597
if (msg.message > WM_APP)
598
wmmsg = QString::fromLatin1("WM_APP + %1").arg(msg.message - WM_APP);
599
else if (msg.message > WM_USER)
600
wmmsg = QString::fromLatin1("WM_USER + %1").arg(msg.message - WM_USER);
603
switch (msg.message) {
607
QString activation = valueCheck(wParam,
608
FLAG_STRING(WA_ACTIVE, "Activate"),
609
FLAG_STRING(WA_INACTIVE, "Deactivate"),
610
FLAG_STRING(WA_CLICKACTIVE, "Activate by mouseclick"),
612
parameters.sprintf("%s Hwnd (0x%p)", activation.toLatin1().data(), (void *)msg.hwnd);
616
#ifdef WM_CAPTURECHANGED
617
case WM_CAPTURECHANGED:
618
parameters.sprintf("Hwnd gaining capture (0x%p)", (void *)lParam);
624
LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
625
QString styles = flagCheck(lpcs->style,
629
FLGSTR(WS_CLIPCHILDREN),
630
FLGSTR(WS_CLIPSIBLINGS),
635
FLGSTR(WS_OVERLAPPED),
636
#if defined(WS_OVERLAPPEDWINDOW) && (WS_OVERLAPPEDWINDOW != 0)
637
FLGSTR(WS_OVERLAPPEDWINDOW),
643
FLGSTR(WS_MAXIMIZEBOX),
645
FLGSTR(WS_MINIMIZEBOX),
646
FLGSTR(WS_OVERLAPPEDWINDOW),
648
#ifdef WS_POPUPWINDOW
649
FLGSTR(WS_POPUPWINDOW),
654
FLGSTR(WS_THICKFRAME),
658
#ifdef WS_TILEDWINDOW
659
FLGSTR(WS_TILEDWINDOW),
665
QString exStyles = flagCheck(lpcs->dwExStyle,
666
#ifdef WS_EX_ACCEPTFILES
667
FLGSTR(WS_EX_ACCEPTFILES),
669
#ifdef WS_EX_APPWINDOW
670
FLGSTR(WS_EX_APPWINDOW),
672
FLGSTR(WS_EX_CLIENTEDGE),
673
FLGSTR(WS_EX_DLGMODALFRAME),
677
FLGSTR(WS_EX_LEFTSCROLLBAR),
678
#ifdef WS_EX_LTRREADING
679
FLGSTR(WS_EX_LTRREADING),
681
#ifdef WS_EX_MDICHILD
682
FLGSTR(WS_EX_MDICHILD),
684
#ifdef WS_EX_NOACTIVATE
685
FLGSTR(WS_EX_NOACTIVATE),
687
#ifdef WS_EX_NOANIMATION
688
FLGSTR(WS_EX_NOANIMATION),
690
FLGSTR(WS_EX_NOPARENTNOTIFY),
691
FLGSTR(WS_EX_OVERLAPPEDWINDOW),
692
#ifdef WS_EX_PALETTEWINDOW
693
FLGSTR(WS_EX_PALETTEWINDOW),
698
#ifdef WS_EX_RIGHTSCROLLBAR
699
FLGSTR(WS_EX_RIGHTSCROLLBAR),
701
#ifdef WS_EX_RTLREADING
702
FLGSTR(WS_EX_RTLREADING),
704
FLGSTR(WS_EX_STATICEDGE),
705
FLGSTR(WS_EX_TOOLWINDOW),
706
FLGSTR(WS_EX_TOPMOST),
707
#ifdef WS_EX_TRANSPARENT
708
FLGSTR(WS_EX_TRANSPARENT),
710
FLGSTR(WS_EX_WINDOWEDGE),
711
#ifdef WS_EX_CAPTIONOKBTN
712
FLGSTR(WS_EX_CAPTIONOKBTN),
717
if (lpcs->lpszClass != 0) {
718
if (HIWORD(lpcs->lpszClass) == 0) // Atom
719
className = QString::number(LOWORD(lpcs->lpszClass), 16);
721
className = QString((QChar*)lpcs->lpszClass,
722
(int)wcslen(reinterpret_cast<const wchar_t *>(lpcs->lpszClass)));
726
if (lpcs->lpszName != 0)
727
windowName = QString((QChar*)lpcs->lpszName,
728
(int)wcslen(reinterpret_cast<const wchar_t *>(lpcs->lpszName)));
730
parameters.sprintf("x,y(%4d,%4d) w,h(%4d,%4d) className(%s) windowName(%s) parent(0x%p) style(%s) exStyle(%s)",
731
lpcs->x, lpcs->y, lpcs->cx, lpcs->cy, className.toLatin1().data(),
732
windowName.toLatin1().data(), (void *)lpcs->hwndParent,
733
styles.toLatin1().data(), exStyles.toLatin1().data());
739
parameters.sprintf("Destroy hwnd (0x%p)", (void *)msg.hwnd);
745
QString imnCommand = valueCheck(wParam,
746
FLGSTR(IMN_CHANGECANDIDATE),
747
FLGSTR(IMN_CLOSECANDIDATE),
748
FLGSTR(IMN_CLOSESTATUSWINDOW),
749
FLGSTR(IMN_GUIDELINE),
750
FLGSTR(IMN_OPENCANDIDATE),
751
FLGSTR(IMN_OPENSTATUSWINDOW),
752
FLGSTR(IMN_SETCANDIDATEPOS),
753
FLGSTR(IMN_SETCOMPOSITIONFONT),
754
FLGSTR(IMN_SETCOMPOSITIONWINDOW),
755
FLGSTR(IMN_SETCONVERSIONMODE),
756
FLGSTR(IMN_SETOPENSTATUS),
757
FLGSTR(IMN_SETSENTENCEMODE),
758
FLGSTR(IMN_SETSTATUSWINDOWPOS),
760
parameters.sprintf("Command(%s : 0x%p)", imnCommand.toLatin1().data(), (void *)lParam);
764
#ifdef WM_IME_SETCONTEXT
765
case WM_IME_SETCONTEXT:
767
bool fSet = (BOOL)wParam;
768
DWORD fShow = (DWORD)lParam;
769
QString showFlgs = flagCheck(fShow,
770
#ifdef ISC_SHOWUICOMPOSITIONWINDOW
771
FLGSTR(ISC_SHOWUICOMPOSITIONWINDOW),
773
#ifdef ISC_SHOWUIGUIDWINDOW
774
FLGSTR(ISC_SHOWUIGUIDWINDOW),
776
#ifdef ISC_SHOWUISOFTKBD
777
FLGSTR(ISC_SHOWUISOFTKBD),
779
FLGSTR(ISC_SHOWUICANDIDATEWINDOW),
780
FLGSTR(ISC_SHOWUICANDIDATEWINDOW << 1),
781
FLGSTR(ISC_SHOWUICANDIDATEWINDOW << 2),
782
FLGSTR(ISC_SHOWUICANDIDATEWINDOW << 3),
784
parameters.sprintf("Input context(%s) Show flags(%s)", (fSet? "Active" : "Inactive"), showFlgs.toLatin1().data());
790
parameters.sprintf("Hwnd gaining keyboard focus (0x%p)", (void *)wParam);
805
int nVirtKey = (int)wParam;
806
long lKeyData = (long)lParam;
807
int repCount = (lKeyData & 0xffff); // Bit 0-15
808
int scanCode = (lKeyData & 0xf0000) >> 16; // Bit 16-23
809
bool contextCode = !!(lKeyData & 0x20000000); // Bit 29
810
bool prevState = !!(lKeyData & 0x40000000); // Bit 30
811
bool transState = !!(lKeyData & 0x80000000); // Bit 31
812
parameters.sprintf("Virual-key(0x%x) Scancode(%d) Rep(%d) Contextcode(%d), Prev state(%d), Trans state(%d)",
813
nVirtKey, scanCode, repCount, contextCode, prevState, transState);
820
parameters = (msg.wParam? QLatin1String("Active Titlebar") : QLatin1String("Inactive Titlebar"));
824
#ifdef WM_MOUSEACTIVATE
825
case WM_MOUSEACTIVATE:
827
QString mouseMsg = QString::fromLatin1(findWMstr(HIWORD(lParam)));
828
parameters.sprintf("TLW(0x%p) HittestCode(0x%x) MouseMsg(%s)", (void *)wParam, LOWORD(lParam), mouseMsg.toLatin1().data());
834
break; // wParam & lParam not used
842
#ifdef WM_MOUSEHWHEEL
845
#ifdef WM_LBUTTONDBLCLK
846
case WM_LBUTTONDBLCLK:
848
#ifdef WM_LBUTTONDOWN
854
#ifdef WM_MBUTTONDBLCLK
855
case WM_MBUTTONDBLCLK:
857
#ifdef WM_MBUTTONDOWN
863
#ifdef WM_RBUTTONDBLCLK
864
case WM_RBUTTONDBLCLK:
866
#ifdef WM_RBUTTONDOWN
875
QString vrtKeys = flagCheck(wParam,
888
parameters.sprintf("x,y(%4d,%4d) Virtual Keys(%s)", GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), vrtKeys.toLatin1().data());
894
parameters.sprintf("x,y(%4d,%4d)", LOWORD(lParam), HIWORD(lParam));
897
#if defined(WM_PAINT) && defined(WM_ERASEBKGND)
900
parameters.sprintf("hdc(0x%p)", (void *)wParam);
903
#ifdef WM_QUERYNEWPALETTE
904
case WM_QUERYNEWPALETTE:
905
break; // lParam & wParam are unused
910
QString mouseMsg = QString::fromLatin1(findWMstr(HIWORD(lParam)));
911
parameters.sprintf("HitTestCode(0x%x) MouseMsg(%s)", LOWORD(lParam), mouseMsg.toLatin1().data());
917
parameters.sprintf("Lost Focus (0x%p)", (void *)wParam);
922
parameters.sprintf("Set Text (%s)", QString((QChar*)lParam, (int)wcslen(reinterpret_cast<const wchar_t *>(lParam))).toLatin1().data()); //Unicode string
928
QString showMode = valueCheck(wParam,
929
FLGSTR(SIZE_MAXHIDE),
930
FLGSTR(SIZE_MAXIMIZED),
931
FLGSTR(SIZE_MAXSHOW),
932
FLGSTR(SIZE_MINIMIZED),
933
FLGSTR(SIZE_RESTORED),
936
parameters.sprintf("w,h(%4d,%4d) showmode(%s)", LOWORD(lParam), HIWORD(lParam), showMode.toLatin1().data());
940
#ifdef WM_WINDOWPOSCHANGED
941
case WM_WINDOWPOSCHANGED:
943
LPWINDOWPOS winPos = (LPWINDOWPOS)lParam;
946
QString hwndAfter = valueCheck(quint64(winPos->hwndInsertAfter),
947
FLAG_STRING((qptrdiff)HWND_BOTTOM, "HWND_BOTTOM"),
948
FLAG_STRING((qptrdiff)HWND_NOTOPMOST, "HWND_NOTOPMOST"),
949
FLAG_STRING((qptrdiff)HWND_TOP, "HWND_TOP"),
950
FLAG_STRING((qptrdiff)HWND_TOPMOST, "HWND_TOPMOST"),
952
if (hwndAfter.isEmpty())
953
hwndAfter = QString::number((quintptr)winPos->hwndInsertAfter, 16);
954
QString flags = flagCheck(winPos->flags,
955
FLGSTR(SWP_DRAWFRAME),
956
FLGSTR(SWP_FRAMECHANGED),
957
FLGSTR(SWP_HIDEWINDOW),
958
FLGSTR(SWP_NOACTIVATE),
959
#ifdef SWP_NOCOPYBITS
960
FLGSTR(SWP_NOCOPYBITS),
963
FLGSTR(SWP_NOOWNERZORDER),
964
FLGSTR(SWP_NOREDRAW),
965
FLGSTR(SWP_NOREPOSITION),
966
#ifdef SWP_NOSENDCHANGING
967
FLGSTR(SWP_NOSENDCHANGING),
970
FLGSTR(SWP_NOZORDER),
971
FLGSTR(SWP_SHOWWINDOW),
973
parameters.sprintf("x,y(%4d,%4d) w,h(%4d,%4d) flags(%s) hwndAfter(%s)", winPos->x, winPos->y, winPos->cx, winPos->cy, flags.toLatin1().data(), hwndAfter.toLatin1().data());
978
parameters.sprintf("wParam(0x%p) lParam(0x%p)", (void *)wParam, (void *)lParam);
981
// Yes, we want to give the WM_ names 20 chars of space before showing the
982
// decoded message, since some of the common messages are quite long, and
983
// we don't want the decoded information to vary in output position
984
QString message = QString::fromLatin1("%1: ").arg(wmmsg, 20);
985
message += rawParameters;
986
message += parameters;
992
QDebug operator<<(QDebug dbg, const MSG &msg)
994
dbg << decodeMSG(msg);
995
return dbg.nospace();