Printing Gray Lines with MFC/VS6 - visual-studio

Does anybody know the "magic trick" for printing gray lines in an MFC/VS6 based application, using the PS_SOLID style?
It works when printing to PDF, but I just get black lines when printing to my black/white laser printer. It also works with the PS_INSIDEFRAME style, but it seems strange to me that a normal PS_SOLID can't do gray
Here's how the CPen is setup:
CPen linePen(PS_SOLID, 50, RGB(128,128,128));
I am using the MoveTo/LineTo functions for drawing.
Thanks!
Fabian

Are you sure the printer context is set correctly, i.e. that you don't have a bit depth of 1?

Related

Windows button ignores alpha channel for fully transparent image

I have a radio button that should display an image (style BS_AUTORADIOBUTTON|BS_PUSHLIKE|BS_BITMAP).
I create a bitmap via CreateDIBSection (using a BITMAPINFO with BI_RGB) and obtain a pointer to the raw pixels via the ppvBits, so that I can manipulate them freely.
I use BM_SETIMAGE to set the button's image to the bitmap I created.
So far, I can set the RGB and alpha by manipulating the pixels by hand. I tested that even semi-transparent (non-premultiplied) alpha values look good.
As far as I can tell, everything works, except if all pixels in the image are transparent. In that case, the button apparently ignores the alpha value, simply displaying a rectangle with each pixel having the respective color with full opacity.
I found a hint that Windows - at least in some cases - actually seems to interpret images whose pixels' alpha values are all 0 as completely opaque images:
When the window manager sees a 32bpp bitmap, it looks at the alpha
channel. If it's all zeroes, then it assumes that the image is in 0RGB
format; otherwise it assumes it is in ARGB format
Is this behavior documented somewhere?
Is this behaviour documented somewhere?
Yes! In Raymond's post! :) That's often the way of it, no?
If you look at the foot of the page here you will find a comments box. If you raise your concerns there then MS will most likely fix their documentation. See here for an example of the process they usually follow if they consider the problem serious enough to fix.

Write in a transparent colour in expression blend (WP7)

I am trying to build a windows phone live tile. I want some text on the tile that is the accent colour. What this means is that I need to draw some text on the tile that is transparent. I don't seem to be able to write in the transparent colour.
I have a User Control which is 173 by 173 pixels which I save as a png file. I use this png as the image for the live tile. The transparent bits of the image come out in the current accent colour.
Any ideas how to write in the transparent colour in xaml?
This behaviour is to be expected. In your original question you are effectively saying "Write invisible text on top of the image", and that's what you're getting (imagine writing in invisible ink on a photograph). You effectively need to do one of two things.
1) Figure out which pixels are part of the text you're writing, and "remove" them from the image so the background colour shows through, or
2) Write text in the background colour ({StaticResource PhoneAccentBrush})
EDIT
You can probably achieve what you need using an Opacity Mask. Apologies for only providing that as a link as I haven't done this myself.

font size bug with CGContextShowTextAtPoint

I have some rather simple code drawing some text into a CGContext. Here is an excerpt (slightly edited).
CGContextSelectFont(context, "Helvetica", 1.5, kCGEncodingMacRoman);
CGContextShowTextAtPoint(context, xpos, ypos, "Hello", 5);
The text renders ok. For some unknown reason, however, the font changes to a smaller size after I click in the view containing the context. Also when I resize the window containing the view the font returns to original size. What is the reason for this?
1.5 points is mighty tiny to begin with. Assuming no other scaling is in effect, that will be one whole pixel and a blurry pixel above it on the screen.
You're probably seeing a bug that I ran into myself: On entry into drawRect:, the current context's text matrix was not the identity matrix. In my case, I saw it contain a scale by 13 on both axes, plus a translation. (Possibly left over from drawing the title bar.) I filed this in Radar as #10585106, in case you want to file your own and cite it.
The solution is to set the text matrix back to the identity transform before trying to draw text.
Once you do that, you'll find that your text will be exactly as tiny as you asked for it to be. You should change your font size to something more reasonable; Core Text contains a function to get the system fonts (from which you can get their sizes), and AppKit's NSFont class contains methods for the same purpose.

