Page 1 of 3
Positioning DOS window
Posted: Mon Mar 07, 2005 12:55 pm
by chippy73
I need to position a DOS window.
I tried SETWINDOWPOS_ but I think that is for Windows only, and not DOS type windows.
Obviously I need the handle first and tried GETWINDOW_ but again I think that is not for DOS windows.
Any help welcomed.
Alan
Posted: Mon Mar 07, 2005 2:30 pm
by Edwin Knoppert
I'm not aware of a PB feature for this but ususally they set the console title to an unique name and use FindWindow_(...) API to locate the hWnd.
Then restore title.
this was the tty class but this could change but does not matter though.
Posted: Mon Mar 07, 2005 5:55 pm
by chippy73
Any ideas on how you would do that? I tried various API's but they didn't work.
Alan
Posted: Mon Mar 07, 2005 7:27 pm
by dracflamloc
I was recently experimenting with this... and its weird. The title you see on the console window is not the title of that window you need to use with FindWindow_(). You could try setting the classname it searches for to the console classname (its in the win32 api hlp) with no title but then you have no guarentee that the window returned is the one you want when more than one console is opened. I wish I could help ya further but I can't seem to get it workin right myself. If you find a way be sure to post it here.
Posted: Mon Mar 07, 2005 7:59 pm
by chippy73
dracflamloc,
I had the same problem. I know it can be done because if you right click on the DOS header you get properties, and in there you can position the DOS window, so there must a way to do it.
Yep, if I find out how, I will post it here.
Alan
Posted: Mon Mar 07, 2005 8:26 pm
by Sparkie
This works for me on WinXP with PB 3.93...
Code: Select all
hDosWin = FindWindow_("ConsoleWindowClass", DosWindowTitle$)
SetWindowPos_(hDosWin, 0, x, y, w, h, #SWP_SHOWWINDOW)
Posted: Mon Mar 07, 2005 8:42 pm
by Henrik
On win98 pb.3.93
Code: Select all
hDosWin = FindWindow_("tty", "MS-DOS-prompt")
SetWindowPos_(hDosWin, 0, 10, 100, 600,400, #SWP_SHOWWINDOW)
*Edit*
Well in fact, on win98 you can skip the class like this
Code: Select all
hDosWin = FindWindow_(0, "MS-DOS-prompt")
SetWindowPos_(hDosWin, 0, 10, 50, 600,400, #SWP_SHOWWINDOW)
Henrik
Posted: Tue Mar 08, 2005 2:47 am
by dracflamloc
And that worked? Weird it's pretty much exactly what I did.
Posted: Tue Mar 08, 2005 3:19 am
by Sparkie
#Null for Class name also works for XP. Thanks for pointing that out Henrik
Code: Select all
If OpenWindow(0, 580, 0, 250, 100, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Test") And CreateGadgetList(WindowID(0))
;--> Just to keep our window on top
SetWindowPos_(WindowID(0), #HWND_TOPMOST, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
ButtonGadget(1, 75, 10, 100, 20, "Move Dos Window")
RunProgram("edit.com")
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = 1
hDosWin = FindWindow_(#Null, "MS-DOS Editor")
SetWindowPos_(hDosWin, 0, 0, 0, 400, 300, #SWP_SHOWWINDOW)
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
Posted: Tue Mar 08, 2005 7:46 am
by chippy73
Sparkie,
Ah yes, now I see how to do it. It was the class name that got me stumped, now you show us how to do it.
Many thanks for the info.
Alan
Posted: Tue Mar 08, 2005 8:12 am
by dracflamloc
#Null is zero correct? Maybe this has issues working on Windows Server 2003? It can't seem to find the window for me... Maybe because I'm running cmd.exe and then running the "title" command?
Posted: Tue Mar 08, 2005 11:56 pm
by Henrik
In all the api samples i have messed with you can write #NULL or 0, no problemo
If you write "command" in w98 you start a dosprompt.
I never used 2003.
But do you have a window-spy program that show you the class and the text ?
In the process of making a program who send a string-part to TotalCommander i needed to make a spy first, you can have the code if you like.
It's a mess cus, the spy was only made to figure out how the heck you pass a part to TotalCmd and i stole code with arms and legs, in that part of the process.
But what the spy does is.
You click the spy buttom and point with the mouse on a window or a controle/gadget,it then show you:
1.The Objects Handler Hex / dec
2. Objects text if anny
3. Objects Class name
4. Objects Rect
Objects Parent Windows
1.The Parent Windows Handler Hex / dec
2. Parent Windows text if anny
3. Parent Windows Class name
4. Parent ProcessID
And if you press F11 it then DubClick where the mouse curser is located and send at string to that object under the mouse curser, that was the way i had to do it to send a string to TotalCmd.
Now you can have the code as is if you like, cus im not cleaning it up, it was only a bumb on the way.
This Forum oh man...

Posted: Mon Mar 14, 2005 3:15 pm
by chippy73
Sparkie,
I am using your code to close a dos window but it doesn't seem to work.
Could someone try it and confirm too.
Any solutions welcomed.
Alan
Code: Select all
If OpenWindow(0, 580, 0, 250, 100, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Test") And CreateGadgetList(WindowID(0))
;--> Just to keep our window on top
SetWindowPos_(WindowID(0), #HWND_TOPMOST, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
ButtonGadget(1, 75, 10, 100, 20, "close Dos Window")
RunProgram("edit.com")
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = 1
hDosWin = FindWindow_(#Null, "edit.com")
DestroyWindow_(hDosWin)
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
Posted: Mon Mar 14, 2005 3:38 pm
by El_Choni
Code: Select all
If OpenWindow(0, 580, 0, 250, 100, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Test") And CreateGadgetList(WindowID(0))
;--> Just to keep our window on top
SetWindowPos_(WindowID(0), #HWND_TOPMOST, -1, -1, -1, -1, #SWP_NOMOVE | #SWP_NOSIZE | #SWP_SHOWWINDOW)
ButtonGadget(1, 75, 10, 100, 20, "close Dos Window")
RunProgram("cmd.exe")
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget And EventGadgetID() = 1
hDosWin = FindWindow_(#Null, "C:\WINDOWS\system32\cmd.exe")
SendMessage_(hDosWin, #WM_CLOSE, 0, 0)
; DestroyWindow_(hDosWin)
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
Posted: Mon Mar 14, 2005 4:07 pm
by Edwin Knoppert
This works under XP:
Code: Select all
Declare.l MyMain()
MyMain()
End
Procedure.l crp( sFileName.s )
CommandLine.s = sFileName
StartupInfo.STARTUPINFO
StartupInfo\cb = SizeOf(STARTUPINFO)
; StartupInfo\dwFlags = #STARTF_USESHOWWINDOW
; StartupInfo\wShowWindow = #SW_SHOW
ProcessInfo.PROCESS_INFORMATION
If CreateProcess_(0, @CommandLine, 0, 0, 0, 0, 0, 0, @StartupInfo, @ProcessInfo) = 0
; CreateProcess FAILED !
Else
ProcessExitCode.l
Repeat
; DoEvents() or anything you like ...
GetExitCodeProcess_(ProcessInfo\hProcess, @ProcessExitCode)
Until ProcessExitCode <> 259
; Delay(250)
If ProcessExitCode > 0
; Do what you have to do with Exit Code
EndIf
EndIf
EndProcedure
Procedure.l MyMain()
Protected nTmr.l
Protected sTmr.s
Protected hWndConsole.l
OpenConsole()
nTmr = GetCurrentThreadId_()
sTmr = Trim( Str( nTmr ) )
ConsoleTitle( sTmr )
hWndConsole = FindWindow_( #NULL, sTmr )
If hWndConsole
SetWindowPos_( hWndConsole, 0, 10, 10, 0, 0, #SWP_NOSIZE + #SWP_NOZORDER )
EndIf
; Do a RunProgram() to EDIT.COM here..
crp( "EDIT.COM")
EndProcedure