Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to alter shell command to direct where window opens

Status
Not open for further replies.

dgr7

IS-IT--Management
Dec 29, 2006
43
US
hello,
I have the following two lines of code in VB6

CabRunmailAppId = Shell("D:\PROGRAM FILES\TELSTAR\TelStar.exe", 1)
CabFilecleanAppId = Shell("D:\PROGRAM FILES\TELSTAR\TelStar.exe", 1)

that I execute to open two Telnet session windows. Right now the windows open one on top of another, and at first glance it looks like there's only one window running. Can the Shell statment be altered to tell the window where to open on the Desktop, so for example, the first Shell line could open the window in the top right of the desktop and the second Shell line open the second window in the bottom left of the desktop?

thanks in advance,
david
 
I don't think there is much you can do with the Shell but after the Shell...

Try something like this (all in a Form);

Private Const SW_MINIMIZE = 6
Private Const SW_SHOW = 5
Private Const SW_SHOWNORMAL As Long = 1

Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Dim Rectan As RECT
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Dim OtherAppHwnd As Long

Private Sub Form_Load()
'Code adapted from that in API-Guide 3.7
' and the Tip submitted by pyp99 (pyp99@hotmail.com)
Dim WinEst As WINDOWPLACEMENT
Dim rtn As Long

Shell "NotePad.exe"

'Find the OtherApp's window
Do Until OtherAppHwnd
OtherAppHwnd = FindWindow(vbNullString, "Untitled - NotePad")
DoEvents
Loop
'get the current window placement of the other app
WinEst.Length = Len(WinEst)
rtn = GetWindowPlacement(OtherAppHwnd, WinEst)
Rectan = WinEst.rcNormalPosition
End Sub
Private Sub Command1_Click()
Dim WinEst As WINDOWPLACEMENT
Dim rtn As Long
'initialize the structure
WinEst.Length = Len(WinEst)
WinEst.showCmd = SW_SHOW
With Rectan
.Left = Rectan.Left + 20
.Top = Rectan.Top + 20
.Bottom = Rectan.Bottom + 20
.Right = Rectan.Right + 20
End With
WinEst.rcNormalPosition = Rectan
'set the new window placement (minimized)
rtn = SetWindowPlacement(OtherAppHwnd, WinEst)
End Sub

HTH Hugh,
 
>'set the new window placement (minimized)
ignore that rem which survived from the original source code
 
Doesn't Telstar allow Sessions? Are the form captions identical?

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
Hugh,
thanks for the code....but I'm not sure how to incorporate it in my existing Form and Module code...please help.

David,

I'm not sure what you mean by Sessions...could you elaborate?

Yes, the form captions look identical when there's two Telstar windows running and if you ctrl-alt-del and see the list of running Applications.
thanks,
david
 
I've seen management session monitors that allow you to open a new session for each use, or reuse the same one. I guess you are using sessions. Look around in the help to see if you can find anything about them.
Finding identical captions will be confusing.

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
dglienna,
>Finding identical captions will be confusing
Finding windows with the same caption need not be confusing if there will be only two instances and the move is only applied to the first (and none are diplayed before you begin of course). Failing that I suppose we could/ would have to trawl though all windows having the same caption and arrange them all, or just the ones we are starting.

dgr7,
The following loads up two instance of Notepad slightly offset from each other. The Sub Command1_Click() code in my previous post is no longer required, the previous declarations section is required. Could be your TelStar.exe will not behave like NotePad. You will need to replace my Shell "NotePad.exe", vbNormalNoFocus with your CabRunmailAppId = Shell("D:\PROGRAM FILES\TELSTAR\TelStar.exe", 1)

Private Sub Form_Load()

Dim WinEst As WINDOWPLACEMENT
Dim rtn As Long

Shell "NotePad.exe", vbNormalNoFocus

'Find the OtherApp's window
Do Until OtherAppHwnd
OtherAppHwnd = FindWindow(vbNullString, "Untitled - NotePad")
DoEvents
Loop
'get the current window placement of the other app
WinEst.Length = Len(WinEst)
rtn = GetWindowPlacement(OtherAppHwnd, WinEst)
Rectan = WinEst.rcNormalPosition

With Rectan
.Left = Rectan.Left + 20
.Top = Rectan.Top + 20
.Bottom = Rectan.Bottom + 20
.Right = Rectan.Right + 20
End With
WinEst.rcNormalPosition = Rectan
'set the new window placement (minimized)
rtn = SetWindowPlacement(OtherAppHwnd, WinEst)

Shell "NotePad.exe", vbNormalNoFocus

End Sub

HTH Hugh,
 
Hugu,
hello, and sorry for the delay in writing back.

I tried cutting-and-pasting your code into my Form_load subroutine and when I run the code I'm getting the error message:

Compile error:
User-defined type not defined

and it's stopping on

Dim WinEst As WINDOWPLACEMENT

What do I do to fix this error?
thanks,
david
 
ref my first post;

Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
 
hugh,
thank you for the code and sorry for the delay in writing back. I was about to get your above code working to move the 1st Telstar window up & above the 2nd Telstar window.

thanks again,
david
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top