Adding the debug console to an MFC form program

Source: Internet
Author: User

In the process of writing complex programs, we often need to export some information to a file or screen. More than console application, MFC form program to appear troublesome!

There are 2 ways to add a debug console to an MFC form program, which allows programmers to debug programs and understand the current program's running state.

Important Windows API:allocconsole(); Creating the console window

Freeconsole     (); Destroying the console window

(1) Start the console window

header files that need to be included

#include <io.h>

#include <cstdio>

#include <FCNTL.H>

voidCtestdebugconsoledlg::onbnclickedbutton6 () {//Start Debugconsoleallocconsole (); intptr_t handle=(intptr_t) GetStdHandle (std_output_handle);intHCRT =_open_osfhandle (Handle,_o_text); FILE* HF = _fdopen (HCRT,"W" );*stdout =*HF;Chartitle[1024x768] ={0};sprintf_s (title,1024x768,"debugcosole[%u]", (unsignedLong)( This-GetSafeHwnd ())); Setconsoletitle (title); Setconsoletextattribute (HANDLE) HANDLE, foreground_red| Foreground_blue |foreground_intensity); HWND hwnd=NULL; while(Null==hwnd) hwnd=:: FindWindow (NULL, (LPCTSTR) title); HMENU HMENU=:: GetSystemMenu (hwnd, FALSE); DeleteMenu (Hmenu, Sc_close, Mf_bycommand);}

MFC Forms Test Program:

Console information displays:

Code Download (VS2008): Http://files.cnblogs.com/kekec/DebugConsole.rar

(2) Design another MFC form program

For this approach, see " Implementing a common Debug console " for Azure Product.

Adding the debug console to an MFC form program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.