wxClientDC

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
KaReL
Experienced Solver
Experienced Solver
Posts: 78
Joined: Mon Aug 30, 2004 8:52 am
Contact:

wxClientDC

Post by KaReL »

I have my own control (derived from wxControl).
(a menubar for a panel).

On this, I add a few wxString's. I calculate the total width/height of the control.

Now I got the following functions overridden:
- DoGetSize
- DoGetClientSize ( used by DC.GetSize() )
- DoGetBestSize ( used by sizer-calculations )

But now when I want to erase the background, I do like this:

Code: Select all

void MenuBar_Control::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) 
{ 
wxClientDC clientDC(this); 
clientDC.BeginDrawing(); 

   clientDC.SetBrush( wxBrush(wxColour(0xff,0,0)) ); 
   clientDC.DrawRectangle( 0,0, clientDC.GetSize().GetWidth(), clientDC.GetSize().GetHeight() ); 

clientDC.EndDrawing(); 
}
This draws a background of 20x20 pixels. Although clientDC.GetSize() returns a wxSize(199, 52).

What am I missing here?

Thanks for any help.
Last edited by KaReL on Mon May 09, 2005 8:14 am, edited 2 times in total.
wxWidgets: SVN/trunk
OS: WinXP/2 + Ubuntu + Mac 10.4.11
Compiler: VS2005 + GCC 4.2 + GCC 4.0.1
-----
home: http://www.salvania.be
Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor »

First, when you erase a background, you must not create a wxClient/PaintDC, you must use one provided by the wxEraseEvent param [1].

Secondly, if you want to erase the entire content of the client surface, wxDC::Clear is usefull [2].

[1] : http://www.wxwidgets.org/manuals/2.6.0/ ... eraseevent
[2] : http://www.wxwidgets.org/manuals/2.6.0/ ... #wxdcclear
What is little and green, witch go up and down ??
Yoda playing with the force.
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

Karel, please do not xpost, wait a couple of days if your post does not get answered on the wx-users list .. the weekends is usually low activity on either forum or board ;-)

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
KaReL
Experienced Solver
Experienced Solver
Posts: 78
Joined: Mon Aug 30, 2004 8:52 am
Contact:

Post by KaReL »

Jorg: :oops:

Cursor: This has the same reaction. The DC associated with the wxEraseEvent parameter is wxScreenDC (I mean, it has the same dimensions as my screen).
Cursor: Also this I know, but also this has no result... The painted area stays 20x20...

It seems like somewhere the clippingregion is set to 20x20, but the wxDC attached to the wxEraseEvent-param is 1280x1024 (and nowhere, there is a clipping region set, I followed every trace of it)... So I would suspect it to draw my complete screen, but it is not drawing on there. Only on a 20x20 restricted area.

I remember reading something about this 20x20 area, but I don't remember exactly where...
wxWidgets: SVN/trunk
OS: WinXP/2 + Ubuntu + Mac 10.4.11
Compiler: VS2005 + GCC 4.2 + GCC 4.0.1
-----
home: http://www.salvania.be
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

At least it does me well to see that the forum has a very high succesrate in helping people.. that is one thing I disliked about the mailinglist. A lot of questions stay unanswered. I think the reason for that is when people are gone from their pc for a couple of days, the articles keep flowing in and get 'snowed under' when they are coming back.

- Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Post Reply