如何自动点击MessageBox中的"确定"按键

霜寒月冷 2008-08-28 03:26:29
如题!
如何自动点击MessageBox中的"确定"按键
...全文
1836 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
ShineSpark 2010-10-08
  • 打赏
  • 举报
回复
???
WanJianPing 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 23 楼 ghostadai 的回复:]
真搞不懂,让程序自己点不如不弹,何必呢!
[/Quote]
朋友你是搞不懂,往往很多地方就是须要,因为那些消息是人家写的,但是在我的程序中弹出,我又不须要,这样就会用到了
tony_jansan 2010-06-24
  • 打赏
  • 举报
回复
...
qijialin 2010-04-16
  • 打赏
  • 举报
回复
dedwefw
bluepingguo 2008-08-29
  • 打赏
  • 举报
回复
晕了,第一次看见这种需求的,不弹消息不就行了么?把弹消息那个地方注释掉。。。。。
GhostAdai 2008-08-29
  • 打赏
  • 举报
回复
真搞不懂,让程序自己点不如不弹,何必呢!
zt_100094 2008-08-29
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 yatobiaf 的回复:]
用try catch啊,不出来messagebox不就行了,干嘛要让他出来然后自己点掉确定呢?
[/Quote]

qinqinhao 2008-08-29
  • 打赏
  • 举报
回复
ding
benjerry 2008-08-29
  • 打赏
  • 举报
回复
11楼写的好棒,findwindow,酷
yatobiaf 2008-08-28
  • 打赏
  • 举报
回复
用try catch啊,不出来messagebox不就行了,干嘛要让他出来然后自己点掉确定呢?
DENGJINGJIE 2008-08-28
  • 打赏
  • 举报
回复
我喜欢用api,学学
霜寒月冷 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 ericzhangbo1982111 的回复:]
如果是确定的话可以
这样写
public class msg
{
[DllImport("user32", EntryPoint = "FindWindow")]
public static extern int FindWindowA(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lps…
[/Quote]
辛苦你了阿,我先试试...
ZengHD 2008-08-28
  • 打赏
  • 举报
回复
那用11楼的方法,使用FindWindow
霜寒月冷 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ZengHD 的回复:]
C# code加个时钟
timer1.Interval = 2000;
timer1.Enabled = true;
timer1.Tick += delegate { SendKeys.Send("{ENTER}"); };
MessageBox.Show("ok");
timer1.Enabled = false;
[/Quote]
谢谢楼上的,问题解决了一部分
这个好像一定要在当前窗口才行的.
如果不在当前窗口..好像还会出错的.
ZengHD 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ZengHD 的回复:]
C# code加个时钟
timer1.Interval=2000;
timer1.Enabled=true;
timer1.Tick+=delegate{ SendKeys.Send("{ENTER}"); };
MessageBox.Show("ok");
timer1.Enabled=false;
[/Quote]
换成Esc好点
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 2000;
timer1.Enabled = true;
timer1.Tick += delegate { SendKeys.Send("{ESC}"); };
MessageBox.Show("ok");
timer1.Enabled = false;
}
ericzhangbo1982111 2008-08-28
  • 打赏
  • 举报
回复
如果是确定的话可以
这样写
public class msg
{
[DllImport("user32", EntryPoint = "FindWindow")]
public static extern int FindWindowA(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(int hWnd, int Msg, IntPtr wParam, string lParam);



public const int WM_CLOSE = 0x10;
public const string MsgTitle = "Test Message";
public void show1(string text)
{
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 3000;
timer1.Enabled = true;
MessageBox.Show("若不回應的話,X秒後此 MsgBox 會自動關閉", MsgTitle);
timer1.Enabled = false;

}
private void timer1_Tick(object sender, EventArgs e)
{
int hWnd;
string lpClassName="";
hWnd = FindWindowA(null, MsgTitle);
//FindWindow(button1_Click, MsgTitle);
SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, "");
((Timer)sender).Stop();
}

}


调用
msg m = new msg();
m.show1("aa");

当然你可以用FindWindowEx来找到确定的按钮
然后发送click的指令就可以了
剩下的我就不写了。 大概就这样了。

http://www.codeproject.com/KB/dialog/MessageBoxManager.aspx
ZengHD 2008-08-28
  • 打赏
  • 举报
回复
加个时钟
timer1.Interval = 2000;
timer1.Enabled = true;
timer1.Tick += delegate { SendKeys.Send("{ENTER}"); };
MessageBox.Show("ok");
timer1.Enabled = false;
newtypebao 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 chz415767975 的回复:]
引用 6 楼 wuyi8808 的回复:
引用 5 楼 chz415767975 的回复:
我是为了防止程序中出错跳出提示,终止运行.所以才自动点messagebox确定的



C# codetry
{
// ...
}
catch
{
}

这个好是好阿.要能自动把它"messagebox"点掉就更好了阿
[/Quote]


你在catch里面什么都不写的话 就等于不报错了。..
霜寒月冷 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wuyi8808 的回复:]
引用 5 楼 chz415767975 的回复:
我是为了防止程序中出错跳出提示,终止运行.所以才自动点messagebox确定的



C# codetry
{
// ...
}
catch
{
}
[/Quote]
这个好是好阿.要能自动把它"messagebox"点掉就更好了阿
霜寒月冷 2008-08-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 gisfarmer 的回复:]
添加消息事件。需要自动点击的时候,执行消息就ok了。

private void tsmLoadbmp_Click(object sender, EventArgs e)
{
btOK_Click(null,null);
}
[/Quote]
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("确定");
button2_Click(null, null);

}

你的意思是这样吗.我试过..好像不行
加载更多回复(6)

111,082

社区成员

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

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

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