Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

laodimage of resouce/IDB_BITMAP?

onkelhotte
New Contributor II
1,091 Views
Hi there,
in my QuickWin App I load a .bmp and display it with loadimage_w. But I have to use a path/filename and to distribute the .bmp with my program.
Is there a way to display an resource bitmap, something like loadimage_w(IDB_BITMAP1,x,y)? I tried to use GetResourceTypeName, but I couldnt find the apropriate module where it is defined...
Thanks in advance,
Markus
0 Kudos
4 Replies
anthonyrichards
New Contributor III
1,091 Views

Here are some replies to a recent similarquery on COMP.OS.MS-WINDOWS.PROGRAMMER.WIN32 NEWSGROUP about how to add bitmap files as resources to an executable. Although the answers are C++-oriented, the windows API routines are callable from CVF/IVF I believe.There are some useful links in the first reply.Hope they help.

Code:

REPLY#1
> 
> Use the following API's to combine several resource files into
> a single executable object program:
> 
> 	// Include the files...
> 
> 	CreateFile() using GENERIC_READ,
> 			0,
> 			NULL,
> 			OPEN_EXISTING,
> 			FILE_ATTRIBUTE_NORMAL,
> 			NULL);
> 
> 	GetFileSize(hFile, NULL);
> 	ReadFile()
> 	CloseHandle()
> 
> 
> 	// Update the resource data...
> 
> 	BeginUpdateResource()
> 	UpdateResource()
> 	EndUpdateResource()
> 
> 
> 	// Extract the data...
> 
> 	LoadLibraryEx()
> 	FindResource()
> 	LoadResource()
> 	LockResource()
> 	FreeLibrary()
> 
> 
> 	// Save the data into a file...
> 
> 	SizeofResource()
> 	CreateFile() using GENERIC_WRITE,
> 			0,
> 			NULL,
> 			CREATE_ALWAYS,
> 			FILE_ATTRIBUTE_NORMAL,
> 			NULL);
> 	WriteFile()
> 	CloseHandle()
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfilesize.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/readfile.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/beginupdateresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/updateresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/endupdateresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/loadresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/lockresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/freelibrary.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/sizeofresource.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/writefile.asp
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/closehandle.asp
> 
> Hope these information helps,
> 
> Kellie.
> 
REPLY#2
> "Software Design"  wrote:
> >Is there a way to include files with my executable program,
> >that I can extract duri
ng the run-time process ?
> 
> Create a ".rc" file with contents like this:
> 
> 1 RCDATA "data.zip"
> 2 RCDATA "picture.bmp"
> 
> Add the .rc file to your project.
> 
> Then in the .cpp code of your executable, use code like this:
>   HRSRC hrsrc=FindResource(hInstance,MAKEINTRESOURCE(2),RT_RCDATA);
>   DWORD size=SizeofResource(hInstance,hrsrc); 
>   HGLOBAL hglob=LoadResource(hInstance,hrsrc);
>   void *buf=LockResource(hglob);
>   //
>   HANDLE hf = CreateFile("pic.bmp",...);
>   WriteFile(hf,buf,size,...);
>   CloseHandle(hf);
> 



0 Kudos
onkelhotte
New Contributor II
1,091 Views

Im getting closesolving my problem.

In my code I load a bitmap file via loadimage_w to display it in an QuickWin Window. But the
disadvantage is, that I have to deliver the .bmp file with my program. So I included it in the
Resource Editor and try to load it from there. Because QuickWin does only allow to load
images from file, I try to save the Resource Bitmap in a file:

Code:

hBmp=FindResource(GetModuleHandle(NULL),245,RT_BITMAP)
hSize=SizeofResource(NULL,hBmp)
hRes=LoadResource(NULL,hBmp)
hLock=LockResource(hRes)
hFile=CreateFile(tempstring,GENERIC_WRITE,null,null,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,null)
l=WriteFile(hFile,hLock,hSize,loc(byteswritten),null)
l=SetEndOfFile(hFile)
l=CloseHandle(hFile)



That does nearly the trick. A new file was created.
The code of my two bitmaps are identical, but the new file misses the bmp header I think.

Original file begins with:
BM v ( A 8

New file begins with:
( A 8

Or would be another way to copy the resource bitmap into memory and paste it the putimage on the QuickQin dialog?

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,091 Views
When you insert the bitmap as "resource", the file header is indeed stripped off (a .bmp file consists of a small header plus series of bits which represent the data in memory). Instead of adding it as "bitmap", you should add it as a "bitstream" (custom resource). See this thread.

Or, better still, drop the QuickWin altogether :-). See also this xeffort sample.
0 Kudos
onkelhotte
New Contributor II
1,091 Views

Getting rid of QuickWin *sigh* I dont exaggerate when I say that sometimes I dreamt of it at night :-)
Our company will move to VS2005 at the beginning of the next year, so I only have to use QuickWin for another 6 months.

Thanks, your link/example works fine. They always do!

Markus

0 Kudos
Reply