Windows && console
来源:互联网 发布:什么网络硬盘最好用 编辑:程序博客网 时间:2024/06/05 04:11
本文参考 : http://blog.csdn.net/mplus/article/details/6053573
有时候程序发布了,但是经常出现异常,你可能需要实时输出调试信息。这时你可以使用OutputDebugString+DebugView来查看调试信息;更灵活一点,你可能做一个INI文件进行配置,当条件打开时进行输出。但是当你你到客户那发现没有DebugView这个工具,又不能上网,也许太极端,但的确会碰到。
这时,你可能会想,哎,当初就应该输出到文件。当然可以,但是我想还会有别的方式,比如说调出一个console控制台进行输出。
1. Windows窗口程序调用控制台输出。
AllocConsole();
WriteConsole(...);
ReadConsole(...);
// 具体用法可以参考MSDN
1)AllocConsole();
2)#define CONSOLE_OUTPUT(s, n) \
{ \
HANDLE hWriteConsole = GetStdHandle(STD_OUTPUT_HANDLE);\
WriteConsole(hWriteConsole, s, n, NULL, NULL);\
WriteConsole(hWriteConsole, "\n", 1, NULL, NULL);\
}
3)void ConsoleOutput(char* lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
CHAR szBuffer[1024] = {0};
vsprintf(szBuffer, lpszFormat, args);
va_end(args);
CONSOLE_OUTPUT(szBuffer, strlen(szBuffer));
}
4)ConsoleOutput("This is a console example! == {%d}", 10);
2. 在window窗口显示前先显示控制台,输出Windows窗口的初始化过程。
1)创建一个MFC Windows程序。
2)添加main.cpp文件。
3)main.cpp 实现 :
//导入WinMain函数声明,此函数为MFC窗口程序的入口函数
extern "C"
{
int PASCAL WinMain(HINSTANCE inst,HINSTANCE dumb,LPSTR param,int show);
}
//定义console程序入口函数
int main(int ac,char *av[])
{
HINSTANCE inst;
inst=(HINSTANCE)GetModuleHandle(NULL);
char buf[256];
buf[0]=0;
for(int i=1; i<ac; i++)
{
strcat(buf,av[i]);
strcat(buf," ");\
}
return WinMain(inst,NULL,buf,SW_SHOWNORMAL);
}
4) 工程设置
Linker -- SubSystem : (/SUBSYSTEM:WINDOWS)变为Console(SUBSYSTEM:CONSOLE)
- Windows && console
- Console Terminal On Windows
- console改windows
- windows console程序一闪而过
- windows console 颜色设置
- /subsystem:windows 与 /subsystem:console
- windows 编程,c,c++,console
- /subsystem:windows 与 /subsystem:console
- Hide the console in windows
- Python - windows - 隐藏Console窗口
- /subsystem:windows 与 /subsystem:console
- Windows下的Console Emulator
- 浅谈Console与Windows子系统
- Python - windows - 隐藏Console窗口
- /subsystem:windows 与 /subsystem:console
- /subsystem:windows 与 /subsystem:console
- windows下隐藏console窗口
- /subsystem:windows 与 /subsystem:console
- Ubuntu主文件夹里的中文文件夹名称改成英文
- WPF/Blend4之自定义控件——制作自己的Button
- Android中onTouch方法的执行过程以及和onClick执行发生冲突的解决办法
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
- 1块钱的路由器,10亿美金的小米网络
- Windows && console
- OSI7层模型
- Android菜鸟的成长笔记(21)——跨进程调用Service
- SSL协议详解
- SUN JDK 代替Open JDK
- INTENT类型,多个Activity交互
- Android 中使用 html 作布局文件
- UTF-8和UTF-16使用对比
- Outlook 2013 重新联姻Hotmail ,Exchange ActiveSync牵线搭桥