Click here to Skip to main content
16,006,531 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get the export table of a given module Pin
22-Feb-02 22:52
suss22-Feb-02 22:52 
AnswerRe: How to get the export table of a given module Pin
Paul M Watt23-Feb-02 6:58
mentorPaul M Watt23-Feb-02 6:58 
GeneralGlobal variable in MFC Pin
22-Feb-02 21:52
suss22-Feb-02 21:52 
GeneralRe: Global variable in MFC Pin
Paul M Watt22-Feb-02 22:06
mentorPaul M Watt22-Feb-02 22:06 
GeneralRe: Global variable in MFC Pin
Nish Nishant22-Feb-02 22:22
sitebuilderNish Nishant22-Feb-02 22:22 
GeneralRe: Global variable in MFC Pin
23-Feb-02 0:10
suss23-Feb-02 0:10 
GeneralOnPaint Handling... Pin
John Cruz22-Feb-02 18:30
John Cruz22-Feb-02 18:30 
GeneralRe: OnPaint Handling... Pin
Paul M Watt22-Feb-02 22:15
mentorPaul M Watt22-Feb-02 22:15 
John Cruz wrote:
// Display the board together with the data inside it.
void CBoard::DisplayData()
{
for (int r = 0; r < mRow; r++)
for (int c = 0; c < mCol; c++)
{
// sets mCell to a string
CString str = mCell[r][c];

mpDC->DrawText(str,mpGrid[r][c],
DT_SINGLELINE | DT_CENTER | DT_VCENTER); }
}
and on my CChildView here is what i did...
void CChildView::OnPaint()
{
mpBoard->DisplayBoard();
}


What you have done is perfectly fine, however there is one mistake. If I am reading your code correctly, mpDC is a DC object that you have cached inside of your Board class. Generally you should not cache DCs. Especially in the case of handling on Paint messages, you should create a new DC every time.

I would recommend code more like this:

<br />
void CBoard::DisplayData(&CPaintDC dc)<br />
{<br />
for (int r = 0; r < mRow; r++)<br />
for (int c = 0; c < mCol; c++)<br />
{<br />
// sets mCell to a string<br />
CString str = mCell[r][c];<br />
<br />
dc->DrawText(str,mpGrid[r][c],<br />
DT_SINGLELINE | DT_CENTER | DT_VCENTER); }<br />
} <br />
and on my CChildView here is what i did...<br />
void CChildView::OnPaint() <br />
{<br />
CPaintDC dc;<br />
mpBoard->DisplayBoard(dc);<br />
}<br />


Windows only generates a paint message for your window when there is an invalid region inside of that window. In regular WIN32 programming you need to call BeginPaint in your paint handler in order to create a DC that will paint on that current invalid area, and validate that area so that Windows does not turn right around and generate a new paint message.

The CPaintDC objects constructor will call BeginPaint for you, hiding this detail.

If you have any more questions, or want more detail just let me know.
GeneralRe: OnPaint Handling... Pin
John Cruz23-Feb-02 2:39
John Cruz23-Feb-02 2:39 
GeneralVC6 Macros: Object model shortcomings & bugs Pin
rseidl22-Feb-02 18:01
rseidl22-Feb-02 18:01 
GeneralRe: VC6 Macros: Object model shortcomings & bugs Pin
rseidl24-Feb-02 21:05
rseidl24-Feb-02 21:05 
GeneralReplacing one CFormView derived view with another Pin
Aaron Schaefer22-Feb-02 17:20
Aaron Schaefer22-Feb-02 17:20 
GeneralRe: Replacing one CFormView derived view with another Pin
Mazdak22-Feb-02 22:01
Mazdak22-Feb-02 22:01 
GeneralSelectObject(HBITMAP) problem. Pin
22-Feb-02 16:49
suss22-Feb-02 16:49 
GeneralRe: SelectObject(HBITMAP) problem. Pin
Paul M Watt22-Feb-02 18:21
mentorPaul M Watt22-Feb-02 18:21 
GeneralRe: SelectObject(HBITMAP) problem. Pin
23-Feb-02 12:27
suss23-Feb-02 12:27 
GeneralRe: SelectObject(HBITMAP) problem. Pin
Paul M Watt23-Feb-02 16:07
mentorPaul M Watt23-Feb-02 16:07 
GeneralProgrammatically Send a menu command Pin
Aaron Schaefer22-Feb-02 16:18
Aaron Schaefer22-Feb-02 16:18 
GeneralRe: Programmatically Send a menu command Pin
Michael Dunn22-Feb-02 16:26
sitebuilderMichael Dunn22-Feb-02 16:26 
GeneralRe: Programmatically Send a menu command Pin
22-Feb-02 16:32
suss22-Feb-02 16:32 
Generalwriting to a file Pin
Steve L.22-Feb-02 14:32
Steve L.22-Feb-02 14:32 
GeneralRe: writing to a file Pin
22-Feb-02 16:29
suss22-Feb-02 16:29 
QuestionResource ID for standard "drop" cursor? Pin
David Fleming22-Feb-02 12:14
David Fleming22-Feb-02 12:14 
AnswerRe: Resource ID for standard "drop" cursor? Pin
Henry Jacobs22-Feb-02 12:58
Henry Jacobs22-Feb-02 12:58 
GeneralAnother MFC Doc/View Question Pin
Aaron Schaefer22-Feb-02 11:22
Aaron Schaefer22-Feb-02 11:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.