For one reason or another, I have a need to detect when the user actually clicked on the X button. What I have so far is this:
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == (int)0xa1) //WM_NCLBUTTONDOWN
        {
            Point p = new Point((int)m.LParam);
            p = this.PointToClient(p);
            if (p.X > 680)
            {
                //do what I need to do...
            }
        }
        base.WndProc(ref m);
    }
Basically, I look out for the "WM_NCLBUTTONDOWN" message which is the Mouse Click on the Non Client Area of a window. Then, I get the X and Y coordinates from the LParam and finally I convert it to Screen Coordinates. So at this point, I know that the user clicked on the non client area and I know where on the Form.
My question is, how can I tell if these coordinates are on the X button. For now, I'm hardcoding 680 because that's what works in the current size of the window (it's not sizable) but the problem is I'm using Windows 7 which has bigger X buttons than XP, so obviously hardocding isn't a viable option. Furthermore, I haven't even coded for the Y coordinates, so if someone clicks on the right edge of the window, that triggers that code as well. So... anyone have any ideas?