Help with WndProc

D

Derrick

Hello all;

I'm trying to create a UI that's a little atypical. In the main form's
Paint event handler, I draw an image on the form - this is what I want to by
my "real" UI. I turned off the form border, and set the form's background
and transparency key to be the same value. As you know, because of this
there is no sign of the form, just the image I painted. So far, so good.

Since the form border - and hence the title bar - is gone, there was no way
to move (drag) the UI around on screen. To accomplish this, I did a bit of
Googling and found an override for WndProc that seems to do the trick (see
code snippet below). Trouble is, now if you double-click on the UI graphic,
the form seems to maximize - i.e., the form border reappears, explodes to
its maximized state (and also moves my graphic along with it), then the
border disappears again. When you double-click while maximized, the reverse
happens, and the form restores to its original size (and again, my graphic
moves as a result).

Looking at the WndProc code, I understand why this happens - I'm just
catching a click in the client area and telling the system that the click
occured on the titlebar. But I've never had to deal with these low level
Windows messages before, and I'm not sure how to get rid of this
double-click behavior while keeping the ability to drag my image around the
screen.

Any help is greatly appreciated!

Derrick

Here is the WndProc code that I have on my form:

// This function allows the user to move the form around even though the
border is off

protected override void WndProc(ref Message m)

{

// Let the base class have first crack

base.WndProc(ref m);


int WM_NCHITTEST = 0x84; // winuser.h

if( m.Msg != WM_NCHITTEST ) return;

// If the user clicked on the client area,

// ask the OS to treat it as a click on the caption

// i.e., allow relocation

int HTCLIENT = 1;

int HTCAPTION = 2;

if( m.Result.ToInt32() == HTCLIENT )

m.Result = (IntPtr)HTCAPTION;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top