Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C
Expertise: Intermediate
May 28, 2003

Navigate the TRACEs in Your Code

If you put many TRACE's, in your code, it might be very convenient to jump to each one of them by double clicking a text line in the Debug window.

//With IMMsgBox function one can Drop an "interactive" message on a
Screen,
//or a message in Debug window


#include "stdafx.h"
#include 
#include 

#define DROP_SCREEN				 0
#define DROP_DEBUG_MSG			-1
#define DROP_DBG_MSG_TRACEBLE	-2
#define TRACE_HERE				__FILE__, -__LINE__

int IMMsgBox(char * Caption, int Type, char * FormatString, ...)
{
	char Text[1024], TracedText[1500];
	va_list pArgList;

	va_start(pArgList, FormatString);
	vsprintf(Text, FormatString, pArgList);
	va_end(pArgList);

	if(Type <= DROP_DBG_MSG_TRACEBLE)
	{
		sprintf(TracedText, 
"\n%s(%d): - %s\n", Caption, (-1) * Type, Text);
		OutputDebugString(TracedText);
		return Type;
	}

	if(Type >= DROP_SCREEN)
		return MessageBox(NULL, Text, Caption, Type);

	if(Type == DROP_DEBUG_MSG)
	{
		OutputDebugString(Text);
		return Type;
	}

	return -1;
}

int main()
{
	if(IMMsgBox("Caption", DROP_SCREEN + 
(MB_YESNOCANCEL | MB_ICONQUESTION),
		"Text containing int %d double %f and string %s", 
123, -1.234, "ABCDefg") == IDYES)
		MessageBox
(NULL, "You've clicked Yes", "Hi, User", MB_OK);

	IMMsgBox(NULL, DROP_DEBUG_MSG, 
"Text containing int %d double %f and string %s",
		123, -1.234, "ABCDefg");

	IMMsgBox(TRACE_HERE, 
"Text containing int %d double %f and string %s",
123, -1.234, "ABCDefg");

	return 0;
}
David Fine
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date