Solved

Movable toggle button in View?

Posted on 1998-10-21
7
256 Views
Last Modified: 2013-11-20
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
Comment
Question by:nicolet
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 200 total points
ID: 1323637
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
 

Author Comment

by:nicolet
ID: 1323638
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1323639
I'll see if I can whip up a short example for you ... get back to you soon.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:nicolet
ID: 1323640
I have not received workable answer for this question yet. Can I post this again to get some more help?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1323641
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
 

Author Comment

by:nicolet
ID: 1323642
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1323643
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 78
sumDigits challenge 9 120
string initialization in java 11 109
Fibonacci challenge 11 108
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now