Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Position a Window
I open a folder with:
Sub folderopen() x = Shell("Explorer.exe ""C:\Temp""", vbNormalFocus) End Sub Once opened, I would like to position the folder window. Neither: ActiveWindow.Top = 0 x.Top = 0 work. Any suggestions?? -- Gary''s Student - gsnu2007xx |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Position a Window
One somewhat convoluted solution is to open a hidden instance of Word and
take advantage of the Word application's 'Tasks' collection. The 'Name' property of each individual task is the friendly name so you would be able to utilize the InStr function to isolate the task containing "C:\Temp" in its name. Once you've gotten the specific task(window), you can take advantage of the 'Left' property and 'Top' property. There can be a bit of a delay while Word opens and the Explorer window will open in one location and then make an obvious jump when it changes position but you will have the window where you want it. Steve "Gary''s Student" wrote in message ... I open a folder with: Sub folderopen() x = Shell("Explorer.exe ""C:\Temp""", vbNormalFocus) End Sub Once opened, I would like to position the folder window. Neither: ActiveWindow.Top = 0 x.Top = 0 work. Any suggestions?? -- Gary''s Student - gsnu2007xx |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Position a Window
Hey there..
Gary''s Student wrote: Once opened, I would like to position the folder window. Neither: I just looked into this because I was curious myself, and once again I got shown that VBA is absolute **** for even half-serious programming. Below is your solution (make sure you get the linebreaks right ;) Just copypaste to a new module and call the sub test from anywhere for a proof of concept. Then just use the code from sub test in your own code: hInstance = Shell("cmd.exe", vbNormalFocus) hWindow = WaitForWindow(hInstance) MoveWindow hWindow, 50, 300, 800, 400, True Best Regards, Lars ''''''''''''''''''''' Option Explicit Public Const GW_HWNDNEXT = 2 Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _ ByVal wCmd As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetWindowThreadProcessId Lib "user32" _ (ByVal hwnd As Long, lpdwprocessid As Long) As Long Public Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Boolean 'Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Public Function WaitAndDoEvents(ByVal waitSeconds As Double) Dim startTime As Double startTime = Timer() While (Timer() - startTime < waitSeconds) DoEvents Wend End Function Function ProcIDFromWnd(ByVal hwnd As Long) As Long Dim idProc As Long ' Get PID for this HWnd GetWindowThreadProcessId hwnd, idProc ' Return PID ProcIDFromWnd = idProc End Function Function GetWinHandle(ByVal hInstance As Long) As Long Dim tempHwnd As Long ' Grab the first window handle that Windows finds: tempHwnd = FindWindow(vbNullString, vbNullString) ' Loop until you find a match or there are no more window handles: Do Until tempHwnd = 0 ' Check if no parent for this window If GetParent(tempHwnd) = 0 Then ' Check for PID match If hInstance = ProcIDFromWnd(tempHwnd) Then ' Return found handle GetWinHandle = tempHwnd ' Exit search loop Exit Do End If End If ' Get the next window handle tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT) Loop End Function ' returns window handle or 0 if timed out Function WaitForWindow(ByVal hInstance As Long, Optional timeout As Double = 5) As Long Dim hWindow As Long Dim startTime As Double startTime = Timer() Do ' wait for process to start hWindow = GetWinHandle(hInstance) ' 0 if hInstance not found DoEvents Loop Until hWindow < 0 Or (Timer() - startTime timeout) WaitForWindow = hWindow ' 0 if timed out & hInstance not found End Function Public Sub test() Dim hInstance As Double Dim hWindow As Long hInstance = Shell("cmd.exe", vbNormalFocus) hWindow = WaitForWindow(hInstance) MoveWindow hWindow, 50, 300, 800, 400, True End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Position a Window
I tried everything with API's etc and got nothing, it just opens the last
place you put it. What I did get to work very well was placing a webbrowser control on a form and on the activate event: Me.WebBrowser1.Navigate2 smURL & "c:\temp" Me.Top = 0 Me.Left = 0 host the folder browser in the form then move the form. Hope that works for you. -- -John Please rate when your question is answered to help us and others know what is helpful. "Gary''s Student" wrote: I open a folder with: Sub folderopen() x = Shell("Explorer.exe ""C:\Temp""", vbNormalFocus) End Sub Once opened, I would like to position the folder window. Neither: ActiveWindow.Top = 0 x.Top = 0 work. Any suggestions?? -- Gary''s Student - gsnu2007xx |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Position a Window
Thank you.
I have adopted a variation of what you reccomended. It is a little painful. -- Gary''s Student - gsnu200800 "Steve Yandl" wrote: One somewhat convoluted solution is to open a hidden instance of Word and take advantage of the Word application's 'Tasks' collection. The 'Name' property of each individual task is the friendly name so you would be able to utilize the InStr function to isolate the task containing "C:\Temp" in its name. Once you've gotten the specific task(window), you can take advantage of the 'Left' property and 'Top' property. There can be a bit of a delay while Word opens and the Explorer window will open in one location and then make an obvious jump when it changes position but you will have the window where you want it. Steve "Gary''s Student" wrote in message ... I open a folder with: Sub folderopen() x = Shell("Explorer.exe ""C:\Temp""", vbNormalFocus) End Sub Once opened, I would like to position the folder window. Neither: ActiveWindow.Top = 0 x.Top = 0 work. Any suggestions?? -- Gary''s Student - gsnu2007xx |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Position a Window
Another interesting approach.
Thanks for taking the time to assist me. -- Gary''s Student - gsnu200800 "John Bundy" wrote: I tried everything with API's etc and got nothing, it just opens the last place you put it. What I did get to work very well was placing a webbrowser control on a form and on the activate event: Me.WebBrowser1.Navigate2 smURL & "c:\temp" Me.Top = 0 Me.Left = 0 host the folder browser in the form then move the form. Hope that works for you. -- -John Please rate when your question is answered to help us and others know what is helpful. "Gary''s Student" wrote: I open a folder with: Sub folderopen() x = Shell("Explorer.exe ""C:\Temp""", vbNormalFocus) End Sub Once opened, I would like to position the folder window. Neither: ActiveWindow.Top = 0 x.Top = 0 work. Any suggestions?? -- Gary''s Student - gsnu2007xx |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Position A2 at top-left of window | Excel Programming | |||
The window opens in a smaller window not full sized window. | Excel Discussion (Misc queries) | |||
Position of CellCursor on Screen (absolute position) | Excel Programming | |||
Position Form on screen v Window Zoom ! | Excel Programming | |||
Window Position & Size | Excel Discussion (Misc queries) |