Solved

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

Posted on 2002-05-06
4
253 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

12 Experts available now in Live!

Get 1:1 Help Now