Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Back to Dos

Posted on 1998-11-08
15
Medium Priority
?
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

722 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