Solved

ExtTextOut to a Bitmap on Widows NT

Posted on 1997-02-20
9
392 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
ID: 1298506
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
ID: 1298507
Edited text of question
0
 

Author Comment

by:schoch
ID: 1298508
Adjusted points to 100
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:schoch
ID: 1298509
Adjusted points to 150
0
 

Author Comment

by:schoch
ID: 1298510
Adjusted points to 200
0
 
LVL 1

Expert Comment

by:mbecker011597
ID: 1298511
Are you sure you are using a palette based
screen mode?
0
 

Author Comment

by:schoch
ID: 1298512
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
ID: 1298513
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
ID: 1298514
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query performance - SQL Server 20 84
Strange - Deleted Resource Info appears in Azure Portal 6 92
Authentication of Web Services 3 89
Problem to open text file 11 131
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…

821 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