zoukankan      html  css  js  c++  java
  • C# WinForm 控制台日志输出

    public class MyConsole : IDisposable
    {
    private const uint STD_INPUT_HANDLE = 0xfffffff6;
    private const uint STD_OUTPUT_HANDLE = 0xfffffff5;
    private const uint STD_ERROR_HANDLE = 0xfffffff4;
    private const uint ATTACH_PARENT_PROCESS = 0xffffffff;
    [DllImport("kernel32.dll")]
    public static extern bool AttachConsole(uint dwProcessId);
    [DllImport("kernel32.dll")]
    public static extern bool AllocConsole();
    [DllImport("kernel32.dll")]
    public static extern bool FreeConsole();
    [DllImport("kernel32.dll")]
    public static extern int GetStdHandle(uint nStdHandle);
    [DllImport("kernel32.dll")]
    public static extern bool WriteConsole(int hConsoleOutput,
    string lpBuffer,
    int nNumberOfCharsToWrite,
    ref int
    lpNumberOfCharsWritten,
    int lpReserved);
    [DllImport("kernel32.dll")]
    public static extern bool ReadConsole(int hConsoleInput,
    StringBuilder lpBuffer,
    int nNumberOfCharsToRead,
    ref int lpNumberOfCharsRead,
    int lpReserved);
    private int stdin;
    private int stdout;
    public MyConsole()
    {
    AllocConsole();
    stdin = GetStdHandle(STD_INPUT_HANDLE);
    stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    }
    public void WriteLine(string s)
    {
    int len = 0;
    WriteConsole(stdout, s + "
    ", s.Length + 2, ref len, 0);
    }
    public string ReadLine()
    {
    int len = 0;
    StringBuilder sb = new StringBuilder();
    ReadConsole(stdin, sb, 256, ref len, 0);
    return sb.ToString(0, sb.Length - 2);
    }
    public void Dispose()
    {
    FreeConsole();
    }
    }
    View Code
  • 相关阅读:
    学生信息录入系统
    作业11(增删改查listview)
    作业10(qq增删改查)
    作业9
    作业8
    作业7
    右键打开Windows Terminal
    axure 动态面板中滚动条
    TortoiseSVN服务端的配置与使用
    hfs使用小技巧
  • 原文地址:https://www.cnblogs.com/tianciliangen/p/7066022.html
Copyright © 2011-2022 走看看