title: Logging the results of mouse clicks in C# Winform app?
body: <p>I'm trying to create a log of each mouse click in my Win form app that records what method or action was triggered by the click event. This would include interacting with not only buttons but tables, docks, etc. (which is where I'm having trouble). Obviously I'd like to avoid going into all my previous code and manually adding a log entry for each event. As of now I've got a MessageFilter that is working fine in terms of intercepting every click, but I haven't figured out how to get the right information about what that click actually did. I am able to detect the button clicked using Control.FromHandle(m.HWnd), but can't distinguish different dock panels for example. Any info on this at all is appreciated; if I'm not able to solve this soon I have to go in and add log entries manually to everything and I'd really love to avoid that. Thanks!</p>
  
  <p>I've tried two potential ways to retrieve that info via the Control, see the PreFilterMessage below: </p>
  
  <pre><code>    public bool PreFilterMessage(ref Message m)
      {
          // if click or doubleclick
          if (m.Msg == 0x201 || m.Msg == 0x0203)
          {
              var oneway = "1st way; " + form.FindForm().ActiveControl.ToString();
              string towrite = "";
  
              if (m.Msg == 0x201)
              { towrite += "CLICK    : "; }
              if (m.Msg == 0x203)
              { towrite += "DBLCLICK : "; }
  
              string anotherway = "1st way; " + "Unknown";
              Control ctl = Control.FromHandle(m.HWnd);
              if (ctl != null) anotherway = "1st way; " + ctl.Name;
  
              //log manager, just takes the log message string
              Admin.Information(towrite + oneway);
              Admin.Information(towrite + anotherway);
  
          }
          return false;
  </code></pre>
  
  <p>The result looks something like this (interspersed with my comments):</p>
  
  <p>**NOTE: I'm using DevExpress to replace the stock UI controls</p>
  
  <p>//selecting different dock panels in the main view, as you can see it doesn't distinguish between them as it should, the 2nd way doesn't display anything</p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; </p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; </p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; </p>
  
  <p>//hitting a custom refresh button, 2nd way is able to pick this up</p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; btnRefresh</p>
  
  <p>//Clicked on different grid/table positions, different dock panels, sorted by different things, selected whole lines. The 2nd way is able to detect action in the proper grid but not what's being done</p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; abcgrid</p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; abcgrid</p>
  
  <p>CLICK    : 1st way; DevExpress.XtraBars.Docking.FloatForm, Text: </p>
  
  <p>CLICK    : 2nd way; abcgrid</p>