📄 0514001.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="../../vckbase.css">
</head>
<body>
<div align="justify">
<table border="0" width="100%" class="font" height="57">
<tr>
<td width="27%" height="6" class="bigfont" bgcolor="#B8CFE7" align="center" bordercolor="#800080">
<font color="#800080">VC知识库(五)</font>
</td>
<td width="73%" height="6" class="bigfont" bgcolor="#B8CFE7" align="center" bordercolor="#800080">
<font color="#800080">www.vckbase.com</font>
</td>
</tr>
<tr>
<td width="100%" height="4" class="header" valign="top" align="center" colspan="2">
<hr>
</td>
</tr>
<tr>
<td width="100%" height="17" class="header" valign="top" align="center" colspan="2">
<font color="#00000A">(DEBUG时)从图形窗口中向控制台窗口输出文本</font>
</td>
</tr>
<tr>
<td width="100%" height="17" class="info" align="center" colspan="2">
<font color="#00000A">闻怡洋译</font>
</td>
</tr>
<tr>
<td width="100%" height="22" class="font" colspan="2">
<hr>
</td>
</tr>
<tr>
<td width="100%" height="5" class="font" colspan="2">
<!-- Author and contact details -->
<p>This article was contributed by <!-- Author Email --><a
href="mailto:wangwj@taslon.com"><!-- Author Name -->Wang Weijun</a>. <!-- Environment eg NT 4.0 SP4, VC6.0 SP2 --> </p>
<p><u>Environment:</u> any MSVC <!-- Text / source code --> </p>
<p><!-- The 'p' starts a paragraph of normal text --> 由于需要在没有安装VC的PC上进行调试,所以在没有IDE环境的情况下TRACE宏无法工作,而使用
MessageBox 并不是一个很好的方法。另一种简单的方法是向<font
face="Times New Roman">Console</font>中输出文本。<br>
<br>
在你的应用中增加如下代码: <!-- start a block of source code --> </p>
<pre><font color="#990000"><tt>
<font size="3">#ifdef _DEBUG
FILE* __fStdOut = NULL;
HANDLE __hStdOut = NULL;
#endif
// width and height is the size of console window, if you specify fname,
// the output will also be writton to this file. The file pointer is automatically closed
// when you close the app
void startConsoleWin(int width=80, int height=25, char* fname = NULL);
void startConsoleWin(int width, int height, char* fname)
{创建一个Console窗口,指明宽度和高度,如果fname不为空则同时将输出写入一个文件。
#ifdef _DEBUG
AllocConsole();//分配
SetConsoleTitle("Debug Window");
__hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);//指明句柄为标准输出HANDLE
COORD co = {width,height};
SetConsoleScreenBufferSize(__hStdOut, co);//指明缓冲区大小
if(fname)
__fStdOut = fopen(fname, "w");
#endif
}
// Use wprintf like TRACE0, TRACE1, ... (The arguments are the same as printf)
int wprintf(char *fmt, ...)
{//类似于printf的函数,向Console写入文本
#ifdef _DEBUG
char s[300];
va_list argptr;
int cnt;
va_start(argptr, fmt);
cnt = vsprintf(s, fmt, argptr);
va_end(argptr);
DWORD cCharsWritten;
if(__hStdOut)// 写Console
WriteConsole(__hStdOut, s, strlen(s), &cCharsWritten, NULL);
if(__fStdOut)
fprintf(__fStdOut, s);
return(cnt);
#else
return 0;
#endif
}</font>
</tt></font></pre>
<p>在CWinApp::InitInstance(...)中调用 startConsoleWin(...),然后你可以在需要输出的时候使用wprintf(....)
代替 TRACE 宏。</p>
</td>
</tr>
<tr>
<td width="100%" height="12" class="font" colspan="2">
</td>
</tr>
<tr>
<td width="100%" height="6" class="font" colspan="2">
</td>
</tr>
<tr>
<td width="100%" height="8" class="font" colspan="2">
</td>
</tr>
<tr>
<td width="100%" height="17" class="font" colspan="2"></td>
</tr>
</table>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -