特定窗口的SetWindowPos [英] SetWindowPos for a specific window
本文介绍了特定窗口的SetWindowPos的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(string hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
我的问题是我希望能够根据标签内的文本移动特定的窗口.
My issue is I want to be able to move a specific window based on the text inside of my label.
private void button1_Click(object sender, EventArgs e)
{
const short SWP_NOSIZE = 1;
const short SWP_NOZORDER = 0X4;
const int SWP_SHOWWINDOW = 0x0040;
Process[] processes = Process.GetProcesses();
foreach (var process in processes)
{
IntPtr handle = process.MainWindowHandle;
string Text = handle.ToString();
if (handle.ToString() == WindowTextBox.Text)
{
SetWindowPos(Text, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
}
}
}
我知道这是行不通的,但是无论如何都想尝试一下,根据WindowTextBox内部的内容,我还能如何移动一个窗口? (在SetWindowPos(IntPtr hWnd,[...]中具有IntPtr句柄),并且只是在更改
I knew this wouldn't work but wanted to try anyway, how else would I be able to move a window based on what is inside my WindowTextBox? (having IntPtr handle in the SetWindowPos(IntPtr hWnd, [...]) and just changing
SetWindowPos(Text, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
到
SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
也不起作用.)有什么建议吗?
doesn't work either.) Any suggestions?
推荐答案
弄清楚了.我用过
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
将行更改为
IntPtr handle = FindWindow(null, WindowTextBox.Text);
以及
if (handle != IntPtr.Zero)
它按我想要的方式工作,但是谢谢!
and it works just the way I want, thanks though!
这篇关于特定窗口的SetWindowPos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文