Solved

Back to Dos

Posted on 1998-11-08
15
155 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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