更新时间:2023-02-14 23:15:26
您好,如果我理解正确,您正在尝试创建一个动态数字标签控件。
我目前没有CStaticEx课程的来源,但我可以帮助你完成。
首先,放一个数组在头文件中的类,我推荐CPtrArray或CPtrList。CPtrArray m_StaticArray;
然后你必须在添加CStaticEx之前添加一个新的和Create()的调用。int nXaxis,nYaxis;
nXaxis = 0;
nYaxis = 0;
for(int i = 0; i< nNumOfCamAttch; i ++){
CRect rect(nXaxis + X_PADDING,nYaxis + Y_PADDING,nXaxis + WIDTH + X_PADDING,HEIGHT + Y_PADDING);
nXaxis = X_PADDING + WIDTH + nXaxis;
CStaticEx * pStaticCtrl = new CStaticEx;
pStaticCtrl->创建(_T(文本),WS_CHILD | WS_VISIBLE,rect,this,nID);
m_StaticArray.Add(pStaticCtrl);
}
然后,记得清理它。在你的OnDestroy()处理程序中:while(m_StaticArray.GetSize()> 0)
{
CStaticEx * pCtrl =(CStaticEx *)m_StaticArray.GetAt(0);
m_StaticArray.RemoveAt(0);
pCtrl-> DestroyWindow();
删除pCtrl;
}
我希望这会有所帮助,如果我的目标错了,请告诉我,我会帮助
I have problem when creating the CArray of the object.
On compiling the code i get following error.
>c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxwin.h(1986):error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'
CArray< CStaticEx, CStaticEx> m_objStaticExArr;
m_objStaticExArr.SetSize(nNumOfCamAttch);
int nXaxis,nYaxis;
nXaxis = 0;
nYaxis = 0 ;
//CStaticEx objStaticEx;
for(int i=0; i < nNumOfCamAttch ; i++){
CRect rect(nXaxis + X_PADDING, nYaxis + Y_PADDING , nXaxis + WIDTH + X_PADDING , HEIGHT + Y_PADDING);
nXaxis = X_PADDING + WIDTH + nXaxis ;
m_objStaticExArr.Add(CStaticEx(rect, this));
}
What may be the problem in the above code. Please let me know.
Thanks in advance.
Hello, if I understand correctly, you are trying to create a dynamic number of label controls.
I currently do not have the source to the CStaticEx class but I can help you through.
First, put an array class in your header file, I recommend CPtrArray or CPtrList.CPtrArray m_StaticArray;
Then you will have to add a new and a call to Create() before adding your CStaticEx(s).int nXaxis,nYaxis; nXaxis = 0; nYaxis = 0; for(int i=0; i < nNumOfCamAttch; i++){ CRect rect(nXaxis + X_PADDING, nYaxis + Y_PADDING , nXaxis + WIDTH + X_PADDING , HEIGHT + Y_PADDING); nXaxis = X_PADDING + WIDTH + nXaxis ; CStaticEx* pStaticCtrl = new CStaticEx; pStaticCtrl->Create(_T("Text"), WS_CHILD|WS_VISIBLE, rect, this, nID); m_StaticArray.Add(pStaticCtrl); }
Then, remember to clean it up. In your OnDestroy() handler:while(m_StaticArray.GetSize() > 0) { CStaticEx* pCtrl = (CStaticEx*)m_StaticArray.GetAt(0); m_StaticArray.RemoveAt(0); pCtrl->DestroyWindow(); delete pCtrl; }
I hope this helps, if I got your goal wrong please let me know and I will help.