Jump to content
Tuts 4 You

How to write ImageList?


alaphate

Recommended Posts

I use ImageList_Write to save imagelist, but the saved bmp is

not really bitmap format! But I can display the ImageList correctly in my app.

Any buddy could help me? Thanks a lot.

Attachment is my project.

//code////////////////////////////////////////////////////////////////

HDC hdc;

PAINTSTRUCT ps;

static HIMAGELIST hil;

HICON hicon1, hicon2, hicon3;

int i;

IStream * pStream;

case WM_CREATE:

pStream = 0;
hil = ImageList_Create(16, 16, ILC_COLORDDB, 3, 0);
ImageList_SetBkColor(hil, RGB(255,255,255));
hicon1 = LoadIcon(hInst, "MYICON1");
ImageList_AddIcon(hil, hicon1);
hicon2 = LoadIcon(hInst, "MYICON2");
ImageList_AddIcon(hil, hicon2);
hicon3 = LoadIcon(hInst, "MYICON3");
ImageList_AddIcon(hil, hicon3);
SHCreateStreamOnFile("o.bmp", STGM_READWRITE | STGM_CREATE, &pStream);
if(ImageList_Write(hil, pStream)) {
MessageBox(0, "write successfully", "", 0);
}
pStream->Release();

imglist.zip

Edited by alaphate
Link to comment

Gday mate.

Remember that an imagelist is a list, or collection of icons. Icons are themselves a special case of bitmaps.

In order to write the imagelist to ordinary bitmaps, a number of descisions need to be made. Among these:

(1) Will you write individual files or will you stitch them all together and save a single file

(2) Will you preserve the transparency of the image

What you need to do is:

  • extract the icon from the imageList
  • get the icon's info (pointer to colour and mask bitmaps, etc)
  • get the app window's hdc
  • create a hdc compatible with this
  • select the icon's color bitmap into this 2nd hdc
  • Save the hdc to a Bitmap file
  • Perform any necessary clean-up

If you don't create a compatibleDC from the app's DC, the image you get is simply a screen-shot of your desk-top. Though strangely, my #2 screen is on the left of my #1 screen - the weird part is that the screen-shot contains the image of screen 1 on the left of the bitmap, yet contains nothing from screen 2 - oh, and it's a 9MB bitmap too. :geek:

I've been playing with this for the past couple of days, and have some code for you that will save any image in an imagelist to a file on it's own. It doesn't respect the transparency of the initial icon, though it's too late for my little brain right now (3am).

Anyway, here y'are - code's often better than idle chit-chat.

imglist.zip

Link to comment

enhzflep,

Thank you for your great work.

I know there's a way to save the imagelist by drawing imagelist

into a bitmap in memory DC, and saving it.

Another problem is how to use SHCreateStreamOnFile function

to save it. IStream class seems complicated for me.

I'd like to learn how to use it.

Are there any examples or tutorials for it?

I appreciate your help very much.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...