Home > Archive > Visual Studio > September 2004 > Copy a bitmap from the source device context to this current device context.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Copy a bitmap from the source device context to this current device context.
|
|
|
| I am using Microsoft Visual C++ 6.0.
I would like to draw a solid color square at the dialog, so I create a
function DrawSquare(), and use BitBlt() to copy a bitmap from the memory
device context to this current device context.
If I put the function DrawSquare() inside of OnInitDialog(), I could not see
the solid color square shown in the dialog. Otherwise if I put it into
OnTimer(), I can see the solid color square. However, I only want this
function being called once, instead of repeatedly by the timer, could
anybody please let me know how I can solve the problem? Should I put the
function DrawSquare() inside of any other function so it can only be called
once?
Thanks.
John
BOOL C***Dialog::OnInitDialog()
{
CDialog::OnInitDialog();
//The Solid Box will not be shown after called.
DrawSquare();
return TRUE;
}
void CPocketMax_PCDlg::OnTimer(UINT nIDEvent)
{
CDialog::OnTimer(nIDEvent);
//The Solid Box will be shown after called.
DrawSquare();
}
BOOL C***Dialog::DrawSquare()
{
CClientDC clientDC (this);
//Create Memory DC.
CDC dlgDC;
dlgDC.CreateCompatibleDC(&clientDC);
//Define the Memory Bitmap. Required!
CBitmap memBitmap;
memBitmap.CreateCompatibleBitmap (&clientDC, 240, 320); //Width, Height
dlgDC.SelectObject (&memBitmap);
CBrush * greyBr = new CBrush ( RGB (150,150,150));
int xStart = 0;
int yStart = 0;
int xEnd = 240;
int yEnd = 200;
//Draw Background
CRect rc(xStart, yStart, xEnd ,yEnd) ;
dlgDC.FillRect( &rc, greyBr); //Useful, to fill the background
clientDC.BitBlt(xStart, yStart, 240, 200, & dlgDC, xStart, yStart,
SRCCOPY) ;
// Be sure to release the DC!
ReleaseDC(&clientDC);
DeleteObject(clientDC);
ReleaseDC(&dlgDC);
DeleteObject(dlgDC);
memBitmap.DeleteObject();
greyBr->DeleteObject();
UpdateData (FALSE);
return TRUE;
}
}
| |
| Jayme Pechan 2004-09-17, 9:00 pm |
| I would think you'd want to call DrawSquare() in your WM_PAINT handler for
the dialog.
-Jayme
"JohnL" <hiliuzhe@hotmail.com> wrote in message
news:uCbguBRnEHA.1248@TK2MSFTNGP09.phx.gbl...
> I am using Microsoft Visual C++ 6.0.
>
> I would like to draw a solid color square at the dialog, so I create a
> function DrawSquare(), and use BitBlt() to copy a bitmap from the memory
> device context to this current device context.
>
> If I put the function DrawSquare() inside of OnInitDialog(), I could not
see
> the solid color square shown in the dialog. Otherwise if I put it into
> OnTimer(), I can see the solid color square. However, I only want this
> function being called once, instead of repeatedly by the timer, could
> anybody please let me know how I can solve the problem? Should I put the
> function DrawSquare() inside of any other function so it can only be
called
> once?
>
> Thanks.
>
> John
>
>
>
> BOOL C***Dialog::OnInitDialog()
> {
> CDialog::OnInitDialog();
>
> //The Solid Box will not be shown after called.
> DrawSquare();
>
> return TRUE;
> }
>
>
> void CPocketMax_PCDlg::OnTimer(UINT nIDEvent)
> {
> CDialog::OnTimer(nIDEvent);
>
> //The Solid Box will be shown after called.
> DrawSquare();
> }
>
>
>
> BOOL C***Dialog::DrawSquare()
> {
> CClientDC clientDC (this);
>
> //Create Memory DC.
> CDC dlgDC;
> dlgDC.CreateCompatibleDC(&clientDC);
>
> //Define the Memory Bitmap. Required!
> CBitmap memBitmap;
> memBitmap.CreateCompatibleBitmap (&clientDC, 240, 320); //Width, Height
> dlgDC.SelectObject (&memBitmap);
>
>
> CBrush * greyBr = new CBrush ( RGB (150,150,150));
>
> int xStart = 0;
> int yStart = 0;
> int xEnd = 240;
> int yEnd = 200;
>
>
> //Draw Background
> CRect rc(xStart, yStart, xEnd ,yEnd) ;
> dlgDC.FillRect( &rc, greyBr); //Useful, to fill the background
>
>
>
> clientDC.BitBlt(xStart, yStart, 240, 200, & dlgDC, xStart, yStart,
> SRCCOPY) ;
>
>
> // Be sure to release the DC!
> ReleaseDC(&clientDC);
> DeleteObject(clientDC);
> ReleaseDC(&dlgDC);
> DeleteObject(dlgDC);
> memBitmap.DeleteObject();
>
>
> greyBr->DeleteObject();
>
> UpdateData (FALSE);
>
>
>
> return TRUE;
> }
>
> }
>
>
>
| |
|
|
Thanks, Jayme,
You are right, I forgot WM_PAINT and WM_SIZE.
John
"Jayme Pechan" <jayme.pechan@whitefeld.com> wrote in message
news:eMKknHRnEHA.2764@TK2MSFTNGP11.phx.gbl...
> I would think you'd want to call DrawSquare() in your WM_PAINT handler for
> the dialog.
>
> -Jayme
>
> "JohnL" <hiliuzhe@hotmail.com> wrote in message
> news:uCbguBRnEHA.1248@TK2MSFTNGP09.phx.gbl...
> see
> called
>
>
|
|
|
|
|