📄 trcview.cpp
字号:
}
else
{
int l_iDataSizeBeforeScrollPos;
if(l_iCharsWritten > l_iBufferSizeChars)
l_iDataSizeBeforeScrollPos =
l_iBufferSizeChars - l_iDataSizeAfterScrollPos;
else
l_iDataSizeBeforeScrollPos = p_iFirstViewPos;
PaintBufferWithCopy(
p_hDC, l_pText, l_iBufferSizeChars,
p_iFirstViewPos, p_iLinesOffset,
l_iDataSizeAfterScrollPos, l_iDataSizeBeforeScrollPos);
}
m_iTotalNumCharsWhenPainted = l_iCharsWritten;
m_iScrollChangedWhenPainted = m_iScrollChanged;
}//void BufferViewer::PaintBuffer
#ifdef WIN32 //{
/*-------------------------------------------------------------
FUNCTION: BufferViewer::OnPaint
PURPOSE: Called to paint screen buffer view window
-------------------------------------------------------------*/
void BufferViewer::OnPaint()
{
PAINTSTRUCT l_Paint;
BeginPaint(m_hWnd, &l_Paint);
FillRect(l_Paint.hdc, &m_ClientRect,
(HBRUSH) GetStockObject(WHITE_BRUSH));
if(m_pBufferPointers && m_pBufferPointers->m_pGlobalFooter)
{
HGDIOBJ l_hPrevFont = SelectObject
(l_Paint.hdc, m_hFont);
if(!m_iFontHeight)
{
SIZE l_Size;
m_iFontHeight = GetTextExtentPoint32(
l_Paint.hdc, _T("W"), 4, &l_Size);
m_iFontHeight = l_Size.cy;
m_iFontWidth = l_Size.cx;
m_iLogicalWidthPixels = m_iLogicalWidthChars *
m_iFontWidth;
OnSizeChanges();
}
//long l_lVertPos = GetScrollPos(m_hWnd, SB_VERT);
int l_iOldestCharInBuffer = ((int)
(m_pBufferPointers->m_pGlobalFooter->m_dwNumBytesWritten-
m_pBufferPointers->m_dwTextAreaSize))/(int)sizeof(TCHAR);
if(m_bMoveToStartNextTime &&
m_iCharShownFirst < l_iOldestCharInBuffer)
{
m_iCharShownFirst = l_iOldestCharInBuffer;
}
m_bMoveToStartNextTime = false;
SetViewportOrgEx(l_Paint.hdc, -m_iHorzPos, 0, NULL);
FillRect(l_Paint.hdc, &m_PaintRect,
(HBRUSH) GetStockObject(WHITE_BRUSH));
PaintBuffer(m_iCharShownFirst, m_iLineOffset,
l_Paint.hdc, &m_PaintRect);
SelectObject(l_Paint.hdc, l_hPrevFont);
}
EndPaint(m_hWnd, &l_Paint);
UpdateScrollPos();
}//void BufferViewer::OnPaint()
/*-------------------------------------------------------------
FUNCTION: BufferViewer::OnSizeChanges
PURPOSE: Called in response to WM_SIZE
-------------------------------------------------------------*/
void BufferViewer::OnSizeChanges()
{
GetClientRect(m_hWnd, &m_ClientRect);
m_iNumLinesInClientArea = 0;
if(m_iFontHeight > 0)
{
m_iNumLinesInClientArea =
(m_ClientRect.bottom - m_ClientRect.top)/m_iFontHeight;
}
m_PaintRect = m_ClientRect;
m_PaintRect.right = m_ClientRect.right + m_iHorzPos;
InvalidateRect(m_hWnd, NULL, FALSE);
}//void BufferViewer::OnSizeChanges()
#endif//WIN32 }
/*-------------------------------------------------------------
FUNCTION: BufferViewer::OnTimerMessage
PURPOSE: Called in response to WM_TIMER message in the
buffer view window. Calculates a new scroll position and
forces repaint
------------------------------------------------------------*/
void BufferViewer::OnTimerMessage()
{
if(!m_pBufferPointers || !m_pBufferPointers->m_pGlobalFooter)
return;
int l_iCharsWritten =
m_pBufferPointers->m_pGlobalFooter->m_dwNumBytesWritten /
sizeof(TCHAR);
if(m_iTotalNumCharsWhenPainted == l_iCharsWritten &&
m_iScrollChangedWhenPainted == m_iScrollChanged)
return;//Nothing new was written since last paint
UpdateScrollPos();
if(m_iCharShownFirst == m_iFirstViewPosWhenPainted &&
m_iNumLinesPainted >= m_iNumLinesInClientArea &&
m_iLineOffset == 0)
{
return;//don't repaint the same place again
}
InvalidateRect(m_hWnd, NULL, FALSE);
}//void BufferViewer::OnTimerMessage
void BufferViewer::UpdateScrollPos()
{
int l_iBufferSizeChars = m_pBufferPointers->m_dwTextAreaSize /
sizeof(TCHAR);
int l_iCharsWritten =
m_pBufferPointers->m_pGlobalFooter->m_dwNumBytesWritten /
sizeof(TCHAR);
int l_iRange = 0;
int l_iScrollPos = 0;
//We will set the scroll range depending where the
//current viewing point (m_iCharShownFirst) is. If it
//is within the memory buffer, we need to set the range
//to the size of the buffer (or the number of bytes
//written, if the buffer is not full yet). If the
//current viewing point is behind the buffer (the data
//were lost), we need to set the range to the whole
//distance between the newest data and the view point.
if(l_iCharsWritten < l_iBufferSizeChars)
{//The buffer is not full yet.
l_iRange = l_iCharsWritten;
l_iScrollPos = m_iCharShownFirst;
}
else
{//The buffer is full
int l_iFirstByteInBuffer =
l_iCharsWritten - l_iBufferSizeChars;
if(m_iCharShownFirst < l_iFirstByteInBuffer)
{ //The view is behind the oldest data in the
//buffer. Set the range to the whole distance
//between the newest data and the view point.
l_iRange = l_iCharsWritten - m_iCharShownFirst;
l_iScrollPos = 0;
}
else
{
//The view point is within the buffer.
//The range should be equal to the buffer size.
l_iRange = l_iBufferSizeChars;
l_iScrollPos = m_iCharShownFirst - l_iFirstByteInBuffer;
}
}
if(m_bStickToEnd)
{
l_iScrollPos = l_iRange;
m_iCharShownFirst = l_iCharsWritten;
}
if(m_iCharShownFirst > l_iCharsWritten)
{
m_iCharShownFirst = 0;//buffer was reset
m_bStickToEnd = true;
}
SetScrollRange(m_hWnd, SB_VERT, 0, l_iRange, FALSE);
SetScrollPos(m_hWnd, SB_VERT, l_iScrollPos, TRUE);
}//void BufferViewer::UpdateScrollPos()
void BufferViewer::OnScrollMessage
(
int p_nScrollBarType,
int p_nScrollCode,
int p_nPos,
int p_nTrackPos,
int p_nMin,
int p_nMax
)
{
if(!m_pBufferPointers || !m_pBufferPointers->m_pGlobalFooter)
return;
long l_lCurPos = p_nPos;
long l_lNewPos = p_nPos;
int l_iLineOffset = 0;
bool l_bStickToEnd = m_bStickToEnd,
l_bMoveToStartNextTime = m_bMoveToStartNextTime;
switch(p_nScrollCode)
{
case SB_THUMBTRACK:
l_lNewPos = p_nTrackPos;
if(p_nTrackPos >= p_nMax)
{
l_bStickToEnd = true;
}
break;
case SB_LINEUP:
if(p_nScrollBarType == SB_VERT)
l_lNewPos -= 1;
else
l_lNewPos -= m_iFontWidth;
break;
case SB_LINEDOWN:
if(p_nScrollBarType == SB_VERT)
l_lNewPos += m_iFirstRowLength;
else
l_lNewPos += m_iFontWidth;
break;
case SB_PAGEUP:
if(p_nScrollBarType == SB_VERT)
l_iLineOffset = -m_iNumLinesInClientArea;
else
l_lNewPos -= m_ClientRect.right - m_ClientRect.left -
m_iFontWidth;
break;
case SB_PAGEDOWN:
if(p_nScrollBarType == SB_VERT)
l_lNewPos += m_iNumBytesPainted-1;
else
l_lNewPos += m_ClientRect.right - m_ClientRect.left -
m_iFontWidth;
break;
case SB_TOP:
l_lNewPos = 0;
l_bMoveToStartNextTime = true;
break;
case SB_BOTTOM:
l_lNewPos = p_nMax;
l_bStickToEnd = true;
break;
}
if(l_lNewPos < p_nMin)
l_lNewPos = p_nMin;
else if(l_lNewPos > p_nMax)
l_lNewPos = p_nMax;
if(p_nScrollBarType == SB_VERT)
{
m_iLineOffset = l_iLineOffset;
int l_iDiffPos = l_lNewPos - l_lCurPos;
if(l_iDiffPos < 0 || l_iLineOffset < 0)
{
l_bStickToEnd = false;
}
m_iCharShownFirst += l_iDiffPos;
m_bStickToEnd = l_bStickToEnd;
m_bMoveToStartNextTime = l_bMoveToStartNextTime;
int l_iOldestCharInBuffer = ((int)
(m_pBufferPointers->m_pGlobalFooter->m_dwNumBytesWritten-
m_pBufferPointers->m_dwTextAreaSize))/(int)sizeof(TCHAR);
if(m_iCharShownFirst < l_iOldestCharInBuffer)
{
m_bMoveToStartNextTime = true;
}
else if(m_iCharShownFirst >= (int)
(m_pBufferPointers->m_pGlobalFooter->m_dwNumBytesWritten/
sizeof(TCHAR)) && m_iLineOffset >= 0)
{
m_bStickToEnd = true;
}
}
else
{
if(m_iHorzPos == l_lNewPos)
return;
m_iHorzPos = l_lNewPos;
m_PaintRect.right = m_ClientRect.right + m_iHorzPos;
}
SetScrollPos(m_hWnd, p_nScrollBarType, l_lNewPos, TRUE);
InvalidateRect(m_hWnd, NULL, FALSE);
m_iScrollChanged++;
}//void BufferViewer::OnScrollMessage
#ifdef WIN32 //{
/*-------------------------------------------------------------
FUNCTION: WindowProc
PURPOSE: Window procedure for the trace buffer view window
------------------------------------------------------------*/
static LRESULT CALLBACK TraceViewWindowProc
(
HWND p_hWnd,
UINT p_uMsg,
WPARAM p_wParam,
LPARAM p_lParam
)
{
HTRACEK((KeyWordAppDebug, _T("View WindowProc %x %x %x %x"),
p_hWnd, p_uMsg, p_wParam, p_lParam ));
long l_lBufferViewer = GetWindowLong(p_hWnd, 0);
BufferViewer * l_pViewer =(BufferViewer * )l_lBufferViewer;
switch(p_uMsg)
{
case WM_CREATE:
{
SetTimer(p_hWnd, 1, 1000, NULL);
BufferViewer * l_pViewer =new BufferViewer(p_hWnd);
l_pViewer->m_pBufferPointers = pGetTraceBuffer();
l_pViewer->m_hFont =
(HFONT)GetStockObject(
#if !defined(_WIN32_WCE)
SYSTEM_FIXED_FONT
#else
SYSTEM_FONT
#endif
);
SetWindowLong(p_hWnd, 0, (long)l_pViewer);
if(l_pViewer->m_pBufferPointers)
{
SetScrollRange(p_hWnd, SB_VERT, 0,
l_pViewer->m_pBufferPointers->m_dwTextAreaSize/
sizeof(TCHAR), FALSE);
l_pViewer->m_iLogicalWidthChars = 512;
SetScrollRange(p_hWnd, SB_HORZ, 0,
l_pViewer->m_iLogicalWidthChars, FALSE);
}
}
case WM_SIZE:
if(l_pViewer)
l_pViewer->OnSizeChanges();
break;
case WM_TIMER:
if(l_pViewer)
l_pViewer->OnTimerMessage();
break;
case WM_VSCROLL:
case WM_HSCROLL:
if(l_pViewer)
{
int l_nScrollBarType =
p_uMsg == WM_VSCROLL? SB_VERT : SB_HORZ;
int l_nScrollCode = (int) LOWORD(p_wParam);
short int l_nPos = (short int) HIWORD(p_wParam);
HWND l_hwndScrollBar = (HWND) p_lParam;
SCROLLINFO l_ScrollInfo;
memset(&l_ScrollInfo, 0, sizeof(l_ScrollInfo));
l_ScrollInfo.cbSize = sizeof(l_ScrollInfo);
l_ScrollInfo.fMask =
SIF_TRACKPOS | SIF_POS | SIF_RANGE;
GetScrollInfo(p_hWnd, l_nScrollBarType, &l_ScrollInfo);
long l_lPos = l_ScrollInfo.nPos;
l_pViewer->OnScrollMessage(
l_nScrollBarType, l_nScrollCode,
l_ScrollInfo.nPos, l_ScrollInfo.nTrackPos,
l_ScrollInfo.nMin, l_ScrollInfo.nMax);
}
break;
case WM_PAINT:
if(l_pViewer)
l_pViewer->OnPaint();
break;
case WM_USER:
KillTimer(p_hWnd, 1);
SetTimer(p_hWnd, 1, p_wParam, NULL);
break;
case WM_USER+1:
if(l_pViewer && l_pViewer->m_pBufferPointers &&
l_pViewer->m_pBufferPointers->m_pGlobalFooter)
l_pViewer->m_pBufferPointers->m_pGlobalFooter->
m_dwNumBytesWritten = 0;
break;
case WM_DESTROY:
KillTimer(p_hWnd, 1);
PostQuitMessage(0);
if(l_pViewer)
{
l_pViewer->m_pBufferPointers = NULL;
delete l_pViewer;
}
SetWindowLong(p_hWnd, 0, 0);
break;
}
return DefWindowProc(p_hWnd, p_uMsg, p_wParam, p_lParam);
}//LRESULT CALLBACK WindowProc
void RegisterTraceView(LPCTSTR p_pszClassName)
{
WNDCLASS l_Class;
memset(&l_Class,0,sizeof(l_Class));
l_Class.lpfnWndProc = TraceViewWindowProc;
l_Class.hCursor = LoadCursor(0,IDC_ARROW);
l_Class.hbrBackground = (HBRUSH)(1 + COLOR_WINDOW);
l_Class.lpszClassName = p_pszClassName;
l_Class.cbWndExtra = 4;
RegisterClass(&l_Class);
}
#endif //#ifdef WIN32 }
#endif //#ifdef TRACE_ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -