[RESOLVED] Move borderless form question [urgent]
Hi,
I have this code to move a borderless form which it works great. However when I double click the form it maximizes the form which I don't want.
I really need to disable the maximizing on double-click.
VB Code:
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT) m.Result = new IntPtr(HTCAPTION);
break;
//If m.Result.ToInt32 = HTCLIENT Then m.Result = IntPtr.op_Explicit(HTCAPTION) 'Try this in VS.NET 2002/2003 if the latter line of code doesn't do it... thx to Suhas for the tip.
default:
//Make sure you pass unhandled messages back to the default message handler.
base.WndProc(ref m);
break;
}
}
BTW, this is VS2003
Re: Move borderless form question [urgent]
The WM_NCHITTEST message is only trapping the clicking of the titlebar wether its a single or a double click. Perhaps you should also trap for the maximize message and cancel it out.
WM_NCLBUTTONDBLCLK or WM_SIZING?
Re: Move borderless form question [urgent]
I'd love to do that Rob, would appreciate if you show me how... ;)
Re: Move borderless form question [urgent]
Ok, got it I think. Its the WM_NCLBUTTONDBLCLK message with the wParam of 00000002. 2 is the value for maximize. Trap that message and either cancel out the call or change the wParam to 0 or Normal windowstate.
Re: Move borderless form question [urgent]
Just free hand replying...
add another case to your switch block but I think the first case may cause an issue for the WM_NCBUTTONDBLCLK...
VB Code:
case WM_NCLBUTTONDBLCLK:
base.WndProc(ref m);
if (m.Result.ToInt32() == HTCAPTION) m.Result = new IntPtr(HTCLIENT);
break;
:confused:
Re: Move borderless form question [urgent]
Not sure if that the correct way to cancel it out but here is the other option of the WM_SYSCOMMAND withthe SC_MAXIMIZE wParam.
VB Code:
case WM_SYSCOMMAND:
base.WndProc(ref m);
if (m.Result.ToInt32() == SC_MAXIMIZE) m.Result = new IntPtr(SC_RESTORE);
break;
Re: Move borderless form question [urgent]
Thanks for your efforts, but I can still maximize by double-clicking the form...
Re: Move borderless form question [urgent]
I really think it has to do with the WM_NCHITTEST way of handling is bypassing the message or such. I see someone that may know is online. Let me send a PM. :)
Re: Move borderless form question [RESOLVED-I hope]
Well, I came accross the following and it seems to work. Let me know if you find a bug or a better solution as I don't really know how it works...
VB Code:
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
private const int WM_NCLBUTTONDBLCLK = 0xA3;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (m.Result.ToInt32() == HTCLIENT) m.Result = new IntPtr(HTCAPTION);
break;
[B] case WM_NCLBUTTONDBLCLK:
m.Msg=0; //Discard double-click
break;[/B]
default:
//Make sure you pass unhandled messages back to the default message handler.
base.WndProc(ref m);
break;
}
}
Re: [RESOLVED] Move borderless form question [urgent]
Well the click on the form is being aliased to the titlebar so to speak with your other case statrement so it may be registering as a double click on the titlebar which causes the form to resize either max or restore depending on its current state. Trapping the double click and canceling it out is fine as it locks the form in its current state.