Hi friends,

Here is an example of displaying embedded bitmap files in the main executable. Instead of using resources, you can display directly bitmaps from memory. This method allows to use encrypted images and to load bitmaps from files.

Thanks f0dder for his bin2o tool.
Posted on 2004-07-03 06:01:29 by Vortex
Nice :)

You could also use the OleLoadPicture stuff, which will enable you to load both bmp, gif and jpeg. There's some code in the MASM32 library to do this, just beware that it's a bit bugged (the CreateStreamOnHGlobal has the "fDeleteOnRelease" parameter set to true BUT the code does a manual memory free too... this is bad, causes crashes on NT4, and perhaps problems on other windows versions as well.)
Posted on 2004-07-03 11:59:51 by f0dder
Hi f0dder,

Thanks for your reply :alright:

Yes, I know those image handling functions coming with masm32 package. Is there a way to fix that bug?
Posted on 2004-07-03 12:23:41 by Vortex
It's pretty easy - it's all in bitmapfrommemory.asm or whatever, there's a memory free routine near the end (CoTaskMemFree, I believe), freeing the same pointer that was passed to CreateStreaOnHGlobal - remove that line :).

I would advise you to create your own function(s) based on ernie's from the m32lib... like, only initialize/deinitialize COM at your app start/end, rather than doing it all the time in the routines. If you want to be pedantic, you should also use GlobalAlloc for the memory allocation, since PlatformSDK says you should (but that _is_ pedantic and it _probably_ won't break on any windows version... I just like to play by the rules when there aren't any disadvantages from doing so.)

But it's pretty cute, you can have bmp/gif/jpeg support with _very_ little code. I guess I should roll out some vmware images of oooold windows versions and see what the compatibility is like, but it should be pretty good.

If you want some sample code or some I guess I might have time to whip up something tomorrow :)
Posted on 2004-07-03 13:23:18 by f0dder
Hi f0dder,

You wrote:

>If you want some sample code or some I guess I might have time to whip up something tomorrow

Thanks :) Could you post some sample code?
Posted on 2004-07-04 04:17:08 by Vortex
Sorry, my friend stayed longer than I thought he would, so I only had time to do this _very_ unfinished code snippet. There's a whole bunch of comments, though :). I included a C version as well, as that one is mostly finished (except for not doing himetric<>pixel conversion).

I'll probably be pretty busy this week, so I suggest you have a look at Ernie's BitmapFrom* in the masm32 lib. I will probably have enough time to to help with specific questions and have a look at code you write.

Hope to help
Posted on 2004-07-05 05:12:22 by f0dder
Thanks f0dder, I will check your example code.
Posted on 2004-07-05 12:17:38 by Vortex
Here is another way to display bitmaps from memory :

CreateBmpFromMem PROC hWind:DWORD,pBmp:DWORD
LOCAL hDC : DWORD
invoke GetDC,hWind
mov hDC,eax
mov edx,pBmp
mov ecx,edx
add ecx,sizeof(BITMAPFILEHEADER) ; start of BITMAPINFOHEADER header
mov eax,DWORD PTR
add edx,eax  ; BITMAPFILEHEADER -> bfOffBits
invoke CreateDIBitmap,hDC,ecx,CBM_INIT,edx,ecx,DIB_RGB_COLORS
ret
CreateBmpFromMem ENDP



.IF uMsg==WM_CREATE
      invoke CreateBmpFromMem,hWnd,ADDR pBitmap
      mov hBitmap,eax

Attachments:
Posted on 2005-10-02 09:05:11 by Vortex