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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Tab Control in existing dialog box

Tab Control in existing dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comtutorial
28 Posts 2 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.
  • M Mark Salsbery

    What class is this called from (which window)? EnableWindow(FALSE); pLoadingDlg = new CLoading; pLoadingDlg->Create(IDD_LOADING, this); //"this" or "GetParent()" pLoadingDlg->ShowWindow(SW_SHOW);

    A Offline
    A Offline
    acerunner316
    wrote on last edited by
    #15

    it is called from what is now a child tab window. The code worked fine as the main dialog window until i started using tabs.

    M 3 Replies Last reply
    0
    • M Mark Salsbery

      acerunner316 wrote:

      The error is "Unhandled exception in [myappname].exe (NTDLL.DLL): 0xC0000005: Access Violation."

      Right, but where? If it's not stopped on a line of your code can you view the stack trace and find the last line of your code that executed before the exception?

      A Offline
      A Offline
      acerunner316
      wrote on last edited by
      #16

      Another question, since the two tabs does very similar tasks and functions, is it possible to use the same dialog class for both tabs, but different resource dialog (ie IDD_TAB1 and IDD_TAB2 both associated with CTabDlg)? The layout will be different, but I will be reusing most of the same functions.

      M 1 Reply Last reply
      0
      • A acerunner316

        it is called from what is now a child tab window. The code worked fine as the main dialog window until i started using tabs.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #17

        Does this work? CRect MainDialogRect, LoadDialogRect; GetParent()->GetClientRect(&MainDialogRect); pLoadingDlg->GetWindowRect(&LoadDialogRect); pLoadingDlg->MoveWindow((MainDialogRect.Width() - LoadDialogRect.Width()) / 2, (MainDialogRect.Height() - LoadDialogRect.Height()) / 2, LoadDialogRect.Width(), LoadDialogRect.Height());

        1 Reply Last reply
        0
        • A acerunner316

          Another question, since the two tabs does very similar tasks and functions, is it possible to use the same dialog class for both tabs, but different resource dialog (ie IDD_TAB1 and IDD_TAB2 both associated with CTabDlg)? The layout will be different, but I will be reusing most of the same functions.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #18

          Yes it's possible. You'll need to create with the appropriate resource ID. You can also use a common base class containing the code for the controls they have in common and derive 2 classes, each with whatever code they need for the unique parts of the dialogs.

          A 1 Reply Last reply
          0
          • A acerunner316

            it is called from what is now a child tab window. The code worked fine as the main dialog window until i started using tabs.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #19

            Argg sorry - try this :) CRect MainDialogRect, LoadDialogRect; GetWindowRect(&MainDialogRect); ::MapWindowPoints(0, *this, (LPPOINT)&MainDialogRect, 2); pLoadingDlg->GetWindowRect(&LoadDialogRect); pLoadingDlg->MoveWindow((MainDialogRect.Width() - LoadDialogRect.Width()) / 2, (MainDialogRect.Height() - LoadDialogRect.Height()) / 2, LoadDialogRect.Width(), LoadDialogRect.Height()); Tab control doesn't really have a useful client rect so I've taken it's window rect (relative to the screen) and mapped it to be relative to itself. I think that will work...

            1 Reply Last reply
            0
            • A acerunner316

              it is called from what is now a child tab window. The code worked fine as the main dialog window until i started using tabs.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #20

              :laugh: Now that I think about it more, the MapWindowPoints() isn't necessary since you only need the size of the tabs control, not it's position. You can probably eliminate that call. The important part is using GetWindowRect instead of GetClientRect.

              A 1 Reply Last reply
              0
              • M Mark Salsbery

                :laugh: Now that I think about it more, the MapWindowPoints() isn't necessary since you only need the size of the tabs control, not it's position. You can probably eliminate that call. The important part is using GetWindowRect instead of GetClientRect.

                A Offline
                A Offline
                acerunner316
                wrote on last edited by
                #21

                I still get the same result with that code. But that gave me an idea. Here's what I did to fix it. CRect MainDialogRect, LoadDialogRect; GetParent()->GetWindowRect(&MainDialogRect); pLoadingDlg->GetWindowRect(&LoadDialogRect); pLoadingDlg->MoveWindow(MainDialogRect.left + ((MainDialogRect.Width() - LoadDialogRect.Width()) / 2), MainDialogRect.top + ((MainDialogRect.Height() - LoadDialogRect.Height()) / 2), LoadDialogRect.Width(), LoadDialogRect.Height()); I found that I was always getting the correct coordinates, just relative to the wrong point (screen origin vs window origin). So I added the location of the main window to the coordinates.

                M 1 Reply Last reply
                0
                • A acerunner316

                  I still get the same result with that code. But that gave me an idea. Here's what I did to fix it. CRect MainDialogRect, LoadDialogRect; GetParent()->GetWindowRect(&MainDialogRect); pLoadingDlg->GetWindowRect(&LoadDialogRect); pLoadingDlg->MoveWindow(MainDialogRect.left + ((MainDialogRect.Width() - LoadDialogRect.Width()) / 2), MainDialogRect.top + ((MainDialogRect.Height() - LoadDialogRect.Height()) / 2), LoadDialogRect.Width(), LoadDialogRect.Height()); I found that I was always getting the correct coordinates, just relative to the wrong point (screen origin vs window origin). So I added the location of the main window to the coordinates.

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #22

                  :laugh: Whatever works. Seems weird (obviously, or you would't have asked about it in the first place) that you'd get screen-relative coordinates from GetClientRect()...

                  A 1 Reply Last reply
                  0
                  • M Mark Salsbery

                    Yes it's possible. You'll need to create with the appropriate resource ID. You can also use a common base class containing the code for the controls they have in common and derive 2 classes, each with whatever code they need for the unique parts of the dialogs.

                    A Offline
                    A Offline
                    acerunner316
                    wrote on last edited by
                    #23

                    When I create a new dialog in resource editor and I use class wizard to assign an existing class to it, I get a warning that the dialog class definition is already using another resource. It asks if I want to change it to the new resource, but I don't want to change it, I want it to use both resource... Is this the correct way to do it? The 2 derived classes sounds like the best solution. I would have to remap all the controls from the existing tab window though. It will take longer, but I think in the long run, this is the better option.

                    M 1 Reply Last reply
                    0
                    • A acerunner316

                      When I create a new dialog in resource editor and I use class wizard to assign an existing class to it, I get a warning that the dialog class definition is already using another resource. It asks if I want to change it to the new resource, but I don't want to change it, I want it to use both resource... Is this the correct way to do it? The 2 derived classes sounds like the best solution. I would have to remap all the controls from the existing tab window though. It will take longer, but I think in the long run, this is the better option.

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #24

                      acerunner316 wrote:

                      Is this the correct way to do it?

                      Yeah I didn't think about how the class wizard would react :) I guess some hand-coding/rearranging will be necessary.

                      acerunner316 wrote:

                      I would have to remap all the controls from the existing tab window though

                      If you choose to go that route, use the class with the most code already in it. Copy the cpp and h files and rename to the base class name or whatever. In the files find/replace all instances of the old class name with the new name. That'll save much work.

                      A 1 Reply Last reply
                      0
                      • M Mark Salsbery

                        :laugh: Whatever works. Seems weird (obviously, or you would't have asked about it in the first place) that you'd get screen-relative coordinates from GetClientRect()...

                        A Offline
                        A Offline
                        acerunner316
                        wrote on last edited by
                        #25

                        Yeah that IS very unusual. Maybe something to do with the fact that it's a tab window. Who knows what actually goes on in the GetClientRect() function. Maybe you do, but I sure don't. :laugh: You are clearly much more experienced in VC++ than me.

                        M 1 Reply Last reply
                        0
                        • A acerunner316

                          Yeah that IS very unusual. Maybe something to do with the fact that it's a tab window. Who knows what actually goes on in the GetClientRect() function. Maybe you do, but I sure don't. :laugh: You are clearly much more experienced in VC++ than me.

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #26

                          acerunner316 wrote:

                          Maybe you do, but I sure don't.

                          Not me. :) I dug in my existing code and saw I was mapping the window rect points like that second code I posted (in my case I handle the tab control and all the associated tab windows from the tab's parent window class so it's a little different). Regardless, the MoveWindow call should move the child window relative to it's parent's client area. :wtf: Beats me!

                          1 Reply Last reply
                          0
                          • M Mark Salsbery

                            acerunner316 wrote:

                            Is this the correct way to do it?

                            Yeah I didn't think about how the class wizard would react :) I guess some hand-coding/rearranging will be necessary.

                            acerunner316 wrote:

                            I would have to remap all the controls from the existing tab window though

                            If you choose to go that route, use the class with the most code already in it. Copy the cpp and h files and rename to the base class name or whatever. In the files find/replace all instances of the old class name with the new name. That'll save much work.

                            A Offline
                            A Offline
                            acerunner316
                            wrote on last edited by
                            #27

                            The class wizard doesn't seem to allow creating a derived class from a derived class. In the Add New Class dialog box, there is no selection for user defined classes, just the standard Windows classes.

                            M 1 Reply Last reply
                            0
                            • A acerunner316

                              The class wizard doesn't seem to allow creating a derived class from a derived class. In the Add New Class dialog box, there is no selection for user defined classes, just the standard Windows classes.

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #28

                              That has to be changed by hand as far as I know. I usually derive from the known (by the class wizard) class (CDialog) and then change all the CDialog to CMyDialog. This is way easier after all the controls and control message handlers have been added using the wizard. Later, if controls are added or removed I just do it by hand, since there's already code there to copy from. It's a fact of life with an advanced UI layout :) Someday the wizards will learn from the way we do things and adapt....I hope!

                              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