Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

ExtTextOut to a Bitmap on Widows NT

I have the following code fragment:
 
hDC = CreateCompatibleDC(NULL);
hBitmap = CreateCompatibleBitmap(hDC);
(void)SelectObject(hDC, hBitmap);
(void)SelectObject(hDC, myFont);
SelectPalette(hDC, myPalette, FALSE);
RealizePalette(hDC);
SetTextColor(hDC, PALETTEINDEX(1));    /* Usually yellow, but all colors fail */
ret = ExtTextOut(hDC, x, y, 0, NULL, chars, nchars, spacing);    /* all valid */
if (ret == 0)
    error = GetLastError();
 
At this point ret is 0 and error is 0.  Why?  Here is some more information:
 
This fails on Windows NT 4.0 with lastest patch.  It works on Windows 95.
TextOut works.  Only ExtTextOut fails.
It works if hDC is a window DC.
 
In summary, the ExtTextOut to a Bitmap fails on Windows NT 4.0.  GetLastError returns 0.
 
Is this a known bug?  Is there a workaround?
0
schoch
Asked:
schoch
1 Solution
 
chensuCommented:
SetTextColor(hDC, PALETTEINDEX(1)); /* Usually yellow, but all colors fail */
You selected the palette into the DC, but didn't realized it (RealizePalette()).
0
 
schochAuthor Commented:
Edited text of question
0
 
schochAuthor Commented:
Adjusted points to 100
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
schochAuthor Commented:
Adjusted points to 150
0
 
schochAuthor Commented:
Adjusted points to 200
0
 
mbecker011597Commented:
Are you sure you are using a palette based
screen mode?
0
 
schochAuthor Commented:
Yes, in this example, the VGA card (an S3 compatible) is set to 256 colors.  If the card is set to more than 256 colors, I use RGB(255,255,0) instead of PALETTEINDEX(1).  The result is the same in both cases.
I was also able to get it to fail on Windows 95 with some display drivers.
0
 
schochAuthor Commented:
If ETO_OPAQUE and a RECT are passed, the background is painted, but the characters are not.
If spacing is NULL, it works (the characters are drawn with the default spacing).  Of course, the reason I'm using ExtTextOut is to get the spacing I want without drawing each character with a separate GDI call.
0
 
dominic01Commented:
It seems to be a bug in NT... However, I have a work around for you. If you get your hBitmap from LoadBitmap() instead of CreateCompatibleBitmap(), that solves the problem.

hBitmap = LoadBitmap([A bitmap of your resource file, for example]);

instead of hBitmap = CreateCompatibleBitmap(hDC); (you miss the x and y here, but i guess you have it in your code).

You can create for example a black bitmap with dimensions x by y in your resource and load that as your hBitmap. I tried it out and it works.

I guess if your create bitmap function does not have a fix x and y, you may want to create a bitmap with the largest x and y possible and blit only the part you need as your result. This takes some space in the .exe but it is better than nothing.

Let me know if that helped!

DOM



0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now