News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Bitmap problem

Started by pro3carp3, October 27, 2005, 02:49:47 AM

Previous topic - Next topic

pro3carp3

I've been able to Bitblt a bitmap into the window's dc, but can't get a second bitmap to appear on the screen.  In the following code, the second Bitblt does not draw to the screen.  Any ideas?

Thanks.


.686
.model flat, stdcall
option casemap:none

include BR3.inc

.code
start:
;APPLICATION INITIALIZATION
invoke GetModuleHandle, NULL
mov hAppInst, eax
invoke GetCommandLine
mov spAppCmdLine, eax
;invoke InitApp, hAppInst

invoke WinMain, hAppInst, NULL, spAppCmdLine, SW_SHOWDEFAULT


invoke ExitProcess, eax

WinMain proc hInst:dword, hPrevInst:dword, spCmdLine:dword, CmdShow:dword
LOCAL WC:WNDCLASSEX
LOCAL Msg:MSG
LOCAL hWnd:dword

;Create main window class
mov   WC.cbSize, SIZEOF WNDCLASSEX
mov   WC.style, CS_HREDRAW or CS_VREDRAW
mov   WC.lpfnWndProc, OFFSET WndProc
mov   WC.cbClsExtra, NULL
mov   WC.cbWndExtra, NULL
push  hInst
pop   WC.hInstance
mov WC.hbrBackground, COLOR_WINDOW+1
mov   WC.lpszMenuName, NULL
mov   WC.lpszClassName, OFFSET sClassName
invoke LoadIcon, NULL, IDI_APPLICATION
mov   WC.hIcon, eax
mov   WC.hIconSm, eax
invoke LoadCursor, NULL, IDC_ARROW
mov   WC.hCursor, eax
invoke RegisterClassEx, addr WC
INVOKE CreateWindowEx, NULL,ADDR sClassName, ADDR sAppName,\
           WS_CAPTION, CW_USEDEFAULT,\
           CW_USEDEFAULT, 1024, 768, NULL, NULL,\
           hInst, NULL
mov   hWnd, eax
invoke ShowWindow, hWnd, SW_SHOWNORMAL
invoke UpdateWindow, hWnd
.WHILE TRUE
invoke GetMessage, ADDR Msg, NULL, 0, 0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR Msg
invoke DispatchMessage, ADDR Msg
.ENDW

;Delete Objects
;~~~~~~~~~~~~~~~~

mov     eax, Msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hdc:HDC
LOCAL PS:PAINTSTRUCT
LOCAL rectClient:RECT
LOCAL hdcMemDisp:HDC
LOCAL hdcMemBlock:HDC

.IF uMsg==WM_CREATE
invoke LoadBitmap, hAppInst, IDB_BKGD
mov hBmBkgd, eax
invoke LoadBitmap, hAppInst, IDB_BLOCK
mov hBmBlock, eax

.ELSEIF uMsg==WM_PAINT
invoke BeginPaint, hWnd, addr PS
mov hdc, eax
invoke CreateCompatibleDC, hdc
mov hdcMemDisp, eax
invoke CreateCompatibleDC, hdc
mov hdcMemBlock, eax
invoke SelectObject, hdcMemDisp, hBmBkgd
invoke SelectObject, hdcMemBlock, hBmBlock


invoke BitBlt, hdc, 0, 0, 1018, 736, hdcMemDisp, 0, 0, SRCCOPY

invoke BitBlt, hdc, 64, 64, 16, 16, hdcMemBlock, 0, 0, SRCCOPY



invoke DeleteDC, hdcMemDisp
invoke DeleteDC, hdcMemBlock
invoke EndPaint, hWnd, addr PS
.ELSEIF uMsg==WM_DESTROY

invoke DeleteObject, hBmBkgd
invoke DeleteObject, hBmBlock
invoke PostQuitMessage, NULL

.ELSE
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start



; INCLUDES
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

; PROCEDURE PROTOTYPES
WinMain proto :DWORD, :DWORD, :DWORD, :DWORD
DrawScreen proto :HDC
InitApp proto :DWORD

; EQUATES
IDB_BKGD equ 50
IDB_BLOCK equ 51

; INITIALIZED DATA
.data
;Main App strings
sClassName db "P3S_BR3", 0d
sAppName  db "BlockRock", 0d

; UN-INITIALIZED DATA
.data?
align 4
;Main App pointers and handles
hAppInst dword ?
spAppCmdLine dword ?

;Bitmap handles
hBmBkgd dword ?
hBmBlock dword ?





#define IDB_BKGD 50
#define IDB_BLOCK 51

IDB_BKGD BITMAP "Bkgd.bmp"
IDB_BRICK BITMAP "Block.bmp"
LGC

hutch--

I have only had a quick lok but perhaps te problem is you are not setting the device context for the actual client area of the Window that is to get the results. Usually you create a compatible DC for the back buffer then blit the result from the back buffer to the DC for the client area.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Manos

The problem is that you can create only one CompatibleDC
and you can select one only object each time of the same type object
into the device context.
Therefor you have to create one only CompatibleDC,to call SelectObject
for the first hBitmap,to call BitBlt and then you can work for the second bitmap,
with the same way.

Manos.


six_L


invoke SelectObject, tempdc1, hbmp1
invoke BitBlt, memdc, 0, 0, BITMAPSIZE, BITMAPSIZE, tempdc1,  0, 0, MERGECOPY;SRCAND

invoke SelectObject, tempdc2, hbmp2
invoke BitBlt, memdc, 250, 70, BITMAPSIZE, BITMAPSIZE, tempdc2, 0, 0, MERGECOPY;SRCAND

[attachment deleted by admin]
regards

pro3carp3

Thanks.  I was able to get it working.
LGC