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 create a button in cview class?

how to create a button in cview class?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncsharpvisual-studiotutorial
6 Posts 5 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.
  • P Offline
    P Offline
    Paulraj G
    wrote on last edited by
    #1

    Hi... I am using Visual Studio 2008, and i am working with a multiple document application, it is CView Based. In CView how can i add cbutton? My code is,

    CRect button1Rect;
    CButton button1;
    button1Rect.SetRect(250,75,400,100);
    button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
    button1.ShowWindow(SW_SHOW);

    the above code not showing the cbutton. but if the code is like,

    CRect button1Rect;
    CButton button1;
    button1Rect.SetRect(250,75,400,100);
    button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
    button1.ShowWindow(SW_SHOW);
    AfxMessageBox(L"Button created");

    It shows the button. How to solve this problem? Any help will be appreciated. Thanks...

    G.Paulraj

    C T S K 4 Replies Last reply
    0
    • P Paulraj G

      Hi... I am using Visual Studio 2008, and i am working with a multiple document application, it is CView Based. In CView how can i add cbutton? My code is,

      CRect button1Rect;
      CButton button1;
      button1Rect.SetRect(250,75,400,100);
      button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
      button1.ShowWindow(SW_SHOW);

      the above code not showing the cbutton. but if the code is like,

      CRect button1Rect;
      CButton button1;
      button1Rect.SetRect(250,75,400,100);
      button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
      button1.ShowWindow(SW_SHOW);
      AfxMessageBox(L"Button created");

      It shows the button. How to solve this problem? Any help will be appreciated. Thanks...

      G.Paulraj

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Umm, your problem is that if you show a message box you see the button on your view but if you don't then there's no button? My guess would be that you need to update your view or maybe your button (make it redraw itself). If you don't bring up the message box but after creating the button you somehow force the view to redraw, like, moving another window around on top of it, do you see your button appearing out of "nowhere"? If yes, then try calling RedrawWindow on your view OR on your button after it was created.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

      P 1 Reply Last reply
      0
      • C Code o mat

        Umm, your problem is that if you show a message box you see the button on your view but if you don't then there's no button? My guess would be that you need to update your view or maybe your button (make it redraw itself). If you don't bring up the message box but after creating the button you somehow force the view to redraw, like, moving another window around on top of it, do you see your button appearing out of "nowhere"? If yes, then try calling RedrawWindow on your view OR on your button after it was created.

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

        P Offline
        P Offline
        Paulraj G
        wrote on last edited by
        #3

        yes.. You are correct. i redraw the window. Thanks...

        G.Paulraj

        1 Reply Last reply
        0
        • P Paulraj G

          Hi... I am using Visual Studio 2008, and i am working with a multiple document application, it is CView Based. In CView how can i add cbutton? My code is,

          CRect button1Rect;
          CButton button1;
          button1Rect.SetRect(250,75,400,100);
          button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
          button1.ShowWindow(SW_SHOW);

          the above code not showing the cbutton. but if the code is like,

          CRect button1Rect;
          CButton button1;
          button1Rect.SetRect(250,75,400,100);
          button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
          button1.ShowWindow(SW_SHOW);
          AfxMessageBox(L"Button created");

          It shows the button. How to solve this problem? Any help will be appreciated. Thanks...

          G.Paulraj

          T Offline
          T Offline
          transoft
          wrote on last edited by
          #4

          Did you try calling "Invalidate(false)" function?

          modified on Monday, February 8, 2010 10:16 AM

          1 Reply Last reply
          0
          • P Paulraj G

            Hi... I am using Visual Studio 2008, and i am working with a multiple document application, it is CView Based. In CView how can i add cbutton? My code is,

            CRect button1Rect;
            CButton button1;
            button1Rect.SetRect(250,75,400,100);
            button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
            button1.ShowWindow(SW_SHOW);

            the above code not showing the cbutton. but if the code is like,

            CRect button1Rect;
            CButton button1;
            button1Rect.SetRect(250,75,400,100);
            button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
            button1.ShowWindow(SW_SHOW);
            AfxMessageBox(L"Button created");

            It shows the button. How to solve this problem? Any help will be appreciated. Thanks...

            G.Paulraj

            S Offline
            S Offline
            sthalasayanam
            wrote on last edited by
            #5

            Hi, button1Rect and button1 should be members to view class. Then only the button will display.Try with that. cheers!.

            nss

            1 Reply Last reply
            0
            • P Paulraj G

              Hi... I am using Visual Studio 2008, and i am working with a multiple document application, it is CView Based. In CView how can i add cbutton? My code is,

              CRect button1Rect;
              CButton button1;
              button1Rect.SetRect(250,75,400,100);
              button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
              button1.ShowWindow(SW_SHOW);

              the above code not showing the cbutton. but if the code is like,

              CRect button1Rect;
              CButton button1;
              button1Rect.SetRect(250,75,400,100);
              button1.Create(_T("HI"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,button1Rect,this,1);
              button1.ShowWindow(SW_SHOW);
              AfxMessageBox(L"Button created");

              It shows the button. How to solve this problem? Any help will be appreciated. Thanks...

              G.Paulraj

              K Offline
              K Offline
              KingsGambit
              wrote on last edited by
              #6

              The button object has to be a member of your CView derived class. Then, I assume you can override OnInitialUpdate() function and put the code for creating the button in that.

              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