The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Duracell on June 16, 2007, 07:45:09 AM

Title: Problem with bitmap
Post by: Duracell on June 16, 2007, 07:45:09 AM
I've problem with bitmap. I want load a bitmap.
I searched solution on forum and in google. I can't found that so I'm writing here.

That is me Window Procedure:
WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL wc: WNDCLASSEX,dm:DEVMODE,rc:RECT, bm:BITMAP,ps:PAINTSTRUCT
LOCAL hwnd:HWND, msg:MSG,hDCBmp:DWORD

mov eax,uMsg

.if eax==WM_DESTROY
invoke PostQuitMessage,0
invoke DeleteDC, hDCBmp
invoke DeleteObject, hBM
.elseif wParam == VK_ESCAPE
invoke PostQuitMessage,0
.elseif eax==WM_CREATE
    invoke LoadBitmap, hInst,100         
    mov hBM,eax
    invoke GetDC, hWnd
    mov ebx,eax
    invoke CreateCompatibleDC, ebx
    mov hDCBmp,eax
    invoke SelectObject, hDCBmp,hBM               
    invoke ReleaseDC, hWnd,ebx
    pop ebx
.elseif eax==WM_PAINT
invoke BeginPaint, hWnd,ADDR ps
    invoke BitBlt, eax,10,10,100,50,hDCBmp,0,0,SRCCOPY
    invoke EndPaint, hwnd,ADDR ps
.else   
    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
    ret


.endif
xor eax, eax
ret
WndProc endp 


Compilator doesn't show any error, but image don't exist on screen...

Thank for any assistance.
Title: Re: Problem with bitmap
Post by: Vortex on June 16, 2007, 07:54:24 AM
Here is a correct code portion to display a BMP from resource. It's from Iczelions's Win32asm tutorial set :

http://win32assembly.online.fr/tut25.html

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   LOCAL ps:PAINTSTRUCT
   LOCAL hdc:HDC
   LOCAL hMemDC:HDC
   LOCAL rect:RECT
   .if uMsg==WM_CREATE
      invoke LoadBitmap,hInstance,IDB_MAIN
      mov hBitmap,eax
   .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
.elseif uMsg==WM_DESTROY
  invoke DeleteObject,hBitmap
  invoke PostQuitMessage,NULL
.ELSE
  invoke DefWindowProc,hWnd,uMsg,wParam,lParam
  ret
.ENDIF
xor eax,eax
ret
WndProc endp
Title: Re: Problem with bitmap
Post by: Duracell on June 16, 2007, 08:13:04 AM
It for me that too don't display image...

code modified a'la Iczelion:

WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL wc: WNDCLASSEX,dm:DEVMODE,rc:RECT, bm:BITMAP,ps:PAINTSTRUCT
LOCAL hwnd:HWND, msg:MSG,hDCBmp:DWORD

mov eax,uMsg

.if eax==WM_DESTROY
   invoke PostQuitMessage,0
   invoke DeleteObject, hBM
.elseif wParam == VK_ESCAPE
   invoke PostQuitMessage,0
.elseif eax==WM_CREATE
    invoke LoadBitmap, hInst,100         
    mov hBM,eax
.elseif eax==WM_PAINT
    invoke BeginPaint,hWnd,addr ps
    mov ebx,eax
    invoke CreateCompatibleDC,eax
    mov    ecx,eax
    invoke SelectObject,ecx,hBM
    invoke GetClientRect,hWnd,addr rc
    invoke BitBlt,ebx,0,0,rc.right,rc.bottom,ecx,0,0,SRCCOPY
    invoke DeleteDC,ecx
    invoke EndPaint,hWnd,addr ps
.else   
    invoke DefWindowProc, hWnd, uMsg, wParam, lParam
    ret


.endif
xor eax, eax
ret
WndProc endp 
Title: Re: Problem with bitmap
Post by: ramguru on June 16, 2007, 08:24:49 AM
Your modification is wrong! You can only assume that ebx esi edi values stay the same after API call..NOT ecx
Title: Re: Problem with bitmap
Post by: Duracell on June 16, 2007, 08:29:23 AM
Right, I forgot about that... Thank you, ramguru