下面是我写的一小段程序,想在对话框上显示文本,程序正常运行了,但是没有显示文本,希望大家帮我指出错误:
GetClientRect(&rect);
pot=rect.CenterPoint();
CString string;
string.Format("%d,%d",pot.x,pot.y);
CClientDC pDC(this);
pDC.TextOut(10,10,string);

解决方案 »

  1.   

    你上面的代码放在哪里呢?最好把你绘图的代码放在OnPaint函数中去做~
      

  2.   

    刷没了,放在OnPaint函数里,每次刷新都会重绘
      

  3.   

    对话框程序的oncreate根本不会调用OnIniDialog也不行,因为后面还会把你写的字覆盖掉正确的应该在OnPaint里
      

  4.   

    我放在OnPaint里,但是文本还是没显示呀
      

  5.   

    OnPaint函数,我编写的代码应该加在哪里?
    void CDirectionDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }

    }
      

  6.   

    OnPaint函数,我编写的代码应该加在哪里?
    ===========
    放在else里面,CDialog::OnPaint的前面。
      

  7.   

    在OnPaint中,
    是使用CPaintDC的,而不是用CClientDC
      

  8.   

    解决了,我在对话框上加了一个文本框,再用SetWindowText函数显示文本
      

  9.   

    我也只会这个方法...不过看你们上面讨论那么激烈的OnPaint函数是view还是对话框啊
      

  10.   

    void CDirectionDlg::OnPaint()  
    {
    CPaintDC dc(this); // device context for painting///////放到外边试试if (IsIconic())
    {SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;// Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }}
      

  11.   

    static_cast<CEdit*>(GetDlgItem(IDC_EDIT))->SetWindowsText(cstring);