c# - 如何停止 Wndproc() 循环?
问题描述
我已经覆盖了 wndproc() 以使用热键。但表格将不再关闭。并关闭程序在 wndproc() 中陷入无限循环。
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x0312)
{
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
int id = m.WParam.ToInt32();
MessageBox.Show("Hotkey has been pressed!");
// do something
}
}
我已将 e.cancel 设置为 true 并在 OnFoemClosing 方法中添加了以下代码`
e.Cancel = false;
base.OnFormClosing(e);
但什么也没有发生。
解决方案
[DllImport("user32.dll")]
static extern bool DestroyWindow(IntPtr hWnd);
//Closes the form
btnCloseWindow_Click(object sender, EventArgs e)
{
DestroyWindow(this.Handle);
}`[DllImport("user32.dll")]
static extern bool DestroyWindow(IntPtr hWnd);
//Closes the form
btnCloseWindow_Click(object sender, EventArgs e)
{
DestroyWindow(this.Handle);
}`
推荐阅读
- python - 使机器人重新发送具有所有属性的嵌入
- javascript - 关于范围界定和提升的新手问题?
- buffer-overflow - 链接器标志 `execstack` 未应用于 `.rodata`、`.data` 或 `.bss` 部分.... 出了什么问题?
- javascript - 是否可以将随机 html 站点与节点 javascript 链接?
- excel - Excel 将功能区选项卡的颜色从绿色更改为灰色
- c - 如何在宏和全局变量之间使用逻辑或运算
- reactjs - 使用 react-router 进行复杂路由
- spring-boot - 从枚举中插入默认实体
- c++ - C ++测试回调是否为空
- python - 应用程序未运行时如何在 kivy 中发送推送通知?