MoveWindow API在Vista上无法正常运行 [英] MoveWindow API doesn't work well on Vista

查看:115
本文介绍了MoveWindow API在Vista上无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!我在Vista上有一个应用程序,该应用程序遍历所有进程并找到相关的主窗口,以便移动和调整它们的大小.

问题在于某些窗口会移动并调整大小,而有些窗口则不会.甚至似乎移动和调整大小后的窗口都没有根据MoveWindow函数调用移动和调整大小,因为它们被调整为标题栏的大小并且它们都在同一行(相同的y坐标)上.

这是示例代码:

Hello! I have an application on Vista which loops through all processes and finds associated main windows in order to move and resize them.

The problem is that some windows get moved and resized and some don''t. Also it even seems that moved and resized windows aren''t moved and resized according to the MoveWindow function call because they are resized to title bar and all of them are on the same line (same y coordinate).

Here''s the sample code:

IntPtr handle;
Process[] processList = Process.GetProcesses();

int i = 0;
foreach (Process process in processList)
{
     handle = process.MainWindowHandle;

     if (handle != IntPtr.Zero)
     {
          MoveWindow(handle, i * 50, i * 50, 500, 500, true);
          i++;
     }
}


这是因为Vista吗?我应该使用什么替代方法?


Is this because of Vista? What alternative should I use?

推荐答案

尝试使用SetWindowPos Windows api函数(您需要为此输入密码),并且看起来它需要很多相同的参数.
Try the SetWindowPos windows api function (you''ll need pinvoke for that), and it looks like it takes many of the same parameters.


似乎MoveWindow函数对最小化的窗口没有任何影响.因此,在MoveWindow之前,我使用了ShowWindow:

ShowWindow(handle,3); //ShowMaximized = 3

这有帮助!

我使用了SetWindowPos函数,但是有关此函数的MSDN文档指出,在Vista中,"hwnd和窗口管理器操作仅在会话内有效,并且跨会话尝试操作hwnd的尝试将失败",并且该语句表明该问题是由于Vista引起的. br/>
http://msdn.microsoft.com/en-us/library/ms633545%28v = VS.85%29.aspx [ ^ ]

http://msdn.microsoft.com/en-us/library/aa480152.aspx [ ^ ]
It seems that MoveWindow function doesn''t have any effect on the minimized windows. So, before MoveWindow I used ShowWindow:

ShowWindow(handle, 3); //ShowMaximized = 3

This helped!

I used SetWindowPos function but MSDN documentation about this function says that in Vista "hwnd and window manager operations are only effective inside a session and cross-session attempts to manipulate the hwnd will fail" and that statement indicated that problem is because of Vista.

http://msdn.microsoft.com/en-us/library/ms633545%28v=VS.85%29.aspx[^]

http://msdn.microsoft.com/en-us/library/aa480152.aspx[^]


这篇关于MoveWindow API在Vista上无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