【发布时间】:2012-12-20 15:57:29
【问题描述】:
我想知道是否可以调整实际应用程序本身以外的程序大小。 IE,我想调整并移动 Word 和我的应用程序以分别填充 70% 和 30% 的屏幕。
Private Sub MinimiseButton_Copy_Click(sender As Object, e As RoutedEventArgs) Handles MinimiseButton_Copy.Click
Me.Left = SystemParameters.PrimaryScreenWidth - Me.Width + 14
Me.Top = -14
Me.Height = SystemParameters.PrimaryScreenHeight
Dim parry As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("winword")
Dim word As System.Diagnostics.Process = parry(0)
SetWindowPos(word.Handle, 0, 0, 0, SystemParameters.PrimaryScreenWidth - Me.Width, SystemParameters.PrimaryScreenHeight - 28, &H10)
End Sub
<DllImport("user32.dll", CharSet:=CharSet.Auto)> Public Shared Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Integer, Y As Integer, W As Integer, H As Integer, uFlags As UInteger) As Boolean
End Function
【问题讨论】:
-
当您的应用程序执行时,Word 是否应该已经加载到内存中,或者您是否打算从您的进程中调用 word?如果您通过自动化调用单词,那么将其放置在您想要的位置应该很容易。如果它已经在运行,你仍然可以使用自动化,但你可能想看看如何获得 MS Word 的 HWnd。
-
它已经在运行了。如果没有,它会启动它。
-
这就是我想要做的。我不知道如何获得 Word 的 HWND。它必须是单词的第一个实例。
-
很久以前我使用 dde 或 ole 容器做过类似的事情,我创建了一个包含单词 ole 对象的表单,并与保存和关闭等接收器事件相关联。我确信 VS2010 字模板包含类似的控制机制。我无法回答关于尺寸的问题,因为我没有使用过这些项目。
-
这是一个适合您使用 FindWindow 和 SetWindowLong 或 SetWindowPos...forums.codeguru.com/… 。如果你得到一个句柄,你“可能”能够 setWindowPos()