Click here to Skip to main content
11,706,728 members (33,618 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ MFC GDI+
Hi all,

I've got a VS2005 MFC program with a GDI+ user-drawn display which runs perfectly under Windows 7. If I run it under XP Mode, each text string has a square box after it, which looks like a missing font character, however it uses Ariel, which is installed. The MFC exe isn't Unicode.

Any ideas if it's a problem with GDI+ under XP or XP Mode, or something else?

Posted 8-Jan-12 23:49pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The first thing to do is examine the string you are trying to display in order to see exactly what the last character is. That should give you a clue as to what is going wrong, possibly a bug in your code.
viaducting at 9-Jan-12 6:09am
The same text strings worked fine with GDI under XP Mode, and they work fine under Windows 7 using GDI+, so I don't think that is the problem. I suspect it's something to do with GDI+ and XP.
Richard MacCutchan at 9-Jan-12 6:16am
You should still look at the actual content and see what this character is and why it is being displayed erroneously. Guessing what might be happening is not the same thing as using the debugger to check the facts.
viaducting at 9-Jan-12 7:48am
I have just checked once again to make sure, and as I said, the text strings sent to the Graphics object are identical (zero-terminated wchar_t strings).
Richard MacCutchan at 9-Jan-12 8:10am
A bit of a mystery then. I've never seen a situation like this and have used GDI+ under XP, Vista and Windows 7.
viaducting at 9-Jan-12 8:35am
Problem solved! Windows 7 ignores the string's zero terminator (or at least, renders it invisibly), but XP renders it as a square box. Reducing the string length passed to the rendering function by one fixed it.
Richard MacCutchan at 9-Jan-12 9:26am
Interesting, I must try this out some time.
JackDingler at 9-Jan-12 11:18am
Right, it's unsafe to assume that char 0 is a non-printable character.
Richard MacCutchan at 9-Jan-12 11:43am
Hmm, I just realised what you said. The string length, if specified, is not supposed to include the terminating null, so it was your code that was in error.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The string length passed to the Graphics::DrawString function shouldn't include the zero terminator.
Richard MacCutchan at 9-Jan-12 11:45am
The same as with any other Windows function that takes a string and its length.
viaducting at 9-Jan-12 12:06pm
mbstowcs_s returns the number of characters that were converted, *including* the null terminator. My mistake was in passing that length to Graphics::DrawString, but as I said before, Windows 7 rendered it correctly.
Richard MacCutchan at 9-Jan-12 12:19pm
Windows 7 rendered it correctly.
Never rely on Microsoft.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 146
1 Sergey Alexandrovich Kryukov 140
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,190
1 Sergey Alexandrovich Kryukov 8,407
2 CPallini 5,189
3 Maciej Los 4,756
4 Mika Wendelius 3,686

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 9 Jan 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100