• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Movable toggle button in View?

I have two view pane separate by splitter, In one of the view window which is CHostView : public CScrollView, I want to place Toggle buttons and possibly to drag each individual button vertically to different position. I also like to have a individual popup dialog popup when the button is right mouse clicked. And also the total number of buttons is variable. I appreciate your expertise advice. Thank You!
0
nicolet
Asked:
nicolet
  • 4
  • 3
1 Solution
 
RONSLOWCommented:
Do you mean that you want the user to be able to drag the button?

You'd need to set the NM_NOTIFY flag for the button (so you get mouse up/down etc) then, on a mouse down event, call ::DragDetect to determine whether the user is clicking of dragging the button (DrawDetect returns TRUE if the button is being dragged).  If it is being dragged, then set a flag (or write your own message pump loop) and respond to mouse moves by changing the window position for your button.

Similarly, you should be able to respond to a OnContextMenu in your button class that would then call TrackPopupMenu to display the context menu.

0
 
nicoletAuthor Commented:
Hi Ronslow,
Thank you for your answer, however I am not clear about how to create these toggle buttons in one of my splitter view area which is a CHostView : public CScrollView. By the way the number of buttons is various, it depends on application to decide how many buttons should it provide in the view area). I am using MFC developer studio, Since the view class is not a dialog, How do I create buttons in View? and how to attach the callback message such as NM_NOTIFY or OnContextMenu for each button in the application's View class?
Thank You!

0
 
RONSLOWCommented:
I'll see if I can whip up a short example for you ... get back to you soon.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nicoletAuthor Commented:
I have not received workable answer for this question yet. Can I post this again to get some more help?
0
 
RONSLOWCommented:
to create a button, add a member to your view

CButton m_myButton;

Setup a CRect with the position and size of the button

CRect myButtonRect;
myButtonRect.left = ... etc

In your OnInitialUpdate (or maybe OnCreate)

m_myButton.Create (
  "&MyButton",
  WS_CHILD | WS_VISIBLE | WS_TABSTOP,
  myButtonRect,
  this,
  IDC_MYBUTTON);

If you want several, then mane an array of CButton's and set the ID's to be sequential (or have an array of ID's)


0
 
nicoletAuthor Commented:
In your first answer you mention that
>Similarly, you should be able to respond to a OnContextMenu in >your button class that would then call TrackPopupMenu to >display the context menu.

If I create a CMyButton() class, to create and postion a button. How do I setup the messages such as "OnContextMenu" or "NM_NOTIFY" for this button in MFC. In App Wizard, I supposed I need to get CMyButton to be added as a new class, but I am confused with what should I enter for "Based class" and "Dialog ID" field in Add new class dialog? Since CMyButton is not a wizard created dialog. I am lost in this MFC way.
Thank you very much for your help!
 

0
 
RONSLOWCommented:
Generate the entries for a button in a dialog.  Put the same code into the message map, class header etc for your view.  The Class Wizard doesn't do anything that you as a programmer cannot (or should not) do ... it just helps by writing some simple code for you.

The only catch is if you don't know how many buttons you will have.  If it is truely dynamic, then you will want to handle all the buttons you created with a single member function (say, OnAnyButtonClicked) and use the ID of the button to take the appropriate action.

MFC supports this with

ON_NOTIFY_RANGE( wNotifyCode, id, idLast, memberFxn )

if your case, wNotifyCode is BN_CLICKED, id and idLast are the range of id numbers for the buttons you create and memberFxn is the name of the handler, which looks like..

afx_msg void memberFxn( UINT id, NMHDR * pNotifyStruct, LRESULT * result );

where id is the id of the button the was clicked, pNotifyStruct you can probably ignore, and *result should probably be set to zero

see MFC technical article TN061: ON_NOTIFY and WM_NOTIFY Messages for more info

Regarding tooltips ... look at the MS KB article:

DOC: How to Display Tool Tips After Calling EnableToolTips
Last reviewed: July 31, 1997
Article ID: Q140595

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now