Click here to Skip to main content
15,917,642 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: putting hex calues in a byte array Pin
Antony M Kancidrowski15-Jul-04 8:47
Antony M Kancidrowski15-Jul-04 8:47 
GeneralRe: putting hex calues in a byte array Pin
pankajdaga15-Jul-04 5:18
pankajdaga15-Jul-04 5:18 
GeneralDll Problem Pin
Bernhard15-Jul-04 4:28
Bernhard15-Jul-04 4:28 
GeneralRe: Dll Problem Pin
Antti Keskinen15-Jul-04 8:32
Antti Keskinen15-Jul-04 8:32 
QuestionMaking objects talk with each other? Pin
0v3rloader15-Jul-04 4:26
0v3rloader15-Jul-04 4:26 
AnswerRe: Making objects talk with each other? Pin
Maximilien15-Jul-04 4:43
Maximilien15-Jul-04 4:43 
GeneralRe: Making objects talk with each other? Pin
0v3rloader15-Jul-04 4:59
0v3rloader15-Jul-04 4:59 
AnswerRe: Making objects talk with each other? Pin
Antti Keskinen15-Jul-04 9:18
Antti Keskinen15-Jul-04 9:18 
If the "events" belong to the category of "Standard Windows events", such as a button click, then you can use the ClassWizard/"Add Event Handler" -wizard to add a handler for the event. Because the CFormView is the parent of all the controls, it will be the class which will contain the handlers.

However, a more important question I have to ask: why wouldn't you use SendMessage ? Everything in Windows(r) is messages, so a few more messages won't crash the system Smile | :)

As these are custom controls, I assume that you have a class for each control which determine it's behaviour. Now, inside these classes, if you create ON_WM_* macro entries into the message map, you can capture any type of WM_* messages, no matter what they are. When you capture this message, and wish to notify the parent (in this case, the CFormView), you can use the CWnd::GetParent function of the control's class (every MFC control derives from CWnd, thus it has GetParent). This will give you a pointer to the CWnd-class of the class hiearchy. Then use DYNAMIC_DOWNCAST macro to cast down into your CFormView-derived class. Now, you can use the pointer to, for example, call a function of the derived class. Here is a concrete example:
// Assuming that CMyButton is a custom button control<DIV>

BEGIN_MESSAGE_MAP(CMyButton, CButton)
   ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP<DIV>

.
.
.<DIV>

void CMyButton::OnLButtonDown(UINT uiPos, CPoint point)
{
   // Let's get the parent
   CWnd* pParent = this->GetParent();<DIV>

   // Because the parent IS a CFormView-derived class, the following pointer cast is valid
   CMyFormView* pForm = DYNAMIC_DOWNCAST(CMyFormView, pParent);<DIV>

   // But let's check it anyway
   VERIFY( pForm != NULL );<DIV>

   // Call a member function in the derived class
   pForm->AnyGivenFunction( param1, param2 );
}
If you don't understand this concept, then you should quickly brush up your skills in object-oriented programming, and more importantly, in pointers to classes in a class hiearchy. Any C++ book is a good place to start, and the thing to look for is 'polymorphism' and 'dynamic_cast'. Search MSDN with the latter one for a few excellent examples.

Hope this will help you out..

-Antti Keskinen

----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
GeneralRe: Making objects talk with each other? Pin
0v3rloader15-Jul-04 10:02
0v3rloader15-Jul-04 10:02 
GeneralRe: Making objects talk with each other? Pin
0v3rloader15-Jul-04 10:12
0v3rloader15-Jul-04 10:12 
GeneralRe: Making objects talk with each other? Pin
Antti Keskinen15-Jul-04 11:36
Antti Keskinen15-Jul-04 11:36 
GeneralRe: Making objects talk with each other? Pin
0v3rloader15-Jul-04 11:46
0v3rloader15-Jul-04 11:46 
Generalpacked data strcutures Pin
Henry miller15-Jul-04 3:51
Henry miller15-Jul-04 3:51 
GeneralRe: packed data strcutures Pin
vmaltsev15-Jul-04 11:52
vmaltsev15-Jul-04 11:52 
GeneralRe: packed data strcutures Pin
Henry miller15-Jul-04 12:04
Henry miller15-Jul-04 12:04 
GeneralCInternetSession timeout Pin
fredvinzenz15-Jul-04 3:46
fredvinzenz15-Jul-04 3:46 
Generalwsprintf Pin
vikramlinux15-Jul-04 2:37
vikramlinux15-Jul-04 2:37 
GeneralRe: wsprintf Pin
V.15-Jul-04 2:47
professionalV.15-Jul-04 2:47 
GeneralRe: wsprintf Pin
vikramlinux15-Jul-04 2:56
vikramlinux15-Jul-04 2:56 
GeneralRe: wsprintf Pin
V.15-Jul-04 3:11
professionalV.15-Jul-04 3:11 
GeneralRe: wsprintf Pin
vikramlinux15-Jul-04 3:46
vikramlinux15-Jul-04 3:46 
GeneralRe: wsprintf Pin
David Crow15-Jul-04 3:23
David Crow15-Jul-04 3:23 
Generala threading question Pin
ns15-Jul-04 2:15
ns15-Jul-04 2:15 
GeneralRe: a threading question Pin
jmkhael15-Jul-04 3:12
jmkhael15-Jul-04 3:12 
GeneralRe: a threading question Pin
David Crow15-Jul-04 3:28
David Crow15-Jul-04 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.