Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing in a Dialog Box, outside of OnPaint()

Status
Not open for further replies.

patapumbum

Programmer
Mar 19, 2004
4
RO
Hy, I am not very familiar with visual c++ and because of this i tried without succes to write a function that can draw into a dialog box, using CClientDC. It looks like this:

void CDesDlg::Deseneaza(int x, int y)
{
CClientDC dc(this);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
dcMem.SelectObject(&bmp_patrat);//"bmp_patrat"
//is a CBitmap global variable, previously loaded
dc.BitBlt(x*10, y*10, 10, 10, &dcMem, 0, 0, SRCCOPY);
}

The problem is that it shows the bitmap only once. If I change the coordinates(x and y) it doesn't show anything. 10x.
 
Great, if you want sa desenezi always the dialog box you should handle message WM_PAINT, I believe if you do a MFC application, there is a standard handler, OnPaint.


Ion Filipski
1c.bmp
 
Thnks for the advise. I still have this problem: I'm trying to move an image on the background of the dialog box. I do this by calling a function from the OnPaint function. The thing is that I want to redraw only one part of the window, keeping the rest of the backround unchanged. I've read some documentation about InvalidateRect(..), ValidateRect(..), CClientDC, but I can't get a clear ideea. If you have more related documentation or any advices I'd be glad to listen.
 
What would you like to accomplish? You can draw in any types of regions. You may use CreatePolygonRgn tp create a region and use FillRgn or something like that.

Ion Filipski
1c.bmp
 
I would like to insert a small bitmap in a dialog box that already has a background(another bitmap) at some coordonates. In essence, I would like to simulate an image mouvement. I can do this in 2 steps:
1. I delete the image at the previous coordonates
2. I insert the bitmap at the new coordonates.

(Like the game "Snake": u delete the bmp-tail of the snake, then you draw the bmp-head at another location. If the snake is "moving" on "grass", i would like to keep the "grass" in the places the snake doesn't touch it.) Sorry for not being very understandable.
 
you don't do it correctly. You should compute in the memory the whole image and transfer it entirely to the box. You should also compute the place traced by the snake on the graass and keep it, not physically on the dialog box DC bitmap but logically in your program.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top