Display text in dialog box with TextOut() 
Author Message
 Display text in dialog box with TextOut()

I want to display some timers on my dialog box. The easiest way is to put
some static boxes on the dialog, attach some variables with the wizard and
call UpdateData() when one or more timers should be updated.

But I want to do it an other way, with drawing to the dialog window.

What I did:

1) Created a couple of picture controls on the dialog.
2) Created a function Dlg::UpdateTimers()
3) Added a call in Dlg::OnPaint() to UpdateTimers()
4) In UpdateTimers() I retrieve the device context (CDC) of the picture
controles, I create a font, set the foreground color, and display the time
with TextOut()

The solution above gave me one problem:

I don't know the background color of the dialog, and I'm using the SetBkMode
( TRANSPARENT ). I thought it would be easy to send a WM_ERASEBKGND message
to the picture control windows to erase the background, but it didn't work.
What should be the best way to delete the background when a timer should be
updated?

Now I'm thinking of creating non-visible static controls, which I can place
on the dialog to indicate the position where I should display the timers.
How can I retrieve the position of these controls, so I can write to this
position (coordinates) off the dialog window?

Sample dialog:

****************************************
* Title                                                 *
****************************************
*  Event started at:  hh:mm:ss         *
*  Estimated time:    hh:mm:ss        *
*  Next event at:     hh:mm:ss          *
*  Current time:      hh:mm:ss         *
****************************************

Any suggestions welcome,

regards,

Rene Balvert
the Netherlands




Mon, 09 Jul 2001 03:00:00 GMT  
 Display text in dialog box with TextOut()
If you want the colour of the dialog try

GetSysColor(COLOR_BTNFACE)

Advertisers using spambots, please don't send to the following addresses:






























Mon, 09 Jul 2001 03:00:00 GMT  
 Display text in dialog box with TextOut()
Rene:

If you want to paint directly on the dialog (and use the picture control merely
to define the drawing area) then I think you can make it invisible in the dialog
editor and do

CMyDialog::OnPaint()
{
  CPaintDC dc(this);
  CRect rect;
  GetDlgItem(IDC_PICTURE)->GetWindowRect(&rect);
  ScreenToClient(&rect);
  // draw your picture

Quote:
}

You should remember that you are drawing in the coordinate system of the dialog,
and that the pixel size of the rectangle will depend on the font magnification
chosen by the user.

But I am also curious how to do it the other way. Your control is a static
control which would normally color itself by sending the WM_CTLCOLOR message to
its parent (the dialog). The trouble is, the way you are doing it, the static
control does not "know" it is being redrawn. Suppose you do

CWnd* pWnd=GetDlgItem(IDC_PICTURE);
pWnd->Invalidate();
pWnd->UpdateWindow();
CDC* pDC=pWnd->GetDC();
//draw here
pWnd->ReleaseDC(pDC);

before you do your drawing?

HTH,

David Wilkinson

=============

Quote:

> I want to display some timers on my dialog box. The easiest way is to put
> some static boxes on the dialog, attach some variables with the wizard and
> call UpdateData() when one or more timers should be updated.

> But I want to do it an other way, with drawing to the dialog window.

> What I did:

> 1) Created a couple of picture controls on the dialog.
> 2) Created a function Dlg::UpdateTimers()
> 3) Added a call in Dlg::OnPaint() to UpdateTimers()
> 4) In UpdateTimers() I retrieve the device context (CDC) of the picture
> controles, I create a font, set the foreground color, and display the time
> with TextOut()

> The solution above gave me one problem:

> I don't know the background color of the dialog, and I'm using the SetBkMode
> ( TRANSPARENT ). I thought it would be easy to send a WM_ERASEBKGND message
> to the picture control windows to erase the background, but it didn't work.
> What should be the best way to delete the background when a timer should be
> updated?

> Now I'm thinking of creating non-visible static controls, which I can place
> on the dialog to indicate the position where I should display the timers.
> How can I retrieve the position of these controls, so I can write to this
> position (coordinates) off the dialog window?

> Sample dialog:

> ****************************************
> * Title                                                 *
> ****************************************
> *  Event started at:  hh:mm:ss         *
> *  Estimated time:    hh:mm:ss        *
> *  Next event at:     hh:mm:ss          *
> *  Current time:      hh:mm:ss         *
> ****************************************

> Any suggestions welcome,

> regards,

> Rene Balvert
> the Netherlands





Tue, 10 Jul 2001 03:00:00 GMT  
 Display text in dialog box with TextOut()
Use GetSysColor(COLOR_BTNFACE) to retreive the normal color of the bkgnd and
override OnEraseBkgnd.
You might have a call to SetDialogBkColor setting the dialog background
color in your InitInstance, use that val if such is the case.
RGB(192,192,192) as default.

for Erase bkgnd:

BOOL CMyWnd::OnEraseBkgnd(CDC* pDC)
/*
 Mapped to the WM_ERASEBKGND windows message. The function paints the
 background if application control is on the binder screen.
 */
{
    if(pDC!=NULL)
    {
        CRect   rc;
        GetClientRect(&rc);
        CBrush bkg;

        bkg.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
        pDC->SelectObject(&bkg);
        pDC->PatBlt(0,0,rc.Width(),rc.Height(),PATCOPY);
        pDC->SelectStockObject(WHITE_BRUSH);
        bkg.DeleteObject();
    }
    return TRUE;
 }

Note that this will have to be implemented for the timer wnd. You can force
a redraw of the background for the timer wnd w RedrawWindow();

I would have gone for a normal static control every day!

Johan Rosengren
Responsable Informatique
PACTA S.A.



Tue, 10 Jul 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Can’t display text in dialog box in original format

2. White background for text displayed using CDC::TextOut(...)

3. White background for text displayed using CDC::TextOut(...)

4. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

5. White background for text displayed using CDC::TextOut(...)

6. Need help on save texts format by Textout to a text file

7. Display values in a Text Box?

8. Displaying text in an Edit Box

9. Displaying text in Edit Box

10. How to display complete long text in combo boxes

11. Wrapping text in text box or edit box

12. display text in the edit box during the excution of program

 

 
Powered by phpBB® Forum Software