Arrays
-
Hello Gurus I've stack in my try to convert this:
CDialog *m_Dialog[2];
Into this:CArray<CDialog *, CDialog *> dlgArray;
I just want to be more flexible.But when I use it by this way:for(int nCount=0; nCount < m_nPageCount; nCount++) dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
I receive an exeption. I think that my mistake is in the template, but I can't solve it. Thanks.I don't know if the mistake is in the template. It is not apparent in the posted code. I suggest you to post the exception received and other relevant code (for instance
CArray
elements assignment. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Hello Gurus I've stack in my try to convert this:
CDialog *m_Dialog[2];
Into this:CArray<CDialog *, CDialog *> dlgArray;
I just want to be more flexible.But when I use it by this way:for(int nCount=0; nCount < m_nPageCount; nCount++) dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
I receive an exeption. I think that my mistake is in the template, but I can't solve it. Thanks.For debugging this kinda code , First do like :
for(int nCount=0; nCount < m_nPageCount; nCount++) { dlgArray.GetAt(nCount); }
This confirms that you can iterate through the container without any problem. If it runs fine, then try :for(int nCount=0; nCount < m_nPageCount; nCount++) { dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent()); }
Then post the actual error message.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus Best wishes to Rexx[^]
-
Hello Gurus I've stack in my try to convert this:
CDialog *m_Dialog[2];
Into this:CArray<CDialog *, CDialog *> dlgArray;
I just want to be more flexible.But when I use it by this way:for(int nCount=0; nCount < m_nPageCount; nCount++) dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
I receive an exeption. I think that my mistake is in the template, but I can't solve it. Thanks.Because the info you provided is not enough, I can not be sure that you are doing correctly. Here is the check list for you. 1) One must add data elements into an array container, then he can enumerate the elements in the container. Getting elements from an empty container would result in access violation. 2) Before invoking
CDialog::Create
, the pointer of typeCDialog*
needs to benew
-ed. 3) Thefor
loop shall check the actual size of the array by callingCArray::GetCount
. That is,for(int nCount=0; nCount < dlgArray.GetCount(); nCount++)
Maxwell Chen
-
Hello Gurus I've stack in my try to convert this:
CDialog *m_Dialog[2];
Into this:CArray<CDialog *, CDialog *> dlgArray;
I just want to be more flexible.But when I use it by this way:for(int nCount=0; nCount < m_nPageCount; nCount++) dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
I receive an exeption. I think that my mistake is in the template, but I can't solve it. Thanks.First Thank you all for replays. I'm still stack. So I will give you additional information . Please excuse my English I still learning. First I create the Array in my header file with template, like this:
CArray<CDialog *, CDialog *> dlgArray;
Then in my .cpp file I add some data:dlgArray.Add(new CDlgSettings());
And I want to use this data by this way:m_nPageCount = 1; for(int nCount=0; nCount < m_nPageCount; nCount++) dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
My idea is to use the above code to insert dialog into Tab Control. The project is compiling without error, but when i try to open the dialog which contains the Tab Control I receive the folowing error.Asseration Failed! MyProgram: File afxwin2.inl, Line 262
modified on Sunday, January 06, 2008 3:12:48 AM
-
First Thank you all for replays. I'm still stack. So I will give you additional information . Please excuse my English I still learning. First I create the Array in my header file with template, like this:
CArray<CDialog *, CDialog *> dlgArray;
Then in my .cpp file I add some data:dlgArray.Add(new CDlgSettings());
And I want to use this data by this way:m_nPageCount = 1; for(int nCount=0; nCount < m_nPageCount; nCount++) dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
My idea is to use the above code to insert dialog into Tab Control. The project is compiling without error, but when i try to open the dialog which contains the Tab Control I receive the folowing error.Asseration Failed! MyProgram: File afxwin2.inl, Line 262
modified on Sunday, January 06, 2008 3:12:48 AM
babamara wrote:
dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
- Make sure that
m_DialogPages[nCount]
refers to a valid dialogbox resource ID. 2) Let's say, dialogbox A has a tab control. In the implementation of A, it creates some child dialogboxes. I think that the second argument forCDialog::Create
should bethis
, notGetParent
. 3) Make sure the dialogboxes to be held in the tab control have the property "child window
".
Maxwell Chen
- Make sure that
-
babamara wrote:
dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());
- Make sure that
m_DialogPages[nCount]
refers to a valid dialogbox resource ID. 2) Let's say, dialogbox A has a tab control. In the implementation of A, it creates some child dialogboxes. I think that the second argument forCDialog::Create
should bethis
, notGetParent
. 3) Make sure the dialogboxes to be held in the tab control have the property "child window
".
Maxwell Chen
- Make sure that
-
Thank you. I change
GetParent
withthis
and this solves the probelm. Now I am going to check why the dialog are not shown in my Tab Control.babamara wrote:
Now I am going to check why the dialog are not shown in my Tab Control.
Try
CDialog::ShowWindow(SW_SHOW)
.
Maxwell Chen
-
babamara wrote:
Now I am going to check why the dialog are not shown in my Tab Control.
Try
CDialog::ShowWindow(SW_SHOW)
.
Maxwell Chen
I use this function
void CPropertyTabControl::ActivateTabDialogs() { int nSel = GetCurSel(); if(dlgArray[nSel]->m_hWnd) dlgArray[nSel]->ShowWindow(SW_HIDE); CRect l_rectClient; CRect l_rectWnd; GetClientRect(l_rectClient); AdjustRect(FALSE,l_rectClient); GetWindowRect(l_rectWnd); GetParent()->ScreenToClient(l_rectWnd); l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top); for(int nCount=0; nCount < m_nPageCount; nCount++) { dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW); } dlgArray[nSel]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW); dlgArray[nSel]->ShowWindow(SW_SHOW); }
-
I use this function
void CPropertyTabControl::ActivateTabDialogs() { int nSel = GetCurSel(); if(dlgArray[nSel]->m_hWnd) dlgArray[nSel]->ShowWindow(SW_HIDE); CRect l_rectClient; CRect l_rectWnd; GetClientRect(l_rectClient); AdjustRect(FALSE,l_rectClient); GetWindowRect(l_rectWnd); GetParent()->ScreenToClient(l_rectWnd); l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top); for(int nCount=0; nCount < m_nPageCount; nCount++) { dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW); } dlgArray[nSel]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW); dlgArray[nSel]->ShowWindow(SW_SHOW); }
babamara wrote:
dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW);
- Which target does
&wndTop+21
point to? 2) Since you've invoked CWnd::SetWindowPos with the flagSWP_SHOWWINDOW
, there is no need to invokeCWnd::ShowWindow(SW_SHOW)
again.
Maxwell Chen
- Which target does
-
I use this function
void CPropertyTabControl::ActivateTabDialogs() { int nSel = GetCurSel(); if(dlgArray[nSel]->m_hWnd) dlgArray[nSel]->ShowWindow(SW_HIDE); CRect l_rectClient; CRect l_rectWnd; GetClientRect(l_rectClient); AdjustRect(FALSE,l_rectClient); GetWindowRect(l_rectWnd); GetParent()->ScreenToClient(l_rectWnd); l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top); for(int nCount=0; nCount < m_nPageCount; nCount++) { dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW); } dlgArray[nSel]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW); dlgArray[nSel]->ShowWindow(SW_SHOW); }
babamara wrote:
SetWindowPos(&wndTop+21
?!?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]