//======     
struct ErrorType
{
	string Code;			//  
	string Identifier;	//  
	string Message;		//  

	//======   
	ErrorType(string , string i, string m)
	{
		Code = c;
		Identifier = i;
		Message = m;
	}
};


typedef vector<ErrorType> ERROR_VECTOR;


	HICON hMyIcon = ::LoadIcon(0,IDI_WINLOGO);
	SetIcon(hMyIcon, TRUE);			// Set big icon
	SetIcon(hMyIcon, FALSE);		// Set small



 
 ()

Dialog
WinError View
IDD_LOOK_DIALOG
Group-box
Error Number:
IDC_STATIC
Spin

IDC_SPIN
Edit
//   IDC_SPIN
IDC_CURRENT
Slider

IDC_SLIDER
Text
Total:
IDC_STATIC
Text
//  Total:
IDC_TOTAL
Button
Close
IDCANCEL
Group-box
Parameters:
IDC_STATIC
Text
Error Code:
IDC_STATIC
Text
//   Error Code:
IDC_CODE
Text
Find:
IDC_STATIC
Edit
//   Find:
IDC_FIND
Picture

IDC_RIGHT
Picture

IDC_LEFT
Text
Severity:
IDC_STATIC
Text
//   Severity:
IDC_SEVERITY
Text
Facility:
IDC_STATIC
Text
//   Facility:
IDC_FACILITY
Text
Identifier:
IDC_STATIC
Text
//   Identifier:
IDC_ID
Text
Message:
IDC_STATIC
Text
//   Message:
IDC_MSG

void CLookDlg::OnDeltaposSpin(NMHDR *pNMHDR,
												LRESULT *pResult)
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;

	// TODO: Add your control notification handler code here
	*pResult = 0;
}


//======   
int nPos = m_Spin.GetPos() + pNMUpDown->iDelta;
//======     ,  
if (nPos < 0 || m_nItems <= nPos)
	return;

//======   
m_Slider.SetPos(nPos);

//======   
GetInfo(nPos);

//======       
UpdateData(FALSE);



CString s;
//======   ,  
GetDlgItemText(IDC_FIND, s);

//======    string,    
string find = s; 

//======     m_Vector
for(int n=0; n < m_nItems && find != m_Vector[n].Code; n++)
		;

if (n < m_nItems)			//  ,
{
	GetInfo(n);				//    
	m_Slider.SetPos(n);		//   
	UpdateData(FALSE);		//    
}


void CLookDlg::OnHScroll(UINT nSBCode, UINT nPos,
											CScrollBar* pScrollBar) 
{
	//======   
	GetInfo(m_Slider.GetPos());
	//======     
	UpdateData(FALSE);
}


void CLookDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	CRect left, right;

	//======    
	GetDlgItem(IDC_LEFT)->GetWindowRect(&left);

	//======    
	ScreenToClient(&left);

	//======    
	GetDlgItem(IDC_RIGHT)->GetWindowRect(&right);
	ScreenToClient(&right);

	//======    
	left.UnionRect(left,right);

	//======      
	if (left.PtInRect(point))
		//======   About
		OnSysCommand(IDM_ABOUTBOX,0);

	//======   	CDialog::OnLButtonDown(nFlags, point);
}


void CLookDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
		CDialog(IDD_ABOUTBOX).DoModal();
	else
		CDialog::OnSysCommand(nID, lParam);
}


BOOL CLookDlg::OnInitDialog()
{
	//=======     
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu)
	{
		//======   About
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING,
								IDM_ABOUTBOX, "About...");
	}
	//======   ()   
	HICON hMyIcon =
		::LoadIcon(GetModuleHandle(0),(char*)(IDI_EYELEFT));
	SetIcon(hMyIcon, TRUE);			// Set big icon
	SetIcon(hMyIcon, FALSE);		// Set small icon
	
	//======     ,
	if (!ReadErrors())
	{
		PostMessage(WM_QUIT);	// 
		return FALSE;
	}

	//======    
	//======   
	m_Total.Format("%d",m_nItems);

	//======      
	GetInfo(0);
	
	//======    
	CDialog::OnInitDialog();
	
	//======  -  
	m_Spin.SetBuddy(GetDlgItem(IDC_CURRENT));
	//======    
	m_Spin.SetRange(0, m_nItems-1);
	
	//======    
	m_Slider.SetRange(0, m_nItems-1);
	//======      
	m_Slider.SetTicFreq(m_nItems/10);

	return TRUE;
}


if ((nID & 0xFFF0) == IDM_ABOUTBOX)
		CDialog(IDD_ABOUTBOX).DoModal();


//======    ErrorType
ERROR_VECTOR m_Vector;
//======  
int m_nItems;


bool CLookDlg::ReadErrors()		
{
	//======      

	//======     
	string sPath = GetPathFromRegistry();

	//======       
	if (sPath.empty())
		sPath = GetPathFromUser();
	if (sPath.empty())
		return false;			//   
	
	//======   
	ifstream is (sPath.c_str());
	if (!is)
	{
		MessageBox ("   WinError.h","");
		return false;
	}
	else
	{
		//======    
		while (GetNextErrorCode(is))
		{
			//====     ErrorType  
			//====    
			m_Vector.push_back(ErrorType(gCode, gsID, gsMsg));
		}
		is.close();					//  
	}

	//======   
	m_nItems = m_Vector.size();
	return bool(m_nItems != 0);
}



//===   ,    
string gCode, gsID, gsMsg;

//======   () 
const int N_FACILITIES = 23; 

//======   
TCHAR *gsFacilities[N_FACILITIES + 1] =
{
	"NULL",		"RPC",				"Dispatch",
 "Storage",	"Interface",		"Unknown",
 "Unknown",	"Win32",			"Windows",
 "SSPI",		"Control",		"Cert",
	"Internet",	"MediaServer",	"MSMQ",
 "SetupAPI",	"Smart Card",		"COM+",
 "AAF",			"URT",				"ACS",
 "DPlay",		"UMI",				"SXS"
};


void CLookDlg::GetInfo(int nPos)
{
	//======  
	m_CurPos.Format("%d",nPos);
		
	if (nPos >= m_nItems)
		return;

	//=======   
	m_Code	= m_Vector[nPos].Code.c_str();
	m_Msg	= m_Vector[nPos].Message.c_str();
	m_ID= m_Vector[nPos].Identifier.c_str();

	//======     
	DWORD dw = strtoul(LPCTSTR(m_Code),0,0);

	//======    (Severity)
	m_Severity = dw & 0x80000000 ? "Fail" : "Success";
	
	//=== COM-  HEX-,   > 8 
	//===      Win32-
	if (m_Code.GetLength() < 8)
	{
		if (dw)
		{	
			//======   facility  severity
			dw = 0x80000000 | (0x7 << 16) | (dw & 0xFFFF);
			m_Severity = "Error";
		}
	}
		
	//======   facility
	UINT f = (dw>>16) & 0x1FFF;

	//======   
	m_Facility = f <= N_FACILITIES ? gsFacilities[f]
										: "Unknown";
}



string CLookDlg::GetPathFromRegistry(void)
{
	HKEY hkey;				//   
	TCHAR path[MAX_PATH];	//  

	TCHAR vs[] =				//    
		"SOFTWARE\\Microsoft\\VisualStudio\\7.0\\Setup\\VC";

	DWORD dw, d;

	//======      ,
	//======      (subkey)
	//======     (value)
	bool ok = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE, vs, 0,
						KEY_READ, &hkey)== ERROR_SUCCESS
			&& ::RegQueryValueEx (hkey,"ProductDir", 0, &dw,
						(LPBYTE)path, &d) == ERROR_SUCCESS;

	string sPath = "";
	if (ok)
	{
		sPath = path;
		//======      
		sPath += "\\Include\\Winerror.h";
	}
	return sPath;
}



string CLookDlg::GetPathFromUser(void)
{
	//======    WinError.h  
	string path = "";
	//======    IMalloc
	LPMALLOC pMalloc;

	if (MessageBox("   ,"
					"   "
					"Visual C++.\r\r    ?",
					"   Windows",
					MB_YESNO | MB_ICONQUESTION)==IDNO
				|| FAILED( SHGetMalloc(&pMalloc) ))
		return path;
	
	BROWSEINFO bi;
	ZeroMemory (&bi,sizeof(bi));
	bi.ulFlags = BIF_RETURNONLYFSDIRS;
	
	//======    
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

	if (pidl)
	{
		TCHAR szDir[MAX_PATH];
		if (SHGetPathFromIDList(pidl,szDir))
		{
			path = szDir;
			path += "\\Include\\Winerror.h";
		}
			
		pMalloc->Free(pidl);
 	pMalloc->Release();
	}
	return path;
}



bool GetNextErrorCode(ifstream& is)
{
	//=====        is
	string s;
	//====    "MessageId: "
	int pos = FindText(is, s, "MessageId: ");
	//====     , 
	if (is.eof())
		return false;

	//===      "MessageId:
	gsID = s.substr(pos);
	//===    "MessageText: "
	FindText(is, s, "MessageText:");

	//       
	FindText(is, gsMsg="");	

	//   ( HRESULT)   #define
	FindText(is, s, "#define");

	//==  'L'     ,    
	s.erase(pos=s.rfind("L"));	

	//=======     
	gCode = s.substr(s.rfind(" ",pos)+1);
	//===  ,   COM-
	if ( (pos=gCode.rfind("(")) != -1)
		gCode.erase(0,pos+1);	//   
	
	return true;
}



int FindText (ifstream& is, string& s, TCHAR *text=NULL)
{
	//===   <text>    
	//===      
	for (int pos=-1;  pos==-1 && !is.eof(); )
	{
		//======    ( '\n')
		getline(is, s, '\n');

		//======    text   
		//======     ,  
		//======   

		pos = text ? s.find(text) : s.find_first_not_of("/ ");

		if (pos!=-1) 			//  
			s.erase(0,pos);	//   
	}
	//===     ,    ,
	//===    ,   
	if (text && !is.eof())
		return strlen(text);

	//==    ,    
	string st;

	for (pos=0;  pos!=-1 && !is.eof(); )
	{
		getline(is,st,'\n');
		pos = st.find_first_not_of("/ ");

		//======    ,
		//======      
		if (pos != -1)
			s += ' ' + st.substr(pos);
	}
	//===  0- ,     
	return 0;
}



~CLookDlg() { m_Vector.clear(); }



#include <iostream>	//  - STL
//===  ,    (STL)
#include <fstream>
#include <string>		//   STL
#include <vector>		//  STL  vector

//======     std
using namespace std;







