Solved

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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 shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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