强制窗口不接收WM_消息? [英] Force a window to not receive WM_ messages ?
问题描述
我该怎么做才能使窗口永远不会收到任何< b> WM_</b>信息 ?还是至少不处理或应用它们?还是要从消息队列中丢弃它们?
< i>这些功能对您有帮助吗? :</i>
-GetMessage函数吗?
或
-DispatchMessage函数吗?
或
-PostQuitMessage函数吗?
或
-WaitMessage函数吗?
或
-PeekMessage()函数?
非常感谢您的帮助!
我来自另一个q/a网站,因为没人愿意在那里提供任何帮助并保持关闭我的线程:(
再次感谢您:)
What can I make to a window to NEVER receive any <b>WM_</b> message ? OR atleast to not process or apply them? Or to discard them from the Message Queue ?
<i>Can those functions be helpful ? :</i>
-GetMessage function ?
or
-DispatchMessage function ?
or
-PostQuitMessage function ?
or
-WaitMessage function ?
or
-PeekMessage()function ?
Thanks alot for any help!
Im coming from another q/a site because no one wants to give any help there and keep closing my threads:(
Thankyou again :)
推荐答案
如何获取窗口的句柄"
http://www.cplusplus.com/forum/beginner/3811/ [
"How to get the handle of the window"
http://www.cplusplus.com/forum/beginner/3811/[^]
我将假设C#.您不想再收到哪种消息?我猜是键盘消息吗?
也许我对您有个主意:
我在项目中使用了某些控件:
KRBTabControl [ ^ ]已被覆盖:
I''ll assume C#. What kind of messages do you not want to receive anymore? I assume keyboard messages?
Maybe I have an idea for you:
I used a certain control in my project:
KRBTabControl[^] that had an override:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if ((keyData == (Keys.Tab | Keys.Control)) || (keyData == (Keys.Tab | Keys.Shift | Keys.Control)))
{
if (!OnNavigateTabPage((keyData & Keys.Shift) != Keys.Shift ? this.SelectedIndex + 1 : this.SelectedIndex - 1, true))
{
msg.Result = new IntPtr(1);
return true;
}
}
else
{
switch (keyData)
{
// Selects Last TabPage
case Keys.End:
if (!OnNavigateTabPage(this.TabCount - 1, false))
{
msg.Result = new IntPtr(1);
return true;
}
break;
// Selects First TabPage
case Keys.Home:
if (!OnNavigateTabPage(0, false))
{
msg.Result = new IntPtr(1);
return true;
}
break;
// Selects the tab on the left side of the currently selected TabPage
//case Keys.Left:
// if (!OnNavigateTabPage(this.SelectedIndex - 1, false))
// {
// msg.Result = new IntPtr(1);
// return true;
// }
// break;
//// Selects the tab on the right side of the currently selected TabPage
//case Keys.Right:
// if (!OnNavigateTabPage(this.SelectedIndex + 1, false))
// {
// msg.Result = new IntPtr(1);
// return true;
// }
// break;
case Keys.Insert:
if (conditionBooleanArray[3] && MessageBox.Show("Do you want to insert a new tab page here?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
TabPageEx tabPage = new TabPageEx();
this.Controls.Add(tabPage);
}
break;
case Keys.Delete:
if (conditionBooleanArray[3] && this.TabCount > 0)
{
if (MessageBox.Show("Do you want to remove the selected tab page?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
TabPageEx removingTabPage = this.SelectedTab as TabPageEx;
if (removingTabPage != null && removingTabPage.IsClosable && removingTabPage.Enabled)
{
using (SelectedIndexChangingEventArgs e = new SelectedIndexChangingEventArgs(removingTabPage, this.SelectedIndex))
{
// Fire a Notification Event.
OnTabPageClosing(e);
if (!e.Cancel)
{
this.TabPages.Remove(removingTabPage);
SelectNextAvailableTabPage();
}
else
MessageBox.Show("The operation was canceled by the user.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show("The selected tab page could not be deleted!!!, it may be due to the following reasons;\r\n\r\n1.Tab page might be null or disposed by the application.\r\n2.Tab page might not be closable.\r\n3.Tab page might be disable.",
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
break;
case Keys.Escape:
break;
case Keys.F1:
break;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
}
return true;
}
如果我删除此控件中的两行:
If I remove the two lines in this control:
default:
return base.ProcessCmdKey(ref msg, keyData);
则控件不会接受任何输入.
那么也许这将以相同的方式在您的项目中起作用?
该方法是此类的一部分:
then the control doesn''t take any input.
So maybe this will work in your project in the same way?
The method is part of this class:
namespace KRBTabControl
{
public partial class KRBTabControl : TabControl
继承自:
which inherits from:
namespace System.Windows.Forms
{
public class TabControl : Control
或覆盖WndProc以您的形式:
受保护的覆盖无效WndProc(参考消息m)
正如他们在这里解释的那样:
http://msdn.microsoft.com/en-us/library/system. windows.forms.message.aspx [ ^ ]
Or override WndProc in your form:
protected override void WndProc(ref Message m)
as they explain here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.message.aspx[^]
这篇关于强制窗口不接收WM_消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!