Some time ago, someone posted an example of making menus without using resources. If found it very useful and use it all the time now.

Is there any way to use icons and images without resources?
Posted on 2003-11-12 21:36:01 by msmith
Hi msmith,

If you mean to store the raw data in your program and not in the resource section you can use the CreateDIBitmap and CreateIconFromResource functions to convert the data to a handle. They are generally used with resource based data but it can come from anywhere as long as it is the right format. Otherwise the only other way I can see is to load them from a file.

For example for bitmaps you would have a DIB bitmap stored at some offset in your program and load it as follows
invoke GetDC,NULL

mov hDC,eax

mov edi,pBitmapData
mov cx,[edi].BITMAPINFO.bmiHeader.biBitCount

mov eax,1
shl eax,cl
imul edx
.IF cx >= 24 ; There is no RGBQUAD array for 24 bit
mov eax,0
add eax,edi

invoke CreateDIBitmap, hDC, edi, CBM_INIT, eax, edi, DIB_RGB_COLORS
push eax
invoke ReleaseDC,NULL,hDC
pop eax

Icons are much easier, save the single icon as raw data to some point in your program and use the following to extract it :
invoke CreateIconFromResource, pIconData, IconDataSize, TRUE, 030000h
Posted on 2003-11-12 22:19:09 by donkey
Hi Donkey,

As usual, Thanks!

You also mention loading them from file. How does this work?
Posted on 2003-11-12 22:52:22 by msmith
Use the LoadImage function and specify LR_LOADFROMFILE.


Posted on 2003-11-12 22:58:05 by donkey

You wrote:

>Some time ago, someone posted an example of making menus without using resources. If found it very useful and use it all the time now.

Is there any way to use icons and images without resources?

You can create dialog boxes without having resource sections in your executables:
Posted on 2003-11-13 10:57:48 by Vortex
I am getting a NULL handle when I try:

invoke CreateIconFromResource,!myicon,766,1,$30000
mov [myicon],eax

I read in camera.ico into memory location !myicon and it is 766 bytes in length. (I read in the entire file with no consideration as to contents). In other words, the working length of the file was 766 bytes and I read all of them into !myicon.
Posted on 2003-11-14 16:14:42 by msmith
Hi msmith,

The icon must be in the same format as it would be in the resource section. If the icon is a file you must adjust it by removing the file header and icondir structure. You can usually just jump past that to the icon data itself.

ICONDIR struct

idReserved WORD ?; // Reserved (must be 0)
idType WORD ?; // Resource Type (1 for icons)
idCount WORD ?; // How many images?
; ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)

bWidth BYTE ?; // Width, in pixels, of the image
bHeight BYTE ?; // Height, in pixels, of the image
bColorCount BYTE ?; // Number of colors in image (0 if >=8bpp)
bReserved BYTE ?; // Reserved ( must be 0)
wPlanes WORD ?; // Color Planes
wBitCount WORD ?; // Bits per pixel
dwBytesInRes DWORD ?; // How many bytes in this resource?
dwImageOffset DWORD ?; // Where in the file is this image?

Your icon will consist of an icondir structure followed by an icondirentry then the raw icon data. Add the size of icondir to the offset and you should get a handle. If not send me a copy of an icon you wish to encorporate and I will pick apart the file to give you a consistent way to derive an offset. If you check Res2Dlg and Toolbar paint I have had alot of experience with icons and ani-icons lately ;)
Posted on 2003-11-14 16:59:57 by donkey
Mmmm, actually it might be a little more difficult than I thought I'll have to think on this one. If you could send me a file it would help.
Posted on 2003-11-14 17:13:49 by donkey
Hi Donkey,

As usual...Donkey to the resque!

invoke CreateIconFromResource,!myicon+22,766-22,1,$30000
mov [myicon],eax

22 is the number of bytes in the header you posted in the last post.

What I am actually doing (in my compiler) is taking a BASIC line:

createicon myicon,camera

