有个程序,通过在vc对话框中添加图片框控件,可以在图片框中绘图.现在的问题是,程序的执行文件错误,程序如下,请各位帮帮忙!
BOOL CDeflineDlg::OnInitDialog()
{
CDialog::OnInitDialog();
         CWnd *pWnd=(CWnd*)this->GetDlgItem(IDC_PIC); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE;  // return TRUE  unless you set the focus to a control
}
////
void CDeflineDlg::OnPic() 
{
// TODO: Add your control notification handler code here
    ///CWnd *pWnd=GetdlgItem(IDC_PIC);
  
pWnd->GetClientRect(&rect);
int w=rect.Width();
int h=rect.Height();
CDC *pDC=pWnd->GetDC();
int sx,lx,sy,ly,xt,yt;
///sx=1,lx=4,sy=1,ly=4; ///下面绘制坐标轴
pDC->MoveTo(0.1*w,0.1*h);
pDC->LineTo(0.1*w,0.9*h);
pDC->LineTo(0.9*w,0.9*h); ///坐标变换
int arrayx[4]={1,2,3,4};
int arrayy[4]={1,2,3,4};
int k=0;
xt=0.8*w*(arrayx[k]-sx)/(lx-sx)+0.1*w;
yt=0.9*h-0.8*h*(arrayy[k]-sy)/(ly-sy);
pDC->MoveTo(xt,yt);
for(k=1;k<4;k++)
{
xt=0.8*w*(arrayx[k]-sx)/(lx-sx)+0.1*w;
yt=0.9*h-0.8*h*(arrayy[k]-sy)/(ly-sy);
    pDC->MoveTo(xt,yt);
}

}

解决方案 »

  1.   

    图贴不上来,程序运行以后弹出界面,我按draw按钮,弹出对话框"Define.exe遇到问题需要关闭.我们对此引起的不便表示抱歉."
      

  2.   

    void CDeflineDlg::OnPic() 函数中的pWnd赋值了吗?
    BOOL CDeflineDlg::OnInitDialog()
    函数中的这一句CWnd *pWnd=(CWnd*)this->GetDlgItem(IDC_PIC);有什么作用?
      

  3.   

    看样子pWnd应该是个成员变量,那么BOOL CDeflineDlg::OnInitDialog()应该如下写:
    pWnd = (CWnd*)this->GetDlgItem(IDC_PIC);
      

  4.   

    顺便提一句,GetDlgItem(IDC_PIC)的返回值不可保存下来供以后使用,应该随用随取,或者保存GetDlgItem(IDC_PIC)的m_hWnd成员,具体看MSDN。
      

  5.   

    编译以后还有这三种警告:
    warning C4244: 'argument' : conversion from 'double' to 'int', possible loss of data
    warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
    warning C4700: local variable 'sx' used without having been initialized
      

  6.   

    前两个警告可以不管,不想看到的话就强行转换成int,
    第三个警告很严重,sx需要初始化。
      

  7.   

    你的程序我没有细看,算法的问题是你的事,你要保证绘制的线条在窗口之内,而且,你应该在对话框的OnPaint函数里面绘制,因为当窗口刷新后,windows是不会自动去调用OnPic()函数的。
    另外,还有个常识问题,GetDC();必需与ReleaseDC函数成对出现。
    如果你愿意等的话,把工程发到[email protected],我今天晚上抽时间给你看看,很简单的问题。
      

  8.   

    你骆语句下面试一下:
               
                     CDC dc("控减对象");
                       在dc上操作