class HostWindow : public QWinHost
{
Q_OBJECT
private:
static CWnd* mp_wnd;
public:
HostWindow
(QWidget* ip_parent
= 0, Qt
::WFlags f
= 0);
~HostWindow();
HWND createWindow(HWND i_parent, HINSTANCE i_instance);
protected:
static LRESULT CALLBACK WndProc(HWND i_hWnd, UINT i_message, WPARAM i_wParam, LPARAM i_lParam);
};
class HostWindow : public QWinHost
{
Q_OBJECT
private:
static CWnd* mp_wnd;
public:
HostWindow(QWidget* ip_parent = 0, Qt::WFlags f = 0);
~HostWindow();
HWND createWindow(HWND i_parent, HINSTANCE i_instance);
protected:
static LRESULT CALLBACK WndProc(HWND i_hWnd, UINT i_message, WPARAM i_wParam, LPARAM i_lParam);
};
To copy to clipboard, switch view to plain text mode
CWnd* HostWindow::mp_wnd = 0;
HostWindow
::HostWindow(QWidget* ip_parent, Qt
::WFlags f
) : QWinHost
(ip_parent, f
) {}
HostWindow::~HostWindow()
{}
HWND HostWindow::createWindow(HWND i_parent, HINSTANCE i_instance)//todo check for if needless
{
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 = i_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_VISIBLE,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, i_parent, NULL, i_instance, NULL);
mp_wnd = new CWnd;
mp_wnd->SubclassWindow(hwnd);
return mp_wnd->GetSafeHwnd();
}
LRESULT CALLBACK HostWindow::WndProc(HWND i_hWnd, UINT i_message, WPARAM i_wParam, LPARAM i_lParam)
{
HostWindow *window = NULL;
if(widget->inherits("HostWindow"))
window = (HostWindow*)widget;
if(window)
{
switch (i_message)
{
case WM_PAINT:
{
qDebug()<<"WM_PAINT\n";
/////////////////////////////////////
CRect rect;
mp_wnd->GetClientRect(rect);
CDC* c_dc = CDC::FromHandle(GetDC(mp_wnd->GetSafeHwnd()));
CBrush brush;
brush.CreateSolidBrush(RGB(255,0,0));
CBrush *pOldBrush= c_dc->SelectObject(&brush);
c_dc->Ellipse(rect);
c_dc->SelectObject(pOldBrush);
/////////////////////////////////////
}
break;
default:
return DefWindowProc(i_hWnd, i_message, i_wParam, i_lParam);
}
}
return 0;
}
{
//..
HostWindow* mp_host_window;
//..
}
{
//... doesn't work (reproduces a black rect area)
mp_host_window = new HostWindow(this);
//..
//.. shows separated window with right drawed ellipse
mp_host_window = new HostWindow;
mp_host_window->show()
//..
}
CWnd* HostWindow::mp_wnd = 0;
HostWindow::HostWindow(QWidget* ip_parent, Qt::WFlags f) : QWinHost(ip_parent, f)
{}
HostWindow::~HostWindow()
{}
HWND HostWindow::createWindow(HWND i_parent, HINSTANCE i_instance)//todo check for if needless
{
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 = i_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_VISIBLE,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, i_parent, NULL, i_instance, NULL);
mp_wnd = new CWnd;
mp_wnd->SubclassWindow(hwnd);
return mp_wnd->GetSafeHwnd();
}
LRESULT CALLBACK HostWindow::WndProc(HWND i_hWnd, UINT i_message, WPARAM i_wParam, LPARAM i_lParam)
{
QWidget *widget = QWidget::find(GetParent(i_hWnd));
HostWindow *window = NULL;
if(widget->inherits("HostWindow"))
window = (HostWindow*)widget;
if(window)
{
switch (i_message)
{
case WM_PAINT:
{
qDebug()<<"WM_PAINT\n";
/////////////////////////////////////
CRect rect;
mp_wnd->GetClientRect(rect);
CDC* c_dc = CDC::FromHandle(GetDC(mp_wnd->GetSafeHwnd()));
CBrush brush;
brush.CreateSolidBrush(RGB(255,0,0));
CBrush *pOldBrush= c_dc->SelectObject(&brush);
c_dc->Ellipse(rect);
c_dc->SelectObject(pOldBrush);
/////////////////////////////////////
}
break;
default:
return DefWindowProc(i_hWnd, i_message, i_wParam, i_lParam);
}
}
return 0;
}
class MainWindow : public QMainWindow
{
//..
HostWindow* mp_host_window;
//..
}
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags): QMainWindow(parent, flags)
{
//... doesn't work (reproduces a black rect area)
mp_host_window = new HostWindow(this);
//..
//.. shows separated window with right drawed ellipse
mp_host_window = new HostWindow;
mp_host_window->show()
//..
}
To copy to clipboard, switch view to plain text mode
Bookmarks