首页 新闻 赞助 找找看

winform messagebox.show自动关闭

0
悬赏园豆:10 [已关闭问题] 关闭于 2012-09-13 13:38

无法找到 PInvoke DLL “User32.dll” 这是什么原因。我要怎样才能获得user32.dll

问题补充:

[DllImport("User32", CharSet = CharSet.Auto)]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32", CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hwd, int msg, IntPtr wparam, IntPtr lParma);// 这是user32外部导入
public const int WM_CLOSE = 0x10;

private void btnShow_Click(object sender, EventArgs e)
{
System.Windows.Forms.Timer setTimer = new System.Windows.Forms.Timer();
setTimer.Interval = (2000);
setTimer.Tick += new EventHandler(setTimer_Tick);
setTimer.Enabled = true;
setTimer.Start();

MessageBox.Show("2秒后关闭", "自动关闭");
}


void setTimer_Tick(object sender, EventArgs e)
{
KillMessageBox();
((System.Windows.Forms.Timer)sender).Stop();
}
void KillMessageBox()
{
IntPtr ptr = FindWindow(null, "自动关闭");//执行到这里 无法找到user32
if (ptr != IntPtr.Zero)

PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);

}

 

是在windows ce 系统下

追逐悟回忆的主页 追逐悟回忆 | 初学一级 | 园豆:119
提问于:2012-07-27 13:06
< >
分享
所有回答(2)
0

你是通过托管代码调用User32.dll内的函数了?WindowsXP与Windows7平台是不一样的。

你可以把问题描述的更清楚一些,方便大家帮你解决问题。

solan3000 | 园豆:223 (菜鸟二级) | 2012-07-27 13:10
1

在WINCE中,"Coredll.dll"对应了"Kernel32.dll"和"User32.dll"这两个文件了,所以将"Kernel32.dll"换成"Coredll.dll"问题就解决了。

 

我也遇到同样问题,在http://www.mysjtu.com/page/M0/S557/557367.html 有解决。

copener | 园豆:202 (菜鸟二级) | 2012-12-07 17:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册