471,348 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Problems with NCHITTEST

I'm currently trying to implement a Form that uses the BorderStyle
"None" property but still allows the user to resize, move the window
around, etc.

This is all working correctly - now I run into a problem where I really
want the window to have a border, but I want it to have just a small
line as a border. Idealy I'd want to use a GroupBox or something to
make everything easy - the problem i'm having is that once the groupbox
is on the form the NCHITTEST doesn't fire anymore because the mouse is
hitting the GroupBox instead of the Form. Also the HTCLOSE doesn't
work, I'm assuming it's because this Form is borderless?

Obviously this is a lot more complicated but I was just wondering what
you guys thought of the whole situation and what you'd do in this case.
Here's my current wndproc code:

protected override void WndProc(ref Message m)
{
int x = MsgParams.LoWord(m.LParam.ToInt32());
int y = MsgParams.HiWord(m.LParam.ToInt32());
Point p = new Point(x, y);
p = this.PointToClient(p);
switch (m.Msg)
{
case (int)MSG.WM_NCHITTEST:
DefWndProc(ref m);
if (p.X < 15 && p.Y > (this.Height - 15))
{
// Allow resizing on bottom left corner
// eventually have an enum handle which corner
// we're currently allowed to resize and check it
// in another switch case statement.
m.Result = new IntPtr((int)HIT_TEST.HTBOTTOMLEFT);
}
else if (p.Y < 30)
{
// Allow the form to be moved around the screen
// Eventually do not hard code the "30" value.
m.Result = new IntPtr((int)HIT_TEST.HTCAPTION);
}
else if (p.X > this.Width - 15 && p.Y < 15)
{
// Allow the form to be closed in the top right
corner
m.Result = new IntPtr((int)HIT_TEST.HTCLOSE);
}
break;
default:
base.WndProc(ref m);
break;
}
}
Dec 2 '05 #1
1 3836
I figured out what to do - onPaint i'm drawing the rectangle the size of
the client rectangle (minus 1 in width and height)

The form itself now has Padding of 10 on the left, right, bottom and 20
on the top

Everything is working now :)

Benny Raymond wrote:
I'm currently trying to implement a Form that uses the BorderStyle
"None" property but still allows the user to resize, move the window
around, etc.

This is all working correctly - now I run into a problem where I really
want the window to have a border, but I want it to have just a small
line as a border. Idealy I'd want to use a GroupBox or something to
make everything easy - the problem i'm having is that once the groupbox
is on the form the NCHITTEST doesn't fire anymore because the mouse is
hitting the GroupBox instead of the Form. Also the HTCLOSE doesn't
work, I'm assuming it's because this Form is borderless?

Obviously this is a lot more complicated but I was just wondering what
you guys thought of the whole situation and what you'd do in this case.
Here's my current wndproc code:

protected override void WndProc(ref Message m)
{
int x = MsgParams.LoWord(m.LParam.ToInt32());
int y = MsgParams.HiWord(m.LParam.ToInt32());
Point p = new Point(x, y);
p = this.PointToClient(p);
switch (m.Msg)
{
case (int)MSG.WM_NCHITTEST:
DefWndProc(ref m);
if (p.X < 15 && p.Y > (this.Height - 15))
{
// Allow resizing on bottom left corner
// eventually have an enum handle which corner
// we're currently allowed to resize and check it
// in another switch case statement.
m.Result = new IntPtr((int)HIT_TEST.HTBOTTOMLEFT);
}
else if (p.Y < 30)
{
// Allow the form to be moved around the screen
// Eventually do not hard code the "30" value.
m.Result = new IntPtr((int)HIT_TEST.HTCAPTION);
}
else if (p.X > this.Width - 15 && p.Y < 15)
{
// Allow the form to be closed in the top right
corner
m.Result = new IntPtr((int)HIT_TEST.HTCLOSE);
}
break;
default:
base.WndProc(ref m);
break;
}
}

Dec 2 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jerome Lefebvre | last post: by
14 posts views Thread by Jim Hubbard | last post: by
5 posts views Thread by Corky | last post: by
2 posts views Thread by Ellen Graves | last post: by
reply views Thread by Sergistm | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.