Solved

ExtTextOut to a Bitmap on Widows NT

Posted on 1997-02-20
9
385 Views
Last Modified: 2013-12-03
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
Comment
Question by:schoch
9 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
SetTextColor(hDC, PALETTEINDEX(1)); /* Usually yellow, but all colors fail */
You selected the palette into the DC, but didn't realized it (RealizePalette()).
0
 

Author Comment

by:schoch
Comment Utility
Edited text of question
0
 

Author Comment

by:schoch
Comment Utility
Adjusted points to 100
0
 

Author Comment

by:schoch
Comment Utility
Adjusted points to 150
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:schoch
Comment Utility
Adjusted points to 200
0
 
LVL 1

Expert Comment

by:mbecker011597
Comment Utility
Are you sure you are using a palette based
screen mode?
0
 

Author Comment

by:schoch
Comment Utility
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
 

Author Comment

by:schoch
Comment Utility
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
 
LVL 1

Accepted Solution

by:
dominic01 earned 250 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now