C# 使用窗口句柄禁用鼠标单击#
我需要禁用鼠标点击,鼠标移动一个特定的窗口为一个信息亭应用程序。这在C#中可行吗 我已经删除了特定窗口的菜单栏和标题栏,这是否是实现上述要求的起点?我怎样才能达到这个要求 使用窗口句柄删除菜单栏和标题栏的代码:C# 使用窗口句柄禁用鼠标单击#,c#,C#,我需要禁用鼠标点击,鼠标移动一个特定的窗口为一个信息亭应用程序。这在C#中可行吗 我已经删除了特定窗口的菜单栏和标题栏,这是否是实现上述要求的起点?我怎样才能达到这个要求 使用窗口句柄删除菜单栏和标题栏的代码: #region Constants //Finds a window by class name [DllImport("USER32.DLL")] public static extern IntPtr FindWindow(string lpClassNam
#region Constants
//Finds a window by class name
[DllImport("USER32.DLL")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
//Sets a window to be a child window of another window
[DllImport("USER32.DLL")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//Sets window attributes
[DllImport("USER32.DLL")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
//Gets window attributes
[DllImport("USER32.DLL")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr GetMenu(IntPtr hWnd);
[DllImport("user32.dll")]
static extern int GetMenuItemCount(IntPtr hMenu);
[DllImport("user32.dll")]
static extern bool DrawMenuBar(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
//assorted constants needed
public static uint MF_BYPOSITION = 0x400;
public static uint MF_REMOVE = 0x1000;
public static int GWL_STYLE = -16;
public static int WS_CHILD = 0x40000000; //child window
public static int WS_BORDER = 0x00800000; //window with border
public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar
public static int WS_SYSMENU = 0x00080000; //window menu
#endregion
public static void WindowsReStyle()
{
Process[] Procs = Process.GetProcesses();
foreach (Process proc in Procs)
{
if (proc.ProcessName.StartsWith("notepad"))
{
IntPtr pFoundWindow = proc.MainWindowHandle;
int style = GetWindowLong(pFoundWindow, GWL_STYLE);
//get menu
IntPtr HMENU = GetMenu(proc.MainWindowHandle);
//get item count
int count = GetMenuItemCount(HMENU);
//loop & remove
for (int i = 0; i < count; i++)
RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE));
//force a redraw
DrawMenuBar(proc.MainWindowHandle);
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_SYSMENU));
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION));
}
}
}
#区域常数
//按类名查找窗口
[DllImport(“USER32.DLL”)]
公共静态外部IntPtr FindWindow(字符串lpClassName,字符串lpWindowName);
//将一个窗口设置为另一个窗口的子窗口
[DllImport(“USER32.DLL”)]
公共静态外部IntPtr SetParent(IntPtr hWndChild、IntPtr hwndnnewparent);
//设置窗口属性
[DllImport(“USER32.DLL”)]
公共静态外部intsetWindowLong(IntPtr hWnd、intnindex、intdwnewlong);
//获取窗口属性
[DllImport(“USER32.DLL”)]
公共静态外部intgetWindowLong(IntPtr hWnd,intnindex);
[DllImport(“user32.dll”,EntryPoint=“FindWindow”,SetLastError=true)]
静态外部IntPtr FindWindowByCaption(IntPtr zeronly,字符串lpWindowName);
[DllImport(“user32.dll”)]
静态外部IntPtr GetMenu(IntPtr hWnd);
[DllImport(“user32.dll”)]
静态外部int GetMenuItemCount(IntPtr hMenu);
[DllImport(“user32.dll”)]
静态外部布尔图菜单栏(IntPtr hWnd);
[DllImport(“user32.dll”)]
静态外部布尔删除菜单(输入菜单、单元上移菜单、单元下移菜单);
//需要分类常数
公共静态uint MF_BYPOSITION=0x400;
公共静态uint MF_REMOVE=0x1000;
公共静态int GWL_STYLE=-16;
公共静态int WS_CHILD=0x40000000//子窗口
公共静态int WS_BORDER=0x00800000//有边框的窗户
公共静态int WS_DLGFRAME=0x00400000//带有双边框但没有标题的窗口
公共静态int-WS_-CAPTION=WS_-BORDER | WS_-DLGFRAME//带有标题栏的窗口
公共静态int WS_SYSMENU=0x00080000//窗口菜单
#端区
公共静态void WindowsReStyle()
{
Process[]Procs=Process.getprocesss();
foreach(过程中的过程)
{
if(proc.ProcessName.StartsWith(“记事本”))
{
IntPtr pFoundWindow=proc.MainWindowHandle;
int style=GetWindowLong(pFoundWindow,GWL_样式);
//获取菜单
IntPtr HUMENU=GetMenu(程序MainWindowHandle);
//获取项目计数
int count=GetMenuItemCount(HMENU);
//循环和移除
for(int i=0;i
要防止在另一个进程中在窗口中输入键盘,您需要。然后,您可以检查并抑制输入。要防止在另一个进程中在窗口中输入键盘,您需要。
然后,您可以检查并抑制输入。这听起来像是您正在寻找的。说明如下: 启用或禁用鼠标和键盘 输入到指定的窗口或 控制当输入被禁用时 窗口不接收输入,例如 鼠标点击和按键。什么时候 如果启用输入,窗口将接收 所有输入 所以你要补充一句
[DllImport("user32.dll")]
static extern bool EnableWindow(IntPtr hWnd, bool enable);
及
这相当于在Windows窗体窗体/控件上设置Enabled属性。这听起来像是您要查找的。说明如下: 启用或禁用鼠标和键盘 输入到指定的窗口或 控制当输入被禁用时 窗口不接收输入,例如 鼠标点击和按键。什么时候 如果启用输入,窗口将接收 所有输入 所以你要补充一句
[DllImport("user32.dll")]
static extern bool EnableWindow(IntPtr hWnd, bool enable);
及
这相当于在Windows窗体窗体/控件上设置Enabled属性。您可以尝试覆盖WndProc并在那里检查WM_MOUSE*事件。如果您没有为这些已处理的事件调用基本WndProc,它应该可以工作。
这里要考虑的一点是,既然你是一个信息亭应用程序,你的特殊鼠标处理会导致触摸屏的任何问题。 < P>你可以尝试重写WNDPROC并检查其中的WMY*鼠标事件。如果您没有为这些已处理的事件调用基本WndProc,它应该可以工作。
这里要考虑的一点是,既然你是一个信息亭应用程序,你的特殊鼠标处理会导致触摸屏出现问题吗?从亭中拔出鼠标和键盘。你想在程序上做这个程序吗?如果是这样的话:OS版本是什么?什么.net版本?什么客户端技术,winforms?WPF?@Rusty,这是WinXp、Dotnet Visual studio c#2008、Framework 3.5、Winforms@srk,您正在编写Kiosk应用程序或试图阻止输入现有应用程序?从Kiosk拔下鼠标和键盘?是否要以编程方式执行此操作?是否编写应用程序?…如果是,请说明操作系统版本?什么.net版本?什么客户端技术,winforms?WPF?@Rusty,这是WinXp、Dotnet Visual studio c#2008、Framework 3.5、Winforms@srk,您正在编写Kiosk应用程序或试图阻止对现有应用程序的输入?可以详细说明吗?现在,我将窗口设置为我的应用程序。现在如何抑制窗口中的输入?可以详细说明吗?现在,我将窗口设置为我的应用程序。现在如何抑制窗口中的输入?