CView and programmatically-created CButtons - Programmer

This is a discussion on CView and programmatically-created CButtons - Programmer ; Hi all, I have a CView-derived class for plotting graphs of acquisition data. However, based on the type of graph I am viewing, I need some number of pushbuttons in the top-left corner of the view. To that end, my ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: CView and programmatically-created CButtons

  1. CView and programmatically-created CButtons

    Hi all,

    I have a CView-derived class for plotting graphs of acquisition data.
    However, based on the type of graph I am viewing, I need some number
    of pushbuttons in the top-left corner of the view. To that end, my
    CView has a vector of buttons which I initialize in my CView's
    OnCreate() method. The pushbuttons are configured with their
    position, style bits, IDs, parent class (the CView) via the
    CButton::Create() method.

    To detect if they are pushed, I added ON_COMMAND entries to the
    message map for each of the buttons and then implemented the
    OnButtonXXX() methods.

    The problem I'm having is this: These buttons are meant to be toggles.
    When clicked, the button should remain depressed until clicked again.
    So, inside my OnButtonXXX() methods, I call SetState() on the button
    based on the feature associated with the button.

    The problem is, it seems that when the *entire* view is repainted, the
    buttons always draw in the unselected state regardless of how I set
    them. When I resize the view or cover the buttons with another window
    and then reveal the view, the buttons are all drawn in their default
    state. Even when I click one of my buttons, it appears in the correct
    state, but the rest of the buttons revert to their default states!
    When I manually invalidate my view due to a new data event, however, I
    shrink the rect to avoid having the buttons in the dirty rect. This
    seems to work, because as the graph redraws, the buttons maintain
    their state. But it seems like in the other cases, the buttons are
    being drawn incorrectly.

    I must have forgotten really simple. Any ideas or help would be
    appreciated.

    Cheers,
    Soren.

  2. Re: CView and programmatically-created CButtons

    Here is what I would do to make things simpler. Instead of using buttons use
    Push like Checkboxs, they look like buttons but are checkbox, onced pressed
    they will stay down until either pressed again, or someone calls its
    SetCheck(BST_UNCHECKED), So change your Button::Create to

    Button.Create("Caption",BS_CHECKBOX|BS_PUSHLIKE,....);

    Oh by the way do you know about ON_CONTROL_RANGE.

    Ali R.

    "Soren Anderssohn" wrote in message
    news:b9436549.0311171019.4f29a31b@posting.google.c om...
    > Hi all,
    >
    > I have a CView-derived class for plotting graphs of acquisition data.
    > However, based on the type of graph I am viewing, I need some number
    > of pushbuttons in the top-left corner of the view. To that end, my
    > CView has a vector of buttons which I initialize in my CView's
    > OnCreate() method. The pushbuttons are configured with their
    > position, style bits, IDs, parent class (the CView) via the
    > CButton::Create() method.
    >
    > To detect if they are pushed, I added ON_COMMAND entries to the
    > message map for each of the buttons and then implemented the
    > OnButtonXXX() methods.
    >
    > The problem I'm having is this: These buttons are meant to be toggles.
    > When clicked, the button should remain depressed until clicked again.
    > So, inside my OnButtonXXX() methods, I call SetState() on the button
    > based on the feature associated with the button.
    >
    > The problem is, it seems that when the *entire* view is repainted, the
    > buttons always draw in the unselected state regardless of how I set
    > them. When I resize the view or cover the buttons with another window
    > and then reveal the view, the buttons are all drawn in their default
    > state. Even when I click one of my buttons, it appears in the correct
    > state, but the rest of the buttons revert to their default states!
    > When I manually invalidate my view due to a new data event, however, I
    > shrink the rect to avoid having the buttons in the dirty rect. This
    > seems to work, because as the graph redraws, the buttons maintain
    > their state. But it seems like in the other cases, the buttons are
    > being drawn incorrectly.
    >
    > I must have forgotten really simple. Any ideas or help would be
    > appreciated.
    >
    > Cheers,
    > Soren.




  3. Re: CView and programmatically-created CButtons

    Thanks, Ali. It worked beautifully, even with my BS_BITMAP style and
    a bitmap attached to the button.

    Surprisingly (or maybe not, depending on how you look at it), I just
    did a quick search on MSDN for BS_PUSHLIKE and came up empty.
    Undocumented, maybe...

    Anyway, thanks again.

    Cheers,
    Soren.

    "Ali R." wrote in message news:...
    > Here is what I would do to make things simpler. Instead of using buttons use
    > Push like Checkboxs, they look like buttons but are checkbox, onced pressed
    > they will stay down until either pressed again, or someone calls its
    > SetCheck(BST_UNCHECKED), So change your Button::Create to
    >
    > Button.Create("Caption",BS_CHECKBOX|BS_PUSHLIKE,....);
    >
    > Oh by the way do you know about ON_CONTROL_RANGE.
    >
    > Ali R.
    >
    > "Soren Anderssohn" wrote in message
    > news:b9436549.0311171019.4f29a31b@posting.google.c om...
    > > Hi all,
    > >
    > > I have a CView-derived class for plotting graphs of acquisition data.
    > > However, based on the type of graph I am viewing, I need some number
    > > of pushbuttons in the top-left corner of the view. To that end, my
    > > CView has a vector of buttons which I initialize in my CView's
    > > OnCreate() method. The pushbuttons are configured with their
    > > position, style bits, IDs, parent class (the CView) via the
    > > CButton::Create() method.
    > >
    > > To detect if they are pushed, I added ON_COMMAND entries to the
    > > message map for each of the buttons and then implemented the
    > > OnButtonXXX() methods.
    > >
    > > The problem I'm having is this: These buttons are meant to be toggles.
    > > When clicked, the button should remain depressed until clicked again.
    > > So, inside my OnButtonXXX() methods, I call SetState() on the button
    > > based on the feature associated with the button.
    > >
    > > The problem is, it seems that when the *entire* view is repainted, the
    > > buttons always draw in the unselected state regardless of how I set
    > > them. When I resize the view or cover the buttons with another window
    > > and then reveal the view, the buttons are all drawn in their default
    > > state. Even when I click one of my buttons, it appears in the correct
    > > state, but the rest of the buttons revert to their default states!
    > > When I manually invalidate my view due to a new data event, however, I
    > > shrink the rect to avoid having the buttons in the dirty rect. This
    > > seems to work, because as the graph redraws, the buttons maintain
    > > their state. But it seems like in the other cases, the buttons are
    > > being drawn incorrectly.
    > >
    > > I must have forgotten really simple. Any ideas or help would be
    > > appreciated.
    > >
    > > Cheers,
    > > Soren.


+ Reply to Thread