• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

## Recommended Posts

I am trying to get a moving bitmap. I am just using the bitblt and etc. The problem is not the loading thou. The problem is the rectangle I am painting to keep it from smearing. For some reason when I CREATE the hbrush it stops the bitmap from loading and displaying? I edited out all but the beginpaint and createsolidbrush and its doing it to the bitmap loading. Must go. thanks [edited by - RyoxSinfar on March 31, 2004 12:04:22 PM] [edited by - RyoxSinfar on March 31, 2004 8:35:32 PM]

##### Share on other sites
I used HDC (device contexts). Look in Win32 API and DirectX SDK (ddutil.cpp). RTFM.

##### Share on other sites
Post you code that paints the screen.

"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

##### Share on other sites
idc = BeginPaint(hwnd, &paintStruct);
hBrush = CreateSolidBrush(RGB(0,0,0));
FillRect(idc, &Per, hBrush);
DeleteObject(hBrush);
ohbm = (HBITMAP)SelectObject(idc,hbm);
BitBlt(hdc,x,y,30,32,idc,0,0,SRCCOPY);
Per.top = y;
Per.left = x;
Per.right = x + 30;
Per.bottom = y + 32;
x++;
y++;
DeleteObject(hbm);
DeleteObject(ohbm);
break;

thats what I do. it is supposed to just move it diagnoly when I hit a character for practice with bitmaps. But when I make the rect to cover the last image it don''t work. When I document out the fill rect it still gives me nothing...

