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!
Who is Participating?
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.

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!

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

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

nicoletAuthor Commented:
I have not received workable answer for this question yet. Can I post this again to get some more help?
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 (

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)

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!

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.