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. Slider Control Why do I need CDialog::OnInitDialog();

Slider Control Why do I need CDialog::OnInitDialog();

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 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.
  • J Offline
    J Offline
    jerry1211a
    wrote on last edited by
    #1

    I used the code below to create a slider control. I tried to put the code into another initialize function of my own but it wouldnt work. Can the code be put into another function? What I really dont understand is why do I need to include: CDialog::OnInitDialog()...to make the project run? Without it I get a run time error condition. Jerry :) /////////////////////////////////////////////////////////////Create slider control here BOOL dialogWnd::OnInitDialog() { CDialog::OnInitDialog(); CWnd* pWnd = GetDlgItem(IDC_SLIDER1); CRect rect; pWnd->GetWindowRect( &rect ); ScreenToClient( &rect ); m_Slider.Create( WS_VISIBLE|WS_CHILD|TBS_HORZ, rect, this, IDC_SLIDER1 ); return TRUE; }

    L D 2 Replies Last reply
    0
    • J jerry1211a

      I used the code below to create a slider control. I tried to put the code into another initialize function of my own but it wouldnt work. Can the code be put into another function? What I really dont understand is why do I need to include: CDialog::OnInitDialog()...to make the project run? Without it I get a run time error condition. Jerry :) /////////////////////////////////////////////////////////////Create slider control here BOOL dialogWnd::OnInitDialog() { CDialog::OnInitDialog(); CWnd* pWnd = GetDlgItem(IDC_SLIDER1); CRect rect; pWnd->GetWindowRect( &rect ); ScreenToClient( &rect ); m_Slider.Create( WS_VISIBLE|WS_CHILD|TBS_HORZ, rect, this, IDC_SLIDER1 ); return TRUE; }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Is your question why does OnInitDialog() exist or why you call it there ? OnInitdialog contains initialisation code that is required by a number of functions such as Create() and DoModal(). As to why call it, your derived OnInitDialog() must call the base class function to use this code. It's that or write it again yourself. Elaine :rose: The tigress is here :-D

      1 Reply Last reply
      0
      • J jerry1211a

        I used the code below to create a slider control. I tried to put the code into another initialize function of my own but it wouldnt work. Can the code be put into another function? What I really dont understand is why do I need to include: CDialog::OnInitDialog()...to make the project run? Without it I get a run time error condition. Jerry :) /////////////////////////////////////////////////////////////Create slider control here BOOL dialogWnd::OnInitDialog() { CDialog::OnInitDialog(); CWnd* pWnd = GetDlgItem(IDC_SLIDER1); CRect rect; pWnd->GetWindowRect( &rect ); ScreenToClient( &rect ); m_Slider.Create( WS_VISIBLE|WS_CHILD|TBS_HORZ, rect, this, IDC_SLIDER1 ); return TRUE; }

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        The bigger question is why are you creating the slider control at run-time?


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        J 1 Reply Last reply
        0
        • D David Crow

          The bigger question is why are you creating the slider control at run-time?


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          J Offline
          J Offline
          jerry1211a
          wrote on last edited by
          #4

          I wasnt sure how else to do it. I have many objects of type dlg that may or may not contain a dialog with a slider. I was attempting to create a slider dynamically only if the dialog window needed it...depending on the requirements. I dont know if I am explaining it very well, but thanks for your help. :) Jerry

          D 1 Reply Last reply
          0
          • J jerry1211a

            I wasnt sure how else to do it. I have many objects of type dlg that may or may not contain a dialog with a slider. I was attempting to create a slider dynamically only if the dialog window needed it...depending on the requirements. I dont know if I am explaining it very well, but thanks for your help. :) Jerry

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            There are a few situations where a control created at run-time makes sense but this is not one of them. Add the control to the dialog's template, create a member control variable for it, and then put the following in the dialog's OnInitDialog() method:

            BOOL dialogWnd::OnInitDialog()
            {
            CDialog::OnInitDialog();

            if (some\_condition)
            {
                m\_Slider.ShowWindow(SW\_SHOWNORMAL);
                m\_Slider.EnableWindow(TRUE);
            }
            else if (some\_other\_condition)
            {
                m\_Slider.ShowWindow(SW\_HIDE);
                m\_Slider.EnableWindow(FALSE);
            }
            
            return TRUE;
            

            }

            Why disable a hidden control? Some folks assume that once a control is hidden, it can no longer be interacted with. Wrong. A hidden control can still receive input focus, even if you can't see it.


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            J 1 Reply Last reply
            0
            • D David Crow

              There are a few situations where a control created at run-time makes sense but this is not one of them. Add the control to the dialog's template, create a member control variable for it, and then put the following in the dialog's OnInitDialog() method:

              BOOL dialogWnd::OnInitDialog()
              {
              CDialog::OnInitDialog();

              if (some\_condition)
              {
                  m\_Slider.ShowWindow(SW\_SHOWNORMAL);
                  m\_Slider.EnableWindow(TRUE);
              }
              else if (some\_other\_condition)
              {
                  m\_Slider.ShowWindow(SW\_HIDE);
                  m\_Slider.EnableWindow(FALSE);
              }
              
              return TRUE;
              

              }

              Why disable a hidden control? Some folks assume that once a control is hidden, it can no longer be interacted with. Wrong. A hidden control can still receive input focus, even if you can't see it.


              "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

              J Offline
              J Offline
              jerry1211a
              wrote on last edited by
              #6

              Thanks...I am a SW Eng and sometimes I really struggle with MFC. Is there a place where I can get a sample dialog program that really explains all the intricate details of what is going on?? I like stepping through all the code to really understand what is happening. You gave me some good ideas... Have a good day. Jerry

              D 1 Reply Last reply
              0
              • J jerry1211a

                Thanks...I am a SW Eng and sometimes I really struggle with MFC. Is there a place where I can get a sample dialog program that really explains all the intricate details of what is going on?? I like stepping through all the code to really understand what is happening. You gave me some good ideas... Have a good day. Jerry

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                jerry1211a wrote: Is there a place where I can get a sample dialog program that really explains all the intricate details of what is going on?? Just keep plugging away at it. Come up with a (small) problem, and then create a little application to solve it. When I started using MFC back in 1993, I created dialog-based applications exclusively. The concept of a document and a view made no sense to me. It was not until the late 90s that the light bulb came on. Once I had a grasp of what role the document and view played, it opened up other possibilities.


                "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                J 1 Reply Last reply
                0
                • D David Crow

                  jerry1211a wrote: Is there a place where I can get a sample dialog program that really explains all the intricate details of what is going on?? Just keep plugging away at it. Come up with a (small) problem, and then create a little application to solve it. When I started using MFC back in 1993, I created dialog-based applications exclusively. The concept of a document and a view made no sense to me. It was not until the late 90s that the light bulb came on. Once I had a grasp of what role the document and view played, it opened up other possibilities.


                  "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                  J Offline
                  J Offline
                  jerry1211a
                  wrote on last edited by
                  #8

                  Ok sounds like a good plan. Jerry

                  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