xiuxiu
asked on
how can i load a bitmap and move it around the dialog box? and muz be flicker free.
HI there....
i want load a bitmap(IDB_CROSS) on button press and animate around the dialog box? is it possible to posiion my bitmap in terms x and y coordinates? how to 'animate' the icon???
and muz be flicker free.
desperate
i want load a bitmap(IDB_CROSS) on button press and animate around the dialog box? is it possible to posiion my bitmap in terms x and y coordinates? how to 'animate' the icon???
and muz be flicker free.
desperate
AlexFM has the answer.
If you want to draw the bitmap yourself at a specific location you can do so but it is difficult to get it flicker free. In particular you have to be careful when you move it that you invalidate all the pixels you move from and all the pixels you move to and any pixels in between so that they are redrawn correctly.
The easiest way is to place the picture in a label or static control and place it there and just move the control around as a regular window.
This is the solution that AlexFM already told you about so I think he should get the points for this one.
Alf
If you want to draw the bitmap yourself at a specific location you can do so but it is difficult to get it flicker free. In particular you have to be careful when you move it that you invalidate all the pixels you move from and all the pixels you move to and any pixels in between so that they are redrawn correctly.
The easiest way is to place the picture in a label or static control and place it there and just move the control around as a regular window.
This is the solution that AlexFM already told you about so I think he should get the points for this one.
Alf
ASKER
sorry but i can't seem to be able to see the bitmap picture. on button push i want to do this:
void CSol2Dlg::Onshow()
{
m_cross.LoadBitmap(IDB_CRO SS2);
m_static_image.SetBitmap(( HBITMAP) m_cross.m_hObject);
}
actually i want the cross to be moving to the specific position i want. Alternatively, i can delete the oldbitmap and set the new position of the bitmap again.
please help...i am willing to give any points u ask for and provided i have it :)
desperate
void CSol2Dlg::Onshow()
{
m_cross.LoadBitmap(IDB_CRO
m_static_image.SetBitmap((
}
actually i want the cross to be moving to the specific position i want. Alternatively, i can delete the oldbitmap and set the new position of the bitmap again.
please help...i am willing to give any points u ask for and provided i have it :)
desperate
ASKER
oh yes...i declare the CBitmap m_cross as a class variable. i wonder do i have to add any header??
desperate
desperate
1) Please check the type of your static control - did you select Bitmap type?
2) Try to set bitmap directly in dialog template (just to check) - do you see it?
3) Check return value of m_cross.LoadBitmap(IDB_CRO SS2);
2) Try to set bitmap directly in dialog template (just to check) - do you see it?
3) Check return value of m_cross.LoadBitmap(IDB_CRO
ASKER
sorry there.....
if i dun use bitmap...and i wanna remove a drawing a have drawn...how do i do it????
if i draw
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen) ;
ReleaseDC(pDC);
how can i use invalidateRect to remove ONLY the particular part so as to prevent flickering
if i dun use bitmap...and i wanna remove a drawing a have drawn...how do i do it????
if i draw
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen)
ReleaseDC(pDC);
how can i use invalidateRect to remove ONLY the particular part so as to prevent flickering
ASKER
sorry there.....
if i dun use bitmap...and i wanna remove a drawing a have drawn...how do i do it????
if i draw
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen) ;
ReleaseDC(pDC);
how can i use invalidateRect to remove ONLY the particular part so as to prevent flickering
if i dun use bitmap...and i wanna remove a drawing a have drawn...how do i do it????
if i draw
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen)
ReleaseDC(pDC);
how can i use invalidateRect to remove ONLY the particular part so as to prevent flickering
Drawing code should be placed on OnPaint function. It should look like this:
if ( m_bDrawFlag )
{
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen) ;
}
To draw line write:
m_bDrawFlag = TRUE;
Invalidate();
UpdateWindow();
To remove line write:
m_bDrawFlag = FALSE;
Invalidate();
UpdateWindow();
if ( m_bDrawFlag )
{
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen)
}
To draw line write:
m_bDrawFlag = TRUE;
Invalidate();
UpdateWindow();
To remove line write:
m_bDrawFlag = FALSE;
Invalidate();
UpdateWindow();
ASKER
sorry there.....
if i dun use bitmap...and i wanna remove a drawing a have drawn...how do i do it????
if i draw
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen) ;
ReleaseDC(pDC);
how can i use invalidateRect to remove ONLY the particular part so as to prevent flickering
if i dun use bitmap...and i wanna remove a drawing a have drawn...how do i do it????
if i draw
pDC->MoveTo(50,100);
pDC->LineTo(150,750);
pDC->SelectObject(pOldPen)
ReleaseDC(pDC);
how can i use invalidateRect to remove ONLY the particular part so as to prevent flickering
ASKER
Thanks AlexFM,
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
ASKER
Thanks AlexFM,
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
ASKER
Thanks AlexFM,
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks AlexFM,
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
U r a king soul. u have been a great help in helping me load the bitmap into my dialog box.
actually the main aim of the program is to move the IDC_CROSS like a device following a signal. Can m_static_image.MoveWindow does that????
MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
but my dialog window will not move, so what do i have to put in nWidth and int nHeight??
side point:
i ever tried to use invalidate() to refresh my dialog box before. the prob is it gives me a lot of flickering
You should be careful when calling invalidate. You probably don't want to invalidate your whole client area, only invalidate the part that actually changes. This means invalidate the area the picture moves from and invalidate the area the picture moves to. Invalidate will cause WM_PAINT message to be sent to windows and MFC will then call OnPaint.
You should absolutely place the bitmap in a control and then move that control around. It means that windows will handle the drawing, invalidating etc all by itself.
If you set the bitmap in a control you don't need any OnDraw function since windows will do the drawing. Just place the bitmap in the control and then move the control around.
However, this means that you place the bitmap at position 0,0 in the control and it stays at that position and you size the control to be so that the client area of the control (for a static control that area is the whole control, it doesn't have any other areas) becomes the size of the image. You then place the control at the position where you want to place the image.
Alf
You should absolutely place the bitmap in a control and then move that control around. It means that windows will handle the drawing, invalidating etc all by itself.
If you set the bitmap in a control you don't need any OnDraw function since windows will do the drawing. Just place the bitmap in the control and then move the control around.
However, this means that you place the bitmap at position 0,0 in the control and it stays at that position and you size the control to be so that the client area of the control (for a static control that area is the whole control, it doesn't have any other areas) becomes the size of the image. You then place the control at the position where you want to place the image.
Alf
ASKER
To AlexFM and all other experts:
my bitmap is moving well. but when it moves on a white background, the previous position of my IDC_CROSS leaves behind mark(a grey rect), which is not what i wanted. how can i solve this???
is there a way to make my bitmap transparent???
my bitmap is moving well. but when it moves on a white background, the previous position of my IDC_CROSS leaves behind mark(a grey rect), which is not what i wanted. how can i solve this???
is there a way to make my bitmap transparent???
How do you move it? What is your window - dialog, view?
ASKER
my window is dialog.
i want to move the IDC_CROSS. here is my code to move the IDC_CROSS in the dialog box
DrawBackgroundWhite();
CRect rect;
m_cross.LoadBitmap(IDB_CRO SS);
m_static_image.SetBitmap(( HBITMAP)m_ cross.m_hO bject);
m_static_image.MoveWindow( 200,300,10 ,10,FALSE) ;
ScreenToClient(&rect);
UpdateWindow();
for(int k=0;k<2000;k++)TRACE("wait ");
m_static_image.GetWindowRe ct(&rect);
ScreenToClient(&rect);
rect.left -= 10;
rect.top -= 10;
rect.right -= 10;
rect.bottom -= 10;
m_static_image.MoveWindow( &rect);
UpdateWindow();
the above code is working fine as my IDB_CROSS is moving. BUT when it moves from A to B... IDB_CROSS left a patch of grey area on the white backgroud...i dun wish this to happen...what should i do? how to set the IDB_CROSS as transparent???
i want to move the IDC_CROSS. here is my code to move the IDC_CROSS in the dialog box
DrawBackgroundWhite();
CRect rect;
m_cross.LoadBitmap(IDB_CRO
m_static_image.SetBitmap((
m_static_image.MoveWindow(
ScreenToClient(&rect);
UpdateWindow();
for(int k=0;k<2000;k++)TRACE("wait
m_static_image.GetWindowRe
ScreenToClient(&rect);
rect.left -= 10;
rect.top -= 10;
rect.right -= 10;
rect.bottom -= 10;
m_static_image.MoveWindow(
UpdateWindow();
the above code is working fine as my IDB_CROSS is moving. BUT when it moves from A to B... IDB_CROSS left a patch of grey area on the white backgroud...i dun wish this to happen...what should i do? how to set the IDB_CROSS as transparent???
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: AlexFM
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: AlexFM
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
CBitmap bmp;
bmp.LoadBitmap(IDB_CROSS);
m_static_image.SetBitmap((
I didn't understand exactly what is "animate around the dialog box". If you want to move an image, move static control on the dialog using MoveWindow.