The MASM Forum

General => The Campus => Topic started by: xandaz on November 01, 2020, 11:44:49 PM

Title: Problems loading bitmap from resource
Post by: xandaz on November 01, 2020, 11:44:49 PM
   Hey guys. It's me again. What does MAKEINTRESOURCE do? if the low order word contains the resource identifier and high order word is zero, eax=100 should work for LoadBitmap right? thandks in advance
Title: Re: Problems loading bitmap from resource
Post by: TouEnMasm on November 02, 2020, 01:17:14 AM
MAKEINTRESOURCE is just a macro used by C who convert the  size of a ressource
Quote
#define MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
HB=(HBITMAP)LoadImage(g_hInst, MAKEINTRESOURCE(resmonimage), IMAGE_BITMAP, 0, 0,
LoadImageA PROTO hInst:HINSTANCE ,aname:XMASM ,atype:DWORD ,acx:DWORD ,cy:DWORD ,fuLoad:DWORD
the aname parameter need a dword or a QWORD in 64,The MAKEINTRESOURCE will change the size of the ressource.
An asm compiler do that without Macro ,just pass the value of the ressource.



Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 02, 2020, 02:16:36 AM
    Sorry ToutEnMasm. I'm not clarified. I did it all manually. Old school works always.
Title: Re: Problems loading bitmap from resource
Post by: jj2007 on November 02, 2020, 02:25:20 AM
Quote from: xandaz on November 01, 2020, 11:44:49 PMif the low order word contains the resource identifier and high order word is zero, eax=100 should work for LoadBitmap right?

Yesss :thumbsup:
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 02, 2020, 04:51:52 AM
   thanks jj. still not working.
Title: Re: Problems loading bitmap from resource
Post by: Vortex on November 02, 2020, 05:50:48 AM
Hi xandaz,

You can have a look at Iczelion's Tutorial 25: Simple Bitmap :

http://www.interq.or.jp/chubu/r6/masm32/tute/tute025.html

It's about using the LoadBitmap API function.
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 02, 2020, 11:04:08 PM
    Ty Vortex
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 02:33:54 AM
    Still doesn't load the resource. I'm using ResEdit for the purpose. Still gives Resource not found. i checked with resource hacker and the bitmaps are in the executable module. i tried hex instead of decimal. thanks a lot anyway
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 02:38:34 AM
   Also doesnt result with resource name type string.
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 02:40:03 AM
   ok... it's working now. thanks guys... you're the best.
Title: Re: Problems loading bitmap from resource
Post by: jj2007 on November 04, 2020, 02:53:35 AM
Now please tell us what was the problem - we are a curious bunch :bgrin:
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 03:58:18 AM
    Not sure. It's working fine now the LoadBitmap function. The problem was with ImageList_xxxx functions. I am having trouble adding the bitmaps to the Image List. I've tried ImageList_Add, ImageList_AddMasked and ImageList_LoadImage. Always returns -1. Why would that be?
Title: Re: Problems loading bitmap from resource
Post by: jj2007 on November 04, 2020, 04:19:04 AM
No idea, but I remember it was tricky. I use this...

  mov eax, tbs.tbButtonSize
  .if !eax
        add eax, 24             ; adapt as needed
        mov tbs.tbButtonSize, eax
  .endif
  mov imgList, rv(ImageList_Create, eax, eax, ILC_MASK or ILC_COLOR24, maxfiles, 0)     ; inspired by deutsche Site (https://www.c-plusplus.net/forum/48288-full)
;
...
invoke ImageList_AddMasked, imgList, hBitmap, 0


... with success :cool:
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 04:58:13 AM
   Ty JJ. I'll check that out. Thanks
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 05:06:16 AM
   Still doesn't work. Check out the code please if you dont mind.
                invoke  ImageList_Create,32,32,ILC_COLOR24+ILC_MASK,9,0
                mov     hIml,eax
                mov     ecx,9
                mov     esi,101
                cld
loop_1:
                push    ecx
                invoke  LoadBitmap,hInstance,esi
                invoke  ImageList_AddMasked,hIml,eax,0
                inc     esi
                pop     ecx
                loop    loop_1
Title: Re: Problems loading bitmap from resource
Post by: Greenhorn on November 04, 2020, 05:53:52 AM
Hi xandaz,

is hIml != NULL ?

Is the loaded bitmap compatible to the ImageList (24bit) ?
Have you tried ILC_COLOR32 instead of ILC_COLOR24 ?

Kind regards
Greenhorn
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 06:05:59 AM
   hIml is valid. the problem is very likely to be the FLAGS on ImageList_Create. I'm checking that. thanks
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 06:18:07 AM
   Hey...tried all thw flags. dosent work. It only works the previous way. Loading image from file. Could it be because it's a UNICODE app?
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 06:35:46 AM
    These lines of code work perfectlly. I feel like cracking my head about this. Damn OS's have these gliches makes a guy go crazy.
                invoke  ImageList_Create,32,32,ILC_COLOR32,9,18
                mov     hIml,eax
                mov     ecx,9
                lea     esi,mdicreate
                cld
loop_1:
                push    ecx
                invoke  LoadImage,0,esi,IMAGE_BITMAP,32,32,LR_LOADFROMFILE
                invoke  ImageList_AddMasked,hIml,eax,0
loop_2:         
                lodsw
                or      al,al
                jnz     loop_2               
                pop     ecx
                loop    loop_1
Title: Re: Problems loading bitmap from resource
Post by: jj2007 on November 04, 2020, 06:40:52 AM
Quote from: xandaz on November 04, 2020, 06:35:46 AM
    These lines of code work perfectlly

lodsw? Sure it isn't lodsb?

Quote from: xandaz on November 04, 2020, 06:18:07 AMCould it be because it's a UNICODE app?

What do you see in the debugger? Are you passing the correct string, i.e. Ansi for LoadImageA or Unicode for LoadImageW?
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 06:42:29 AM
    no. like i said it's working, those are unicode strings pointed by esi.
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 06:49:02 AM
   Hey thank you guys. Like i said: it's working perfectlly using LoadImage/LR_LOADFROMFILE. Doesn't work with LoadBitmap,hInstance,resource_number. Why the hell is that?
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 06:53:51 AM
    Hey guys again. I got it to work with LoadImage and LR_SHARED Flag set. Problem solved. Thanks a lot guys.
Title: Re: Problems loading bitmap from resource
Post by: Greenhorn on November 04, 2020, 07:07:03 AM
Try to use LR_CREATEDIBSECTION in LoadImage flags if you load from EXE/DLL.
ILC_COLOR32 creates a DIB section in ImageList_Create.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagew (https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-loadimagew)
https://docs.microsoft.com/en-us/windows/win32/controls/ilc-constants (https://docs.microsoft.com/en-us/windows/win32/controls/ilc-constants)

Kind regards
Greenhorn
Title: Re: Problems loading bitmap from resource
Post by: Mikl__ on November 04, 2020, 02:54:30 PM
hi, xandaz!
better late than never. Show here (https://translate.google.com/translate?sl=ru&tl=en&u=https://wasm.in/threads/skazki-djadjushki-rimusa.31832/page-3%23post-383943)
Title: Re: Problems loading bitmap from resource
Post by: Vortex on November 04, 2020, 06:02:48 PM
Hi xandaz,

You could also try the bitmap from file method :

http://masm32.com/board/index.php?topic=4642.msg49923#msg49923
Title: Re: Problems loading bitmap from resource
Post by: xandaz on November 04, 2020, 07:42:47 PM
    Thanks guys. You're the best.