CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2011
    Posts
    39

    "Fixing down" a CButton or CEdit control.

    Hello again,

    I was wondering how I could "fix down" a CButton or CEdit control in a scrollable main window. The problem is that when such a window is scrolled, the CButton or CEdit control floats over to the next scrolled region. How can I stop this from happening?

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: "Fixing down" a CButton or CEdit control.

    Place the controls (buttons, edits, and so on) in a control bar (preferable a dialog bar).
    See CDialogBar and CControlBar MFC classes.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Feb 2011
    Posts
    39

    Re: "Fixing down" a CButton or CEdit control.

    Quote Originally Posted by ovidiucucu View Post
    Place the controls (buttons, edits, and so on) in a control bar (preferable a dialog bar).
    See CDialogBar and CControlBar MFC classes.
    Thank you so much for replying! I'm working on it and I will get back to you about it. I've sub-classed CControlBar and i'm transferring all the control related functions.

    Thanks again.

  4. #4
    Join Date
    Feb 2011
    Posts
    39

    Re: "Fixing down" a CButton or CEdit control.

    I tried making a CControlBar derived class, but it signals this error:

    Code:
    1>        'void CControlBar::OnUpdateCmdUI(CFrameWnd *,BOOL)' : is abstract
    1>        c:\program files (x86)\microsoft visual studio 8\vc\atlmfc\include\afxext.h(167) : see declaration of 'CControlBar::OnUpdateCmdUI'
    What is an abstract class? Why is this happening?

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: "Fixing down" a CButton or CEdit control.

    Am abstract class is a class which contains just abstract/general stuff and has no sense to be instantiated.
    In C++, a class is abstract if has at least one pure virtual function.

    Imagine a class Shape:

    Code:
    class Shape
    {
    protected:
       int pen_color;
    public:
       void Draw();
    };
    Can we implement Shape::Draw? What to draw? A rectangle, an ellipse, something else? I think, in Shape class we have no idea.

    So, let's make Shape abstract:
    Code:
    class Shape // abstract class
    {
    protected:
       int pen_color;
    public:
       virtual void Draw() = 0; // pure virtual function
    };
    To make a derived class "concrete" we have to override all the base pure virtual functions, in our case the function Shape::Draw.
    Code:
    class Rectangle : public Shape
    {
    // ....
    public:
       virtual void Draw() 
       {
           // draw a rectangle here.
       }
    };
    CControlBar is like Shape: an abstract class. It has no sense to create an object of CControlBar type, then the compiler doesn't let you to do silly things. ;).
    Use one of its derived concrete classes CDialogBar, CToolBar and so on.
    As I already said, for your purpose, CDialogBar is preferable.
    Last edited by ovidiucucu; February 23rd, 2011 at 09:55 AM. Reason: typos
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Feb 2011
    Posts
    39

    Re: "Fixing down" a CButton or CEdit control.

    Thanks very much for the explanation. I've now tried using the CDialogBar instead.

    1.) Since I've chosen to use CDialogBar, do i still subclass it and create the controls as private?

    2.) Further, how could I reposition the CDialopBar? It's create function does not accept any CRect parameter.

    3.) The CDialogBar will be created dynamically in the program. The CEdit controls may be created anywhere in a table in the program. Is this possible?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: "Fixing down" a CButton or CEdit control.

    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured