WIndows 8上的MoveWindow API [英] MoveWindow API on WIndows 8

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

问题描述

我正在尝试从.Net VB应用程序中打开一个外部exe窗口(如记事本)并将其移动到特定位置。



我正在使用Windows 2011 x64上的VS 2011。代码没有返回任何错误,但它不起作用。



这是我的代码:

< DllImport(  user32.dll)> _ 
公共 功能 MoveWindow( ByVal hWnd 作为 IntPtr ByVal x 作为 整数 ByVal y As 整数 ByVal nWidth 作为 整数 ByVal nHeight 整数 ByVal bRepaint As 布尔作为 布尔
结束 功能

公共 Sub NoveNotepad( )
Dim ApplicationProcess = System.Diagnostics.Process.Start( Notepad.exe
ApplicationProcess.WaitForInputIdle()
Dim ApplicationHandle = ApplicationProcess.MainWindowHandle
Dim z = MoveWindow(ApplicationHandle, 600 600 600 600 True ' 此返回正确
结束 Sub



有什么想法吗?

解决方案
<块引用>当您尝试检索ApplicationHandle时,ApplicationHandle的实际值是多少?这可能是一个信任问题:对于直接调用者来说是完全信任。这个成员不能被部分受信任的代码使用。请在此处查看: http://msdn.microsoft.com/en-us /library/system.diagnostics.process.mainwindowhandle.aspx [ ^ ]



要简单测试这是否是问题,请右键单击您的应用程序并以管理员身份执行然后查看记事本是否按照您的要求移动。如果是这样,你知道问题是什么。



祝你好运!


I am trying to open an external exe window (like Notepad) from within a .Net VB application and move it to a specific location.

I am using VS 2011 on Windows 8 x64. The code is not returning any errors, but it is not working.

Here is my code:

<DllImport("user32.dll")> _
   Public Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
   End Function

   Public Sub NoveNotepad()
       Dim ApplicationProcess = System.Diagnostics.Process.Start("Notepad.exe")
       ApplicationProcess.WaitForInputIdle()
       Dim ApplicationHandle = ApplicationProcess.MainWindowHandle
       Dim z = MoveWindow(ApplicationHandle, 600, 600, 600, 600, True) ' THIS RETURNS TRUE
   End Sub


Any ideas?

解决方案

What is the actual value of the ApplicationHandle when you try to retrieve it? It might be a trust issue: "for full trust for the immediate caller. This member cannot be used by partially trusted code.". Check it out here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx[^]

To simply test if this is the issue, right click your application and execute it as administrator to see if notepad is then moved as you requested. If so, you know what the problem is.

Good luck!


这篇关于WIndows 8上的MoveWindow API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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