Solved

ExtTextOut to a Bitmap on Widows NT

Posted on 1997-02-20
9
398 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
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.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

626 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