Click here to Skip to main content
15,881,898 members
Articles / Desktop Programming / MFC

Brainchild, A syntax coloring edit control

Rate me:
Please Sign up or sign in to vote.
4.85/5 (64 votes)
16 Jun 2005CPOL5 min read 703.4K   26.8K   263  
Syntax coloring, multi-level undo/redo editor control.
/*
 *	messagebox.c
 *
 *	(C) Copyright 1999-2005 Jan van den Baard.
 *	    All Rights Reserved.
 */

#include "defs.h"

static int MsgBox( LPCLASSDATA lpcd, HWND hParent, DWORD dwType, LPCTSTR lpszBody, va_list args )
{
	TCHAR		szBuffer[ 1024 ];
	
	/*
	 *	Clear qualifiers.
	 */
	lpcd->cQualifier = 0;

	/*
	 *	Format the arguments.
	 */
	_vstprintf( szBuffer, lpszBody, args );
	return MessageBox( hParent ? hParent : lpcd->hWnd, szBuffer, lpcd->szFileName, dwType );
}

int OkWarning( LPCLASSDATA lpcd, HWND hParent, LPCTSTR lpszBody, ... )
{
	va_list		args;
	int		rc;

	va_start( args, lpszBody );
	rc = MsgBox( lpcd, hParent, MB_OK | MB_APPLMODAL | MB_ICONWARNING, lpszBody, args );
	va_end( args );

	return rc;
}

int OkInformation( LPCLASSDATA lpcd, HWND hParent, LPCTSTR lpszBody, ... )
{
	va_list		args;
	int		rc;

	va_start( args, lpszBody );
	rc = MsgBox( lpcd, hParent, MB_OK | MB_APPLMODAL | MB_ICONINFORMATION, lpszBody, args );
	va_end( args );

	return rc;
}

int YesNoWarning( LPCLASSDATA lpcd, HWND hParent, LPCTSTR lpszBody, ... )
{
	va_list		args;
	int		rc;

	va_start( args, lpszBody );
	rc = MsgBox( lpcd, hParent, MB_YESNO | MB_APPLMODAL | MB_ICONWARNING, lpszBody, args );
	va_end( args );

	return rc;
}

int YesNoCancelWarning( LPCLASSDATA lpcd, HWND hParent, LPCTSTR lpszBody, ... )
{
	va_list		args;
	int		rc;
	
	va_start( args, lpszBody );
	rc = MsgBox( lpcd, hParent, MB_YESNOCANCEL | MB_APPLMODAL | MB_ICONWARNING, lpszBody, args );
	va_end( args );

	return rc;
}

int OkIOError( LPCLASSDATA lpcd, HWND hParent, LPCTSTR lpszBody, ... )
{
	TCHAR		sz[ 1024 ];
	va_list		args;
	LPVOID		lpMsgBuf;
	int		rc = 0;
	
	va_start( args, lpszBody );

	if ( FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
			    FORMAT_MESSAGE_FROM_SYSTEM |
			    FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
			    ( LPTSTR )&lpMsgBuf, 0, NULL))
	{
		/*
		 *	Build the message.
		 */
		_tcsncpy( sz, lpszBody, 1024 );
		_tcsncat( sz, _T( "\n\n" ), 1024 );
		_tcsncat( sz, lpMsgBuf, 1024 );
		
		/*
		 *	Free the formatted output.
		 */
		LocalFree( lpMsgBuf );

		/*
		 *	Put up the message box.
		 */
		rc = MsgBox( lpcd, hParent, MB_OK | MB_APPLMODAL | MB_ICONERROR, sz, args );
	}
	va_end( args );
	return rc;
}

int OkError( LPCLASSDATA lpcd, HWND hParent, LPCTSTR lpszBody, ... )
{
	va_list		args;
	int		rc;
	
	va_start( args, lpszBody );
	rc = MsgBox( lpcd, hParent, MB_OK | MB_APPLMODAL | MB_ICONERROR, lpszBody, args );
	va_end( args );

	return rc;
}

void ErrorMsg( LPCTSTR lpszBody, ... )
{
	va_list		args;
	TCHAR		szBuffer[ 1024 ];
	
	/*
	 *	Format the arguments.
	 */
	va_start( args, lpszBody );
	_vstprintf( szBuffer, lpszBody, args );
	MessageBox( NULL, szBuffer, _T("Brainchild DLL"), MB_OK | MB_APPLMODAL | MB_ICONERROR );
	va_end( args );
}

void AboutControl( LPCLASSDATA lpcd )
{
	TCHAR		szBuffer[ 1024 ];
	
	/*
	 *	Clear qualifiers.
	 */ 
	lpcd->cQualifier = 0;

	/*
	 *	Show the messagebox.
	 *
	 *	These strings are not translated.
	 */
	_stprintf( szBuffer, _T("Brainchild custom control DLL.\n\nVersion %ld.%ld.\nCompiled: %s (%s)\n\n(C) Copyright 1993-2005 Jan van den Baard.\nAll Rights Reserved."), BCVERSION, BCREVISION, __DATE__, __TIME__ );
	MessageBox( lpcd->hWnd, szBuffer, lpcd->szFileName, MB_OK | MB_APPLMODAL | MB_ICONINFORMATION );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

Comments and Discussions