Click here to Skip to main content
15,905,504 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralManaging right click in a CListBox control Pin
doctorpi28-Jul-03 4:25
doctorpi28-Jul-03 4:25 
GeneralRe: Managing right click in a CListBox control Pin
Beer2628-Jul-03 4:30
Beer2628-Jul-03 4:30 
GeneralRe: Managing right click in a CListBox control Pin
doctorpi28-Jul-03 4:33
doctorpi28-Jul-03 4:33 
Generalretrieving hardware information(win2k) Pin
Alexander M.,28-Jul-03 4:11
Alexander M.,28-Jul-03 4:11 
GeneralRe: retrieving hardware information(win2k) Pin
Mike Nordell28-Jul-03 13:46
Mike Nordell28-Jul-03 13:46 
GeneralRe: retrieving hardware information(win2k) Pin
Alexander M.,29-Jul-03 2:29
Alexander M.,29-Jul-03 2:29 
GeneralRe: retrieving hardware information(win2k) Pin
Alexander M.,29-Jul-03 9:39
Alexander M.,29-Jul-03 9:39 
Generalusing PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 3:58
Joel Lipschultz28-Jul-03 3:58 
I am attempting to write a simple MFC application that can pass user defined messages across classes.

I start a new MFC app and created 2 classes via classwizard, say CSendClass and CReceiveClass (both derived from generic Cwnd). To create the user-defined message stuff, I:

1. add the line "#define WMU_FUN_MSG (WM_APP + 20)" to stdafx.h (making it global)

2. Add the line "ON_MESSAGE(WMU_FUN_MSG, OnFunMessage)" in CReceiveClass.cpp, inbetween the lines BEGIN_MESSAGE_MAP(CReceiveClass, CWnd) and END_MESSAGE_MAP()

3. Add the line "afx_msg LRESULT OnFunMessage(WPARAM wParam, LPARAM lParam)" in CReceiveClass.h, just before DECLARE_MESSAGE_MAP()

4. Add the following message handling function to the end of CReceiveClass:

LRESULT CReceiveClass::OnFunMessage(WPARAM wParam, LPARAM lParam){
MessageBox("In WMU_FUN_MSG handler", NULL, MB_OK);
return 0;
}

Now that all the Message Handler stuff resides in CReceiveClass, I add the following line to the constructor of CSendClass:
"PostMessage(WMU_FUN_MSG, 0, 0);"

Finally, I added the following two lines to the Dialog Box's OnCreate Function:

CReceiveClass obj1; //Create instance of the receiving class
CSendClass obj2; //Create an instance of the sending class

Ideally, this is what the program should do:
1.. Program starts, creates CReceiveClass obj1 and CSendClass obj2.
2. In constructor for CSendClass obj2, PostMessage() is called, send a user defined message
3. CReceiveClass's message handler function is called, printed a MessageBox to the screen.

Unfortunately, it doesnt work that way. My program crashes when it gets to the PostMessage command, displaying a "Debug Assertion Failed!" dialog box. Because of this, my MessageBox is never displayed.

Any insight you can give would be most appreciated.

-Joel L.



Joel L.
GeneralRe: using PostMessage with user defined messages Pin
David Chamberlain28-Jul-03 4:16
David Chamberlain28-Jul-03 4:16 
GeneralRe: using PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 4:30
Joel Lipschultz28-Jul-03 4:30 
GeneralRe: using PostMessage with user defined messages Pin
Cedric Moonen28-Jul-03 4:38
Cedric Moonen28-Jul-03 4:38 
GeneralRe: using PostMessage with user defined messages Pin
Beer2628-Jul-03 4:56
Beer2628-Jul-03 4:56 
GeneralRe: using PostMessage with user defined messages Pin
David Crow28-Jul-03 4:39
David Crow28-Jul-03 4:39 
GeneralRe: using PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 5:21
Joel Lipschultz28-Jul-03 5:21 
GeneralRe: using PostMessage with user defined messages Pin
David Crow28-Jul-03 5:30
David Crow28-Jul-03 5:30 
GeneralRe: using PostMessage with user defined messages Pin
peterchen28-Jul-03 4:40
peterchen28-Jul-03 4:40 
GeneralRe: using PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 5:04
Joel Lipschultz28-Jul-03 5:04 
GeneralRe: using PostMessage with user defined messages Pin
Beer2628-Jul-03 4:41
Beer2628-Jul-03 4:41 
GeneralRe: using PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 5:16
Joel Lipschultz28-Jul-03 5:16 
GeneralRe: using PostMessage with user defined messages Pin
Beer2628-Jul-03 5:40
Beer2628-Jul-03 5:40 
GeneralRe: using PostMessage with user defined messages Pin
Beer2628-Jul-03 4:47
Beer2628-Jul-03 4:47 
GeneralRe: using PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 5:37
Joel Lipschultz28-Jul-03 5:37 
GeneralRe: using PostMessage with user defined messages Pin
Joel Lipschultz28-Jul-03 7:31
Joel Lipschultz28-Jul-03 7:31 
GeneralRe: using PostMessage with user defined messages Pin
Beer2628-Jul-03 11:07
Beer2628-Jul-03 11:07 
GeneralRe: using PostMessage with user defined messages Pin
Beer2628-Jul-03 11:11
Beer2628-Jul-03 11:11 

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.