and generating a file read and subsequently generating a label followed by a series of db's in hex of the data read.

To permanently fix the problem, I will probably just throw away the 1st 22 bytes and calc the length from there. Is there any reason that I would want those 1st 22 bytes in memory?

BTW I avoided calls such as LoadIcon because I did not want to read the icon data into a buffer, but rather create it with db's.

Thanks again Donkey.

PS Most people don't realize that compilers "like" to write asm diferently than humans. Compilers (at least mine) can do icons easier using the above example than by using resources. Many other aspects of doing asm are easier for humans than for compilers because compilers don't have overview and insight. In particular things that are tedious and boring for humans are ideal for compilers. That's why asm macros are of marginal value for compilers because compilers don't mind spitting out repetitive code.
Posted on 2003-11-14 17:38:29 by msmith
You're very welcome as usual msmith,

BTW your BETA testers for OMNIBASIC are giving it rave reviews, I have gotten a few comments about it and have proudly stated that I helped a bit with advice for some of the GDI stuff :) Maybe overstating the case a bit but I have never been shy of tooting my own horn. You should be very proud of your work over there, from what I hear it is excellent and very powerful.

If you are interested I have a rather good bitmap to icon routine that you can use that converts a bitmap into an icon and generates the mask from a user selected colour, it works very well and can be seen in the icon plug in for toolbar paint, just click my WWW
Posted on 2003-11-14 17:55:09 by donkey
Hi Donkey,

Thanks for the kind words!

OmniBasic has been around about 8 years, but never with a Win32 API interface.

Almost all of the work involved in doing this Win32 API port is grinding through the non-orthangonal API. Nothing is consistant.

Thanks to your help, I have most of the port done. There are still details to do. I had sent you a pre-beta months ago when it did't really do much. I'll send you a new one(s) as things progress. The early one I sent you didn't even have events yet.

You deserve to toot your horn, and many of us on this forum owe you a debt of gratitude.

BTW I'm one of those guys who designed instruction sets and minicomputers back before microprocessors were invented where the most complex chips were a 74181 ALU and if course WD1401 UART ( I actually designed TeleType serial interfaces before the UART was invented). So it is not the complexity of the API that bothers me, it is the extreme irregularity of it. (Talk about tooting one's own horn!)
Posted on 2003-11-14 18:16:54 by msmith
Hi Donkey,

Of course I would be interested in your BitMap conversion routine.
Posted on 2003-11-14 18:19:55 by msmith
Hi msmith,

I have emailed the procedure to you, I will also look at snipping out the save bitmap routine from tbpaint for you, it has excellent colour reduction (better than some commercial software) and can save at 4, 16, 24 and 32 bit depth. Might be useful to you, it also provides some good image info like actual # of colours used, width, height estimated file size etc...
Posted on 2003-11-14 18:46:38 by donkey
Hi Donkey,

I'm still using the -22 and +22 as above (I haven't changed things to skip the 1st 22 yet).

All of the icons that show a 1K Size on Windows Explorer work. All others return a NULL handle. Any ideas?

I can send samples if you wish.

Posted on 2003-11-14 19:55:27 by msmith
It may be that they have a color table, If you send a few samples I can probably figure it out.
Posted on 2003-11-14 20:15:09 by donkey
Here is a similar method with an example:

1.Create a resource script containing the following:

100 ICON Smiley.ico

2.Extract the icon from the res file to a binary file

3.Convert the binary file to an .inc file (bin2db tool)

To extract the icon as a binary file,you need to use Resource Hacker,a
freeware resource editor/manager:

To display the icon:

invoke CreateIconFromResource,ADDR Icon,ICON_SIZE,TRUE,030000h
mov hIcon,eax
invoke BeginPaint,hWnd, ADDR ps
mov hDC,eax
invoke DrawIcon,hDC,76,68,hIcon
invoke EndPaint,hWnd, ADDR ps

You can check the example in the attachment.
Posted on 2003-11-16 12:16:53 by Vortex