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. How to hide or show button from another class MFC vc++

How to hide or show button from another class MFC vc++

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
7 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
    Member_14575556
    wrote on last edited by
    #1

    How can I access controls of one class from another class. Example, Initially the button is hidden. I tried to make it visible from another class by doing like this

    GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);

    inside a function. But this doesn't seem to work. How can I make it visible from another class. Thanks in advance.

    V D 2 Replies Last reply
    0
    • M Member_14575556

      How can I access controls of one class from another class. Example, Initially the button is hidden. I tried to make it visible from another class by doing like this

      GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);

      inside a function. But this doesn't seem to work. How can I make it visible from another class. Thanks in advance.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Member 14575556 wrote:

      But this doesn't seem to work.

      What exactly "doesn't seem to work"? Could you show your code?

      M 1 Reply Last reply
      0
      • V Victor Nijegorodov

        Member 14575556 wrote:

        But this doesn't seem to work.

        What exactly "doesn't seem to work"? Could you show your code?

        M Offline
        M Offline
        Member_14575556
        wrote on last edited by
        #3

        There are two button in Dialog 1.

        BOOL CMyFirstDlg::OnInitDialog()
        {
        CDialogEx::OnInitDialog();
        GetDlgItem(IDC_BUTTON)->ShowWindow(FALSE);

        ShowWindow(SW_MINIMIZE);

        return TRUE;
        }

        When I click one button i want to make the other button visible again.

        void CMyFirstDlg::OnBnClickedButton()
        {
        CSecondDlg* Obj = new CSecondDlg();
        Obj->DisplayButton();
        }

        Inside the DisplayButton function which is in another class there is

        GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);

        V D 2 Replies Last reply
        0
        • M Member_14575556

          There are two button in Dialog 1.

          BOOL CMyFirstDlg::OnInitDialog()
          {
          CDialogEx::OnInitDialog();
          GetDlgItem(IDC_BUTTON)->ShowWindow(FALSE);

          ShowWindow(SW_MINIMIZE);

          return TRUE;
          }

          When I click one button i want to make the other button visible again.

          void CMyFirstDlg::OnBnClickedButton()
          {
          CSecondDlg* Obj = new CSecondDlg();
          Obj->DisplayButton();
          }

          Inside the DisplayButton function which is in another class there is

          GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Member 14575556 wrote:

          When I click one button i want to make the other button visible again.

          void CMyFirstDlg::OnBnClickedButton()
          {
          CSecondDlg* Obj = new CSecondDlg();
          Obj->DisplayButton();
          }

          You created the object of CSecondDlg class but you have not created the window of this dialog!

          1 Reply Last reply
          0
          • M Member_14575556

            How can I access controls of one class from another class. Example, Initially the button is hidden. I tried to make it visible from another class by doing like this

            GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);

            inside a function. But this doesn't seem to work. How can I make it visible from another class. Thanks in advance.

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

            Member 14575556 wrote:

            How can I access controls of one class from another class.

            Your question should probably be something like, "How can I access controls on one dialog from a separate dialog?" While it is not a good idea to do so directly (see "loose coupling"), a better way would be to send a message to the parent (the one that owns the control) dialog.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            M 1 Reply Last reply
            0
            • M Member_14575556

              There are two button in Dialog 1.

              BOOL CMyFirstDlg::OnInitDialog()
              {
              CDialogEx::OnInitDialog();
              GetDlgItem(IDC_BUTTON)->ShowWindow(FALSE);

              ShowWindow(SW_MINIMIZE);

              return TRUE;
              }

              When I click one button i want to make the other button visible again.

              void CMyFirstDlg::OnBnClickedButton()
              {
              CSecondDlg* Obj = new CSecondDlg();
              Obj->DisplayButton();
              }

              Inside the DisplayButton function which is in another class there is

              GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);

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

              Member 14575556 wrote:

              CSecondDlg* Obj = new CSecondDlg(); Obj->DisplayButton();

              See here.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              • D David Crow

                Member 14575556 wrote:

                How can I access controls of one class from another class.

                Your question should probably be something like, "How can I access controls on one dialog from a separate dialog?" While it is not a good idea to do so directly (see "loose coupling"), a better way would be to send a message to the parent (the one that owns the control) dialog.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                M Offline
                M Offline
                Member_14575556
                wrote on last edited by
                #7

                Thank you for the pointing me to the right direction. :) I'll read about "loose coupling" and to be honest I don't really get how to send message as of now, so I'll read about that too. I've solve my problem in a naive way for now but i'll definitely follow your suggestions. Thanks again.

                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