Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2262047
  • 博文数量: 218
  • 博客积分: 5767
  • 博客等级: 大校
  • 技术积分: 5883
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-01 14:44
文章存档

2012年(53)

2011年(131)

2009年(1)

2008年(33)

分类: WINDOWS

2011-10-17 16:00:12

1、在项目自动生成的stdafx.h文件中添加下面头文件
#include
#include
#include
 
2、把下面的函数加到你初始化的地方,然后你就可以使用printf函数了
void InitConsoleWindow()
{
    int nCrt = 0;
    FILE* fp;
    AllocConsole();
    nCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
    fp = _fdopen(nCrt, "w");
    *stdout = *fp;
    setvbuf(stdout, NULL, _IONBF, 0);
}
以下红色部分是我初始化函数中添加的
BOOL CSerialPortptestDlg::OnInitDialog()
{
 CDialogEx::OnInitDialog();
  CString str;
 int    Index;
 HKEY   hKey;
 LONG   ret;  
  OSVERSIONINFO     osvi;  
  BOOL   bOsVersionInfoEx;  
 char   keyinfo[100],comm_name[200],ValueName[200];  
 int   i;  
 DWORD   sType,Reserved,cbData,cbValueName;
 // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
 //  执行此操作
 SetIcon(m_hIcon, TRUE);   // 设置大图标
 SetIcon(m_hIcon, FALSE);  // 设置小图标
 InitConsoleWindow();
 printf( "str   =   %s\n ",   "debug");
调用此函数后会弹出一个CONSOLE,然后printf的东西就会出现在上面。
阅读(19118) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~