msdn上MessageWindow例子的报错

jennelee 2012-04-10 02:01:13
代码的话我是完全拷贝 msdn上的MessageWindow

我的asp.net版本是v2.0.50727
我用过的dll版本2.0的分别有
2.0.5236.0
2.0.5238.0
2.0.7045.0
我初步怀疑还是我版本用的不对。如果有合适v2.0.50727 的dll麻烦发给我一下,谢谢大虾
如果不是该问题的话,可否有其他的解决办法

这个错误的话是我移动鼠标时报的异常
1.0的话连运行都报错

以下是报错详细信息
未处理 System.InvalidProgramException
Message="公共语言运行库检测到无效的程序。"
Source="Microsoft.WindowsCE.Forms"
StackTrace:
在 Microsoft.WindowsCE.Forms.MessageWindow.get_Hwnd()
在 MsgWindow.MessageWindowForm.OnMouseMove(MouseEventArgs e) 位置 D:\play\ro3\ro3\MessageWindowForm.cs:行号 42
在 System.Windows.Forms.Control.WmMouseMove(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 ro3.Program.Main() 位置 D:\play\ro3\ro3\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()


示例代码如下:
using System;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace MsgWindow
{
public class MessageWindowForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;

// Create an instance of MsgWindow, a derived MessageWindow class.
MsgWindow MsgWin;

public MessageWindowForm()
{

InitializeComponent();

// Create the message window using this form for its constructor.
this.MsgWin = new MsgWindow(this);

}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.Menu = this.mainMenu1;
this.Text = "Message Window Test";

}
#endregion

// Process taps to generate messages
// with the WParam and LParam parameters
// using the X and Y mouse coordinates.
protected override void OnMouseMove(MouseEventArgs e)
{
Microsoft.WindowsCE.Forms.Message msg = Microsoft.WindowsCE.Forms.Message.Create(MsgWin.Hwnd,
MsgWindow.WM_CUSTOMMSG,
(IntPtr)e.X,
(IntPtr)e.Y);
//这步报错
MessageWindow.SendMessage(ref msg);
base.OnMouseMove(e);
}

// This callback method responds to the Windows-based message.
public void RespondToMessage(int x, int y)
{
this.Text = "X = " + x.ToString() + ", Y= " + y.ToString();
}
}

// Derive MessageWindow to respond to
// Windows messages and to notify the
// form when they are received.
public class MsgWindow : MessageWindow
{
// Assign integers to messages.
// Note that custom Window messages start at WM_USER = 0x400.
public const int WM_CUSTOMMSG = 0x0400;


// Create an instance of the form.
private MessageWindowForm msgform;

// Save a reference to the form so it can
// be notified when messages are received.
public MsgWindow(MessageWindowForm msgform)
{
this.msgform = msgform;
}

// Override the default WndProc behavior to examine messages.
protected override void WndProc(ref Microsoft.WindowsCE.Forms.Message msg)
{
switch (msg.Msg)
{
// If message is of interest, invoke the method on the form that
// functions as a callback to perform actions in response to the message.
case WM_CUSTOMMSG:
this.msgform.RespondToMessage((int)msg.WParam, (int)msg.LParam);
break;
}
// Call the base WndProc method
// to process any messages not handled.
base.WndProc(ref msg);
}
}
}

...全文
81 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