何时调用框架函数CFrameWnd* CWnd::GetParentFrame() const

gaoxiaofeng 2000-05-23 08:12:00
我的程序中有在图像中采样本的要求,我原先用现采现用的办法,程序通过,但如果样本数据从文件中读出,则会“框架函数CFrameWnd* CWnd::GetParentFrame() const”出错。
出错行用********标出:
CFrameWnd* CWnd::GetParentFrame() const
{
if (GetSafeHwnd() == NULL) // no Window attached
return NULL;

ASSERT_VALID(this);

CWnd* pParentWnd = GetParent(); // start with one parent up
while (pParentWnd != NULL)
{
************** if (pParentWnd->IsFrameWnd()) ************光标停留在此
return (CFrameWnd*)pParentWnd;
pParentWnd = pParentWnd->GetParent();
}
return NULL;
}
...全文
230 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
元明 2000-08-29
  • 打赏
  • 举报
回复
attention
loutingyv 2000-05-26
  • 打赏
  • 举报
回复
问题出在 CWnd* pParentWnd = GetParent();
如果给为 CFrameWnd * pParentWnd
pParentWnd =(CFrameWnd *)GetParent();
应该没问题



gaoxiaofeng 2000-05-24
  • 打赏
  • 举报
回复
哪位老兄有空帮我看看?谢谢!
fjp 2000-05-23
  • 打赏
  • 举报
回复
GetParentFrame()返回指向父框架窗口的指针。
IsFrameWnd()是虚函数,当对象是框架窗口时返回TRUE,否则返回FALSE.
可能是你的窗口不是框架窗口才出错。
GetParentFrame()一般用在View中,返回包围View的框架窗口的指针。
例如:
void CEx5View::OnRButtonDown(UINT nFlags, CPoint point)
{
// CView::OnRButtonDown(nFlags, point);
CWnd *pWnd = GetParentFrame() ;
ASSERT(pWnd!=NULL) ;
pWnd->SetWindowText("Main!!!!!") ;
}
gaoxiaofeng 2000-05-23
  • 打赏
  • 举报
回复
void CRsgisView::OnJuli()
{
// TODO: Add your command handler code here


//fenlei在次一下

CFileDialog fenleis(TRUE,"*.vec",NULL,OFN_HIDEREADONLY and OFN_OVERWRITEPROMPT,"样本文件(*.vec) and *.vec and 所有文件(*.*) and *.* and and ",this);
if(fenleis.DoModal()==IDOK)
{
CString name=fenleis.GetFileName();
CFile file;
file.Open(name,CFile::modeReadWrite,NULL);
int sample=file.GetLength()/40-1;
int i,j,k;
float *bian;
bian = new float[(sample+1)*3];
CRsgisDoc* pDoc=GetDocument();
BYTE* jiandu0=(BYTE*)pDoc->DibBits;
sizes=pDoc->size;
jiandu1=(BYTE*)new char[sizes];
for(k=0;k<sizes+1;k++)
jiandu1[k]=jiandu0[k];
flags=3;
add=0;
float temp;
for(i=0;i<sample+1;i++)
{
for(j=0;j<9;j++)
{
file.Read(&temp,4);
bian[i*9+j]=temp;
}
int temp2;
file.Read(&temp2,4);
id[i]=temp2;
}
file.Close();
float dix1=0,dix;int lei=0;
int n0=0,n1=0,n2=0,n3=0,n4=0,n5=0;
for(i=0;i<pDoc->DibInfo->bmiHeader.biHeight;i++)
for(int j=0;j<pDoc->DibInfo->bmiHeader.biWidth;j++)
{
int n=i*pDoc->bytes_per_line+j*3;
dix=100000000;
for(k=0;k<sample+1;k++)
{
dix1=(jiandu1[n]-bian[k*9])*(jiandu1[n]-bian[k*9])+(jiandu1[n+1]-bian[k*9+1])*(jiandu1[n+1]-bian[k*9+1])+(jiandu1[n+2]-bian[k*9+2])*(jiandu1[n+2]-bian[k*9+2]);
if(dix1<dix)
{
dix=dix1;
lei=k;
}
}
int t=id[lei];
int cla=t;

switch(cla)
{
case 0:jiandu1[n+1]=255,jiandu1[n]=jiandu1[n+2]=0;n0++;break;
case 1:jiandu1[n+2]=255,jiandu1[n]=jiandu1[n+1]=0;n1++;break;
case 2:jiandu1[n]=255,jiandu1[n+2]=jiandu1[n+1]=0;n2++;break;
case 3:jiandu1[n+2]=jiandu1[n+1]=255;jiandu1[n]=0;n3++;break;
case 4:jiandu1[n+2]=jiandu1[n]=0;jiandu1[n+1]=0;n4++;break;
case 5:jiandu1[n+1]=jiandu1[n]=255;jiandu1[n+2]=0;n5++;break;
default:jiandu1[n]=jiandu1[n+1]=jiandu1[n+2]=255;
}

}
int test=0;
Invalidate();

}

}









