Actually, you don’t have to laugh - it sounds to me as if you are doing it right. Since you do not have your own desktop, you do not have to draw it directly. Instead, you need to model it by imposing a transparent shape on it, and then leaning on it. Since you have a transparent overlay form, there is no problem with it.
But beyond that, it sounds like you're just trying to evaluate values without a clear understanding of what they actually do. It's like throwing darts with your eyes closed. You will not have a lot of hits.
Let's start by understanding what your code does. The magic value 0x84 corresponds to the WM_NCHITTEST message that Windows sends to the window to determine how to handle mouse clicks in this window. In response to this message, you will respond with one of the HT* values specified in the related documentation. Each of these values has a special meaning, also explained in the documentation. For example:
HTCAPTION (which has a value of 2) means that the clicked part of the window should be considered as a title bar / window title. You know that with Windows you can drag windows on the screen using the title bar, so it makes sense that returning HTCAPTION in response to mouse clicks will allow you to drag your window. You will see that this is used in borderless formats (i.e. those that do not have a title) so that they can be movable.
HTTRANSPARENT (which has a value of -1) is another available value. It is pretty simple. It just makes your window transparent. I like to say "don't mind me, no window!" Mouse clicks are simply sent to the window, which is below your in order Z, as if you were not there.
HTCLIENT (value 1) is the default result when a click occurs anywhere in the client area of the window. You will return this (or just call the default window procedure) if you want everything to work fine. Click events that return this value will be normally processed by the framework, raising either the Click form event or passing the child controls located on the form.
So, when you are not drawing, you probably want to return HTTRANSPARENT . When you draw, you probably want to return HTCLIENT so that your drawing code can see mouse events and draw the result.
Commit your code, then:
// Code for allowing clicking through of the form protected override void WndProc(ref Message m) { const uint WM_NCHITTEST = 0x84; const int HTTRANSPARENT = -1; const int HTCLIENT = 1; const int HTCAPTION = 2; // ... or define an enum with all the values if (m.Msg == WM_NCHITTEST) { // If it the message we want, handle it. if (penMode) { // If we're drawing, we want to see mouse events like normal. m.Result = new IntPtr(HTCLIENT); } else { // Otherwise, we want to pass mouse events on to the desktop, // as if we were not even here. m.Result = new IntPtr(HTTRANSPARENT); } return; // bail out because we've handled the message } // Otherwise, call the base class implementation for default processing. base.WndProc(ref m); }
Cody gray
source share