本文介绍了Delphi - 隐藏控制台窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm reposting this to make it more clear. So, here is my console application:

That opens a socket to 127.0.0.1:81, when the console application is visible it works fine, now how do I keep it working fine as a console but make the console invisible?

I am using Delphi 2007 (7).

Thanks.

解决方案

You can use ShowWindow and the GetConsoleWindow WinAPi functions.

Try this sample

{$APPTYPE CONSOLE}

uses
  Windows,
  SysUtils;

function GetConsoleWindow: HWND; stdcall; external kernel32;


begin
  try
    Writeln('Press enter to hide console the window');
    Readln;
    //hide the console window
    ShowWindow(GetConsoleWindow, SW_HIDE);

    //do something
    Sleep(5000);

    Writeln('Press enter to exit');
    //show the console window
    ShowWindow(GetConsoleWindow, SW_SHOW);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

这篇关于Delphi - 隐藏控制台窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:07