Click here to Skip to main content
15,922,584 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How do I pass a value to a class? Pin
Bo Hunter4-Jan-04 8:38
Bo Hunter4-Jan-04 8:38 
GeneralRe: How do I pass a value to a class? Pin
Bob Stanneveld4-Jan-04 23:16
Bob Stanneveld4-Jan-04 23:16 
AnswerRe: How do I pass a value to a class? Pin
Michael Dunn4-Jan-04 8:56
sitebuilderMichael Dunn4-Jan-04 8:56 
AnswerRe: How do I pass a value to a class? Pin
Bo Hunter4-Jan-04 9:05
Bo Hunter4-Jan-04 9:05 
GeneralRe: How do I pass a value to a class? Pin
DanYELL4-Jan-04 9:43
DanYELL4-Jan-04 9:43 
GeneralRe: How do I pass a value to a class? Pin
PJ Arends4-Jan-04 10:07
professionalPJ Arends4-Jan-04 10:07 
GeneralRe: How do I pass a value to a class? Pin
DanYELL4-Jan-04 15:04
DanYELL4-Jan-04 15:04 
GeneralRe: How do I pass a value to a class? Pin
Tim Smith4-Jan-04 15:41
Tim Smith4-Jan-04 15:41 
AnswerRe: How do I pass a value to a class? Pin
Shenthil4-Jan-04 20:52
Shenthil4-Jan-04 20:52 
Questionwhat is the definitive version of VC++ Pin
Ger Hayden4-Jan-04 7:15
Ger Hayden4-Jan-04 7:15 
AnswerRe: what is the definitive version of VC++ Pin
User 66584-Jan-04 7:58
User 66584-Jan-04 7:58 
AnswerRe: what is the definitive version of VC++ Pin
Michael Dunn4-Jan-04 8:57
sitebuilderMichael Dunn4-Jan-04 8:57 
Generalinvalid integer constant expression Pin
ABean4-Jan-04 6:47
ABean4-Jan-04 6:47 
GeneralRe: invalid integer constant expression Pin
PJ Arends4-Jan-04 10:48
professionalPJ Arends4-Jan-04 10:48 
GeneralRe: invalid integer constant expression Pin
ABean5-Jan-04 6:43
ABean5-Jan-04 6:43 
QuestionWinsock? Pin
Stan the man4-Jan-04 6:35
Stan the man4-Jan-04 6:35 
GeneralToolBar close Pin
Burl D4-Jan-04 6:24
Burl D4-Jan-04 6:24 
GeneralRe: ToolBar close Pin
PJ Arends4-Jan-04 10:55
professionalPJ Arends4-Jan-04 10:55 
GeneralGDI drawing in layers Pin
mirano4-Jan-04 5:52
mirano4-Jan-04 5:52 
GeneralRe: GDI drawing in layers Pin
PJ Arends4-Jan-04 9:30
professionalPJ Arends4-Jan-04 9:30 
GeneralSending a packet using PostMessage Pin
__Cerb4-Jan-04 4:38
__Cerb4-Jan-04 4:38 
GeneralRe: Sending a packet using PostMessage Pin
Stefan Pedersen4-Jan-04 4:46
Stefan Pedersen4-Jan-04 4:46 
GeneralRe: Sending a packet using PostMessage Pin
__Cerb4-Jan-04 5:33
__Cerb4-Jan-04 5:33 
GeneralRe: Sending a packet using PostMessage Pin
Gary R. Wheeler4-Jan-04 5:30
Gary R. Wheeler4-Jan-04 5:30 
I'm going to assume you are asking how you should use PostMessage to send a packet of information. "Which type of message" you should send depends on what you are trying to accomplish, which you haven't described. I'm also going to assume you are using MFC, and that you are trying to send a packet to a window created by your application.

If you are using PostMessage(), the message is placed on the window's message queue, and PostMessage() returns immediately. The window that receives the message may take some time before it processes the message. This means that the message will have to persist until the window gets around to looking at it. The easiest way to do this is to allocate your 'packet' on the heap, and deallocate it in the message handler. Here's an example:
#define MY_MESSAGE (WM_APP + 1)

class Packet {
public:
    Packet();
    ~Packet();
    // ... data members
    int m1;
};

...

// allocate a packet, set its contents

Packet *packet = new Packet;
packet->m1 = 123456;

// here's how you post a message

CString strWndName = "My wnd";
CString strClassName = "Wnd class";
HWND hwnd = ::FindWindow(strClassName,strWndName);

::PostMessage(hwnd,MY_MESSAGE,0,(LPARAM)packet);
This code sends your user-defined message MY_MESSAGE to the window with handle hwnd. Your handler for this message should be declared as follows:
afx_msg LRESULT OnMyMessage(WPARAM wParam,LPARAM lParam);
and it's implementation will look like the following:
BEGIN_MESSAGE_MAP( MyWindowClass, <window base class> )
...
ON_MESSAGE(MY_MESSAGE,OnMyMessage)
END_MESSAGE_MAP()
...

LRESULT MyWindowClass::OnMyMessage(WPARAM wParam,LPARAM lParam)
{
    Packet *packet = (Packet *)lParam;

    // ... use information in packet

    delete packet;

    return (LRESULT)0;
}
I hope this helps. If you are trying to send messages between applications, there are other methods of interprocess communication (named pipes, sockets, and so on) that are simpler.



Software Zen: delete this;
GeneralRe: Sending a packet using PostMessage Pin
__Cerb4-Jan-04 5:45
__Cerb4-Jan-04 5:45 

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.