Get theme properties of Group Box lines

My goal is to draw a Group Box that is not rectangular but instead has the corners cut away. I do not mean just clipping the corners, but rather have a continuous closed path where the corners are "indented." I want this to match the colors/style of the current theme.
I noticed on Windows XP that the Group Box has 1-pixel gray lines, but on Windows 7 there is a 3D effect created by having a gray line next to a white line (the white line on the interior except on the bottom where it's below the gray line).
You can get the color of the text label of a Group Box using something like this:
COLORREF cref;
GetThemeColor(hTheme, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref);
So, I'm trying to figure out how to get the color(s) and/or properties of the lines used in a Group Box, then (I hope to) be able to draw the lines I want matching the Group Box style by separately drawing each piece of the shape I want. I'm not sure what properties are used to describe the lines or if functions line DrawRect will draw the 3D effect with a suitable Pen. Is there a way to set a Pen to draw these 3D effects (2-shade parallel lines)?
Thanks.
The thing I always find unexpected about groupboxes is that they are really a style of buttons. (BS_GROUPBOX).
Themed groupboxes (XP and later with classic mode off) use theme part BP_GROUPBOX in VSCLASS_BUTTON. You can use the usual theme APIs to get and draw. If your Group box needs text you can use DrawThemeText.
There are APIs for drawing non-themed group boxes too (e.g. DrawEdge), but I don't remember the details and it's unlikely that you need them.
As usual, I will point out that reproducing the behaviour of controls is always harder than you think it is going to be.
Martyn

Cocoa Different text color in the same letter

What i need is a bit difficult to explain. Let's try...
I need to write a text in my app, and that text will gradually change color from left to right.
I think i could say it's a similar effect to what you see in a karaoke screen.
For instance. I draw a text line, in blue color, and gradually, using a timer, the color from left to right changes to red. But i don't want it to change letter by letter, but gradually. That would require that at some moment, the same letter can have a part in red and a part in blue.
I've been reading about core drawing, and maybe it's the solution, but i really don't know how to start. I was thinking about using a background layer and in top of it draw a transparent text (only with border), but i am not very sure how to do it.
any ideas would be appreciated.
You can probably do the job with a CGLayer.
Best of all you should be able to use your existing code to draw the characters (or anything else) in to the CGLayer.
Here's some rough code:
// first, make a CGLayer...
CGLayerRef yourDrawingPad =
CGLayerCreateWithContext(UIGraphicsGetCurrentContext(),etc..
CGContextRef yourRef = CGLayerGetContext(yourDrawingPad);
// now, draw to yourRef .. draw your various typography (or anything)
// use your current drawing code.
// all done drawing, now make an image mask...
UIGraphicsBeginImageContext(CGLayerGetSize(yourDrawingPad));
CGContextRef temp = UIGraphicsGetCurrentContext();
CGContextDrawLayerAtPoint(temp, CGPointZero, yourDrawingPad);
CGImageRef anAlphaMask = CGBitmapContextCreateImage(temp);
UIGraphicsEndImageContext();
You now have a nice mask you can use:
CGContextSaveGState(UIGraphicsGetCurrentContext()) ...
CGContextClipToMask(UIGraphicsGetCurrentContext(), self.frame, anAlphaMask);
So just mask it in to an image of a gradient, or whatever works.
(Conceivably: perhaps you will have to construct a bitmap image offscreen, and then use that as the mask?)
Footnote: Don't forget it is very likely you will have to paint upside down! Fortunately that is simple to deal with. Where it says "now, draw to yourRef" before drawing save your state and add the two lines of code:
CGContextTranslateCTM(refForMask, 0, self.frame.size.height);
CGContextScaleCTM(refForMask, 1.0, -1.0);
Hope it helps
I have an idea of how this could be done, but it is kind of complex. You could create an NSBezierPath and add the glyphs for each character. Then, set that as the clip and draw a NSGradient. Then you would just have to change the offset of the colors in the NSGradient to move the color along.

Resources