Solved

Win32 API: CreateIcon()

Posted on 1998-09-21
16
586 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
[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
  • 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
Technology Partners: 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!

 

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
 

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

Independent Software Vendors: 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 is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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.
Suggested Courses

752 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