[wxDC::GetTextExtent()] Generates different values after
wxMemoryDC::SelectObject()
Vadim Zeitlin
vadim at wxwidgets.org
Tue Sep 4 01:24:13 PDT 2007
On Mon, 3 Sep 2007 13:13:24 +0100 Mario Figueiredo <marfig at gmail.com> wrote:
MF> Hello everyone,
MF>
MF> This is a short code snippet that, while not related to my own code,
MF> better displays the problem and its easier to copy/paste:
MF>
MF> wxMemoryDC dc;
MF>
MF> wxString str("Mountains");
MF> wxCoord w, h;
MF>
MF> wxLogDebug(wxT("Before SelectObject():"), NULL);
You can't use wxMemoryDC before selecting a bitmap into it. All method
calls should fail.
MF> I do need to calculate GetTextExtent() before building the bitmap for
MF> the wxMemoryDC because it will be part of the calculation needed to
MF> determine that bitmap size. Later I need that value again (which I
MF> expect to be the same) to actually draw the text on the DC.
You can select a temporary 1*1 bitmap initially, it should be enough for
the calculations to work correctly. You can also use wxClientDC of some
window -- if you use the same fonts, the results should be the same.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
More information about the wx-users
mailing list