我在一个对话框类里建了一个函数如下,获取当前CWND*时会出现运行错误,不知道为什么…………大家帮忙看一下
void CfloatWnd::setPos(int OriX, int OriY, int width, int heigth)
{
::SetWindowPos(m_hWnd,NULL,OriX,OriY,0,0,SWP_NOZORDER | SWP_NOSIZE ); CWnd *pWnd;
pWnd = GetDlgItem(IDC_STATIC_floatWnd); //出现运行错误, IDC_STATIC_floatWnd为一 picture 控件ID CDC *pdc = pWnd->GetDC();
CRgn rgn;
CBrush br;
br.CreateSolidBrush(RGB(202,225,255));
rgn.CreateRoundRectRgn(0,0,width,heigth,20,20);
pdc->FillRgn(&rgn,&br);
rgn.DeleteObject();
br.DeleteObject(); pWnd->SetWindowPos( NULL,0,0,width,heigth,SWP_NOZORDER | SWP_NOMOVE );
::SetWindowPos(m_hWnd,NULL,0,0,width,heigth,SWP_NOZORDER | SWP_NOMOVE);
}
void CfloatWnd::setPos(int OriX, int OriY, int width, int heigth)
{
::SetWindowPos(m_hWnd,NULL,OriX,OriY,0,0,SWP_NOZORDER | SWP_NOSIZE ); CWnd *pWnd;
pWnd = GetDlgItem(IDC_STATIC_floatWnd); //出现运行错误, IDC_STATIC_floatWnd为一 picture 控件ID CDC *pdc = pWnd->GetDC();
CRgn rgn;
CBrush br;
br.CreateSolidBrush(RGB(202,225,255));
rgn.CreateRoundRectRgn(0,0,width,heigth,20,20);
pdc->FillRgn(&rgn,&br);
rgn.DeleteObject();
br.DeleteObject(); pWnd->SetWindowPos( NULL,0,0,width,heigth,SWP_NOZORDER | SWP_NOMOVE );
::SetWindowPos(m_hWnd,NULL,0,0,width,heigth,SWP_NOZORDER | SWP_NOMOVE);
}
你要看你的对话框资源上有没有这个ID的控件,很多时候如果你在对话框上删除了控件,其ID也会保留的。