Hi I need to write a code which takes a picture from it's resource and then loads it only into the memory and show it in the default viewer installed in windows.
Does anybody know how to do this (I would appreciated a piece of code);
Posted on 2001-09-07 04:50:06 by RAGuru
Afternoon, RAGuru.

What do you mean - "... the default viewer installed in windows."?:confused:

Are you talking about Windows Explorer (which displays piccys automatically), or your own app?

Posted on 2001-09-07 04:55:16 by Scronty
Hi Scronty
I mean some app like ACDSee which is runned after clicking on an image in Explorer.
Posted on 2001-09-07 06:06:12 by RAGuru
I dont know the registry at all... (afraid of screwing up).. but I believe all this is stored in registry keys. So if you look up the right key you should get this file pointer...

Posted on 2001-09-07 09:38:27 by NaN
You don't understand me.
I mean that my code runs and takes one picture from it's EXE where it has been stored. and load it to memory that is the most important.
Posted on 2001-09-07 10:03:27 by RAGuru
The simplest method is to use the LoadBitmap API function. By passing the resource id to it, it will then return a handle to a bitmap.

Then if you create a memory DC using CreateCompatibleDC you can select the bitmap into this with SelectObject. Then you can proform GDI opertaions on the DC and when your finished you can BitBlt to your window for viewing.

If you need to be able to acces the bitmap bits then there are two ways. You can use FindResource, LoadResource and LocKResource together to get a pointer to the binary bitmap data.

The first thing here will be a BITMAPFILEHEADER, you can use the bfOffbits member to get a pointer to the bitmap bits. egmov edx,.BITMAPFILEHEADER.bfOffBits
add edx,eax
This takes the pointer to the binary data (assumes its eax, you could change this) and sets edx as a pointer to the bits.

Theres also other useful info here such as image width, height, bit depth. You'll have to search the various structres for it.

A simpler (relativly) method to access the bits and also this can proform bit depth conversion for you is to create a memory DC and create a DIB section for it through CreateDIBSection. Then use the first method I explained to load the bitmap and Blt it into the DC with the DIB section. While you create the DIB section you'll get a pointer to the bits.

If you need a better explanation just ask. :alright:
Posted on 2001-09-07 12:28:54 by Eóin
Thanks for now!
I need to work with it a little.
I will ask more I ams sure.:)
Posted on 2001-09-07 12:57:59 by RAGuru
i'm not sure if i understood your question well, but you want to load a bitmap from another exe file and then display it in the standard viewer in windows, right?

hmm, the only possibility for this could be, that you save the bitmap in a seperate file from memory, and then get the program path of the standard viewer, and call it with one parameter: the path of the bitmap.

Posted on 2001-09-08 03:52:48 by NOP-erator
I don need to load picture from my EXE where it is stored in resource I thing with help of Zadkiel I have done It succesfully
Here Is my code

hInstance dd 0

hBmp dd ?
HDConte dd ?


invoke LoadBitmap,hInstance,150
mov hBmp, eax
invoke CreateCompatibleDC,NULL
mov HDConte,eax
invoke CreateCompatibleBitmap,HDConte,300,200
invoke SelectObject,HDConte,eax

But now I need to show that picture in default viewer.
How to do that?
I don't have a path to that file so how to show it?

{Thank you Zadkiel i hope I coded it right}:alright:
Posted on 2001-09-08 04:25:05 by RAGuru
ShellExecute can run an executable, but also documents, which will be opened with default registered application (like a double click on the file name). The only problem is that I think it requires a file, so you will have to use a temporary one (it is not such 'elegant' but it should work :)).
Posted on 2001-09-08 06:13:29 by LuHa
I think you won't need the CretaeCompatibleBitmap call. Rather just select the hBmp into HDConte.

Probably the easiest thing to do next is to save the DC as a bitmap. Theres an program demonstrating this which comes with Masm32 called ShowDIB. Its in one of the example folders.

I assume as LuHu says you can then use ShellExecute to load this bmp in the default viewer. It might not sound elegant but its probably the only way.

Edit: Hmm, actually ShowBID won't help, it doesn't save DCs. In fact its very hard to find info on how to save a DC.
Posted on 2001-09-08 06:46:40 by Eóin
Ok I will do that.
it is not what i exactly wanted before but what should I do!:)

Thank you.
Posted on 2001-09-08 06:52:28 by RAGuru
I still do need help I tried to work with ShowDIB example but it still won't work for me!

How can I save a bitmat from Device Context to file on the disk?

It must be matter of 3 lines i think !!!
I am bit stupid.:rolleyes:
Posted on 2001-09-08 07:23:27 by RAGuru
You know, its only when you fully understand a problem do you see the easy solution. Theres no need for your program to load the bmp into memory, just transfer the resource to a file.

eg in your resourse declare the bmp as:
1 BIT "Test.bmp"

the following will do what you want.
include \masm32\include\shell32.inc
includelib \masm32\lib\shell32.lib

tRsc db "BIT",0
tFile db "tmp.bmp",0
tOpen db "open",0

hRsc dd ?
pRsc dd ?
hFle dd ?
tDD dd ?

invoke FindResource,hInstance,1,addr tRsc
invoke LoadResource,hInstance,eax
mov hRsc,eax
invoke LockResource,eax
mov pRsc,eax

invoke CreateFile,addr tFile,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
mov hFle,eax

invoke WriteFile,hFle,pRsc,edi,addr tDD,0

invoke CloseHandle,hFle
invoke FreeResource,hRsc

invoke ShellExecute,hWnd,addr tOpen,addr tFile,0,0,SW_SHOWNA
Posted on 2001-09-08 07:52:10 by Eóin
Thank you very much It seams like explanation for the stupid one, and that's exactly what i needed. :tongue:
Posted on 2001-09-08 14:56:59 by RAGuru
Now it works.but I have one more question.
Is it possible to ad to resource and save on disk a different file ?
let's say *.JPG ?

How should then this routine looks like?
Posted on 2001-09-09 05:19:15 by RAGuru
The source code should be almost the same, the only difference is that you can't use bfSize field of bitmap file header, you have to use:
dwSize = SizeofResource(hInstance, hRes);
and use this value when you call WriteFile.
Posted on 2001-09-09 06:10:15 by LuHa
Ok !
I will do that!
Posted on 2001-09-09 06:21:49 by RAGuru
Hi LuHa

I am sure you have forgotten to tell something to me.:)

I made changes as you recommanded and now it won't work even with the BMP files.
Here is that code >

invoke FindResource,hInstance,1,addr tRsc
invoke LoadResource,hInstance,eax
mov hRsc,eax
invoke LockResource,eax
mov pRsc,eax

invoke SizeofResource,hInstance, hRsc
mov edi,eax
; mov dwSize,edi

invoke CreateFile,addr tFile,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
mov hFle,eax

invoke WriteFile,hFle,pRsc,edi,addr tDD,0

invoke CloseHandle,hFle
invoke FreeResource,hRsc

invoke ShellExecute,0,addr tOpen,addr tFile,0,0,SW_SHOWNA

Tehe must be some problem my machine crashed 3 times when I tried to delete created BMP.
Thank you .
Posted on 2001-09-09 13:22:53 by RAGuru
Sorry, I gave you a wrong information :(. You have to use SizeofResource to retrieve resource size, but second parameter is not the HGLOBAL returnet by LoadResoure, but the HRSRC returned by FindResource. Sorry again.
Posted on 2001-09-09 14:10:23 by LuHa