
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