Problem with class derived from wxScrolledWindow Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
spamiam
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Wed Apr 22, 2009 1:40 am

Problem with class derived from wxScrolledWindow

Post by spamiam » Sun Sep 20, 2009 3:20 pm

I have modified a class derived from wxScrolledWindow. It was a simple modification. I just enabled and used the horizontal scrollbar. Previously only the vertical scrollbar was used.

Anyway, when I instantiate the class, I get a near-crash.

The constructor args to the derived class are the exact same as to a wxScrolledWindow. I can prevent the crash in 2 ways.

Do not call the base class constructor, or do not capture the EVT_PAINT(GraphicsWindow::OnPaint) event. Even if the OnPaint method is empty, the problem occurs. If I call the base class constructor with just the minimum args, and let the rest be defaults, I get the problem.

Here is my prototype for the constructor:

Code: Select all

class GraphicsWindow : public wxScrolledWindow
{
     GraphicsWindow::GraphicsWindow( wxWindow* parent, 
                                        wxWindowID id = wxID_ANY, 
                                        const wxPoint& pos = wxDefaultPosition, 
                                        const wxSize& size = wxDefaultSize, 
                                        long style = 0, 
                                        const wxString& name = "Default Name");
.
.
.
DECLARE_EVENT_TABLE()
};
Here is how I use the constructor:

Code: Select all

GraphicsWindow::GraphicsWindow(wxWindow* parent, 
                                wxWindowID id, const wxPoint& pos, const wxSize& size, 
                                long style, const wxString& name)
                : wxScrolledWindow(parent)
I checked the pointer to parent and it is valid, not null and not wild.

This seems odd, and maybe the error is elsewhere, but why would these changes seemingly prevent the problem?

There were very few changes from the other functional version!

-Tony

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sun Sep 20, 2009 3:57 pm

I think you must create a wxPaintDC in the paint event, even if you do nothing with it; try that first.
"Keyboard not detected. Press F1 to continue"
-- Windows

spamiam
I live to help wx-kind
I live to help wx-kind
Posts: 180
Joined: Wed Apr 22, 2009 1:40 am

Post by spamiam » Sun Sep 20, 2009 8:54 pm

Auria wrote:I think you must create a wxPaintDC in the paint event, even if you do nothing with it; try that first.
Auria,

THANK YOU That was the answer. I coded for the DC after I did a check for valid material to draw. I just moved the wxPaintDC creation to the very first thing and BINGO! it worked.

Then I had a problem because I store certain display configuration settings in the registry and they were mucked up. I deleted that material from the registry and I could see stuff again!

I still need to get the new horizontal scrollbar working properly, but it is trying to work.

I am back to work. Thanks again!

-Tony

Post Reply