zoukankan      html  css  js  c++  java
  • 在Win32程序中显示Dos调试窗口

    在很多程序中,都可以看到程序运行中,会有一个Dos窗口,实时显示一些运行信息,这里就告诉大家是如何实现的,我们做个简单的,其实对控制台的操作还有很多,有兴趣的可以去查资料。

        用到的API函数如下:

      //创建控制台
      AllocConsole;

      //获取控制台窗口
      GetStdHandle;

      //向控制台输出信息
      WriteConsole;

      //释放控制台
      FreeConsole;

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
        //控制台句柄
        h_Console:THandle;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      p:PChar;
      num:Cardinal;
    begin
      //获取控制台窗口
      h_Console := GetStdHandle(STD_OUTPUT_HANDLE );
      p := PChar(Edit1.Text);
      //向控制台输出信息
      WriteConsole(h_Console,p,Length(Edit1.Text),num,nil);
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      //创建控制台
      AllocConsole;
    end;
    
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      if h_Console = 0 then Exit;
      //释放控制台
      FreeConsole;
    end;
    
    end.
    View Code
  • 相关阅读:
    spring 好处与优点
    在SSH框架中使用Spring的好处
    xml配置文件详解
    了解OpenStack
    剖析云计算中的“共享型数据库”(转载)
    云计算开始。。。
    (一)使用springAPI以及自定义类 实现AOP-aop编程
    依赖注入之针对不同类型变量的几种注入方式
    Spring学习笔记--环境搭建和初步理解IOC
    hdu5305Friends dfs
  • 原文地址:https://www.cnblogs.com/key-ok/p/3429861.html
Copyright © 2011-2022 走看看