Posting Message in .NET

  • Thread starter Thread starter H.B.
  • Start date Start date
It depends on what you want to do.

If you are implementing a WinForms app, Control.BeginInvoke is the function
you want. It expects any delegate and an argument array. If you call it on a
control, and internally calls PostMessage with the control's HWND to ensure
that the control's thread will handle the event. The event handler on the
control's thread will the call the delegate with the arguments.

If you are not implementing a WinForms app, you may call PostMessage by just
including windows.h. The compiler will automatically generate a quite
interesting PInvoke function for you.

Marcus
 
I just want to make something like the following code and the easiest way
possible ... (I have a Windows Forms Application)

/////////////////////////////// VC++ 6.0 Old Code
///////////////////////////////////

#define WM_MYMSG WM_APP+100

PostMessage(this->GetSafeHwnd(), WM_MYMSG, 0, 0);

////////////////////////////////////////////////////////////////////////////
////////////////////////
 
System::Windows::Forms::Control supports IWin32Windows which allows you to
get a HWND via it's handle property.

If you compile with /clr or /clr:pure, you can include windows.h and call

PostMessage(this->Handle, WM_MYMSG, 0, 0);

without any extra efforts.

Marcus
 
Back
Top