Solved

child cwnd detect other chlid cwnd  --- magnetic cwnd?

Posted on 2002-05-06
4
254 Views
Last Modified: 2013-11-20
I want to have 2 cbutton that if they are placed close to each other (say 30 pixels or so) they will attract eachother and stick together.

I have my own little hack of drag n' drop, and I can make the one cbutton link up with the second, if I know that it is close enough.

But, that is the problem I don't know what is the best way to tell if a cbutton is close to another cbutton.

I'd like the behavior to be in the MagButton class, not in my CDialog class.

the only solution I know how to work is by putting all my cbuttons that I will be using in a list, and then cycling through that list, looking at the RECTS to see where they are.

I don't like it because that code would have to go in the CDialog class.

I want code that could go in the MagButton class, ...

how can I tell from a child cwnd where other child cwnds are, and where they are.

that is my question

more details available if needed.

Thanks,

Bob
0
Comment
Question by:bebonham
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:mblat
ID: 6991451
Here is an idea:

class CMagButton
{
static std::list<CMagButton*> m_buttonList;
// so there is one and only one copy
};

void CMagButton::OnMove()
{
  // loop through you list here!!!!

   std::for_each(m_buttonList.begin(),.......);
}


Hope it helps....
0
 
LVL 8

Author Comment

by:bebonham
ID: 6991486
yes, that appears to be part of the answer.
but can you suggest how do I get the data into the list inside the class?

it seems like I would have to pass it from the main dialog?

Bob
0
 
LVL 4

Accepted Solution

by:
mblat earned 100 total points
ID: 6991502
May be several ways....

One would be to have to overwrite PreSubclassWindow and do it there...

void CMagButton::PreSubclassWindow()
{
  m_buttonList.push_back(this);

  CButton::PreSubclassWindow();
}

just as a side note (and you may know it already - so no offence....)
if you declate you list static there will be only one copy of it.  That is all good, but if you have MORE THAN ONE dialog with CMagButtons it may represent some problem - you need to remember to clear that list when dialog is closed....

Or lets say there is one dialog brings up other dialogs, both having CMagButtons? THen what?  I don't know structure of your app - so take it for what it is - trying to think about you potencial problem - may be there is none....

By the way if something like this is the case you could use something like this:

class MyPair
{
 CDialog*    m_pParent;
 CMagButton* m_pButton;
};

std::vector<MyPair> m_buttonList;

void CMagButton::PreSubclasssWindow()
{
  MyPair  pair;
  pair.m_pParent = GetParent();
  pair.m_pButton = this;

  m_buttonList.push_back(MyPair);
}

and go from there....


Hope it helps....
0
 
LVL 8

Author Comment

by:bebonham
ID: 6991554
thanks a lot, very helpful!
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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

25 Experts available now in Live!

Get 1:1 Help Now