简体   繁体   中英

Change Existing Window Size & Position

I'm currently working on a C# program to manage some configuration files. 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.

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.


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.

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.

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(); Though I'm still not able to strip the border of it.

FindWindow (user32) Reference (Pinvoke.net)

Perhaps the alternative text at the top of the page would be simpler:

If you need to find windows for a given process ID, try using EnumWindows in combination with GetWindowThreadProcessId .

To implement the above, try using the Process.GetProcessesByName Method

Once you're able to obtain a reference to the Window, this link may help you remove its borders .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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