Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ExtTextOut to a Bitmap on Widows NT

Posted on 1997-02-20
9
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…

722 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