# Win32 Rotating Icons ?

## Recommended Posts

Hello, I was wondering if it is possible to rotate icon images (somewhat easily :) ) e.g. I display an arrow icon next to the cursor when dragging something. I would like this arrow to be able to point in any direction (e.g. always have it pointing to a certain point on the screen). To be sure, im not talking animated cursors/icons or something, but the ability to actually rotate an HICON. thanx

##### Share on other sites
I'm pretty sure you can't rotate a HICON but you may be able to use an animated cursor and select which frame to display based on the direction you want

##### Share on other sites
Technically, you can rotate an icon arbitrarily if you are willing to do it on the raw bits of the image. However, that's not exactly "simple" [smile]

You'll want to start by using LockResource to obtain a pointer to the IconImage structure for your icon. Unfortunately, that structure is not provided by the Windows SDK, so you need to declare it yourself:

#pragma pack(push)#pragma pack(2)struct IconImage{	BITMAPINFOHEADER Header;	RGBQUAD Colors[1];	BYTE XOR[1];	BYTE AND[1];};#pragma pack(pop)

Note that Colors, XOR, and AND provide pointers to the corresponding DIB data, which can then be modified by the standard Win32 API functions for working with DIBs. (If you're not familiar with DIBs, this page should get you started.)

You will have to code the image rotation yourself, but that's pretty easy. I'm sure you can find code for it floating around someplace [smile]

My suggestion would be to start with the icon pointing one direction, then generate the icons for the remaining directions programmatically. You can do this when the program first loads and then just save off the various icons you generated. You should be able to get away with a fairly small number of variations, maybe 16 or so.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627731
• Total Posts
2978831

• 10
• 9
• 21
• 14
• 12