##### Share on other sites
quote:
Original post by RyoxSinfar
idc = BeginPaint(hwnd, &paintStruct);			hBrush = CreateSolidBrush(RGB(0,0,0));			FillRect(idc, &Per, hBrush);			DeleteObject(hBrush);			hbm = (HBITMAP)LoadImage(*hi,"Ship.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);			ohbm = (HBITMAP)SelectObject(idc,hbm);			BitBlt(hdc,x,y,30,32,idc,0,0,SRCCOPY);			Per.top = y;			Per.left = x;			Per.right = x + 30;			Per.bottom = y + 32;			x++;			y++;			DeleteObject(hbm);			DeleteObject(ohbm);			break;

You get idc from the BeginPaint, but where is hdc coming from?

Also, I don't think you want to select the bitmap into idc. You probably want to select it into a temporary compatible dc (using CreateCompatibleDC() and then blit it to idc from there.

EDIT: also, what's with that ohbm business? You realise you're just getting a handle to the brush you've just deleted, don't you? You should probably deselect objects from their dc before deleting them, you can get some weird bugs otherwise.

[edited by - Sandman on March 31, 2004 7:55:37 AM]

##### Share on other sites
Is the WM_Paint message sent whenever anything with painting is done? Like would my brush filling a rectangle send the WinProc a WM_PAINT message?

Thou even if it did, the bitmap should still appear over it.

So far nothing has worked... heres the code as it stands now...

(The colored rectangle doesn''t even appear)

Per.top = y;
Per.left = x;
Per.right = x + 30;
Per.bottom = y + 32;
hdc = BeginPaint(hwnd, &paintStruct);
hBrush = CreateSolidBrush(RGB(255,0,0));
FillRect(hdc, &Per, hBrush);
ohbm = (HBITMAP)SelectObject(idc,hbm);
x++;
y++;
BitBlt(hdc,x,y,30,32,idc,0,0,SRCCOPY);
DeleteObject(hbm);
DeleteObject(ohbm);
DeleteObject(hBrush);

##### Share on other sites
quote:
Original post by RyoxSinfar
Is the WM_Paint message sent whenever anything with painting is done? Like would my brush filling a rectangle send the WinProc a WM_PAINT message?

WM_PAINT is called every time the area gets invalidated, either by a call to InvalidateRect() or something similar, or as a result of being covered by something else (another window) and then revealed. Note that even in the latter case, a WM_PAINT isn't always caused, because sometimes Windows saves a copy of the covered area as a bitmap and just repaints it itself.

For a constantly updating image you should probably call InvalidateRect() to force a redraw your image every frame.

Try the code below (written off the top of my head, so it might not be perfect) I've removed the coordinate updating stuff for clarity. You might also want to check the values you're setting x and y to initially.

hdc = BeginPaint(hwnd, &paintStruct);hBrush = CreateSolidBrush(RGB(255,0,0));FillRect(hdc, &Per, hBrush);HDC hdcTemp = CreateCompatibleDC(hdc);hbm =  (BITMAP)LoadImage(*hi,"Ship.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);SelectObject(hdcTemp,hbm);BitBlt(hdc,x,y,30,32,hdcTemp,0,0,SRCCOPY);SelectObject(hdcTemp,0);DeleteObject(hbm);DeleteObject(hBrush);   DeleteDC(hdcTemp);EndPaint(hwnd,&paintStruct);

[edited by - Sandman on March 31, 2004 9:24:02 AM]

##### Share on other sites
um, I am not sure how it would help... I tried puting it in... it said that load image was giving a void return...?

I still am not sure how it was different from my own code. And the thing is, the same code copied from the WM_PAINT case was put there and did not do anything... *shrug*

hdc = BeginPaint(hwnd, &paintStruct);
hBrush = CreateSolidBrush(RGB(255,0,0));
FillRect(hdc, &windowRect, hBrush);

these lines do NOT work when I am in the WM_CHAR case
they DO work in WM_PAINT case. nothing is deleted anywhere right now. *shrug* anyone?
I HAVE tried using an HPEN in there before and it worked...

[edited by - RyoxSinfar on March 31, 2004 12:03:59 PM]

[edited by - RyoxSinfar on March 31, 2004 12:05:21 PM]

##### Share on other sites
quote:
Original post by RyoxSinfar
hdc = BeginPaint(hwnd, &paintStruct);
hBrush = CreateSolidBrush(RGB(255,0,0));
FillRect(hdc, &windowRect, hBrush);

these lines do NOT work when I am in the WM_CHAR case
they DO work in WM_PAINT case. nothing is deleted anywhere right now. *shrug* anyone?
I HAVE tried using an HPEN in there before and it worked...

Erm, why are you trying to do this in the WM_CHAR case?

BeginPaint() and EndPaint() should only ever be called in response to a WM_PAINT message. If you want to redraw after a WM_CHAR message then call InvalidateRect() to force a redraw.

quote:

it said that load image was giving a void return...?

I just noticed a typo - I cast the return value to a BITMAP instead of an HBITMAP. Otherwise, the only difference is the way the bitmap is copied (selected into a temporary dc and then blitted)

##### Share on other sites
it works! Thank you! I had thought the begin paint was required in order to use the HBRUSH (thou it seemed odd, but I got used to that sorta stuff in Java ) but yes that definatly did the trick! Now on to networking and asteroids and etc! ... ... or I could just go ahead and play some UT2004... CURSES! The irony!

If anyone sees this, maybe they can explain the huge amount of code I saw for a tut's way of making a bitmap follow the cursor? I will post a small bit of it here...

Bmp->hFileMapping = CreateFileMapping(Bmp->hFilePointer, NULL, PAGE_READONLY, 0, 0, NULL);
Bmp->BeginOfFile = (PUCHAR)MapViewOfFile(Bmp->hFileMapping, FILE_MAP_READ, 0, 0, 0);
Bmp->bmFileInfo = (BITMAPINFO*)Bmp->BeginOfFile;

whats the difference, should I figure out what this is or should I keep the other way?

You guys have beeen a huge help so far.

[edited by - RyoxSinfar on March 31, 2004 8:04:26 PM]

[edited by - RyoxSinfar on March 31, 2004 8:07:55 PM]

[edited by - RyoxSinfar on March 31, 2004 8:33:18 PM]

• ### Forum Statistics

• Total Topics
627700
• Total Posts
2978695

• 21
• 14
• 12
• 10
• 12