Solved

Hiding a Dos window

Posted on 1998-10-06
3
293 Views
Last Modified: 2010-04-06
I need a function in delphi, that execute DOS programs , but doesn't appear the DOS window.
0
Comment
Question by:sabadao
  • 3
3 Comments
 
LVL 5

Accepted Solution

by:
knowlton earned 200 total points
ID: 1342045
You can call WinExec() and pass in WS_HIDE or something like that.
0
 
LVL 5

Expert Comment

by:knowlton
ID: 1342046
Here it is:

WinExec('c:\test\my.bat',SW_HIDE);


More info:

The WinExec function runs the specified application.

This function is provided for compatibility with earlier versions of Windows. For Win32-based applications, use the CreateProcess function.

UINT WinExec(

    LPCSTR  lpszCmdLine,      // address of command line
    UINT  fuCmdShow       // window style for new application
   );      
Parameters

lpszCmdLine

Points to a null-terminated character string that contains the command line (filename plus optional parameters) for the application to be executed. If the name of the executable file in the lpszCmdLine parameter does not contain a directory path, Windows searches for the executable file in this sequence:

1.      The directory from which the application loaded.
      2.      The current directory.
      3.      The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
      4.      The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
      5.      The directories listed in the PATH environment variable.

fuCmdShow

Specifies how a Windows-based application window is to be shown and is used to supply the wShowWindow member of the STARTUPINFO parameter to the CreateProcess function. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function. For a non-Windows - based application, the PIF file, if any, for the application determines the window state.

Return Value

If the function succeeds, the return value is greater than 31.
If the function fails, the return value is one of the following error values:

Value      Meaning
0      The system is out of memory or resources.
ERROR_BAD_FORMAT      The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
ERROR_FILE_NOT_FOUND      The specified file was not found.
ERROR_PATH_NOT_FOUND      The specified path was not found.
Remarks

Win32-based applications should use the CreateProcess function rather than this function. The WinExec function exists in Win32 to provide compatibility with earlier versions of Windows. For more information about how the WinExec function is implemented, see the Remarks section of the LoadModule function.
In Win32, the WinExec function returns when the launched process calls the GetMessage function or a time-out limit is reached. To avoid waiting for the time out delay, call the GetMessage function as soon as possible in any process launched by a call to WinExec.

See Also

CreateProcess, GetMessage, GetSystemDirectory, GetWindowsDirectory, LoadModule, ShowWindow

ALSO:

The ShowWindow function sets the specified window's show state.

BOOL ShowWindow(

    HWND  hwnd,      // handle of window
    int  nCmdShow       // show state of window
   );      
Parameters

hwnd

Identifies the window.

nCmdShow

Specifies how the window is to be shown. This parameter can be one of the following values:

Value      Meaning
SW_HIDE      Hides the window and activates another window.
SW_MAXIMIZE      Maximizes the specified window.
SW_MINIMIZE      Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE      Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW      Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT      Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED      Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED      Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE      Displays the window as a minimized window. The active window remains active.
SW_SHOWNA      Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE      Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL      Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
Return Value

If the window was previously visible, the return value is TRUE. If the window was previously hidden, the return value is FALSE.

Remarks

ShowWindow must be called only once per program with the WinMain function's nCmdShow parameter. Subsequent calls to ShowWindow must use one of the values in the preceding list, instead of the one specified by the WinMain function's nCmdShow parameter.
As noted in the discussion of the nCmdShow parameter, an application should call ShowWindow with nCmdShow set to SW_SHOWDEFAULT to use application startup information that affects how a window is displayed. For example, Program Manager specifies that applications start with a minimized main window. Win32-based applications also use the application startup information when calling ShowWindow for the first time and set nCmdShow to SW_SHOW. This behavior is designed for the following situations:

7      Applications that create their main window by calling CreateWindow with the WS_VISIBLE flag set.
7      Applications that create their main window by calling CreateWindow with the WS_VISIBLE flag cleared, and later call ShowWindow with the SW_SHOW flag set to make it visible.

See Also

CreateProcess, CreateWindow, ShowOwnedPopups, STARTUPINFO, WinMain
0
 
LVL 5

Expert Comment

by:knowlton
ID: 1342047
Thanks.  I hope this answer works out for you.

Tom
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

23 Experts available now in Live!

Get 1:1 Help Now