Solved

Back to Dos

Posted on 1998-11-08
15
149 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

19 Experts available now in Live!

Get 1:1 Help Now