summaryrefslogtreecommitdiffstats
path: root/qtwinmigrate/examples/winwidget
diff options
context:
space:
mode:
authoraavit <qt-info@nokia.com>2010-10-06 12:57:48 +0200
committeraavit <qt-info@nokia.com>2010-10-06 12:57:48 +0200
commit5019ece540d1f9dc08157f67b55d1c4ed896ae39 (patch)
tree2983f19a546336def390f7a43fa4f8426eea8bc8 /qtwinmigrate/examples/winwidget
Long live the Qt Solutions archive!
This commit adds the contents of distribution packages of the relevant subset of the Qt Solutions components, generated from the last versions in Perforce.
Diffstat (limited to 'qtwinmigrate/examples/winwidget')
-rw-r--r--qtwinmigrate/examples/winwidget/main.cpp182
-rw-r--r--qtwinmigrate/examples/winwidget/winwidget.pro4
-rw-r--r--qtwinmigrate/examples/winwidget/winwidget.qdoc91
3 files changed, 277 insertions, 0 deletions
diff --git a/qtwinmigrate/examples/winwidget/main.cpp b/qtwinmigrate/examples/winwidget/main.cpp
new file mode 100644
index 0000000..901278e
--- /dev/null
+++ b/qtwinmigrate/examples/winwidget/main.cpp
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of a Qt Solutions component.
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+****************************************************************************/
+
+#include <QtGui>
+#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(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(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 = 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();
+}
diff --git a/qtwinmigrate/examples/winwidget/winwidget.pro b/qtwinmigrate/examples/winwidget/winwidget.pro
new file mode 100644
index 0000000..dbed0a5
--- /dev/null
+++ b/qtwinmigrate/examples/winwidget/winwidget.pro
@@ -0,0 +1,4 @@
+TEMPLATE = app
+SOURCES += main.cpp
+
+include("../../src/qtwinmigrate.pri")
diff --git a/qtwinmigrate/examples/winwidget/winwidget.qdoc b/qtwinmigrate/examples/winwidget/winwidget.qdoc
new file mode 100644
index 0000000..bb9fc41
--- /dev/null
+++ b/qtwinmigrate/examples/winwidget/winwidget.qdoc
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of a Qt Solutions component.
+**
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+****************************************************************************/
+
+/*! \page winmigrate-qt-in-win32-example.html
+ \title Qt widgets in Win32
+
+ This examples shows how to use the QWinWidget class to use Qt widgets
+ inside a native Win32 user interface.
+
+ \quotefromfile winwidget/main.cpp
+ \skipto WndProc
+
+ The Window procedure for the native Win32 window implements a message
+ handlers for left and right mouse button clicks.
+
+ \printto WM_RBUTTONUP
+ When the left button is clicked a modal message box is opened. The
+ QWinWidget class is used to provide a bridge between the Win32 window
+ and the QMessageBox, and ensures that the Win32 window is modally
+ blocked by the message box.
+
+ \printto WM_KEYDOWN
+ When the right button is clicked a modeless message box is opened.
+ The QWinWidget class is used again to provide proper placement and
+ stacking of the message box. Note that this time both the QWinWidget
+ and the QMessageBox are created on the heap using operator new. Since
+ the \c WDestructiveClose flag is passed to the QMessageBox constructor
+ it is however not necessary to delete either of those objects.
+
+ \printto return 0;
+ \printuntil }
+ When the Win32 window is closed the application is terminated. Unhandled
+ messages are processed by the default window procedure.
+
+ \printto int argc
+ The application's entry point function \c wWinMain registers a window
+ class and creates a window using the CreateWindow API. Note that the
+ UNICODE versions of all Win32 APIs are used.
+
+ \printuntil QApplication
+ Before the Qt based user interface can be created a QApplication object
+ must exist. The translation of the command line arguments is omitted
+ for brevity.
+
+ \printuntil win.move
+ The QWinWidget class is once again used as a bridge between the Win32
+ window and a Qt widget, QPushButton this time.
+ Since the QWinWidget is a proper QWidget it can be layouted and
+ positioned like any other QWidget.
+
+ \printuntil }
+ Finally the Win32 user interface is displayed, and control is passed to
+ the QApplication event loop. Since Windows doesn't show child windows
+ recoursively the Qt widget has to be shown explicitly.
+*/