Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 83
NotAlone Challenge 20 84
Detect file exist or not 3 158
Way to decrease size of apk file 9 70
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

803 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