Thanks
Jacob
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.709 / Virus Database: 465 - Release Date: 22-6-2004
>I have an application that starts another application (e.g. Exel or
>Powerpoint) and than I want to move the window of that application to
>another postion on the screen and resize it. How do I do that? Do that with
>api? I am not familiar with api and so, so can you explain? Maybe with an
>example?
>
>Thanks
>Jacob
Start off by finding the target window using (oddly enough) the
FindWindow API function....
' the declare
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName$, ByVal lpWindowName$) As Long
' the call
Dim hWndApp&
hWndApp = FindWindow("Class name for the target", "Window caption
for the targert")
You can get the class name by using the Spy++ application that comes
with visual studio.
After you have the hWnd for the application's main window, you can
move the window using (oddly enough) the MoveWindow API function....
' the declare
Public Declare Function MoveWindow Lib "user32" (ByVal hWnd&, ByVal
x&, ByVal y&, ByVal nWidth&, ByVal nHeight&, ByVal bRepaint&) As Long
Const API_TRUE As Long = 1&
' the call
Call MoveWindow(hWndApp, nLeft, nTop, nWidth, nHeight, API_TRUE)
where nLeft, nTop, etc... are the desired left, top, etc...
positions.
HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsen...@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
>I have an application that starts another application (e.g. Exel or
>Powerpoint) and than I want to move the window of that application to
>another postion on the screen and resize it. How do I do that? Do that with
>api? I am not familiar with api and so, so can you explain? Maybe with an
>example?
Essentially the steps are:
1) Launch the app
2) Find it's main window's hwnd
3) Make sure it's the correct instance.
4) Move / size it as needed.
Here's an example that does it for notepad. Since notepad's caption,
like that of many apps, changes to include the open filename you'll
need to key on the window's ~classname~. Notepad's main window
classname is just "notepad". For Excel it's "XLMAIN". (You can use the
Spy++ tool on any running instance of an app to determine the
classname.)
'Api declarations...
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOREDRAW = &H8
Public Const SWP_NOACTIVATE = &H10
Public Const SWP_FRAMECHANGED = &H20
Public Const SWP_SHOWWINDOW = &H40
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_NOCOPYBITS = &H100
Public Const SWP_NOOWNERZORDER = &H200
Public Const HWND_TOP = 0
Public Const HWND_BOTTOM = 1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWndParent As Long, _
ByVal hWndChildAfter As Long, ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" ( _
ByVal hwnd As Long, lpdwProcessId As Any) As Long
'usage...
Private Sub SomeSub()
Dim PID As Long
Dim hwndFound As Long
Dim pidFound As Long
'launch app...
PID = Shell("notepad", vbNormalFocus)
Do
'look for an instance of notepad...
hwndFound = FindWindowEx(0, hwndFound, _
"notepad", vbNullString)
If hwndFound <> 0 Then 'found one
'check to make sure it's the one you launched...
GetWindowThreadProcessId hwndFound, pidFound
If pidFound = PID Then 'pid match - it's ours
'move / size (note units are pixels) ...
SetWindowPos hwndFound, 0, 100, 50, 400, 250, _
SWP_NOZORDER
Exit Do
End If
Else 'none (or no more) found
Exit Do
End If
Loop
End Sub
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Jacob
"Jacob" <jacob_...@notreal.com> schreef in bericht
news:40da8b22$0$161$3a62...@reader1.nntp.hccnet.nl...