Hi friends,

I am trying to use CreateBitmap function to display a bitmap from a binary file;but I get error (null return value) after SelectObject. Where is the problem?



if uMsg==WM_CREATE
mov edi,OFFSET Bitmap
mov eax,DWORD PTR [edi+10]
add eax,edi
invoke CreateBitmap,284,277,1,8,eax
mov hBitmap,eax
.elseif uMsg==WM_PAINT
invoke BeginPaint,hWnd,addr ps
mov hdc,eax
invoke CreateCompatibleDC,hdc
mov hMemDC,eax
invoke SelectObject,eax,hBitmap
invoke BitBlt,hdc,0,0,284,277,hMemDC,0,0,SRCCOPY
invoke DeleteDC,hMemDC
invoke EndPaint,hWnd,addr ps
.elseif uMsg==WM_DESTROY
invoke DeleteObject,hBitmap


The attachment contains all the source files.
Posted on 2004-01-07 05:16:20 by Vortex
The hBitmap is ok, but SelectObject isn't - because you're not running in 8-bit video mode. Set your videocard to 8-bit, run the app - and it'll be OK , in fact you'll see things upside-down :grin: . Silly MS... I've had a lot of trouble drawing DIBs upside-down with heavy optimization and custom-drawn shaded rectangles...
The colors will be bad, too, you'll have to update the palette manually...
To make things easier, you should use CreateDIBSection.
To make things even easier and better, use the masm32.lib - the jpg/gif loader.
Posted on 2004-01-07 06:44:05 by Ultrano
Hi Ultrano,

Many thanks for the technical infos.:alright:
Posted on 2004-01-07 11:48:22 by Vortex