找回密码
 注册
搜索
查看: 4355|回复: 0

我的一个类

[复制链接]
蒙面人  发表于 2002-8-2 13:58:35 |阅读模式
/*console.h*/
#ifndef CONSOLE_DEBUG_WINDOW
#define CONSOLE_DEBUG_WINDOW
#include "stdlib.h"
#include "stdio.h"
#include "windows.h"

class TMyOutputConsole
{
private:
      FILE    *__fStdOut;
      HANDLE   __hStdOut;
      int iWidth;
      int iHeight;
      char *pFname;
      void __fastcall startConsoleWin(int,int,char *);
      bool __fastcall EndConsoleWin();
protected:
public:
  __fastcall TMyOutputConsole(int width = 80,int height=25,char *fname=NULL);
  __fastcall ~TMyOutputConsole();
  HANDLE __fastcall GetConsoleHanle();
  int __fastcall  wprintf(char *fmt);
};
#endif

/*console.cpp*/
#include "console.h"
__fastcall TMyOutputConsole::TMyOutputConsole(int width,int height,char *fname)
{
    __fStdOut = NULL;
    __hStdOut = NULL;
    iWidth = width;
    iHeight = height;
    pFname = fname;
    startConsoleWin(iWidth,iHeight,pFname);
}
__fastcall TMyOutputConsole::~TMyOutputConsole()
{
    EndConsoleWin();
}
void __fastcall TMyOutputConsole::startConsoleWin(int width,int height,char *fname)
{
    //
    AllocConsole();
    SetConsoleTitle("Debug Window");
    __hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    char szBuff[100];
    sprintf(szBuff,"My Handle is %08X\n",__hStdOut);
    wprintf(szBuff);
    COORD co;
    co.X  = (short)width;
    co.Y =  (short)height;
    SetConsoleScreenBufferSize(__hStdOut,co);
    if(fname)
        __fStdOut = fopen(fname,"w");

}
HANDLE __fastcall TMyOutputConsole::GetConsoleHanle()
{
    return __hStdOut;
}
bool __fastcall TMyOutputConsole::EndConsoleWin()
{
    if(__hStdOut)
    {
        return(FreeConsole());
    }
    return false;
}
int __fastcall TMyOutputConsole::wprintf(char *fmt)
{
     char s[300];
     va_list argptr;
     int cnt;
     va_start(argptr,fmt);
     cnt = vsprintf(s,fmt,argptr);
     va_end(artptr);
     DWORD cCharsWritten;
     if(__hStdOut)
        WriteConsole(__hStdOut,s,strlen(s),&cCharsWritten,NULL);
     if(__fStdOut)
        fprintf(__fStdOut,s);
        return cnt;
}

/****************************************************************************/
现在关键是如何抓住WM_DESTROY消息?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|宁德市腾云网络科技有限公司 ( 闽ICP备2022007940号-5|闽公网安备 35092202000206号 )

GMT+8, 2025-6-20 03:13 , Processed in 0.035485 second(s), 14 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表