summaryrefslogtreecommitdiffstats
path: root/qtwinmigrate/examples/winhost
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/winhost
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/winhost')
-rw-r--r--qtwinmigrate/examples/winhost/main.cpp142
-rw-r--r--qtwinmigrate/examples/winhost/winhost.pro4
-rw-r--r--qtwinmigrate/examples/winhost/winhost.qdoc76
3 files changed, 222 insertions, 0 deletions
diff --git a/qtwinmigrate/examples/winhost/main.cpp b/qtwinmigrate/examples/winhost/main.cpp
new file mode 100644
index 0000000..213a720
--- /dev/null
+++ b/qtwinmigrate/examples/winhost/main.cpp
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** 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 <qwinhost.h>
+
+#include <windows.h>
+
+class HostWindow : public QWinHost
+{
+ Q_OBJECT
+public:
+ HostWindow(QWidget *parent = 0, Qt::WFlags f = 0)
+ : QWinHost(parent, f)
+ {
+ setFocusPolicy(Qt::StrongFocus);
+ }
+
+ HWND createWindow(HWND parent, HINSTANCE instance)
+ {
+ static ATOM windowClass = 0;
+ if (!windowClass) {
+ WNDCLASSEX wcex;
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = (WNDPROC)WndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = instance;
+ 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;
+
+ windowClass = RegisterClassEx(&wcex);
+ }
+
+ HWND hwnd = CreateWindow((TCHAR*)windowClass, 0, WS_CHILD|WS_CLIPSIBLINGS|WS_TABSTOP,
+ CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, parent, NULL, instance, NULL);
+
+ return hwnd;
+ }
+
+signals:
+ void message(const QString &msg, int timeout);
+
+public slots:
+ void returnPressed()
+ {
+ QMessageBox::information(topLevelWidget(), "Message from Qt", "Return pressed in QLineEdit!");
+ }
+
+protected:
+ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+ {
+ QWidget *widget = QWidget::find(GetParent(hWnd));
+ HostWindow *window = qobject_cast<HostWindow*>(widget);
+
+ if (window) switch (message) {
+ case WM_SETFOCUS:
+ window->message("SetFocus for Win32 window!", 1000);
+ break;
+ case WM_KILLFOCUS:
+ window->message("KillFocus for Win32 window!", 1000);
+ break;
+ case WM_MOUSEMOVE:
+ window->message("Moving the mouse, aren't we?", 200);
+ break;
+ case WM_KEYDOWN:
+ if (wParam != VK_TAB)
+ window->message("Key Pressed!", 500);
+ break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ return 0;
+ }
+};
+
+#include "main.moc"
+
+int main(int argc, char **argv)
+{
+ QApplication a(argc, argv);
+
+ QMainWindow mw;
+ mw.menuBar()->addMenu("&File")->addAction("&Exit", &a, SLOT(quit()));
+
+ QWidget central(&mw);
+
+ QLineEdit edit(&central);
+ HostWindow host(&central);
+ QObject::connect(&host, SIGNAL(message(const QString&,int)), mw.statusBar(), SLOT(showMessage(const QString&,int)));
+ QObject::connect(&edit, SIGNAL(returnPressed()), &host, SLOT(returnPressed()));
+
+ QVBoxLayout vbox(&central);
+ vbox.addWidget(&edit);
+ vbox.addWidget(&host);
+
+ mw.setCentralWidget(&central);
+ mw.show();
+ return a.exec();
+}
diff --git a/qtwinmigrate/examples/winhost/winhost.pro b/qtwinmigrate/examples/winhost/winhost.pro
new file mode 100644
index 0000000..b1dbd7e
--- /dev/null
+++ b/qtwinmigrate/examples/winhost/winhost.pro
@@ -0,0 +1,4 @@
+TEMPLATE = app
+SOURCES += main.cpp
+
+include(../../src/qtwinmigrate.pri)
diff --git a/qtwinmigrate/examples/winhost/winhost.qdoc b/qtwinmigrate/examples/winhost/winhost.qdoc
new file mode 100644
index 0000000..da39147
--- /dev/null
+++ b/qtwinmigrate/examples/winhost/winhost.qdoc
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** 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-win32-in-qt-example.html
+ \title Qt Application using Win32 Windows
+
+ This examples shows how to use the QWinHost class to use a native Win32
+ window inside a Qt based user interface.
+
+ \quotefromfile winhost/main.cpp
+ \skipto class HostWindow
+
+ \printto signals:
+ The HostWindow class is a subclass of QWinHost and reimplements the
+ virtual function QWinHost::createWindow() to register a Win32 window
+ class using the RegisterClassEx API, and to create a window using the
+ CreateWindow API. Note that the UNICODE version of all Win32 APIs is
+ used.
+
+ \printto protected:
+ The class implements a signal \c message to report status changes.
+
+ \printto if (window) switch
+ The static \c WndProc function implements the message handling of the
+ Win32 window. Since the method is static we have to use QWidget::find()
+ to get the QWidget object for the window handle. Since we want to use
+ the signal of the HostWindow class, which is the parent window of the
+ native Win32 window, we have to cast the QWidget pointer to HostWindow,
+ which is safe when using qobject_cast().
+
+ \printuntil };
+ The message is then handled in the switch statement. Unhandled messages
+ are passed on to the default window procedure.
+
+ \printuntil }
+ The \c main function creates a standard Qt user interface using
+ QMainWindow. The main window's central widget contains a
+ QLineEdit as well as the HostWindow. Messages sent by the HostWindow
+ object are displayed in the main window's default statusbar.
+*/