Click here to Skip to main content
Rate this: bad
good
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?
 
TIA.
Posted 9-Jan-12 0:49am
viaducting91.5K
Rate this: bad
good
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.
  Permalink  
Comments
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
good
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.
  Permalink  
Comments
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 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 9 Jan 2012
Copyright © CodeProject, 1999-2014
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