Positioning DOS window

Windows specific forum
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Positioning DOS window

Post 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
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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.
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post by chippy73 »

Any ideas on how you would do that? I tried various API's but they didn't work.

Alan
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post 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.
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post 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
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post 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
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

And that worked? Weird it's pretty much exactly what I did.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post 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
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post 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?
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post 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... :evil:
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post 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
PB v3.94 PVXP v2.13 JaPBe v2.5.4.22
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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
El_Choni
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post 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
Post Reply