原先的程序是:
void CRsgisView::OnJuli()
{
// TODO: Add your command handler code here
int geshu=0;
CPtrArray all;
add=0;int size[20];
int i,j,k,m;
CPoint *begin;
int total;
float *bian;
bian = new float[(sample+1)*3];
for(m=0;m<sample+1;m++)
{
total=0;
size[m]=0;
for(k=0;k<m;k++)
total+=s[k];
begin=(CPoint*)m_mouseposition[total];
int minx=begin->x,maxx=begin->x,miny=begin->y,maxy=begin->y;
for(i=1;i<s[m];i++)
{
begin=(CPoint*)m_mouseposition[total+i];
if(begin->x<minx)
minx=begin->x;
if(begin->x>maxx)
maxx=begin->x;
if(begin->y<miny)
miny=begin->y;
if(begin->y>maxy)
maxy=begin->y;
}
CRgn poly;

CPoint *dian;
dian=(CPoint*)new char[s[m]*20];
for(i=0;i<s[m];i++)
dian[i]=*(CPoint*)m_mouseposition[total+i];

// poly.CreatePolygonRgn(ptr,s[0],1);
poly.CreatePolygonRgn(dian,s[m],1);

CPoint temp;
BeginWaitCursor();
for(i=minx;i<maxx+1;i++)
for(j=miny;j<maxy+1;j++)
{

if(PtInRegion(poly,i,j))
{


temp.x=i;temp.y=j;
CPoint *pnewpoint=new CPoint(temp);
all.Add((void*)pnewpoint);
size[m]+=1;
geshu+=1;

}
}
EndWaitCursor();
delete [] dian;
// char mm[10];
// _itoa(m,mm,10);AfxMessageBox(mm);
// _itoa(size[m],mm,10);AfxMessageBox(mm);
// _itoa(id[m],mm,10);AfxMessageBox(mm);
// _itoa(geshu,mm,10);AfxMessageBox(mm);
}
//*****将各点都读入all数组,各多边形的点的个数为size[m]

CPoint *tmp;int n;
CRsgisDoc* pDoc=GetDocument();
BYTE* jiandu0=(BYTE*)pDoc->DibBits;
sizes=pDoc->size;
jiandu1=(BYTE*)new char[sizes];
for(k=0;k<sizes+1;k++)
jiandu1[k]=jiandu0[k];
flags=3;
float p1,p2,p3;
total=0;
for(i=0;i<sample+1;i++)
{
//total=0;
// for(k=0;k<i;k++)
//total+=size[k];
if(i>0) total+=size[i-1];
int zong1=0,zong2=0,zong3=0;
for(j=0;j<size[i];j++)
{
tmp=(CPoint*)all[total+j];
n=(pDoc->DibInfo->bmiHeader.biHeight-tmp->y-1)*pDoc->bytes_per_line+tmp->x*3;
zong1+=jiandu1[n];zong2+=jiandu1[n+1];
zong3+=jiandu1[n+2];

}
p1=(float)zong1/(float)size[i];p2=(float)zong2/(float)size[i];p3=(float)zong3/(float)size[i];
bian[i*3]=p1;bian[i*3+1]=p2;bian[i*3+2]=p3;
}
CPoint *ppoint;
int n_size=all.GetSize();
for(i=0;i<n_size;i++)
{
ppoint=(CPoint*)all[i];
delete ppoint;
}
all.RemoveAll();

float dix1=0,dix;int lei=0;;
for(i=0;i<pDoc->DibInfo->bmiHeader.biHeight;i++)
for(int j=0;j<pDoc->DibInfo->bmiHeader.biWidth;j++)
{
int n=i*pDoc->bytes_per_line+j*3;
dix=100000000;
for(k=0;k<sample+1;k++)
{
dix1=(jiandu1[n]-bian[k*3])*(jiandu1[n]-bian[k*3])+(jiandu1[n+1]-bian[k*3+1])*(jiandu1[n+1]-bian[k*3+1])+(jiandu1[n+2]-bian[k*3+2])*(jiandu1[n+2]-bian[k*3+2]);
if(dix1<dix)
{
dix=dix1;
lei=k;
}
}
int t=id[lei];
int cla=t;
int n0=0,n1=0,n2=0,n3=0,n4=0,n5=0;
switch(cla)
{
case 0:jiandu1[n+1]=255,jiandu1[n]=jiandu1[n+2]=0;n0++;break;
case 1:jiandu1[n+2]=255,jiandu1[n]=jiandu1[n+1]=0;n1++;break;
case 2:jiandu1[n]=255,jiandu1[n+2]=jiandu1[n+1]=0;n2++;break;
case 3:jiandu1[n+2]=jiandu1[n+1]=255;jiandu1[n]=0;n3++;break;
case 4:jiandu1[n+2]=jiandu1[n]=0;jiandu1[n+1]=0;n4++;break;
case 5:jiandu1[n+1]=jiandu1[n]=255;jiandu1[n+2]=0;n5++;break;
default:jiandu1[n]=jiandu1[n+1]=jiandu1[n+2]=255;

}

}
Invalidate();
}
fjp 2000-05-23
  • 打赏
  • 举报
回复
能否看看你的程序?
gaoxiaofeng 2000-05-23
  • 打赏
  • 举报
回复
为什么会不是框架窗口呢?

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