Solved

Win32 API: CreateIcon()

Posted on 1998-09-21
16
543 Views
Last Modified: 2008-01-16
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.
0
Comment
Question by:shvetsov
  • 7
  • 6
  • 2
  • +1
16 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252925
Most video drivers:
Planes to 1
Bits per pixel to 4

The AND mask should be monochrome
0
 
LVL 1

Expert Comment

by:Bonev
ID: 1252926
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.

0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252927
Incidentally
Colors = 2 ^ ( Planes * Bits_Per_Pixel )

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


0
 

Expert Comment

by:iliya
ID: 1252928
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
0
 

Expert Comment

by:iliya
ID: 1252929
By the way, maybe you have to use GetDeviceCaps for finding the plains and the bits per pixel for your videocard....
0
 

Author Comment

by:shvetsov
ID: 1252930
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.
0
 

Expert Comment

by:iliya
ID: 1252931
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 :-)


0
 

Author Comment

by:shvetsov
ID: 1252932
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"
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:iliya
ID: 1252933
What is this "technicolor"?
And how you perform the resizing?

0
 

Author Comment

by:shvetsov
ID: 1252934
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"
0
 

Author Comment

by:shvetsov
ID: 1252935
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.
0
 

Expert Comment

by:iliya
ID: 1252936
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.

0
 

Author Comment

by:shvetsov
ID: 1252937
Yes, it's a good idea.
0
 

Expert Comment

by:iliya
ID: 1252938
Who will win the points?
0
 

Author Comment

by:shvetsov
ID: 1252939
First who mark his message for me as "answer", not "comment". Only in that case I can give points.
0
 

Accepted Solution

by:
iliya earned 100 total points
ID: 1252940
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."
You have to use GetDeviceCaps for finding the available plains and bits per pixel for the videocard.
JRFM

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now