I get this error randomly that doesn't seem to cause anything to not work
correctly. The exception is caught, and seems to not affect the application
at all:
The code I used to make is so the form cannot be moved:
private const int WM_NCLBUTTONDOWN = 0XA1;
private const int WM_SYSCOMMAND = 0X112;
private const int HTCAPTION = 0X2;
private const int SC_MOVE = 0XF010;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MOVE || m.Msg ==
WM_NCLBUTTONDOWN && m.WParam.ToInt32() == HTCAPTION)
return;
}
base.WndProc(ref m);
}
The exception:
General Information
*********************************************
Additional Info:
ExceptionManager.MachineName: XXXXXXXXXX
ExceptionManager.TimeStamp: 12/1/2004 1:26:24 PM
ExceptionManager.FullName: Microsoft.ApplicationBlocks.ExceptionManagement,
Version=1.0.1441.27626, Culture=neutral, PublicKeyToken=null
ExceptionManager.AppDomainName: AdltTestUILoader.exe
ExceptionManager.ThreadIdentity:
ExceptionManager.WindowsIdentity:XXXXXXXXXX\Administrator
1) Exception Information
*********************************************
Exception Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
TargetSite: Void Form_Activated(System.Object, System.EventArgs)
HelpLink: NULL
Source: Microsoft.ApplicationBlocks.UIProcess
StackTrace Information
*********************************************
at
Microsoft.ApplicationBlocks.UIProcess.WindowsFormViewManager.Form_Activated(
Object source, EventArgs e)
at System.Windows.Forms.Form.OnActivated(EventArgs e)
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at TxDpsAdlt.UI.BaseForm.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
Is there anyway to figure out what is happening? Like I said, it happens
very irregularly, so I can't really debug it.
thanks a bunch!
Serg - 03 Dec 2004 03:25 GMT
below is the Forms's WndProc, see if anything in it pertains to moving your
window and maybe it will help you disable it.
[EditorBrowsable(EditorBrowsableState.Advanced),
SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
protected override void WndProc(ref Message m)
{
int num1 = m.Msg;
if (num1 <= 0xa1)
{
if (num1 <= 0x18)
{
if (num1 == 1)
{
this.WmCreate(ref m);
return;
}
switch (num1)
{
case 5:
{
this.WmSize(ref m);
return;
}
case 6:
{
this.WmActivate(ref m);
return;
}
case 0x10:
case 0x11:
case 0x16:
{
this.WmClose(ref m);
return;
}
case 0x12:
case 0x13:
case 0x15:
case 0x17:
{
goto Label_0209;
}
case 20:
{
this.WmEraseBkgnd(ref m);
return;
}
case 0x18:
{
this.WmShowWindow(ref m);
return;
}
}
goto Label_0209;
}
if (num1 <= 0x47)
{
if (num1 == 0x24)
{
this.WmGetMinMaxInfo(ref m);
return;
}
if (num1 == 0x47)
{
this.WmWindowPosChanged(ref m);
return;
}
goto Label_0209;
}
switch (num1)
{
case 130:
{
this.WmNCDestroy(ref m);
return;
}
case 0x83:
case 0x85:
{
goto Label_0209;
}
case 0x84:
{
this.WmNCHitTest(ref m);
return;
}
case 0x86:
{
if (this.IsRestrictedWindow)
{
base.BeginInvoke(new
MethodInvoker(this.RestrictedProcessNcActivate));
}
base.WndProc(ref m);
return;
}
case 0xa1:
{
goto Label_0163;
}
}
goto Label_0209;
}
if (num1 <= 0x112)
{
if (num1 <= 0xa7)
{
if ((num1 == 0xa4) || (num1 == 0xa7))
{
goto Label_0163;
}
goto Label_0209;
}
if (num1 == 0xab)
{
goto Label_0163;
}
if (num1 == 0x112)
{
this.WmSysCommand(ref m);
return;
}
goto Label_0209;
}
if (num1 <= 0x120)
{
if (num1 == 0x117)
{
this.WmInitMenuPopup(ref m);
return;
}
if (num1 == 0x120)
{
this.WmMenuChar(ref m);
return;
}
goto Label_0209;
}
switch (num1)
{
case 0x211:
{
this.WmEnterMenuLoop(ref m);
return;
}
case 530:
{
this.WmExitMenuLoop(ref m);
return;
}
case 0x213:
case 0x214:
{
goto Label_0209;
}
case 0x215:
{
base.WndProc(ref m);
if (base.Capture && (Control.MouseButtons ==
MouseButtons.None))
{
base.CaptureInternal = false;
}
return;
}
case 0x222:
{
this.WmMdiActivate(ref m);
return;
}
default:
{
goto Label_0209;
}
}
Label_0163:
this.WmNcButtonDown(ref m);
return;
Label_0209:
base.WndProc(ref m);
}
Serg - 03 Dec 2004 03:49 GMT
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
base.WndProc(ref m);
if(m.Msg == WM_NCHITTEST && m.Result == (IntPtr)2)
{
m.Result = (IntPtr) 1;
}
}
TS - 06 Dec 2004 15:45 GMT
ok, so i just replace what i had with this?
I still need to call base.WndProc(), right?
> protected override void WndProc(ref Message m)
> {
[quoted text clipped - 6 lines]
> }
> }
TS - 06 Dec 2004 15:54 GMT
The application is going to be run on a touch screen with the cursor set to
invisible. Does this have any implications?
> protected override void WndProc(ref Message m)
> {
[quoted text clipped - 6 lines]
> }
> }
TS - 06 Dec 2004 18:17 GMT
the touch system calls mouse events, so its treated as a mouse
> The application is going to be run on a touch screen with the cursor set to
> invisible. Does this have any implications?
[quoted text clipped - 9 lines]
> > }
> > }
Claes Bergefall - 03 Dec 2004 09:11 GMT
Are you sure the problem is in WndProc?
The stack trace seems to indicate something else
When you handle WM_SYSCOMMAND and
WM_NCLBUTTONDOWN you should return 0
(i.e. m.Result = IntPtr.Zero before return;)
/claes
> I get this error randomly that doesn't seem to cause anything to not work
> correctly. The exception is caught, and seems to not affect the application
[quoted text clipped - 47 lines]
> *********************************************
> at
Microsoft.ApplicationBlocks.UIProcess.WindowsFormViewManager.Form_Activated(
> Object source, EventArgs e)
> at System.Windows.Forms.Form.OnActivated(EventArgs e)
[quoted text clipped - 11 lines]
>
> thanks a bunch!
Serg - 03 Dec 2004 18:43 GMT
Claes you don't need any of that. Why WM_SYSCOMMAND? I posted the codes that
does exactly what he needed. Here it is again for you:
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x84;
base.WndProc(ref m);
if(m.Msg == WM_NCHITTEST && m.Result == (IntPtr)2)
{
m.Result = (IntPtr) 1;
}
}
> Are you sure the problem is in WndProc?
> The stack trace seems to indicate something else
[quoted text clipped - 75 lines]
> >
> > thanks a bunch!