Link to home
Start Free TrialLog in
Avatar of shvetsov
shvetsov

asked on

Win32 API: CreateIcon()

This function has two parameters, that I can't understand - number of planes and number of bits per pixel. I managed to create b/w icon setting that parameters to 1. But if I want to create 16-color icon, should I set number of planes to 4 and bits per pixel to 1 ? And how should I fill XOR buffer in that case ? I tried to duplicate 4 times b/w buffer, but failed - the resulting icon didn't look good.
Avatar of Answers2000
Answers2000

Most video drivers:
Planes to 1
Bits per pixel to 4

The AND mask should be monochrome
I think that you have to use 1 plane, 4 bits per pixel.
The AND mask should be 0xF outside the icon image, and 0x0 inside the image.
The XOR mask should be 0x0 outside the image, and the icon colors inside.

Incidentally
Colors = 2 ^ ( Planes * Bits_Per_Pixel )

Therefore 4 Bits per pixel and 1 plane is 16 colors.  


I am not very sure, but let me tell you what I found from the help.
Here is the definition of the function:
HICON CreateIcon(
HINSTANCE hInstance, // handle to application instance
int nWidth,  // icon width
int nHeight,  // icon height
BYTE cPlanes,  // number of planes in XOR bitmask
BYTE cBitsPixel, // number of bits per pixel in XOR bitmask
CONST BYTE *lpbANDbits,  // pointer to AND bitmask array
CONST BYTE *lpbXORbits  // pointer to XOR bitmask array
);
Because lpbXORbits is a pointer to monochrome OR DEVICE DEPENDENT bitmap (AND mask is only monochrome), so cPlanes and cBitsPixel describe this bitmap.
If your XOR mask is only monochrome bitmap - use cPanes = 1 and cBitsPixel = 1. If not - use the method of Answers2000
Example: For 16 colors - 1 plane and 4 bits per pixel. And you have to supply (32*4 * 32*4) bits = 256 BYTES XOR mask for 32x32 Icon.

You can find example of using CreateIcon in MSVC help.
And one last from the help:
"...To determine the width and height supported by the display driver, use the GetSystemMetrics function, specifying the SM_CXICON or SM_CYICON value."
And by my opinion, LoadIcon is better way of creating Icons.
JRFM
By the way, maybe you have to use GetDeviceCaps for finding the plains and the bits per pixel for your videocard....
Avatar of shvetsov

ASKER

Thank you for your comments. Who will get the points ?
To iliya: try to LoadIcon(), put in in the taskbar notification area and then change window title height (from display properties). The height of taskbar will change and your icon will be deformed.
Yes, I agree with you and I know about this global problem :-).
And it is not only with the Icons.
Maybe the best will be if you generate the icon on-the-fly by some mathematical way - by drawing circles, fractals, ...
This is a lot of code and a lot of time, but may be not lost for you.
The problem is that the software firms put in the Icons almost only some fixed pictures, logos, etc.

P.S. Give me 1 point. It is enough for me :-)


I can't give points for commenters - Experts-exchange system will give you points only for answer.
I've already realized dynamic icon resizing, but only for monochrome icon. Now I can make the "technicolor"
What is this "technicolor"?
And how you perform the resizing?

I can't give points for commenters - Experts-exchange system will give you points only for answer.
I've already realized dynamic icon resizing, but only for monochrome icon. Now I can make the "technicolor"
Sorry for duplicate comment.
"Technicolor" - it's joke. I mean color icons.
And "resize" is not correct termin. I leave central part of icon unchanged and resize only black square, so I have to perform some bitwise shift operations to place source image on that square.
Why not to create Icons for several sizes? (like the TTF fonts, which have diverent shape for diferent size)
This will make your program bigger, but with more percision.
And it is not nessasary to create Icons for 1, 2, 3 ... 100, 101, ... sizes - just for some of the them whith some step.
And to load the closest.

P.S. I know that this idea is a sort of stupid, but there are some cases in which it can be better.

Yes, it's a good idea.
Who will win the points?
First who mark his message for me as "answer", not "comment". Only in that case I can give points.
ASKER CERTIFIED SOLUTION
Avatar of iliya
iliya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial