Click here to Skip to main content
15,886,026 members
Articles / Desktop Programming / WTL

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read 90.9K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
#include "stdafx.h"
#include "../include/_com_error_msg.h"

#include "../include/GSMessageBox.h"
#pragma message( "Auto load library gsmsgbox.lib " __FILE__ )
#pragma comment(lib,"../lib/gsmsgbox.lib")
namespace misc{							 
BOOL _com_error_msg(_com_error& e,LPCTSTR file,int linenum,bool bShowcontinue,BSTR bstrDesc,bool bShowCheck)
{
	USES_CONVERSION;
	const UINT uType=bShowcontinue?MB_OK|MB_ICONERROR|MB_YESNO:MB_OK|MB_ICONERROR;
	UINT uCheck=BST_UNCHECKED;
	GSMSGBOX gm;
	gm.cbSize=sizeof(GSMSGBOX);
	gm.uFlags=GS_MSGBOX_CHECKBOX;
	gm.pcszCheckBoxText=_T("������ʾ����ʾ");
	gm.puValue=&uCheck;
	LPGSMSGBOX lpMsgBoxOpt=bShowCheck?&gm:NULL;

#ifdef _DEBUG
	TCHAR psz[100];
	wsprintf(psz,_T("file:%s,line:%d"),file,linenum);//__FILE__,__LINE__);
	CComBSTR bstrTitle(psz),msg;
	msg.Append(L"������Ϣ��"); 
	msg.Append((BSTR)e.Description());
	if(bShowcontinue)
		msg.Append(L"\r\n�Ƿ������");
	LPCTSTR str=0;
	if(msg.Length()>0)
		str=OLE2CT(msg);
	if(bShowCheck){
		BOOL const bRet=GSMessageBox(::GetActiveWindow(),str,OLE2CT(bstrTitle),uType,lpMsgBoxOpt);
		if(IDYES!=bRet)
			return FALSE;
		if(lpMsgBoxOpt){
			if(BST_CHECKED==*lpMsgBoxOpt->puValue)
				return 2;
		}
	}else{
		if(IDYES!=MessageBox(::GetActiveWindow(),str,OLE2CT(bstrTitle),uType))
			return FALSE;
	}
	return TRUE;
#else
	CComBSTR msg((BSTR)e.Description());
	if(msg.Length()<1 && bstrDesc)
		msg=bstrDesc;
	if(msg.Length()>0 && bShowcontinue){
		msg+=_T("\r\n�Ƿ������");
	}
	LPCTSTR str=0;
	if(msg.Length()>0)
		str=OLE2CT(msg);
	if(bShowCheck){
		BOOL bRet=GSMessageBox(::GetActiveWindow(),OLE2CT(msg),_T("��ʾ"),uType,lpMsgBoxOpt);
		if(IDYES!=bRet)
			return FALSE;
		if(lpMsgBoxOpt){
			if(BST_CHECKED==*lpMsgBoxOpt->puValue)
				return 2;
		}
	}else{
		if(IDYES!=MessageBox(::GetActiveWindow(),OLE2CT(msg),_T("��ʾ"),uType))
			return FALSE;
	}
	return TRUE;
#endif
}

BOOL ComErrorMsg::operator()(_com_error& e,bool bShowcontinue,BSTR bstrDesc,bool bShowCheck)
{
	USES_CONVERSION;
	const UINT uType=bShowcontinue?MB_OK|MB_ICONERROR|MB_YESNO:MB_OK|MB_ICONERROR;
	UINT uCheck=BST_UNCHECKED;
	GSMSGBOX gm;
	gm.cbSize=sizeof(GSMSGBOX);
	gm.uFlags=GS_MSGBOX_CHECKBOX;
	gm.pcszCheckBoxText=_T("������ʾ����ʾ");
	gm.puValue=&uCheck;
	LPGSMSGBOX lpMsgBoxOpt=bShowCheck?&gm:NULL;

#ifdef _DEBUG
	TCHAR psz[100];
	wsprintf(psz,_T("%s,line:%d"),m_file,m_line);//__FILE__,__LINE__);
	CComBSTR bstrTitle(psz),msg;
	msg.Append(L"������Ϣ��"); 
	msg.Append((BSTR)e.Description());
	if(bShowcontinue)
		msg.Append(L"\r\n�Ƿ������");
	LPCTSTR str=0;
	if(msg.Length()>0)
		str=OLE2CT(msg);
	if(bShowCheck){
		BOOL const bRet=GSMessageBox(::GetActiveWindow(),str,OLE2CT(bstrTitle),uType,lpMsgBoxOpt);
		if(IDYES!=bRet)
			return FALSE;
		if(lpMsgBoxOpt){
			if(BST_CHECKED==*lpMsgBoxOpt->puValue)
				return 2;
		}
	}else{
		if(IDYES!=MessageBox(::GetActiveWindow(),str,OLE2CT(bstrTitle),uType))
			return FALSE;
	}
	return TRUE;
#else
	CComBSTR msg((BSTR)e.Description());
	if(msg.Length()<1 && bstrDesc)
		msg=bstrDesc;
	if(msg.Length()>0 && bShowcontinue){
		msg+=_T("\r\n�Ƿ������");
	}
	LPCTSTR str=0;
	if(msg.Length()>0)
		str=OLE2CT(msg);
	if(bShowCheck){
		BOOL bRet=GSMessageBox(::GetActiveWindow(),OLE2CT(msg),_T("��ʾ"),uType,lpMsgBoxOpt);
		if(IDYES!=bRet)
			return FALSE;
		if(lpMsgBoxOpt){
			if(BST_CHECKED==*lpMsgBoxOpt->puValue)
				return 2;
		}
	}else{
		if(IDYES!=MessageBox(::GetActiveWindow(),OLE2CT(msg),_T("��ʾ"),uType))
			return FALSE;
	}
	return TRUE;
#endif
}
}//namespace misc

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
Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions