开发者

getting last events

ho开发者_高级运维w can I see the last events that my program threw?

for example all the onClick and onPaint events


It depends what events exactly? Just events from controls or all events or what?

There are 4 alternative ways:
a) If you create the objects yourself -> register the events yourself
b) If you want windows events like click, paint or somthing -> register a message filter
c) If it is some special kind of class there might be undocumented ways of intercepting calls in managed code, but it really depends.
d) If there are no other ways you can still hack around using pointers (e.g. api hooking or somthing)


The op decided for option b in my previous post:

Application.AddMessageFilter(new MyMessageFilter());

class MyMessageFilter:IMessageFilter
{
    void PreFilterMessage(ref Message m)
    {
        Control target=Control.FromHandle(m.HWnd);
        //if(target!=null)
        switch((WM)m.Msg)
        {
            case WM.LBUTTONDOWN://left mouse click
            uint x=((uint)m.LParam)&0xFFFF;
            uint y=((uint)m.LParam)>>16;
            ...
            break;
        }
    }
}

The WM-enum can be found here: http://pinvoke.net/default.aspx/Enums/WindowsMessages.html

for more messages have a look at msdn:
- http://msdn.microsoft.com/en-us/library/ff468861%28v=VS.85%29.aspx
- http://msdn.microsoft.com/en-us/library/ff468877%28v=VS.85%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