Solved

Back to Dos

Posted on 1998-11-08
15
156 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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