News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Issue with Display of wxFrame

Started by cotede2, May 01, 2010, 10:33:40 AM

Previous topic - Next topic

cotede2

Hello I face an issue when I use codeblocks and create a wxFrame. http://yfrog.com/2ftroublerj

Look, on my design view it looks okai http://yfrog.com/5eokaij

Here is my code . any ideas?
#include "MainFrame.h"

//(*InternalHeaders(MainFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(MainFrame)
const long MainFrame::ID_TEXTCTRL2 = wxNewId();
const long MainFrame::ID_TEXTCTRL1 = wxNewId();
const long MainFrame::ID_STATICTEXT3 = wxNewId();
const long MainFrame::ID_STATICTEXT2 = wxNewId();
const long MainFrame::ID_BUTTON1 = wxNewId();
const long MainFrame::ID_PANEL1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(MainFrame,wxFrame)
//(*EventTable(MainFrame)
//*)
END_EVENT_TABLE()

MainFrame::MainFrame(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
//(*Initialize(MainFrame)
Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(56,24), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
TextCtrl2 = new wxTextCtrl(Panel1, ID_TEXTCTRL2, _("Text"), wxPoint(144,128), wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
TextCtrl1 = new wxTextCtrl(Panel1, ID_TEXTCTRL1, _("Text"), wxPoint(144,168), wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
StaticText3 = new wxStaticText(Panel1, ID_STATICTEXT3, _("Identifiant"), wxPoint(64,136), wxDefaultSize, 0, _T("ID_STATICTEXT3"));
StaticText2 = new wxStaticText(Panel1, ID_STATICTEXT2, _("Mot De Passe"), wxPoint(64,168), wxDefaultSize, 0, _T("ID_STATICTEXT2"));
Button1 = new wxButton(Panel1, ID_BUTTON1, _("Valider"), wxPoint(144,208), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));

Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&MainFrame::OnButton1Click);
Panel1->Connect(ID_PANEL1,wxEVT_PAINT,(wxObjectEventFunction)&MainFrame::OnPanel1Paint,0,this);
//*)
}

MainFrame::~MainFrame()
{
//(*Destroy(MainFrame)
//*)
}


void MainFrame::OnPanel1Paint(wxPaintEvent& event)
{
}

void MainFrame::OnButton1Click(wxCommandEvent& event)
{
}

seb_seb0

#1
Well, your topic will be locked because it is a wxWidgets question, and not a CodeBlocks question

Your problem comes certainly from the panel paint handler
void MainFrame::OnPanel1Paint(wxPaintEvent& event)

and from the event connector:
Panel1->Connect(ID_PANEL1,wxEVT_PAINT,(wxObjectEventFunction)&MainFrame::OnPanel1Paint,0,this);

There are 2 mistakes in these 2 lines:
 1 - the wxEVT_PAINT handling is not needed - wxPanel manages it internally
 2 - you are doing nothing in the event handler (empty function). On windows (I assume you are on Windows, seeing your screenshots), you MUST create a wxPaintDC object in the paint handler, even if you do not use it. Otherwise, Windows will keep asking to update the panel, making an infinite loop. I bet that when you run your program, your CPU usage is near 100%
       this infinite loop prevents the child window from the panel being repainted - hence you have 4 nice black rectangles on your window.

Everything is in the wxWidgets doc. You should read them.

Regards,

Sebastien

oBFusCATed

seb_seb0, by reading your explanation, I conclude that this is a wxSmith bug.

It should generate wxPaintDC dc(this); in the on_paint handler, so the user knows that this object is needed.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

seb_seb0

Quote from: oBFusCATed on May 01, 2010, 01:30:51 PM
seb_seb0, by reading your explanation, I conclude that this is a wxSmith bug.

It should generate wxPaintDC dc(this); in the on_paint handler, so the user knows that this object is needed.

This is needed only on Windows platform, as far as I know.
Perhaps it can be added, but we should be cautious: there can be scenarios where creating a wxPaintDC is not desired.
I think it is better to let the wxSmith user decide.

Here is the related part of wxWidgets doc (2.9.0 version, but applies to 2.8.xx as well - in the wxPaintDC entry)
QuoteA wxPaintDC must be constructed if an application wishes to paint on the client area of a window from within an EVT_PAINT() event handler.
This should normally be constructed as a temporary stack object; don't store a wxPaintDC object. If you have an EVT_PAINT() handler, you must create a wxPaintDC object within it even if you don't actually use it.

So perhaps you are right. I prefer to let the programmer decide.

Sebastien

Jenna

Quote from: seb_seb0 on May 01, 2010, 03:06:42 PM
So perhaps you are right. I prefer to let the programmer decide.

If someone wants to use wxwidgets as toolkit, he/she should read the documentation, even if he/she uses a gui-designer like wxsmith.

By the way, I just looked into the wxwidgets code: changing the behaviour of wxwidgets in this case is not so easy.
See: wxsEventsEditor::CreateNewFunction (wxseventseditor.cpp:395).

Englishuk

Quote from: seb_seb0 on May 01, 2010, 11:16:42 AM
Well, your topic will be locked because it is a wxWidgets question, and not a CodeBlocks question

Your problem comes certainly from the panel paint handler
void MainFrame::OnPanel1Paint(wxPaintEvent& event)

and from the event connector:
Panel1->Connect(ID_PANEL1,wxEVT_PAINT,(wxObjectEventFunction)&MainFrame::OnPanel1Paint,0,this);

There are 2 mistakes in these 2 lines:
 1 - the wxEVT_PAINT handling is not needed - wxPanel manages it internally
 2 - you are doing nothing in the event handler (empty function). On windows (I assume you are on Windows, seeing your screenshots), you MUST create a wxPaintDC object in the paint handler, even if you do not use it. Otherwise, Windows will keep asking to update the panel, making an infinite loop. I bet that when you run your program, your CPU usage is near 100%
       this infinite loop prevents the child window from the panel being repainted - hence you have 4 nice black rectangles on your window.

Everything is in the wxWidgets doc. You should read them.

Regards,

Sebastien

You Sir are a star!

I installed code::blocks on Ubuntu, got a helloworld app going with wxsmith. Setup code::blocks for cross compile for win32 using mingw32 (which I must say is not easy to do for a newbie).

Compiled my program for win32, and was seeing 100% cpu usage using wine and also on native Windows.

For anyone else who is using the wxsmith helloworld tutorial, I commented out the following line:

//Panel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&HelloApp2Frame::OnPanel1Paint,0,this);

Located in Main.cpp

Further down, I commented out the following block of code:

//void HelloApp2Frame::OnPanel1Paint(wxPaintEvent& event)
//{
//   wxPaintDC dc(this);
//}

Many thanks to the original poster for asking the question and for Sebastien who correctly identified how this issue presents itsself in Windows.

The only issue now is every time I change by frame/panel, the first line above is uncommented and I have to re-comment it before compiling.

Why am I posting? Just in case it helps someone else resolve the same issue...........