I get the "good" result on windows no matter whether I use wxFRAME_SHAPED or not.
Code: Select all
#ifndef __COMMON_H
#define __COMMON_H
#include "wx/wx.h"
#include "wx/taskbar.h"
#include "wx/sizer.h"
#endif
//------- WIDGETSTESTAPP.H
#pragma once
#include "Common.h"
class WidgetsTestApp : public wxApp
{
public:
WidgetsTestApp(void);
virtual ~WidgetsTestApp(void);
virtual bool OnInit();
};
IMPLEMENT_APP(WidgetsTestApp)
//------- WIDGETSTESTAPP.CPP
#include "WidgetsTestApp.h"
#include "WidgetsTestFrame.h"
WidgetsTestApp::WidgetsTestApp(void)
{
}
WidgetsTestApp::~WidgetsTestApp(void)
{
}
bool WidgetsTestApp::OnInit()
{
WidgetsTestFrame *frame = new WidgetsTestFrame( wxT("") );
frame->Show( true );
SetTopWindow( frame );
return true;
}
#ifndef __WIDGETSTESTFRAME_H
#define __WIDGETSTESTFRAME_H
#include "Common.h"
class WidgetsTestFrame: public wxFrame
{
public:
WidgetsTestFrame(const wxString& title);
virtual ~WidgetsTestFrame(void);
private:
DECLARE_EVENT_TABLE()
};
#endif
//---------- WIDGETSTESTFRAME.CPP
#include "WidgetsTestFrame.h"
#include "WidgetsCustom.h"
#define ID_MAINFRAME 1000
WidgetsTestFrame::~WidgetsTestFrame(void)
{
}
WidgetsTestFrame::WidgetsTestFrame(const wxString& title)
: wxFrame((wxFrame *)NULL,ID_MAINFRAME, title, wxDefaultPosition, wxSize(250,500),wxDEFAULT_FRAME_STYLE|wxFRAME_SHAPED )
{
SetBackgroundColour(wxColour(65,130,195));
wxFlexGridSizer *mysizer = new wxFlexGridSizer(3,3,0,0);
WidgetsCustom* custom1 = new WidgetsCustom(this,this);
WidgetsCustom* custom2 = new WidgetsCustom(this,this);
WidgetsCustom* custom3 = new WidgetsCustom(this,this);
WidgetsCustom* custom4 = new WidgetsCustom(this,this);
WidgetsCustom* custom5 = new WidgetsCustom(this,this);
WidgetsCustom* custom6 = new WidgetsCustom(this,this);
WidgetsCustom* custom7 = new WidgetsCustom(this,this);
WidgetsCustom* custom8 = new WidgetsCustom(this,this);
WidgetsCustom* custom9 = new WidgetsCustom(this,this);
mysizer->Add(custom1,0,wxEXPAND);
mysizer->Add(custom2,0,wxEXPAND);
mysizer->Add(custom3,0,wxEXPAND);
mysizer->Add(custom4,0,wxEXPAND);
mysizer->Add(custom5,0,wxEXPAND);
mysizer->Add(custom6,0,wxEXPAND);
mysizer->Add(custom7,0,wxEXPAND);
mysizer->Add(custom8,0,wxEXPAND);
mysizer->Add(custom9,0,wxEXPAND);
mysizer->AddGrowableRow(0);
mysizer->AddGrowableRow(1);
mysizer->AddGrowableRow(2);
mysizer->AddGrowableCol(0);
mysizer->AddGrowableCol(1);
mysizer->AddGrowableCol(2);
this->SetSizer(mysizer);
//this->SetShape(wxRegion(0,-20,250,520));
Centre();
}
BEGIN_EVENT_TABLE(WidgetsTestFrame, wxFrame)
END_EVENT_TABLE()
#ifndef __WIDGETSCUSTOM_H
#define __WIDGETSCUSTOM_H
#include "Common.h"
class WidgetsCustom : public wxWindow
{
DECLARE_CLASS(WidgetsCustom)
public:
WidgetsCustom(wxWindow *parent, wxFrame* parent_frame);
virtual ~WidgetsCustom(void);
void OnPaint(wxPaintEvent& WXUNUSED(event));
void OnEraseBackground(wxEraseEvent& WXUNUSED(event));
private:
DECLARE_EVENT_TABLE()
wxFrame* m_parent_frame;
};
#endif
// -------------- WIDGETSCUSTOM.CPP
#include "WidgetsCustom.h"
#include "WidgetsTestFrame.h"
BEGIN_EVENT_TABLE(WidgetsCustom, wxWindow)
EVT_PAINT(WidgetsCustom::OnPaint)
EVT_ERASE_BACKGROUND(WidgetsCustom::OnEraseBackground)
END_EVENT_TABLE()
IMPLEMENT_CLASS(WidgetsCustom, wxWindow)
WidgetsCustom::WidgetsCustom(wxWindow *parent,wxFrame *parent_frame) : wxWindow(parent, -1, wxDefaultPosition,wxSize(20,20),wxNO_BORDER|wxFULL_REPAINT_ON_RESIZE)
{
m_parent_frame = parent_frame;
// SetSizeHints(20, -1, 20,-1, -1, -1);
}
WidgetsCustom::~WidgetsCustom(void)
{
}
void WidgetsCustom::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
}
void WidgetsCustom::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
wxRect r = this->GetRect();
wxBitmap memBitmap(r.width,r.height);
wxMemoryDC memDC;
memDC.SelectObject(memBitmap);
wxPen pen(wxColor(255,255,255));
wxBrush brush(wxColor(255,255,255));
memDC.SetPen(pen);
memDC.SetBrush(brush);
memDC.DrawRectangle(0,0,r.width,r.height);
wxPen pen2(wxColor(0,0,0));
memDC.SetPen(pen2);
memDC.DrawRectangle(0,0,r.width,r.height);
memDC.DrawLine(0,0,r.width,r.height);
dc.Blit(0, 0, r.width, r.height, &memDC, 0, 0);
}