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. Subclassing Dialogs

Subclassing Dialogs

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
3 Posts 3 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 Offline
    M Offline
    Mike Zinni
    wrote on last edited by
    #1

    Hey all, I've got to create 5 similar dialogs for a new app I'm writing. All 5 dialogs have the same 3 controls on them (a couple of CStatics and a CEdit control) in addition to a few controls that will be unique for each of the 5 dialogs. Is there any way to accomplish the following? - Create a base dialog (CBaseDialog), derive it from CDialog, add those 3 common controls to it. - Use that new CBaseDialog class as the base class for my 5 similar dialogs so that I don't have to copy/paste the 3 controls onto each of the 5 dialogs? I'm thinking that since the controls are created from the resource file, I might run into a problem with something like that... Thanks. -Mike -Mike Zinni "Don't take life too seriously, you'll never make it out alive" - Van Wilder

    M PJ ArendsP 2 Replies Last reply
    0
    • M Mike Zinni

      Hey all, I've got to create 5 similar dialogs for a new app I'm writing. All 5 dialogs have the same 3 controls on them (a couple of CStatics and a CEdit control) in addition to a few controls that will be unique for each of the 5 dialogs. Is there any way to accomplish the following? - Create a base dialog (CBaseDialog), derive it from CDialog, add those 3 common controls to it. - Use that new CBaseDialog class as the base class for my 5 similar dialogs so that I don't have to copy/paste the 3 controls onto each of the 5 dialogs? I'm thinking that since the controls are created from the resource file, I might run into a problem with something like that... Thanks. -Mike -Mike Zinni "Don't take life too seriously, you'll never make it out alive" - Van Wilder

      M Offline
      M Offline
      Michael Bergman
      wrote on last edited by
      #2

      Why not just host a modeless dialog box inside your main CBaseDialog? CBaseDialog _base ; CCustomDialog _custom ; _base.SetChild( &_custom ) ; _base.DoModal() ; ... BOOL CBaseDialog::OnInitDialog() { BOOL bReturn = TRUE ; CDialog::OnInitDialog(); m_pDialog->Create( this ) ; // m_pDialog is set to &_custom // create a frame resource in your CBaseDialog to host the child // dialog CRect rFrame ; CWnd * pFrame = GetDlgItem(IDC_STATIC_FRAME) ; pFrame->GetWindowRect( rFrame ) ; ScreenToClient( rFrame ) ; m_pDialog->MoveWindow(rFrame, FALSE) ; // change bReturn to FALSE if you want to set the focus // to one of the child dialog items. return bReturn ; } There is more to do such as chaining the child's DoDataExchange() in the CBaseDialog::DoDataExchange() and maintaining the dialog position in OnMouseMove() but that is a fairly trivial.

      1 Reply Last reply
      0
      • M Mike Zinni

        Hey all, I've got to create 5 similar dialogs for a new app I'm writing. All 5 dialogs have the same 3 controls on them (a couple of CStatics and a CEdit control) in addition to a few controls that will be unique for each of the 5 dialogs. Is there any way to accomplish the following? - Create a base dialog (CBaseDialog), derive it from CDialog, add those 3 common controls to it. - Use that new CBaseDialog class as the base class for my 5 similar dialogs so that I don't have to copy/paste the 3 controls onto each of the 5 dialogs? I'm thinking that since the controls are created from the resource file, I might run into a problem with something like that... Thanks. -Mike -Mike Zinni "Don't take life too seriously, you'll never make it out alive" - Van Wilder

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        Yes, it is possible. Just make sure the common controls all have the same IDs. http://www.codeproject.com/dialog/dialogsubclass.asp[^]


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        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