Custom handling of the non-client area

I recently saw a post in an MS newsgroup and as I had an example that I wrote earlier, I just thought I’d make it available. What this does is simple: it implements custom handling of the non-client area of a window. The non-client area is, normally, the area of a window that is not part of the client area (duh!), like that used for adornments, window buttons, borders, that kind of thing.

While the user moves the mouse over a window’s area, Windows sends messages to figure out which part of the window is currently underneath the mouse cursor, and if it finds certain areas, it handles the corresponding functionality itself. By overriding the default behaviour and returning the right values for these messages, it’s therefore easy to have Windows activate the resize behaviour of the right border, for instance, although the mouse cursor is actually not over the right border at that moment (or even if there isn’t any right border at all).

My sample program draws some rects on its client area that “pose” as the borders of the window, as well as the title bar and the resize rect in the lower right hand corner. Looks like this:

CustomNCHandling

Here’s the download, which includes source code as well as a compiled version of the application, in case you just want to try it quickly.

CustomNCHandling.zip (15 KB)

3 Comments on Custom handling of the non-client area

  1. Carlos Simões // March 29, 2007 at 2:37 pm // Reply

    This was very helpful.Thank you.

    Like

  2. Thank you Oliver, this short article helped me to handle easily any mouse event -coming from the client area or not- in the OnMouseDown/Up/Move methods.

    Like

  3. Fastflood // June 5, 2011 at 5:02 pm // Reply

    Thank you very much for this article. I tested different codes to resize a form without using the border and this one is the best.

    Like

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s