News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Problems with resource.

Started by xandaz, November 12, 2019, 05:08:52 AM

Previous topic - Next topic

Vortex

Hi xandaz,

You should respond the WM_PAINT message to display the bitmap with BitBlt :

Tutorial 25: Simple Bitmap

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

.elseif uMsg==WM_PAINT
      invoke BeginPaint,hWnd,addr ps
      mov    hdc,eax
      invoke CreateCompatibleDC,hdc
      mov    hMemDC,eax
      invoke SelectObject,hMemDC,hBitmap
      invoke GetClientRect,hWnd,addr rect
      invoke BitBlt,hdc,0,0,rect.right,rect.bottom,hMemDC,0,0,SRCCOPY
      invoke DeleteDC,hMemDC
      invoke EndPaint,hWnd,addr ps

xandaz

    I still remember that part. the thing is that the LoadBitmap function resturns ERRROR_RESOURCE_NAME_NOT_FOUND.
    thanks vortex

jj2007

Hi Xandaz,

Some error checks help to find the culprits:
        invoke  LoadImage,hInstance,addr MainWindowIcon,IMAGE_ICON,32,32,LR_LOADFROMFILE
        deb 4, "LoadImg", eax, $Err$()
...
            invoke  LoadBitmap,hInstance, addr Bmp
            deb 4, "LoadBmp", eax, $Err$()

LoadImg
eax             0
$Err$()         Access denied.

LoadBmp
eax             0
$Err$()         Impossible finding the name of resource.


With a few changes:
        invoke  LoadImageW,hInstance,addr MainWindowIcon,IMAGE_ICON,32,32,LR_LOADFROMFILE
        deb 4, "LoadImg", eax, $Err$()
...
            invoke  LoadBitmap,hInstance, 100
            deb 4, "LoadBmp", eax, $Err$()

LoadImg
eax             248644207
$Err$()         Operation completed.

LoadBmp
eax             285541561
$Err$()         Operation completed.


I have added Vortex' code, too. Now it shows a little red circle in the upper left corner.

Note that resources can have names like "bmp". But in general, integers are easier to handle - and you did use an integer in the rc file: #define bmp 100

xandaz

    Thanks JJ. You solved the problem.
    Thanks you guys. You're the best.

xandaz

    Well guys a new problem takes place when you use LoadImage instead of loadBitmap. I've tried both the resource name and identifier and it doesn't work. The thing is i wanted to use ImageList_LoadImage to load the images for a toolbar. Any ideas?
   Thanks in advance.

Vortex

Hi xandaz,

You can load a bitmap without creating a resource file :

   .IF uMsg==WM_CREATE
   
        invoke  LoadImage,0,ADDR filename,\
                IMAGE_BITMAP,0,0,LR_LOADFROMFILE
        mov     hBitmap,eax   

        invoke  GetObject,eax,SIZEOF(BITMAP),ADDR bm
       
   .ELSEIF uMsg==WM_PAINT
   
        invoke  BeginPaint,hWnd,ADDR ps
        mov     hdc,eax
        invoke  CreateCompatibleDC,eax
        mov     hMemDC,eax
       
        invoke  SelectObject,eax,hBitmap

        mov     edx,OFFSET bm
           
        xor     eax,eax
        invoke  BitBlt,hdc,eax,eax,\
                BITMAP.bmWidth[edx],\
                BITMAP.bmHeight[edx],\
                hMemDC,eax,eax,SRCCOPY

        invoke  DeleteDC,hMemDC
        invoke  EndPaint,hWnd,ADDR ps

Vortex

Hi xandaz,

Loading a bitmap from a resource, the .rc script :

100 BITMAP logo.bmp

   .IF uMsg==WM_CREATE
   
        invoke  LoadImage,hInstance,100,\
                IMAGE_BITMAP,0,0,0
        mov     hBitmap,eax

xandaz

    Vortex....tried the same but still not working. take a look if you will....
    thanks.

fearless

You have this:
invoke  LoadImage,hInstance,addr Bmp,IMAGE_BITMAP,64,64,0

Which refers to this:
UCSTR              Bmp,"bmp",0

try:
.const
BMP_MYBITMAP EQU 100 ; same ID as defined in the resource


invoke LoadImage, hInstance, BMP_MYBITMAP, IMAGE_BITMAP, 64, 64, 0

xandaz

    Hey guys ... it still dont work. what am i forgetting to do? there's always something....
    ty guys

Vortex

Hi xandaz,

The bitmap handle should not be a local variable :

WndProc     PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

         ; local    hBitmap:DWORD


.data?

hBitmap dd ?


Modifying the resource script :

100 BITMAP "bmp.bmp"

And this one :

invoke  LoadImage,hInstance,100,IMAGE_BITMAP,64,64,0

After building the application, I can see the red ball in the window.

xandaz

    ahhh.... that's right vortex....thanks