The information for BM_SETIMAGE says:

wParam = (WPARAM) fImageType;      // image-type flag
lParam = (LPARAM) (HANDLE) hImage;  // handle to the image

My question is whether the hImage parameter can be the handle returned from CreateBitmap.

I am trying to put an image on a button by reading a bitmap into memory, doing a CreateBitmap on it, and doing a BM_SETIMAGE.

For some reason it does not work.

Any help please.
Posted on 2005-11-24 19:10:27 by mikes
Have you specified BS_BITMAP during the button creation?
Posted on 2005-11-24 20:07:15 by ti_mo_n

The actual value being used as STYLE is 50000080h.
Posted on 2005-11-24 20:10:53 by mikes
I replaced the CreateBitMap with:

invoke LoadBitmap,NULL,OBM_CHECK

and it works fine.

So it appears that doing a CreateBitMap on a bitmap in memory is not adequate to do the job. Do I have to create a DC?
Posted on 2005-11-24 20:58:15 by mikes
I also replaced the CreateBitmap with a LoadImage with LR_LOADFROMFILE set. This worked fine.

There must be a way to create a bitmap from memory whose handle can be used with a SendMessage with BM_SETIMAGE.

I know it would be relatively easy to do this using resources, but my application does not allow the use of resources.

I just want to create a working bitmap handle from a bitmap in memory.
Posted on 2005-11-25 00:11:41 by mikes
LoadBitmap and CreateBitmap both return a GDI bitmap handle

You can verify this by calling GetObjectType with these handles.

What are the parameters you used for CreateBitmap?

BTW, instead of CreateBitmap it may be better to call CreateCompatibleBitmap and SetDIBits.
Posted on 2005-11-25 06:04:47 by japheth
Here is the code where !bell is the address of the image of bell.bmp in memory and bell is the handle I am trying to create.

mov edi,!bell
mov eax,
add eax,edi
mov [_ArgSafe0],eax
mov eax, dword
mov ebx, dword
xor ecx,ecx
mov cx, word
xor edx,edx
mov dx, word
invoke CreateBitmap,eax,ebx,ecx,edx,[_ArgSafe0]
mov ,eax
Posted on 2005-11-25 12:26:07 by mikes

CreateBitmap seems to be critical. I have some code which reads a .BMP and it works fine with CreateDIBSection(), but fails with CreateBitmap. CreateBitmap itself doesn't fail, but the following SelectObject fails.

I attached the source of both variants, but you most likely will not be able to assemble it, so Im not sure if it helps.

Posted on 2005-11-25 13:29:19 by japheth

Thank you very much for your help.

invoke GetDC,NULL
mov ebx,!bell+14
mov edi,!bell
invoke CreateDIBSection,eax,ebx,0,_ArgSafe0,0,0
mov ,eax
mov edi,[_ArgSafe0]
mov esi,!bell
mov ecx,
mov edx,
sub ecx,edx
add esi,edx
mov eax,
mov ,eax
inc esi
inc edi
dec ecx
jne lp

This code works. I'm sure it could be done differently, but this is compiler output.
Posted on 2005-11-25 19:41:54 by mikes