Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Arrays

Arrays

Scheduled Pinned Locked Moved C / C++ / MFC
data-structures
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    babamara
    wrote on last edited by
    #1

    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.

    CPalliniC E M B 4 Replies Last reply
    0
    • B babamara

      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.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      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]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • B babamara

        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.

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #3

        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[^]

        1 Reply Last reply
        0
        • B babamara

          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.

          M Offline
          M Offline
          Maxwell Chen
          wrote on last edited by
          #4

          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 type CDialog* needs to be new -ed. 3) The for loop shall check the actual size of the array by calling CArray::GetCount. That is,

          for(int nCount=0; nCount < dlgArray.GetCount(); nCount++)


          Maxwell Chen

          1 Reply Last reply
          0
          • B babamara

            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.

            B Offline
            B Offline
            babamara
            wrote on last edited by
            #5

            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

            M 1 Reply Last reply
            0
            • B babamara

              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

              M Offline
              M Offline
              Maxwell Chen
              wrote on last edited by
              #6

              babamara wrote:

              dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());

              1. 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 for CDialog::Create should be this, not GetParent. 3) Make sure the dialogboxes to be held in the tab control have the property "child window".

              Maxwell Chen

              B 1 Reply Last reply
              0
              • M Maxwell Chen

                babamara wrote:

                dlgArray.GetAt(nCount)->Create(m_DialogPages[nCount],GetParent());

                1. 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 for CDialog::Create should be this, not GetParent. 3) Make sure the dialogboxes to be held in the tab control have the property "child window".

                Maxwell Chen

                B Offline
                B Offline
                babamara
                wrote on last edited by
                #7

                Thank you. I change GetParent with this and this solves the probelm. Now I am going to check why the dialog are not shown in my Tab Control.

                M 1 Reply Last reply
                0
                • B babamara

                  Thank you. I change GetParent with this and this solves the probelm. Now I am going to check why the dialog are not shown in my Tab Control.

                  M Offline
                  M Offline
                  Maxwell Chen
                  wrote on last edited by
                  #8

                  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

                  B 1 Reply Last reply
                  0
                  • M 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

                    B Offline
                    B Offline
                    babamara
                    wrote on last edited by
                    #9

                    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); }

                    M CPalliniC 2 Replies Last reply
                    0
                    • B babamara

                      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); }

                      M Offline
                      M Offline
                      Maxwell Chen
                      wrote on last edited by
                      #10

                      babamara wrote:

                      dlgArray[nCount]->SetWindowPos(&wndTop+21, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW);

                      1. Which target does &wndTop+21 point to? 2) Since you've invoked CWnd::SetWindowPos with the flag SWP_SHOWWINDOW, there is no need to invoke CWnd::ShowWindow(SW_SHOW) again.

                      Maxwell Chen

                      1 Reply Last reply
                      0
                      • B babamara

                        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); }

                        CPalliniC Offline
                        CPalliniC Offline
                        CPallini
                        wrote on last edited by
                        #11

                        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]

                        In testa che avete, signor di Ceprano?

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups