使用c#删除外部应用程序的标题栏
我的应用程序启动另一个外部应用程序。
我想在该外部应用程序启动后删除其标题栏。
这是否可行?如果可行,将如何实现?
根据评论,我正在使用下面的工作代码
//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);
//assorted constants needed
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 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);
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION));
}
}
}
My application starts up another external application.
I want to remove the title bar of this external application once it has started.
Is this feasible, and if so how would it be done?
Based on the comments I am using the working code below
//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);
//assorted constants needed
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 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);
SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION));
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
无需注入任何内容,您只需使用 API 即可修改 Windows 样式位,例如,这适用于记事本,但 YMMV 取决于您正在使用的应用程序。
No need to inject anything, you can just modify the windows style bits as using the API, e.g. this works for Notepad, however YMMV depending on the app you're playing with.
好吧,Alex 从未详细说明过代码,至少这不是一个即插即用的解决方案,但这仍然主要归功于他......这有点错误,除非您使用“SetParent”来放置它在某种容器中(例如表单或面板)只是想我会分享结果。
Visual Basic:
C Sharp(C#)
再次感谢 Alex
Well, Alex never elaborated with the code, well at least it wasn't a plug-n-play solution, but still the main credit for this goes to him... It IS kind of buggy unless you use "SetParent" to put it in some kind of container(such as a form or panel) Just thought I would share the result.
Visual Basic:
C Sharp(C#)
Again, Thank you Alex
这与之前提出的问题非常相似,我很确定答案是你做不到。 (或者,如果可以的话,您需要深入研究 Windows API,这可能具有挑战性,具体取决于您的经验。)
如何将按钮添加到其他应用程序窗口标题栏(XP/Vista)
This is very similar to a previously asked question, and I'm pretty sure that the answer is you can't do it. (or, if you can, you need to dig into the Windows API, which can be challenging, depending on your experience.)
How to add button to other apps window title bar (XP/Vista)
如果是同步融合,则不会。如果没有,是的。
VB:
C#:
If Syncfusion, no. If not, yes.
VB:
C#:
如果其他人需要,Alex 答案的 Python 版本:
Python version of Alex's answer if someone else needs:
一般来说,除非您正在启动的应用程序直接支持(例如,如果它需要一个命令行开关来删除标题栏),否则您不能这样做。
您只能控制
ProcessStartInfo
类(即打开一个新窗口、启动最小化/最大化等...)。In general, you can't do that unless there is direct support for in by the application you are starting (for example, if it takes a command line switch for removal of the title bar).
You can only control the things that are already present on the
ProcessStartInfo
class (i.e. open a new window, start minimized/maximized etc...).