Solved

Back to Dos

Posted on 1998-11-08
15
151 Views
Last Modified: 2010-04-04
Hi all
I have written a windows application that is executed with command line from a full size Dos window.
My problem is that when the application is finished it doesn't get back to Dos.
I tried using :
  FParentHWND := GetParent(Handle);
  ShowWindow(FParentHWND, SW_RESTORE);
  SetActiveWindow(FParentHWND);

but with no luck ??!!
0
Comment
Question by:dotan
  • 6
  • 4
  • 3
  • +2
15 Comments
 

Author Comment

by:dotan
ID: 1346107
Edited text of question
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1346108
Try SetForegroundWindow
0
 

Expert Comment

by:Aleq
ID: 1346109
Well, you must find handle of that dos window.
Use findwindow (See Win32 help)
than just call ShowWIndow(<FOUND_HANDLE,....)
It will work....
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346110
var
  H : HWND;
  buf : array[0..MAX_PATH] of char;
  str : string;
begin
  GetWindowText(buf);
  str := StrPas(buf);
  if Pos(str, 'MS-DOS') > 0 then begin
    H := FindWindow(nil, str);
    SetForegroundWindow(H);
  end;
end;

Cheers,
Viktor
0
 

Author Comment

by:dotan
ID: 1346111
TNQ all for your comments and answer but.........
Since there can be several MS-DOS windows open at the same time i have to know which one made the call and i can't just look for the first one like "FindWindow" does.
Any other ideas ????
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346112
What's the name of your DOS program...if it is TC for example you can look for  MS-DOS TC as a caption...

Cheers,
Viktor
0
 

Author Comment

by:dotan
ID: 1346113
It can be one of many...........and there is no way to know
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:viktornet
ID: 1346114
Nope... The caption would be "MS-DOS ExenameWithoutAnExtension" w/o the quotes when run in Windows...

Cheers,
Viktor
0
 

Author Comment

by:dotan
ID: 1346115
Hi all
Just for the record here is how i solved this:

constructor xxx.yyy;
bagin
  FParenWin :=  GetForegroundWindow;
  .....
end;

destructor xxx.yyy;
begin
  .......
  ShowWindow(FParenWin, SW_MAXIMIZE);  
end;
0
 
LVL 3

Expert Comment

by:williams2
ID: 1346116
You say you are writing an windows application from a Fullsize window? But are you using any forms?

If not, then forget all those hacks, it is easily done without.

To make a commandline executable, you'll need to go to the Mainmenu selecting Project->Options->Linker and select
the "Generate console application".

Thereafter, you will need to remove unit1 from the project.
You will then need to add a new Unit. You can write procedures and functions as usual, but you will need to add..

Initialization
  Main;

right before the 'end.' command, supposing that Main is the main procedure in the program. If you will need to add forms to your application, you should not worry about getting back to DOS, visual windows applications simply doesn't do that in generel.

Am I wrong?

Regards,
Williams
0
 

Author Comment

by:dotan
ID: 1346117
Sorry Williams but this is not the case.
My application is a windows application and could not run as a console application.
The problem was that it can be executed from a dos window and in that case i whanted the focus to reuren to the dos window even if it was full sized.
0
 
LVL 3

Accepted Solution

by:
williams2 earned 80 total points
ID: 1346118
Ok! ..dotan got very close, but it's not explicitely right. If you go and select another window before exiting the application, you will find, that the last active window will get the focus, and get maximized instead.

But a few changes solved it, and it both works in Windows 95,98 and NT.

I don't know if dotan should have some of the credits for this, for this is build on his idea:

Try paste this on unit1 on a new project, and then run it from a fullscreen DOS-window:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  FParenWin: THandle;

implementation

{$R *.DFM}

Initialization
  FParenWin :=  GetForegroundWindow;
Finalization
  SetForegroundWindow(FParenWin);
  SetActiveWindow(FParenWin);
  ShowWindow(FParenWin, SW_MAXIMIZE);
end.

This will work, no matter what you are going to select in the desktop afterwards (Thanks to dotan), except in one case: If you close the DOS-window, nothing will happen!

Cheers,
Williams
0
 
LVL 3

Expert Comment

by:williams2
ID: 1346119
Hmmm.. dotan, I forgot, that it's actually you who did ask the question hehe.

Cheers,
Williams
0
 

Author Comment

by:dotan
ID: 1346120
TNQ all
0
 
LVL 3

Expert Comment

by:williams2
ID: 1346121
You are always welcome :-)

Regards,
Williams
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 185
Simple Delphi Question 9 83
When I am typing into a TEdit last word repeats 7 115
Tembedded WB animatid gifs not animated on some pcs 2 71
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now