Receive a WIN32 message in a C # class

0

What I'm trying to do is send a WIN32 message using

[DllImport("user32")]
public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);

and receive it in my static Program class, where I have the main() method.

I know that in a form it can be received by protected override void WndProc(ref Message m) , but I do not know how to do it (or if it can be done) in a normal class.

    
asked by gabriel-ar 02.01.2018 в 19:21
source

1 answer

0

If possible using Application.AddMessageFilter(msg_filter) .

First, the IMessageFilter interface is implemented, this is where the messages are received:

class MessageFilter:IMessageFilter {
    public bool PreFilterMessage(ref Message m) {
        if(m.Msg == mensaje_a_procesar) {
            //Aqui se realiza la acción
            return true;
            }
            return false;
        }
    }

Then it is used to fill in the function parameter:

MessageFilter msg_filter = new MessageFilter();
Application.AddMessageFilter(msg_filter);
    
answered by 02.01.2018 / 21:09
source