Hi,

can anybody tell me if there is a way to define and send a custom windows
message to a window and to specify
a handler function for it in C#?

The reason I'm asking this is following - I use some 3d party component that
start its own threads. When my
command is executed by this component it invokes my callback in the context
of its thread. But
I need to somehow update my GUI after that. I can't access my GUI controls
from this callback (get an
exception - wrong thread or something like that), so I thought that if I
could place a message into my app's
message queue then I could handle this situation properly.

Thanks in advance!

Regards,
Dmitry.

Re: Sending a custom Windows message by Jay

Jay
Fri Aug 01 12:22:08 CDT 2003

Dmitry,
You will need to use P/Invoke to define the Win32 SendMessage api, to send
your message.

Then you will need to override Control.WndProc to handle the message.

The following article shows how to use SendMessage.
http://msdn.microsoft.com/vbasic/using/building/windows/printing/default.aspx?pull=/library/en-us/dnwinforms/html/wnf_richtextbox.asp

Hope this helps
Jay

"Dmitry" <dpristin@att.net> wrote in message
news:us2Z7AFWDHA.1280@tk2msftngp13.phx.gbl...
> Hi,
>
> can anybody tell me if there is a way to define and send a custom windows
> message to a window and to specify
> a handler function for it in C#?
>
> The reason I'm asking this is following - I use some 3d party component
that
> start its own threads. When my
> command is executed by this component it invokes my callback in the
context
> of its thread. But
> I need to somehow update my GUI after that. I can't access my GUI controls
> from this callback (get an
> exception - wrong thread or something like that), so I thought that if I
> could place a message into my app's
> message queue then I could handle this situation properly.
>
> Thanks in advance!
>
> Regards,
> Dmitry.
>
>



Re: Sending a custom Windows message by Dmitry

Dmitry
Fri Aug 01 12:43:53 CDT 2003

That's great!

Thanks a lot,
Dmitry.

"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in message
news:e4YszFFWDHA.3220@tk2msftngp13.phx.gbl...
> Dmitry,
> You will need to use P/Invoke to define the Win32 SendMessage api, to send
> your message.
>
> Then you will need to override Control.WndProc to handle the message.
>
> The following article shows how to use SendMessage.
>
http://msdn.microsoft.com/vbasic/using/building/windows/printing/default.aspx?pull=/library/en-us/dnwinforms/html/wnf_richtextbox.asp
>
> Hope this helps
> Jay
>
> "Dmitry" <dpristin@att.net> wrote in message
> news:us2Z7AFWDHA.1280@tk2msftngp13.phx.gbl...
> > Hi,
> >
> > can anybody tell me if there is a way to define and send a custom
windows
> > message to a window and to specify
> > a handler function for it in C#?
> >
> > The reason I'm asking this is following - I use some 3d party component
> that
> > start its own threads. When my
> > command is executed by this component it invokes my callback in the
> context
> > of its thread. But
> > I need to somehow update my GUI after that. I can't access my GUI
controls
> > from this callback (get an
> > exception - wrong thread or something like that), so I thought that if I
> > could place a message into my app's
> > message queue then I could handle this situation properly.
> >
> > Thanks in advance!
> >
> > Regards,
> > Dmitry.
> >
> >
>
>



Re: Sending a custom Windows message by Dmitry

Dmitry
Fri Aug 01 13:04:55 CDT 2003

Just one more thing - can I get away with using
Application.AddMessageFilter
instead of overriding Control.WndProc ? If, say, my implementation of the
filter
modified some GUI controls this would ultimately end up in sending some
"normal"
messages into my app's message queue etc. Is there any hidden problem with
this approach?

Thanks,
Dmitry.


"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in message
news:e4YszFFWDHA.3220@tk2msftngp13.phx.gbl...
> Dmitry,
> You will need to use P/Invoke to define the Win32 SendMessage api, to send
> your message.
>
> Then you will need to override Control.WndProc to handle the message.
>
> The following article shows how to use SendMessage.
>
http://msdn.microsoft.com/vbasic/using/building/windows/printing/default.aspx?pull=/library/en-us/dnwinforms/html/wnf_richtextbox.asp
>
> Hope this helps
> Jay
>
> "Dmitry" <dpristin@att.net> wrote in message
> news:us2Z7AFWDHA.1280@tk2msftngp13.phx.gbl...
> > Hi,
> >
> > can anybody tell me if there is a way to define and send a custom
windows
> > message to a window and to specify
> > a handler function for it in C#?
> >
> > The reason I'm asking this is following - I use some 3d party component
> that
> > start its own threads. When my
> > command is executed by this component it invokes my callback in the
> context
> > of its thread. But
> > I need to somehow update my GUI after that. I can't access my GUI
controls
> > from this callback (get an
> > exception - wrong thread or something like that), so I thought that if I
> > could place a message into my app's
> > message queue then I could handle this situation properly.
> >
> > Thanks in advance!
> >
> > Regards,
> > Dmitry.
> >
> >
>
>



Re: Sending a custom Windows message by Jay

Jay
Fri Aug 01 14:01:21 CDT 2003

Dmitry,
I believe so, I forget about AddMessageFilter.

I have not really used AddMessageFilter to say if there are any hidden
problems or not.

Hope this helps
Jay

