Set position and size of an external application

Call to unmanaged Windows API MoveWindow()

Page 1 of 1

2 Replies - 22835 Views - Last Post: 19 December 2010 - 02:16 PM Rate Topic: -----

#1 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Set position and size of an external application

Posted 23 April 2009 - 04:47 PM

I am trying to reposition and resize an application I have launched. The hwnd is extracted from the process that is returned from the application start. The call to the Windows API MoveWindow() call moves the window to the top of my screen and collapses it to the height of the title bar. The x position appears to be correct and the width appears to be correct, but the y position and the height are not correct. I may have the wrong signature (but I don't think so) or there is something I don't understand about the call. Any guidance appreciated!

Imports System.Windows


Module FileParse

	Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Int32, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Boolean) As Boolean


	Friend ApplicationProcess As System.Diagnostics.Process
	Friend ApplicationHandle As Long

	Public Function OpenApplication()
		ApplicationProcess = System.Diagnostics.Process.Start("c:\testapp.exe")
		System.Threading.Thread.Sleep(1000)
		ApplicationHandle = ApplicationProcess.MainWindowHandle
		MoveWindow(ApplicationHandle, 600, 600, 600, 600, True)
		Return (True)
	End Function

End Module



Is This A Good Question/Topic? 1

Replies To: Set position and size of an external application

#2 Guest_Roy*


Reputation:

Re: Set position and size of an external application

Posted 19 December 2010 - 06:30 AM

View Postmark.bottomley, on 23 April 2009 - 03:47 PM, said:

I am trying to reposition and resize an application I have launched. The hwnd is extracted from the process that is returned from the application start. The call to the Windows API MoveWindow() call moves the window to the top of my screen and collapses it to the height of the title bar. The x position appears to be correct and the width appears to be correct, but the y position and the height are not correct. I may have the wrong signature (but I don't think so) or there is something I don't understand about the call. Any guidance appreciated!

Imports System.Windows


Module FileParse

	Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Int32, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Boolean) As Boolean


	Friend ApplicationProcess As System.Diagnostics.Process
	Friend ApplicationHandle As Long

	Public Function OpenApplication()
		ApplicationProcess = System.Diagnostics.Process.Start("c:\testapp.exe")
		System.Threading.Thread.Sleep(1000)
		ApplicationHandle = ApplicationProcess.MainWindowHandle
		MoveWindow(ApplicationHandle, 600, 600, 600, 600, True)
		Return (True)
	End Function

End Module



The MoveWindow API requires Int32, Long, Long, Long, Long, Boolean inputs. You are giving it Intptr, Integer, Integer, Integer, Integer, Boolean.
Was This Post Helpful? 0

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Set position and size of an external application

Posted 19 December 2010 - 02:16 PM

IntPtr is correct has it changes size depending on the platform it on. 32/64 bit.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1