有个程序,通过在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);
}
}
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);
}
}
BOOL CDeflineDlg::OnInitDialog()
函数中的这一句CWnd *pWnd=(CWnd*)this->GetDlgItem(IDC_PIC);有什么作用?
pWnd = (CWnd*)this->GetDlgItem(IDC_PIC);
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
第三个警告很严重,sx需要初始化。
另外,还有个常识问题,GetDC();必需与ReleaseDC函数成对出现。
如果你愿意等的话,把工程发到[email protected],我今天晚上抽时间给你看看,很简单的问题。
CDC dc("控减对象");
在dc上操作