C# 从外部应用程序隐藏或删除按钮
我正在从我的WPF项目运行一个外部应用程序,我正在使用“user32.dll”将外部应用程序放入我的WPF表单中 外部应用程序有一个退出按钮。我想删除或隐藏该按钮。我可以“使用user32.dll”或其他方法来实现吗 先谢谢你 “使用user32.dll” 不,你不能使用user32.dll,因为每个应用程序都在自己的沙盒中,可以说应该不会受到外部不需要的操作的影响C# 从外部应用程序隐藏或删除按钮,c#,wpf,user32,C#,Wpf,User32,我正在从我的WPF项目运行一个外部应用程序,我正在使用“user32.dll”将外部应用程序放入我的WPF表单中 外部应用程序有一个退出按钮。我想删除或隐藏该按钮。我可以“使用user32.dll”或其他方法来实现吗 先谢谢你 “使用user32.dll” 不,你不能使用user32.dll,因为每个应用程序都在自己的沙盒中,可以说应该不会受到外部不需要的操作的影响 (问:您是否有权构建此外部应用程序?答:是)…还是其他方法 由于您可以访问这两个应用程序的代码,请让它们实现一个名为pipe的进程
(问:您是否有权构建此外部应用程序?答:是)…还是其他方法 由于您可以访问这两个应用程序的代码,请让它们实现一个名为pipe的进程间应用程序。在接收应用程序中,让它监视管道中的消息,以关闭按钮或更改其windows框架样式 看 “使用user32.dll” 不,你不能使用user32.dll,因为每个应用程序都在自己的沙盒中,可以说应该不会受到外部不需要的操作的影响
(问:您是否有权构建此外部应用程序?答:是)…还是其他方法 由于您可以访问这两个应用程序的代码,请让它们实现一个名为pipe的进程间应用程序。在接收应用程序中,让它监视管道中的消息,以关闭按钮或更改其windows框架样式 看
下面的代码找到按钮并将其隐藏。它在我的系统上运行良好。代码搜索窗口标题,然后找到控件。您必须提供窗口标题和按钮文本。您可以根据需要更新代码 注意:下面的代码将隐藏所有具有常量文本按钮中指定的匹配文本的控件
const string TEXT_TITLE = "My Specific Window";
const string TEXT_BUTTON = "&HideMeButton";
public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
const int SW_HIDE = 0;
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);
[DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)]
static extern IntPtr GetWindowCaption(IntPtr hwnd, StringBuilder lpString, int maxCount);
public void HideSpecificButton()
{
//Contains the handle, can be zero if title not found
var handleWindow = WinGetHandle(TEXT_TITLE);
if (GetWindowCaption(handleWindow).Trim() != TEXT_TITLE)
MessageBox.Show("Window is hidden or not running.");
else
GetChildWindows(handleWindow);
}
public IntPtr WinGetHandle(string title)
{
IntPtr hWnd = IntPtr.Zero;
foreach (Process pList in Process.GetProcesses())
{
if (pList.MainWindowTitle.Contains(title))
{
hWnd = pList.MainWindowHandle;
}
}
return hWnd;
}
private string GetWindowCaption(IntPtr hwnd)
{
StringBuilder sb = new StringBuilder(256);
GetWindowCaption(hwnd, sb, 256);
return sb.ToString();
}
public void GetChildWindows(IntPtr parent)
{
List<IntPtr> result = new List<IntPtr>();
GCHandle listHandle = GCHandle.Alloc(result);
try
{
EnumWindowProc childProc = new EnumWindowProc(EnumControls);
EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
}
finally
{
if (listHandle.IsAllocated)
listHandle.Free();
}
}
private bool EnumControls(IntPtr handle, IntPtr pointer)
{
var controlTitle = GetWindowCaption(handle).Trim();
if (string.Equals(controlTitle, TEXT_BUTTON, StringComparison.CurrentCultureIgnoreCase))
{
//hide the control
ShowWindow(handle, SW_HIDE);
}
return true;
}
const string TEXT\u TITLE=“我的特定窗口”;
常量字符串文本按钮=“&HideMeButton”;
公共委托bool EnumWindowProc(IntPtr hWnd,IntPtr参数);
[DllImport(“user32.dll”)]
专用静态外部布尔显示窗口(IntPtr hwnd、int nCmdShow);
常量int SW_HIDE=0;
[DllImport(“user32”)]
[返回:Marshallas(UnmanagedType.Bool)]
公共静态外部bool EnumChildWindows(IntPtr窗口、EnumWindowProc回调、IntPtr i);
[DllImport(“user32.dll”,EntryPoint=“GetWindowText”,CharSet=CharSet.Auto)]
静态外部IntPtr GetWindowCaption(IntPtr hwnd、StringBuilder lpString、int maxCount);
public void HideSpecificButton()
{
//包含句柄,如果未找到标题,则可以为零
var handleWindow=Wingthandle(文本标题);
如果(GetWindowCaption(handleWindow).Trim()!=文本标题)
Show(“窗口隐藏或未运行”);
其他的
GetChildWindows(handleWindow);
}
公共IntPtr Wingthandle(字符串标题)
{
IntPtr hWnd=IntPtr.0;
foreach(Process.getprocesss()中的进程pList)
{
if(pList.MainWindowTitle.Contains(title))
{
hWnd=pList.MainWindowHandle;
}
}
返回hWnd;
}
私有字符串GetWindowCaption(IntPtr hwnd)
{
StringBuilder sb=新的StringBuilder(256);
GetWindowCaption(hwnd,sb,256);
使某人返回字符串();
}
公共无效GetChildWindows(IntPtr父级)
{
列表结果=新列表();
GCHandle listHandle=GCHandle.Alloc(结果);
尝试
{
EnumWindowProc childProc=新的EnumWindowProc(EnumControls);
EnumChildWindows(父、childProc、GCHandle.ToIntPtr(listHandle));
}
最后
{
if(listHandle.IsAllocated)
Free();
}
}
私有布尔枚举控件(IntPtr句柄、IntPtr指针)
{
var controlTitle=GetWindowCaption(handle.Trim();
if(string.Equals(controlTitle、TEXT_按钮、StringComparison.CurrentCultureIgnoreCase))
{
//隐藏控件
显示窗口(手柄、开关隐藏);
}
返回true;
}
下面的代码找到按钮并将其隐藏。它在我的系统上运行良好。代码搜索窗口标题,然后找到控件。您必须提供窗口标题和按钮文本。您可以根据需要更新代码
注意:下面的代码将隐藏所有具有常量文本按钮中指定的匹配文本的控件
const string TEXT_TITLE = "My Specific Window";
const string TEXT_BUTTON = "&HideMeButton";
public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
const int SW_HIDE = 0;
[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);
[DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)]
static extern IntPtr GetWindowCaption(IntPtr hwnd, StringBuilder lpString, int maxCount);
public void HideSpecificButton()
{
//Contains the handle, can be zero if title not found
var handleWindow = WinGetHandle(TEXT_TITLE);
if (GetWindowCaption(handleWindow).Trim() != TEXT_TITLE)
MessageBox.Show("Window is hidden or not running.");
else
GetChildWindows(handleWindow);
}
public IntPtr WinGetHandle(string title)
{
IntPtr hWnd = IntPtr.Zero;
foreach (Process pList in Process.GetProcesses())
{
if (pList.MainWindowTitle.Contains(title))
{
hWnd = pList.MainWindowHandle;
}
}
return hWnd;
}
private string GetWindowCaption(IntPtr hwnd)
{
StringBuilder sb = new StringBuilder(256);
GetWindowCaption(hwnd, sb, 256);
return sb.ToString();
}
public void GetChildWindows(IntPtr parent)
{
List<IntPtr> result = new List<IntPtr>();
GCHandle listHandle = GCHandle.Alloc(result);
try
{
EnumWindowProc childProc = new EnumWindowProc(EnumControls);
EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
}
finally
{
if (listHandle.IsAllocated)
listHandle.Free();
}
}
private bool EnumControls(IntPtr handle, IntPtr pointer)
{
var controlTitle = GetWindowCaption(handle).Trim();
if (string.Equals(controlTitle, TEXT_BUTTON, StringComparison.CurrentCultureIgnoreCase))
{
//hide the control
ShowWindow(handle, SW_HIDE);
}
return true;
}
const string TEXT\u TITLE=“我的特定窗口”;
常量字符串文本按钮=“&HideMeButton”;
公共委托bool EnumWindowProc(IntPtr hWnd,IntPtr参数);
[DllImport(“user32.dll”)]
专用静态外部布尔显示窗口(IntPtr hwnd、int nCmdShow);
常量int SW_HIDE=0;
[DllImport(“user32”)]
[返回:Marshallas(UnmanagedType.Bool)]
公共静态外部bool EnumChildWindows(IntPtr窗口、EnumWindowProc回调、IntPtr i);
[DllImport(“user32.dll”,EntryPoint=“GetWindowText”,CharSet=CharSet.Auto)]
静态外部IntPtr GetWindowCaption(IntPtr hwnd、StringBuilder lpString、int maxCount);
public void HideSpecificButton()
{
//包含句柄,如果未找到标题,则可以为零
var handleWindow=Wingthandle(文本标题);
如果(GetWindowCaption(handleWindow).Trim()!=文本标题)
Show(“窗口隐藏或未运行”);
其他的
GetChildWindows(handleWindow);
}
公共IntPtr Wingthandle(字符串标题)
{
IntPtr hWnd=IntPtr.0;
foreach(Process.getprocesss()中的进程pList)
{
if(pList.MainWindowTitle.Contains(title))
{
hWnd=pList.MainWindowHandle;
}
}
返回hWnd;
}
私有字符串GetWindowCaption(IntPtr hwnd)
{
StringBuilder sb=新的StringBuilder(256);
GetWindowCaption(hwnd,sb,256);
使某人返回字符串();
}
公共无效GetChildWindows(IntPtr父级)
{
列表结果=新列表();
GCHandle listHandle=GCHandle.Alloc(结果);
尝试
{
EnumWindowProc childProc=新的EnumWindowProc(EnumControls);
EnumChildWindows(父、childProc、GCHandle.ToIntPtr(listHandle));
}
最后
{
if(listHandle.IsAllocated)
Free();
}
}
私有布尔枚举控件(IntPtr句柄、IntPtr指针)
{
var控制权