?? mmaloglistbox.cpp
字號:
}
// --------------------------------------------------------------------------
LINEDATA_MEMORY *CMMALogListBox::GetItemData(HWND hListBox, int iIndex)
{
int iCount = SendMessage(hListBox, LB_GETCOUNT, 0L, 0L);
if (iIndex < 0 || iIndex >= iCount) return NULL;
LINEDATA_MEMORY *pstLDM = (LINEDATA_MEMORY *)SendMessage(hListBox, LB_GETITEMDATA, (WPARAM)iIndex, 0L);
return pstLDM;
}
// --------------------------------------------------------------------------
char *CMMALogListBox::GetLengthlyType(HWND hListBox)
{
static char st_szGetLengthlyType[MMALOGLISTBOX_LINEDATA_TYPELEN + 1];
memset(st_szGetLengthlyType, 0, sizeof(st_szGetLengthlyType));
unsigned int iLen = 0;
MMALOGLISTBOX_USERDATA *pstUserData = CMMALogListBox::GetUserData(hListBox);
if (strlen(LOGLBSTRING_INFO ) > iLen) iLen = strlen(LOGLBSTRING_INFO);
if (strlen(LOGLBSTRING_WARNING) > iLen) iLen = strlen(LOGLBSTRING_WARNING);
if (strlen(LOGLBSTRING_ERROR ) > iLen) iLen = strlen(LOGLBSTRING_ERROR);
if (strlen(LOGLBSTRING_FATAL ) > iLen) iLen = strlen(LOGLBSTRING_FATAL);
if (strlen(LOGLBSTRING_SYSTEM ) > iLen) iLen = strlen(LOGLBSTRING_SYSTEM);
if (strlen(LOGLBSTRING_DEBUG1 ) > iLen) iLen = strlen(LOGLBSTRING_DEBUG1);
if (strlen(LOGLBSTRING_DEBUG2 ) > iLen) iLen = strlen(LOGLBSTRING_DEBUG2);
if (strlen(LOGLBSTRING_DEBUG3 ) > iLen) iLen = strlen(LOGLBSTRING_DEBUG3);
if (strlen(LOGLBSTRING_DEBUG4 ) > iLen) iLen = strlen(LOGLBSTRING_DEBUG4);
if (strlen(LOGLBSTRING_TRACE ) > iLen) iLen = strlen(LOGLBSTRING_TRACE);
if (pstUserData)
{
if (strlen(pstUserData->szPersonal[ 0] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 0]);
if (strlen(pstUserData->szPersonal[ 1] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 1]);
if (strlen(pstUserData->szPersonal[ 2] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 2]);
if (strlen(pstUserData->szPersonal[ 3] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 3]);
if (strlen(pstUserData->szPersonal[ 4] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 4]);
if (strlen(pstUserData->szPersonal[ 5] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 5]);
if (strlen(pstUserData->szPersonal[ 6] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 6]);
if (strlen(pstUserData->szPersonal[ 7] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 7]);
if (strlen(pstUserData->szPersonal[ 8] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 8]);
if (strlen(pstUserData->szPersonal[ 9] ) > iLen) iLen = strlen(pstUserData->szPersonal[ 9]);
if (strlen(pstUserData->szPersonal[10] ) > iLen) iLen = strlen(pstUserData->szPersonal[10]);
if (strlen(pstUserData->szPersonal[11] ) > iLen) iLen = strlen(pstUserData->szPersonal[11]);
if (strlen(pstUserData->szPersonal[12] ) > iLen) iLen = strlen(pstUserData->szPersonal[12]);
}
for (unsigned int I=0; I<iLen; I++) st_szGetLengthlyType[I] = 'O';
return st_szGetLengthlyType;
}
// --------------------------------------------------------------------------
int CMMALogListBox::GetLineCount(LPCTSTR lpszString)
{
int iLineCount = 1;
for (unsigned int I=0; I<strlen(lpszString); I++)
{
if (lpszString[I] == '\n') iLineCount++;
}
return iLineCount;
}
// --------------------------------------------------------------------------
WNDPROC CMMALogListBox::GetOldWndProc(HWND hListBox)
{
if ( !IsWindow(hListBox) ) return NULL;
MMALOGLISTBOX_USERDATA *pstUserData = GetUserData(hListBox);
if (!pstUserData) return NULL;
return pstUserData->pOldWndProc;
}
// --------------------------------------------------------------------------
int CMMALogListBox::GetPixelStringHeight(HDC hDC, char *szText)
{
SIZE stSize;
if (!GetTextExtentPoint32(hDC, szText, strlen(szText), &stSize)) return -1;
return stSize.cy;
}
// --------------------------------------------------------------------------
char *CMMALogListBox::GetStringTime(SYSTEMTIME &stST)
{
static char st_szGetStringTime[255];
sprintf(st_szGetStringTime, "%02d.%02d.%04d %02d:%02d:%02d:%03d", stST.wDay,
stST.wMonth,
stST.wYear,
stST.wHour,
stST.wMinute,
stST.wSecond,
stST.wMilliseconds);
return st_szGetStringTime;
}
// --------------------------------------------------------------------------
char *CMMALogListBox::GetStringType(HWND hListBox, long lType)
{
if (lType & LOGLB_INFO ) return LOGLBSTRING_INFO;
if (lType & LOGLB_WARNING ) return LOGLBSTRING_WARNING;
if (lType & LOGLB_ERROR ) return LOGLBSTRING_ERROR;
if (lType & LOGLB_FATAL ) return LOGLBSTRING_FATAL;
if (lType & LOGLB_SYSTEM ) return LOGLBSTRING_SYSTEM;
if (lType & LOGLB_DEBUG1 ) return LOGLBSTRING_DEBUG1;
if (lType & LOGLB_DEBUG2 ) return LOGLBSTRING_DEBUG2;
if (lType & LOGLB_DEBUG3 ) return LOGLBSTRING_DEBUG3;
if (lType & LOGLB_DEBUG4 ) return LOGLBSTRING_DEBUG4;
if (lType & LOGLB_TRACE ) return LOGLBSTRING_TRACE;
MMALOGLISTBOX_USERDATA *pstUserData = CMMALogListBox::GetUserData(hListBox);
if (pstUserData)
{
if (lType & LOGLB_PERSONAL1 ) return pstUserData->szPersonal[0];
if (lType & LOGLB_PERSONAL2 ) return pstUserData->szPersonal[1];
if (lType & LOGLB_PERSONAL3 ) return pstUserData->szPersonal[2];
if (lType & LOGLB_PERSONAL4 ) return pstUserData->szPersonal[3];
if (lType & LOGLB_PERSONAL5 ) return pstUserData->szPersonal[4];
if (lType & LOGLB_PERSONAL6 ) return pstUserData->szPersonal[5];
if (lType & LOGLB_PERSONAL7 ) return pstUserData->szPersonal[6];
if (lType & LOGLB_PERSONAL8 ) return pstUserData->szPersonal[7];
if (lType & LOGLB_PERSONAL9 ) return pstUserData->szPersonal[8];
if (lType & LOGLB_PERSONAL10) return pstUserData->szPersonal[9];
if (lType & LOGLB_PERSONAL11) return pstUserData->szPersonal[10];
if (lType & LOGLB_PERSONAL12) return pstUserData->szPersonal[11];
if (lType & LOGLB_PERSONAL13) return pstUserData->szPersonal[12];
}
return "";
}
// --------------------------------------------------------------------------
MMALOGLISTBOX_USERDATA *CMMALogListBox::GetUserData(HWND hListBox)
{
if ( !IsWindow(hListBox) ) return NULL;
MMALOGLISTBOX_USERDATA *pstUserData = (MMALOGLISTBOX_USERDATA *)GetWindowLong(hListBox, GWL_USERDATA);
long lVersion = -1;
if (pstUserData)
{
try
{
memcpy(&lVersion, pstUserData, sizeof(long));
}
catch(...)
{
OutputDebugString("Access Violation was or will be treated correctly\n");
lVersion = -1;
throw;
}
}
if (lVersion == -1 || lVersion != MMALOGLISTBOX_VERSION) return NULL;
return pstUserData;
}
// --------------------------------------------------------------------------
long CMMALogListBox::IsSeparatorLine(long lType)
{
if (lType & LOGLB_SEPARATOR) return LOGLB_SEPARATOR;
if (lType & LOGLB_DBLSEPARATOR) return LOGLB_DBLSEPARATOR;
if (lType & LOGLB_DASHSEPARATOR) return LOGLB_DASHSEPARATOR;
if (lType & LOGLB_DOTSEPARATOR) return LOGLB_DOTSEPARATOR;
if (lType & LOGLB_DASHDOTSEPARATOR) return LOGLB_DASHDOTSEPARATOR;
if (lType & LOGLB_DASHDOTDOTSEPARATOR) return LOGLB_DASHDOTDOTSEPARATOR;
return 0;
}
// --------------------------------------------------------------------------
BOOL CMMALogListBox::ResetListBoxContent(HWND hListBox)
{
if (hListBox == NULL) return FALSE;
LRESULT lCount = SendMessage(hListBox, LB_GETCOUNT, 0L, 0L);
if (lCount != LB_ERR)
{
for (int I=0; I<lCount; I++)
{
LINEDATA_MEMORY *pstLDM = (LINEDATA_MEMORY *)SendMessage(hListBox, LB_GETITEMDATA, (WPARAM)I, 0L);
if ((LRESULT)pstLDM != LB_ERR)
{
if (pstLDM->hFont) DeleteObject(pstLDM->hFont);
delete pstLDM;
}
}
}
SendMessage(hListBox, LB_RESETCONTENT, 0L, 0L);
return TRUE;
}
// --------------------------------------------------------------------------
BOOL CMMALogListBox::SetUserData(HWND hListBox, MMALOGLISTBOX_USERDATA *pstUserData)
{
if (hListBox == NULL) return FALSE;
SetWindowLong(hListBox, GWL_USERDATA, (LONG)pstUserData);
return TRUE;
}
// --------------------------------------------------------------------------
// PROTECTED MEMBERS
// --------------------------------------------------------------------------
BOOL CMMALogListBox::AddListBoxLine(HWND hListBox, LINEDATA_MEMORY &stLDM, BOOL bFirstAdd)
{
#ifndef _DEBUG
if (stLDM.stLDF.lType == LOGLB_TRACE) return TRUE;
#endif
if (hListBox == NULL) return FALSE;
MMALOGLISTBOX_USERDATA *pstUserData = GetUserData(hListBox);
LRESULT lResult;
if (bFirstAdd == FALSE)
{
GetSystemTime(&stLDM.stLDF.stST);
if (m_lBias > 0) stLDM.stLDF.stST.wHour += (unsigned short)m_lBias;
else stLDM.stLDF.stST.wHour -= (unsigned short)m_lBias;
long lNewActIndex = IncreaseActIndex(m_hFile);
if (lNewActIndex == -1) return FALSE;
if (!WriteLineDataAt(m_hFile, lNewActIndex, stLDM.stLDF)) return FALSE;
if ( !DeleteListBoxString(hListBox, 0) ) return FALSE;
stLDM.stLDF.bNewLineData = TRUE;
}
LINEDATA_MEMORY *pstAllocatedLDM = new LINEDATA_MEMORY;
memcpy(pstAllocatedLDM, &stLDM, sizeof(LINEDATA_MEMORY));
// set default settings for some special items
if (pstAllocatedLDM->stLDF.lType & LOGLB_ERROR)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = RGB(255,255,255);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = RGB(255,0,0);
}
if (pstAllocatedLDM->stLDF.lType & LOGLB_FATAL)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = RGB(255,255,255);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = RGB(100,40,0);
}
if (pstAllocatedLDM->stLDF.lType & LOGLB_DEBUG1)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = pstUserData ? pstUserData->clrTextDebug[0] : RGB(0,0,0);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = pstUserData ? pstUserData->clrBkDebug[0] : RGB(255,255,255);
}
if (pstAllocatedLDM->stLDF.lType & LOGLB_DEBUG2)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = pstUserData ? pstUserData->clrTextDebug[1] : RGB(0,0,0);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = pstUserData ? pstUserData->clrBkDebug[1] : RGB(255,255,255);
}
if (pstAllocatedLDM->stLDF.lType & LOGLB_DEBUG3)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = pstUserData ? pstUserData->clrTextDebug[2] : RGB(0,0,0);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = pstUserData ? pstUserData->clrBkDebug[2] : RGB(255,255,255);
}
if (pstAllocatedLDM->stLDF.lType & LOGLB_DEBUG4)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = pstUserData ? pstUserData->clrTextDebug[3] : RGB(0,0,0);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = pstUserData ? pstUserData->clrBkDebug[3] : RGB(255,255,255);
}
#ifdef _DEBUG
if (pstAllocatedLDM->stLDF.lType & LOGLB_TRACE)
{
pstAllocatedLDM->stLDF.stTypeColors.bUseTextColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.bUseBkColor = TRUE;
pstAllocatedLDM->stLDF.stTypeColors.clrText = RGB(0,0,0);
pstAllocatedLDM->stLDF.stTypeColors.clrBk = RGB(0,255,0);
}
#endif
// First calculate the width of the listbox
if (pstUserData && pstUserData->iListBoxWidth < 2000)
{
pstUserData->iListBoxWidth = 2000;
SendMessage(hListBox, LB_SETHORIZONTALEXTENT, (WPARAM)pstUserData->iListBoxWidth, 0L);
}
lResult = SendMessage(hListBox, LB_ADDSTRING, 0L, (LPARAM)(LPCTSTR)pstAllocatedLDM);
if (lResult == LB_ERR || lResult == LB_ERRSPACE) return FALSE;
LRESULT lCount = SendMessage(hListBox, LB_GETCOUNT, 0L, 0L);
SendMessage(hListBox, LB_SETCURSEL, (WPARAM)(lCount-1), 0L);
return TRUE;
}
// --------------------------------------------------------------------------
void CMMALogListBox::CloseClassLogFile()
{
if (m_hFile == -1) return;
_close(m_hFile);
m_hFile = -1;
}
// --------------------------------------------------------------------------
void CMMALogListBox::CloseLogFile(HFILE hFile)
{
if (hFile == -1) return;
_close(hFile);
hFile = NULL;
}
// --------------------------------------------------------------------------
BOOL CMMALogListBox::CreateEmptyLogFile(char *szFileName, long lNbrLines)
{
HFILE hFile = _open(szFileName, _O_RDWR | _O_BINARY | _O_TRUNC | _O_CREAT, _S_IREAD | _S_IWRITE);
if (hFile == -1)
{
TRACE("(CMMALogListBox) CreateEmptyLogFile(szFileName = %s, lNbrLines = %ld) : Error opening/creating file (code = %ld)\n", szFileName, lNbrLines, GetLastError());
return FALSE;
}
long lActIndex = 0;
if (_write(hFile, (char *)&lActIndex, sizeof(long)) != sizeof(long))
{
TRACE("(CMMALogListBox) CreateEmptyLogFile(szFileName = %s, lNbrLines = %ld) : Error writing start index\n", szFileName, lNbrLines);
_close(hFile);
return FALSE;
}
LINEDATA_FILE stLDF;
memset(&stLDF, 0, sizeof(stLDF));
for (long I=0; I<lNbrLines; I++)
{
if (_write(hFile, (char *)&stLDF, sizeof(LINEDATA_FILE)) != sizeof(LINEDATA_FILE))
{
TRACE("(CMMALogListBox) CreateEmptyLogFile(szFileName = %s, lNbrLines = %ld) : Error writing line data N
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -