Changing static text in dialog box at runtime

I have created a dialog box and linked it to the menu item. In this case the menu item is Help -> Statistics. It all works. So when I run the program, click on the menu Help, then Statistics, a dialog box pops up.

I also have a static text box in the dialog box. How do you change the text of this static text box at runtime?

P.S: Though I have a dialog box up and running, I do not have the handle for the dialog box. If any of your solutions involve knowing the handle to the dialog box, please tell me how to retrieve it. Thanks.


class CStatisticsDlg : public CDialogEx

// Dialog Data
    enum { IDD = IDD_STATISTICS };

    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation

CStatisticsDlg::CStatisticsDlg() : CDialogEx(CStatisticsDlg::IDD)

void CStatisticsDlg::DoDataExchange(CDataExchange* pDX)

BEGIN_MESSAGE_MAP(CStatisticsDlg, CDialogEx)


  1. In Class Wizard, create a CString member variable for the label. Note: by default, labels don't have a custom id so you have to give it one like IDC_MY_LABEL.
  2. Somewhere before showing the dialog call m_strMyLabel.SetWindowText("blah");

If you need to do it while the dialog is open you have to call UpdateData(FALSE)

Edit: if you don't want to create a member variable you can **corrected - typing from memory....

// Find the label
// if called from within CStatusDlg class
CWnd *label = GetDlgItem(IDC_MY_LABEL);

// If called from elsewhere
CStatusDlg dlg.....  // create the dialog
CWnd *label = dlg.GetDlgItem(IDC_MY_LABEL);

Need Your Help

How can I make SimpleCV show image?

python simplecv

I am using the following code from Simple CV tutorial