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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
// SPDX-License-Identifier: BSD-3-Clause
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <qwinwidget.h>
#include <windows.h>
HWND winId = 0;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONUP:
{
QWinWidget w(hWnd, 0, 0);
w.showCentered();
QMessageBox mb("Qt on Win32 - modal",
"Is this dialog modal?",
QMessageBox::NoIcon,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape,
QMessageBox::NoButton, &w);
int result = mb.exec();
Q_UNUSED(result);
}
break;
case WM_RBUTTONUP:
{
QWinWidget *w = new QWinWidget(hWnd, 0, 0);
w->showCentered();
QMessageBox *mb = new QMessageBox("Qt on Win32 - modeless",
"Is this dialog modal?",
QMessageBox::NoIcon,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No | QMessageBox::Escape,
QMessageBox::NoButton, w);
mb->setModal(false);
mb->setAttribute(Qt::WA_DeleteOnClose);
mb->show();
}
break;
case WM_KEYDOWN:
if (wParam != VK_TAB)
return DefWindowProc(hWnd, message, wParam, lParam);
SetFocus(winId);
break;
case WM_SETFOCUS:
{
QString str("Got focus");
QWidget *widget = QWidget::find((WId)HWND(wParam));
if (widget)
str += QString(" from %1 (%2)").arg(widget->objectName()).arg(widget->metaObject()->className());
str += "\n";
OutputDebugStringA(str.toLocal8Bit().data());
}
break;
case WM_KILLFOCUS:
{
QString str("Lost focus");
QWidget *widget = QWidget::find((WId)HWND(wParam));
if (widget)
str += QString(" to %1 (%2)").arg(widget->objectName()).arg(widget->metaObject()->className());
str += "\n";
OutputDebugStringA(str.toLocal8Bit().data());
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/,
int nCmdShow)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = L"qtest";
wcex.hIconSm = NULL;
ATOM windowClass = RegisterClassEx(&wcex);
HWND hWnd = CreateWindow((TCHAR*)windowClass, L"Windows Migration Framework Example",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, hInstance, 0);
if (!hWnd)
return FALSE;
int argc = 0;
QApplication a(argc, 0);
QWinWidget win(hWnd);
winId = (HWND)win.winId();
QHBoxLayout hbox(&win);
hbox.setSpacing(5);
hbox.setMargin(0);
QPushButton *pb = new QPushButton("Qt command button", &win);
pb->setObjectName("pb");
hbox.addWidget(pb);
QLabel *label = new QLabel("Some label", &win);
label->setObjectName("label");
hbox.addWidget(label);
QLineEdit *le1 = new QLineEdit(&win);
le1->setObjectName("le1");
hbox.addWidget(le1);
QLineEdit *le2 = new QLineEdit(&win);
le1->setObjectName("le2");
hbox.addWidget(le2);
QLineEdit *le3 = new QLineEdit(&win);
le1->setObjectName("le3");
hbox.addWidget(le3);
win.move(0, 0);
win.show();
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return a.exec();
}
|