Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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;
}

}




Report this thread to moderator Post Follow-up to this message
Old Post
JohnL
09-18-04 02:00 AM


Re: Copy a bitmap from the source device context to this current device context.
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;
> }
>
> }
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Jayme Pechan
09-18-04 02:00 AM


Re: Copy a bitmap from the source device context to this current device context.
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 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
JohnL
09-20-04 09:02 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Studio archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:12 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.