Solved

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

Posted on 2002-05-06
4
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 87
fizzArray  challenge 1 115
Modbus - whats the maximum I can store in one register? 4 84
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 134
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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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