473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

drawing a moving abject on a bitmapped background in dialog

1
The drawings are getting erased when the dialog is dragged or other drawing applied afterwards
I need all the drawings to stay permanently so, i can continue to draw in dialog depanding on user's response...
A working code sample is appreciated

////////////////////////////////////////////////////////
BOOL CFlickerFreeDlg::OnInitDialog()
{
CDialog::OnInitDialog();

BITMAP bm;
CClientDC dc(this);

m_picture.topleft.x = 0;m_picture.topleft.y = 0;
m_offs.cx = 0;m_offs.cy = 0;
m_CanvasDC->CreateCompatibleDC(&dc);
m_PicDC->CreateCompatibleDC(&dc);

m_BkgBitmap->LoadBitmap(IDB_BG);
m_BkgBitmap->GetBitmap(&bm);
m_hBkg = bm.bmHeight;
m_wBkg = bm.bmWidth;
m_Bitmap->LoadBitmap(IDB_PIC);
m_Bitmap->GetBitmap(&bm);
m_picture.height = bm.bmHeight;
m_picture.width = bm.bmWidth;

return TRUE; // return TRUE unless you set the focus to a control
}


void CFlickerFreeDlg::OnPaint()
{

CPaintDC dc(this);
OnDraw(&dc);
}


HCURSOR CFlickerFreeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}


void CFlickerFreeDlg::OnDestroy()
{
delete m_CanvasBitmap;
delete m_Bitmap;
delete m_BkgBitmap;
delete m_CanvasDC;
delete m_PicDC;
}


void CFlickerFreeDlg::OnDraw(CDC* pDC)
{

CBitmap* pOldBmp1;
CBitmap* pOldBmp2;
CRect cr;
//selects canvas
pOldBmp1 = m_CanvasDC->SelectObject(m_CanvasBitmap);
//selects background, blits into canvas

pOldBmp2 = m_PicDC->SelectObject(m_BkgBitmap);
m_CanvasDC->BitBlt(0, 0, m_wBkg, m_hBkg, m_PicDC, 0, 0, SRCCOPY);
//selects small pic, blits into canvas
m_PicDC->SelectObject(m_Bitmap);
m_CanvasDC->BitBlt(m_picture.topleft.x,
m_picture.topleft.y,
m_picture.width,
m_picture.height,
m_PicDC,
0, 0, SRCCOPY);
//blits canvas on screen.Well only part of it - the "dirty rectangle" part.
pDC->GetClipBox(cr);
pDC->BitBlt(cr.left, cr.top, cr.right, cr.bottom, m_CanvasDC, cr.left, cr.top, SRCCOPY);
//deselects all the bitmaps
m_CanvasDC->SelectObject(pOldBmp1);
m_PicDC->SelectObject(pOldBmp2);

}


void CFlickerFreeDlg::OnSize(UINT nType, int cx, int cy)
{
ASSERT(!(m_CanvasBitmap == NULL));
delete m_CanvasBitmap;
m_CanvasBitmap = new CBitmap;
CClientDC dc(this);
m_CanvasBitmap->CreateCompatibleBitmap(&dc, cx, cy);

CDialog::OnSize(nType, cx, cy);
}


BOOL CFlickerFreeDlg::OnEraseBkgnd(CDC* pDC)
{
return false;
}


CRect CFlickerFreeDlg::CalcDirtyRect(int pic_w, int pic_h, CPoint p1, CPoint p2)
{
CSize PicSize(pic_w,pic_h);
CRect r1(p1,PicSize);
CRect r2(p2,PicSize);

return r1 | r2;
}

void CFlickerFreeDlg::Animate(int count)
{
bAnimate = TRUE;
for (int i = 0; i < 40; i ++)
{

CRect DirtyRc;
DirtyRc.left = 0 + i*5;
DirtyRc.right = DirtyRc.left + m_picture.width;
DirtyRc.top = 0 + i*5;
DirtyRc.bottom = DirtyRc.top + m_picture.height;

// m_picture.topleft = point - m_offs;
m_picture.topleft.x = i*5;
m_picture.topleft.y = i*5;

if(i > (40 - count))
{
InvalidateRect(DirtyRc,1);
}else if( i <= (40 - count) )
{
InvalidateRect(NULL,1);
}


UpdateWindow();

Sleep(10);
}

bAnimate = FALSE;
}


void CFlickerFreeDlg::OnButton1()
{
Animate(9);
}
/////////////////////////////////////////////////////////
Jun 10 '10 #1
0 1069

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Victor Bastiaansen | last post by:
For use in a menu I build a stylesheet which crops an image which contains both the normal button-state and the mouseover-state. On a mouseover the layer background-images 'moves', and another part...
8
by: Ron Holmes | last post by:
I want to place a background image on a windows form. Is there a way to prevent the image from Tiling without using an image box resized to the size of the form? I am using Visual Studio 2003...
0
by: Andrew | last post by:
I get a Null Reference Exception if I close a modeless form (that is, a form displayed using Show()) when a selection is made from a ComboxBox. If the form is modal (displayed using ShowDialog())...
3
by: Andrew | last post by:
I get a Null Reference Exception if I close a non-modal dialog (that is, a form opened with Show()) when a selection is made from a ComboBox. The error message refers to Unsafe Native Methods, but...
4
by: Steve Barnett | last post by:
I want to give one of my forms a "steel" effect background. While I could find a bitmap and tile it over the surface, I've always found this gives a poor effect over a large area. Is there anywhere...
0
by: Gino | last post by:
Hi, I wish to code a control that writes a text over a picturebox and that can be dragged with mouse. Here is what i've actually coded to obtain a similar effect, but as you can see i've...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
4
by: jsavagedesign | last post by:
I am working on a site where we are doing some experamental Javascript and Flash actionscript. Basicly, at a certain point the flash movie tells the javascript function on the page to move the div...
8
by: Brian Ward | last post by:
I am looking for a simple way to set the image transparency in a PictureBox. I have a moving PictureBox containing a graphic image .. moving by incrementing its Left property. The background...
9
by: Peter Webb | last post by:
I want to animate one object moving in front of another. I cannot re-render the background as the object moves, as it would be extremely time consuming. This is what I would like to do. I draw...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.