"Dmitry" <dpristin@att.net> wrote in message
news:uUpESkFWDHA.2156@TK2MSFTNGP11.phx.gbl...
> Just one more thing - can I get away with using
> Application.AddMessageFilter
> instead of overriding Control.WndProc ? If, say, my implementation of the
> filter
> modified some GUI controls this would ultimately end up in sending some
> "normal"
> messages into my app's message queue etc. Is there any hidden problem with
> this approach?
>
> Thanks,
> Dmitry.
>
>
> "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in
message
> news:e4YszFFWDHA.3220@tk2msftngp13.phx.gbl...
> > Dmitry,
> > You will need to use P/Invoke to define the Win32 SendMessage api, to
send
> > your message.
> >
> > Then you will need to override Control.WndProc to handle the message.
> >
> > The following article shows how to use SendMessage.
> >
>
http://msdn.microsoft.com/vbasic/using/building/windows/printing/default.aspx?pull=/library/en-us/dnwinforms/html/wnf_richtextbox.asp
> >
> > Hope this helps
> > Jay
> >
> > "Dmitry" <dpristin@att.net> wrote in message
> > news:us2Z7AFWDHA.1280@tk2msftngp13.phx.gbl...
> > > Hi,
> > >
> > > can anybody tell me if there is a way to define and send a custom
> windows
> > > message to a window and to specify
> > > a handler function for it in C#?
> > >
> > > The reason I'm asking this is following - I use some 3d party
component
> > that
> > > start its own threads. When my
> > > command is executed by this component it invokes my callback in the
> > context
> > > of its thread. But
> > > I need to somehow update my GUI after that. I can't access my GUI
> controls
> > > from this callback (get an
> > > exception - wrong thread or something like that), so I thought that if
I
> > > could place a message into my app's
> > > message queue then I could handle this situation properly.
> > >
> > > Thanks in advance!
> > >
> > > Regards,
> > > Dmitry.
> > >
> > >
> >
> >
>
>



Re: Sending a custom Windows message by Dmitry

Dmitry
Fri Aug 01 14:23:31 CDT 2003

Thank you very much, I really appreciate your help!

Regards,
Dmitry.

"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in message
news:e7TjQ9FWDHA.1512@TK2MSFTNGP11.phx.gbl...
> Dmitry,
> I believe so, I forget about AddMessageFilter.
>
> I have not really used AddMessageFilter to say if there are any hidden
> problems or not.
>
> Hope this helps
> Jay
>
> "Dmitry" <dpristin@att.net> wrote in message
> news:uUpESkFWDHA.2156@TK2MSFTNGP11.phx.gbl...
> > Just one more thing - can I get away with using
> > Application.AddMessageFilter
> > instead of overriding Control.WndProc ? If, say, my implementation of
the
> > filter
> > modified some GUI controls this would ultimately end up in sending some
> > "normal"
> > messages into my app's message queue etc. Is there any hidden problem
with
> > this approach?
> >
> > Thanks,
> > Dmitry.
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow@email.msn.com> wrote in
> message
> > news:e4YszFFWDHA.3220@tk2msftngp13.phx.gbl...
> > > Dmitry,
> > > You will need to use P/Invoke to define the Win32 SendMessage api, to
> send
> > > your message.
> > >
> > > Then you will need to override Control.WndProc to handle the message.
> > >
> > > The following article shows how to use SendMessage.
> > >
> >
>
http://msdn.microsoft.com/vbasic/using/building/windows/printing/default.aspx?pull=/library/en-us/dnwinforms/html/wnf_richtextbox.asp
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "Dmitry" <dpristin@att.net> wrote in message
> > > news:us2Z7AFWDHA.1280@tk2msftngp13.phx.gbl...
> > > > Hi,
> > > >
> > > > can anybody tell me if there is a way to define and send a custom
> > windows
> > > > message to a window and to specify
> > > > a handler function for it in C#?
> > > >
> > > > The reason I'm asking this is following - I use some 3d party
> component
> > > that
> > > > start its own threads. When my
> > > > command is executed by this component it invokes my callback in the
> > > context
> > > > of its thread. But
> > > > I need to somehow update my GUI after that. I can't access my GUI
> > controls
> > > > from this callback (get an
> > > > exception - wrong thread or something like that), so I thought that
if
> I
> > > > could place a message into my app's
> > > > message queue then I could handle this situation properly.
> > > >
> > > > Thanks in advance!
> > > >
> > > > Regards,
> > > > Dmitry.
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: Sending a custom Windows message by Claes

Claes
Mon Aug 04 03:47:43 CDT 2003

How about solving the original problem instead :-)
To update your GUI from another thread you use
Invoke or BeginInvoke (sync. and async. resp.)

No need to call SendMessage

/claes


"Dmitry" <dpristin@att.net> wrote in message
news:us2Z7AFWDHA.1280@tk2msftngp13.phx.gbl...
> Hi,
>
> can anybody tell me if there is a way to define and send a custom windows
> message to a window and to specify
> a handler function for it in C#?
>
> The reason I'm asking this is following - I use some 3d party component
that
> start its own threads. When my
> command is executed by this component it invokes my callback in the
context
> of its thread. But
> I need to somehow update my GUI after that. I can't access my GUI controls
> from this callback (get an
> exception - wrong thread or something like that), so I thought that if I
> could place a message into my app's
> message queue then I could handle this situation properly.
>
> Thanks in advance!
>
> Regards,
> Dmitry.
>
>