简体   繁体   English

更改现有窗口的大小和位置

[英]Change Existing Window Size & Position

I'm currently working on a C# program to manage some configuration files. 我目前正在使用C#程序来管理一些配置文件。 One of the things I feel I need to do is modify the size and/or position of an open window. 我觉得我需要做的一件事是修改打开的窗口的大小和/或位置。 The window already has a fullscreen function but not a maximize. 该窗口已经具有全屏功能,但没有最大化功能。

What I'm trying to do is to hook to that window (which always runs off a java process and has one of 2 names no matter the situation) and change it's size to the size of the screen and remove the border from it. 我想做的是钩到该窗口(无论在什么情况下,该窗口始终在java进程上运行,并且具有2个名称之一),并将其大小更改为屏幕大小,并从中删除边框。

I've searched extensively and the best answer I've found so far is How do I change another program's window's size? 我已经进行了广泛的搜索,到目前为止找到的最佳答案是如何更改另一个程序的窗口大小? but that doesn't affect the border of the program and I can't seem to get any variation of WindowFromPoint to work correctly in C#, not something I've ever come across. 但这不会影响程序的边界,而且我似乎无法获得WindowFromPoint的任何变体以在C#中正常工作,这是我从未遇到过的事情。


As I've said so far the program always is running inside java so the "javaw" process, but it has it's own jar, though it always has the same window title. 到目前为止,我已经说过该程序始终在java内部运行,因此“ javaw”进程仍在运行,但它具有自己的jar,尽管它始终具有相同的窗口标题。

I'm using: 我正在使用:

[DllImport("User32.Dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.Dll")]
public static extern int GetClassName(int hwnd, StringBuilder lpClassName, int nMaxCount);

int nWinHandle = FindWindow("Name", null);

But no matter what combination of class and windowname, with & without extention I use I always return a 0. Without that I feel I can use any other code. 但是,无论使用class和windowname进行何种组合,无论是否使用扩展名,我都始终返回0。没有该扩展名,我觉得我可以使用任何其他代码。

For those who didn't wanna read the whole thing... I'm looking for a way to hook to an existing window, remove it's border and set it's size to the user's primary screen size. 对于那些不想阅读全部内容的人……我正在寻找一种钩接到现有窗口的方法,删除其边框并将其大小设置为用户的主屏幕尺寸。

Edit: So by referencing FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName) I'm able to get the window name into a IntPtr and then use MoveWindow(); 编辑:因此,通过引用FindWindowByCaption(IntPtr ZeroOnly,字符串lpWindowName),我可以将窗口名称转换为IntPtr,然后使用MoveWindow();。 Though I'm still not able to strip the border of it. 尽管我仍然无法消除它的边界。

FindWindow (user32) Reference (Pinvoke.net) FindWindow(user32)参考(Pinvoke.net)

Perhaps the alternative text at the top of the page would be simpler: 页面顶部的alternative文本可能会更简单:

If you need to find windows for a given process ID, try using EnumWindows in combination with GetWindowThreadProcessId . 如果需要查找给定进程ID的窗口,请尝试将EnumWindowsGetWindowThreadProcessId结合使用。

To implement the above, try using the Process.GetProcessesByName Method 要实现上述目的,请尝试使用Process.GetProcessesByName方法

Once you're able to obtain a reference to the Window, this link may help you remove its borders . 一旦能够获得对Window的引用, 此链接就可以帮助您删除它的borders

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM