Author Topic: Problems with resource.  (Read 836 times)

Vortex

  • Member
  • *****
  • Posts: 2090
Re: Problems with resource.
« Reply #15 on: November 20, 2019, 07:05:46 AM »
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

Code: [Select]
.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

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Problems with resource.
« Reply #16 on: November 20, 2019, 07:09:31 AM »
    I still remember that part. the thing is that the LoadBitmap function resturns ERRROR_RESOURCE_NAME_NOT_FOUND.
    thanks vortex
nothing to report.

jj2007

  • Member
  • *****
  • Posts: 10026
  • Assembler is fun ;-)
    • MasmBasic
Re: Problems with resource.
« Reply #17 on: November 20, 2019, 09:19:03 AM »
Hi Xandaz,

Some error checks help to find the culprits:
Code: [Select]
        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$()
Code: [Select]
LoadImg
eax             0
$Err$()         Access denied.

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

With a few changes:
Code: [Select]
        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$()
Code: [Select]
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

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Problems with resource.
« Reply #18 on: November 20, 2019, 09:25:15 PM »
    Thanks JJ. You solved the problem.
    Thanks you guys. You're the best.
nothing to report.

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Problems with resource.
« Reply #19 on: November 23, 2019, 07:22:02 AM »
    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.
nothing to report.

Vortex

  • Member
  • *****
  • Posts: 2090
Re: Problems with resource.
« Reply #20 on: November 23, 2019, 07:53:48 AM »
Hi xandaz,

You can load a bitmap without creating a resource file :

Code: [Select]
   .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

  • Member
  • *****
  • Posts: 2090
Re: Problems with resource.
« Reply #21 on: November 23, 2019, 08:06:36 AM »
Hi xandaz,

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

Code: [Select]
100 BITMAP logo.bmp
Code: [Select]
   .IF uMsg==WM_CREATE
   
        invoke  LoadImage,hInstance,100,\
                IMAGE_BITMAP,0,0,0
        mov     hBitmap,eax

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Problems with resource.
« Reply #22 on: November 23, 2019, 09:15:54 AM »
    Vortex....tried the same but still not working. take a look if you will....
    thanks.
nothing to report.

fearless

  • Member
  • ***
  • Posts: 469
    • LetTheLightIn
Re: Problems with resource.
« Reply #23 on: November 23, 2019, 10:02:01 AM »
You have this:
Code: [Select]
invoke  LoadImage,hInstance,addr Bmp,IMAGE_BITMAP,64,64,0
Which refers to this:
Code: [Select]
UCSTR              Bmp,"bmp",0
try:
Code: [Select]
.const
BMP_MYBITMAP EQU 100 ; same ID as defined in the resource

Code: [Select]
invoke LoadImage, hInstance, BMP_MYBITMAP, IMAGE_BITMAP, 64, 64, 0
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Problems with resource.
« Reply #24 on: November 23, 2019, 08:23:56 PM »
    Hey guys ... it still dont work. what am i forgetting to do? there's always something....
    ty guys
nothing to report.

Vortex

  • Member
  • *****
  • Posts: 2090
Re: Problems with resource.
« Reply #25 on: November 23, 2019, 08:44:26 PM »
Hi xandaz,

The bitmap handle should not be a local variable :

Code: [Select]
WndProc     PROC    hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

         ; local    hBitmap:DWORD

Code: [Select]
.data?

hBitmap dd ?

Modifying the resource script :

Code: [Select]
100 BITMAP "bmp.bmp"
And this one :

Code: [Select]
invoke  LoadImage,hInstance,100,IMAGE_BITMAP,64,64,0
After building the application, I can see the red ball in the window.

xandaz

  • Member
  • **
  • Posts: 129
  • I luv you babe
Re: Problems with resource.
« Reply #26 on: November 23, 2019, 08:48:39 PM »
    ahhh.... that's right vortex....thanks
nothing to report.