mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 07:23:15 +00:00
[0.4.7][TASKMGR] Mainly Graph-stuff backports 2023-10-31
This backports the following commits: 0.4.15-dev-6770-gddd1d19b3f
[TASKMGR] Get rid of cplusplus extern c (#5808) partially 0.4.15-dev-6120-g6e77747b30
[TASKMGR] Simplify tray icon code 0.4.15-dev-6114-g9a6c85f68a
[TASKMGR] Fix PerfDataDeallocCommandLineCache, part of CORE-18014 (unresolved still) 0.4.15-dev-6113-g7989e3f26c
[TASKMGR] GraphCtrl_Dispose: Delete hdcGraph first, part of CORE-18014 (unresolved still) 0.4.15-dev-6112-gdc14a9f6e0
[TASKMGR] GraphCtrl: Use DeleteDC instead of DeleteObject to delete inst->hdcGraph, part of CORE-18014 (unresolved still) partially 0.4.15-dev-4994-g15a0f7adb0
picked a tiny part from PR4657 (I picked only the refactoring to switch-statement, no functional changes. Especially NOT the formatting changes which would require the additional winnls.h-include) 0.4.15-dev-3737-gf8faa0b660
[TASKMGR] Fix a heap corruption bug (#4311), just an addendum to PR4141 which is picked with this backport as well. Older branches were never affected. partially 0.4.15-dev-3514-g1c82bf0324
[TASKMGR] Avoid freezing in getting icons, from (PR4180) CORE17894. I picked only the 1000ms->100ms part and the stripping of WM_QUERYDRAGICON call. Therefore I don't consider CORE17894 as fully covered. 0.4.15-dev-3486-g545e1190f2
[TASKMGR] Avoid hangs as much as possible (#4166) CORE17894 partially 0.4.15-dev-3483-g403222dd4f
[TASKMGR] Preserve graphs history on resizes (#4141). I left aside the structs type renaming and OOM-Handling upon graph creation. Picked all the logical changes though. 0.4.15-dev-3269-g0ed04e3640
[TASKMGR] Make performance graph grid scroll (#3581) 0.4.15-dev-3268-ga4ab9a1e19
[TASKMGR] Formatting only (#3581). Covers the last bits of that PR. Main motivation was getting the toggling of ShowKernelTimes in the Performance tab switch on and off in realtime without introducing gaps in the graph. It also makes the grid scroll together with the data, like on Windows. Most other parts I picked solely for their binary-shrinking effect. I decided to strip the ID_HELP_TOPICS from the rc files, as this was not implemented, and I would never port that back later. So it is one less non-functional-button in the older branches. I favored memset() over Zeromemory() in this usermode-app everywhere, and favored for (;;) over while(1). Binary size shrinks slightly on all branches: master taskmgr.exe RosBEWin2.2.2 GCC8.4.0dbg 696.832 (0.4.15-dev-6820-gb3194e3) 0.4.14 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 549.888 -> 548.864 0.4.13 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 542.720 -> 542.208 0.4.12 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 545.792 -> 543.232 0.4.11 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 545.792 -> 543.232 0.4.10 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 532.480 -> 530.432 0.4. 9 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 532.480 -> 530.432 0.4. 8 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 532.480 -> 530.432 0.4. 7 taskmgr.exe RosBEWin2.1.6 GCC4.7.2dbg 531.456 -> 529.408 taskmgr.exe MS XPSP3 german 140.800 Bytes 0.4.14 taskmgr.exe RosBEWin2.1.6 MSVC2010SP1rls I18N=de-DE 110.080 Bytes -> 109.056 Bytes (my current taskmgr of choice) 0.4. 8 taskmgr.exe RosBEWin2.1.6 MSVC2010SP1rls I18N=en-US 108.032 Bytes -> 105.984 Bytes 0.4. 7 taskmgr.exe RosBEWin2.1.6 MSVC2010SP1rls I18N=en-US 107.520 Bytes -> 105.472 Bytes
This commit is contained in:
parent
89f60aba16
commit
f49cead384
42 changed files with 456 additions and 1109 deletions
|
@ -6,311 +6,252 @@
|
|||
|
||||
#include "precomp.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
WNDPROC OldGraphCtrlWndProc;
|
||||
|
||||
static void GraphCtrl_Init(TGraphCtrl* this)
|
||||
void GraphCtrl_Create(PTGraphCtrl inst, HWND hWnd, HWND hParentWnd, PTFormat fmt)
|
||||
{
|
||||
int i;
|
||||
HDC hdc, hdcg;
|
||||
HBITMAP hbmOld;
|
||||
UINT Size;
|
||||
INT p;
|
||||
RECT rc;
|
||||
|
||||
this->m_hWnd = 0;
|
||||
this->m_hParentWnd = 0;
|
||||
this->m_dcGrid = 0;
|
||||
this->m_dcPlot = 0;
|
||||
this->m_bitmapOldGrid = 0;
|
||||
this->m_bitmapOldPlot = 0;
|
||||
this->m_bitmapGrid = 0;
|
||||
this->m_bitmapPlot = 0;
|
||||
this->m_brushBack = 0;
|
||||
inst->hParentWnd = hParentWnd;
|
||||
inst->hWnd = hWnd;
|
||||
|
||||
this->m_penPlot[0] = 0;
|
||||
this->m_penPlot[1] = 0;
|
||||
this->m_penPlot[2] = 0;
|
||||
this->m_penPlot[3] = 0;
|
||||
Size = GetSystemMetrics(SM_CXSCREEN);
|
||||
inst->BitmapWidth = Size;
|
||||
Size /= PLOT_SHIFT;
|
||||
inst->PointBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size * NUM_PLOTS);
|
||||
if (!inst->PointBuffer)
|
||||
goto fail;
|
||||
|
||||
this->m_dPreviousPosition[0] = 0.0;
|
||||
this->m_dPreviousPosition[1] = 0.0;
|
||||
this->m_dPreviousPosition[2] = 0.0;
|
||||
this->m_dPreviousPosition[3] = 0.0;
|
||||
inst->NumberOfPoints = Size;
|
||||
inst->CurrIndex = 0;
|
||||
|
||||
this->m_nYDecimals = 3;
|
||||
inst->hPenGrid = CreatePen(PS_SOLID, 0, fmt->clrGrid);
|
||||
inst->hPen0 = CreatePen(PS_SOLID, 0, fmt->clrPlot0);
|
||||
inst->hPen1 = CreatePen(PS_SOLID, 0, fmt->clrPlot1);
|
||||
inst->hBrushBack = CreateSolidBrush(fmt->clrBack);
|
||||
|
||||
this->m_dLowerLimit = 0.0;
|
||||
this->m_dUpperLimit = 100.0;
|
||||
this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit;
|
||||
if (!inst->hPenGrid || !inst->hPen0 || !inst->hPen1 || !inst->hBrushBack)
|
||||
goto fail;
|
||||
|
||||
this->m_nShiftPixels = 4;
|
||||
this->m_nHalfShiftPixels = this->m_nShiftPixels/2;
|
||||
this->m_nPlotShiftPixels = this->m_nShiftPixels + this->m_nHalfShiftPixels;
|
||||
if (fmt->GridCellWidth >= PLOT_SHIFT << 2)
|
||||
inst->GridCellWidth = fmt->GridCellWidth;
|
||||
else
|
||||
inst->GridCellWidth = PLOT_SHIFT << 2;
|
||||
if (fmt->GridCellHeight >= PLOT_SHIFT << 2)
|
||||
inst->GridCellHeight = fmt->GridCellHeight;
|
||||
else
|
||||
inst->GridCellHeight = PLOT_SHIFT << 2;
|
||||
|
||||
this->m_crBackColor = RGB( 0, 0, 0);
|
||||
this->m_crGridColor = RGB( 0, 128, 64);
|
||||
this->m_crPlotColor[0] = RGB(255, 255, 255);
|
||||
this->m_crPlotColor[1] = RGB(100, 255, 255);
|
||||
this->m_crPlotColor[2] = RGB(255, 100, 255);
|
||||
this->m_crPlotColor[3] = RGB(255, 255, 100);
|
||||
inst->DrawSecondaryPlot = fmt->DrawSecondaryPlot;
|
||||
|
||||
for (i = 0; i < MAX_PLOTS; i++)
|
||||
this->m_penPlot[i] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[i]);
|
||||
this->m_brushBack = CreateSolidBrush(this->m_crBackColor);
|
||||
GetClientRect(hWnd, &rc);
|
||||
inst->BitmapHeight = rc.bottom;
|
||||
inst->ftPixelsPerPercent = (FLOAT)(inst->BitmapHeight) / 100.00f;
|
||||
|
||||
strcpy(this->m_strXUnitsString, "Samples");
|
||||
strcpy(this->m_strYUnitsString, "Y units");
|
||||
hdc = GetDC(hParentWnd);
|
||||
hdcg = CreateCompatibleDC(hdc);
|
||||
inst->hdcGraph = hdcg;
|
||||
inst->hbmGraph = CreateCompatibleBitmap(hdc, inst->BitmapWidth, inst->BitmapHeight);
|
||||
|
||||
this->m_bitmapOldGrid = NULL;
|
||||
this->m_bitmapOldPlot = NULL;
|
||||
}
|
||||
if (!hdc || !hdcg || !inst->hbmGraph)
|
||||
goto fail;
|
||||
|
||||
void GraphCtrl_Dispose(TGraphCtrl* this)
|
||||
{
|
||||
int plot;
|
||||
ReleaseDC(hParentWnd, hdc);
|
||||
hbmOld = (HBITMAP)SelectObject(hdcg, inst->hbmGraph);
|
||||
DeleteObject(hbmOld);
|
||||
|
||||
for (plot = 0; plot < MAX_PLOTS; plot++)
|
||||
DeleteObject(this->m_penPlot[plot]);
|
||||
SetBkColor(hdcg, fmt->clrBack);
|
||||
rc.right = inst->BitmapWidth;
|
||||
FillRect(hdcg, &rc, inst->hBrushBack);
|
||||
|
||||
if (this->m_bitmapOldGrid != NULL) SelectObject(this->m_dcGrid, this->m_bitmapOldGrid);
|
||||
if (this->m_bitmapOldPlot != NULL) SelectObject(this->m_dcPlot, this->m_bitmapOldPlot);
|
||||
if (this->m_bitmapGrid != NULL) DeleteObject(this->m_bitmapGrid);
|
||||
if (this->m_bitmapPlot != NULL) DeleteObject(this->m_bitmapPlot);
|
||||
if (this->m_dcGrid != NULL) DeleteDC(this->m_dcGrid);
|
||||
if (this->m_dcPlot != NULL) DeleteDC(this->m_dcPlot);
|
||||
if (this->m_brushBack != NULL) DeleteObject(this->m_brushBack);
|
||||
}
|
||||
|
||||
void GraphCtrl_Create(TGraphCtrl* this, HWND hWnd, HWND hParentWnd, UINT nID)
|
||||
{
|
||||
GraphCtrl_Init(this);
|
||||
this->m_hParentWnd = hParentWnd;
|
||||
this->m_hWnd = hWnd;
|
||||
|
||||
GraphCtrl_Resize(this);
|
||||
}
|
||||
|
||||
void GraphCtrl_SetRange(TGraphCtrl* this, double dLower, double dUpper, int nDecimalPlaces)
|
||||
{
|
||||
this->m_dLowerLimit = dLower;
|
||||
this->m_dUpperLimit = dUpper;
|
||||
this->m_nYDecimals = nDecimalPlaces;
|
||||
this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit;
|
||||
this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange;
|
||||
GraphCtrl_InvalidateCtrl(this, FALSE);
|
||||
}
|
||||
|
||||
void GraphCtrl_SetGridColor(TGraphCtrl* this, COLORREF color)
|
||||
{
|
||||
this->m_crGridColor = color;
|
||||
GraphCtrl_InvalidateCtrl(this, FALSE);
|
||||
}
|
||||
|
||||
void GraphCtrl_SetPlotColor(TGraphCtrl* this, int plot, COLORREF color)
|
||||
{
|
||||
this->m_crPlotColor[plot] = color;
|
||||
DeleteObject(this->m_penPlot[plot]);
|
||||
this->m_penPlot[plot] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[plot]);
|
||||
GraphCtrl_InvalidateCtrl(this, FALSE);
|
||||
}
|
||||
|
||||
void GraphCtrl_SetBackgroundColor(TGraphCtrl* this, COLORREF color)
|
||||
{
|
||||
this->m_crBackColor = color;
|
||||
DeleteObject(this->m_brushBack);
|
||||
this->m_brushBack = CreateSolidBrush(this->m_crBackColor);
|
||||
GraphCtrl_InvalidateCtrl(this, FALSE);
|
||||
}
|
||||
|
||||
void GraphCtrl_InvalidateCtrl(TGraphCtrl* this, BOOL bResize)
|
||||
{
|
||||
int i;
|
||||
int nCharacters;
|
||||
HPEN oldPen;
|
||||
HPEN solidPen = CreatePen(PS_SOLID, 0, this->m_crGridColor);
|
||||
HDC dc = GetDC(this->m_hParentWnd);
|
||||
|
||||
if (this->m_dcGrid == NULL)
|
||||
inst->CurrShift = 0;
|
||||
SelectObject(hdcg, inst->hPenGrid);
|
||||
for (p = inst->GridCellHeight - 1; p < inst->BitmapHeight; p += inst->GridCellHeight)
|
||||
{
|
||||
this->m_dcGrid = CreateCompatibleDC(dc);
|
||||
this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
|
||||
this->m_bitmapOldGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapGrid);
|
||||
MoveToEx(hdcg, 0, p, NULL);
|
||||
LineTo(hdcg, inst->BitmapWidth, p);
|
||||
}
|
||||
else if(bResize)
|
||||
for (p = inst->BitmapWidth - 1; p > 0; p -= inst->GridCellWidth)
|
||||
{
|
||||
if(this->m_bitmapGrid != NULL)
|
||||
MoveToEx(hdcg, p, 0, NULL);
|
||||
LineTo(hdcg, p, inst->BitmapHeight);
|
||||
}
|
||||
SelectObject(hdcg, inst->hPen0);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
GraphCtrl_Dispose(inst);
|
||||
}
|
||||
|
||||
void GraphCtrl_Dispose(PTGraphCtrl inst)
|
||||
{
|
||||
if (inst->PointBuffer)
|
||||
HeapFree(GetProcessHeap(), 0, inst->PointBuffer);
|
||||
|
||||
if (inst->hdcGraph)
|
||||
DeleteDC(inst->hdcGraph);
|
||||
|
||||
if (inst->hPenGrid)
|
||||
DeleteObject(inst->hPenGrid);
|
||||
|
||||
if (inst->hPen0)
|
||||
DeleteObject(inst->hPen0);
|
||||
|
||||
if (inst->hPen1)
|
||||
DeleteObject(inst->hPen1);
|
||||
|
||||
if (inst->hBrushBack)
|
||||
DeleteObject(inst->hBrushBack);
|
||||
|
||||
if (inst->hbmGraph)
|
||||
DeleteObject(inst->hbmGraph);
|
||||
}
|
||||
|
||||
void GraphCtrl_AddPoint(PTGraphCtrl inst, BYTE val0, BYTE val1)
|
||||
{
|
||||
HDC hdcg;
|
||||
PBYTE t;
|
||||
RECT rcDirt;
|
||||
UINT Prev0, Prev1, RetainingWidth;
|
||||
INT PrevY, CurrY, p, v;
|
||||
|
||||
hdcg = inst->hdcGraph;
|
||||
RetainingWidth = inst->BitmapWidth - PLOT_SHIFT;
|
||||
t = inst->PointBuffer;
|
||||
Prev0 = *(t + inst->CurrIndex);
|
||||
Prev1 = *(t + inst->CurrIndex + inst->NumberOfPoints);
|
||||
if (inst->CurrIndex < inst->NumberOfPoints - 1)
|
||||
inst->CurrIndex++;
|
||||
else
|
||||
inst->CurrIndex = 0;
|
||||
*(t + inst->CurrIndex) = val0;
|
||||
*(t + inst->CurrIndex + inst->NumberOfPoints) = val1;
|
||||
|
||||
// Drawing points, first shifting the plot left
|
||||
BitBlt(hdcg, 0, 0, RetainingWidth, inst->BitmapHeight, hdcg, PLOT_SHIFT, 0, SRCCOPY);
|
||||
|
||||
rcDirt.left = RetainingWidth;
|
||||
rcDirt.top = 0;
|
||||
rcDirt.right = inst->BitmapWidth;
|
||||
rcDirt.bottom = inst->BitmapHeight;
|
||||
FillRect(hdcg, &rcDirt, inst->hBrushBack);
|
||||
|
||||
SelectObject(hdcg, inst->hPenGrid);
|
||||
for (p = inst->GridCellHeight - 1; p < inst->BitmapHeight; p += inst->GridCellHeight)
|
||||
{
|
||||
MoveToEx(hdcg, RetainingWidth, p, NULL);
|
||||
LineTo(hdcg, inst->BitmapWidth, p);
|
||||
}
|
||||
v = inst->CurrShift + PLOT_SHIFT;
|
||||
if (v >= inst->GridCellWidth)
|
||||
{
|
||||
v -= inst->GridCellWidth;
|
||||
p = inst->BitmapWidth - v - 1;
|
||||
MoveToEx(hdcg, p, 0, NULL);
|
||||
LineTo(hdcg, p, inst->BitmapHeight);
|
||||
}
|
||||
inst->CurrShift = v;
|
||||
|
||||
if (inst->DrawSecondaryPlot)
|
||||
{
|
||||
SelectObject(inst->hdcGraph, inst->hPen1);
|
||||
|
||||
PrevY = inst->BitmapHeight - Prev1 * inst->ftPixelsPerPercent;
|
||||
MoveToEx(inst->hdcGraph, RetainingWidth - 1, PrevY, NULL);
|
||||
CurrY = inst->BitmapHeight - val1 * inst->ftPixelsPerPercent;
|
||||
LineTo(inst->hdcGraph, inst->BitmapWidth - 1, CurrY);
|
||||
}
|
||||
|
||||
SelectObject(inst->hdcGraph, inst->hPen0);
|
||||
PrevY = inst->BitmapHeight - Prev0 * inst->ftPixelsPerPercent;
|
||||
MoveToEx(inst->hdcGraph, RetainingWidth - 1, PrevY, NULL);
|
||||
CurrY = inst->BitmapHeight - val0 * inst->ftPixelsPerPercent;
|
||||
LineTo(inst->hdcGraph, inst->BitmapWidth - 1, CurrY);
|
||||
}
|
||||
|
||||
inline void GraphCtrl_RedrawBitmap(PTGraphCtrl inst, INT h)
|
||||
{
|
||||
HDC hdcg;
|
||||
PBYTE t;
|
||||
RECT rc;
|
||||
INT i, j, y, x, p;
|
||||
FLOAT coef;
|
||||
|
||||
hdcg = inst->hdcGraph;
|
||||
rc.left = 0; rc.top = 0;
|
||||
rc.right = inst->BitmapWidth; rc.bottom = h;
|
||||
FillRect(hdcg, &rc, inst->hBrushBack);
|
||||
|
||||
SelectObject(hdcg, inst->hPenGrid);
|
||||
|
||||
for (p = inst->GridCellHeight - 1; p < inst->BitmapHeight; p += inst->GridCellHeight)
|
||||
{
|
||||
MoveToEx(hdcg, 0, p, NULL);
|
||||
LineTo(hdcg, inst->BitmapWidth, p);
|
||||
}
|
||||
|
||||
for (p = inst->BitmapWidth - inst->CurrShift - 1; p > 0; p -= inst->GridCellWidth)
|
||||
{
|
||||
MoveToEx(hdcg, p, 0, NULL);
|
||||
LineTo(hdcg, p, inst->BitmapHeight);
|
||||
}
|
||||
|
||||
coef = inst->ftPixelsPerPercent;
|
||||
|
||||
if (inst->DrawSecondaryPlot)
|
||||
{
|
||||
SelectObject(hdcg, inst->hPen1);
|
||||
t = inst->PointBuffer + inst->NumberOfPoints;
|
||||
x = inst->BitmapWidth - 1;
|
||||
j = inst->CurrIndex;
|
||||
y = h - *(t + j) * coef;
|
||||
MoveToEx(hdcg, x, y, NULL);
|
||||
for (i = 0; i < inst->NumberOfPoints; i++)
|
||||
{
|
||||
this->m_bitmapGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapOldGrid);
|
||||
DeleteObject(this->m_bitmapGrid);
|
||||
this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
|
||||
SelectObject(this->m_dcGrid, this->m_bitmapGrid);
|
||||
j = (j ? j : inst->NumberOfPoints) - 1;
|
||||
y = h - *(t + j) * coef;
|
||||
x -= PLOT_SHIFT;
|
||||
LineTo(hdcg, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
SetBkColor(this->m_dcGrid, this->m_crBackColor);
|
||||
SelectObject(hdcg, inst->hPen0);
|
||||
t = inst->PointBuffer;
|
||||
x = inst->BitmapWidth - 1;
|
||||
j = inst->CurrIndex;
|
||||
y = h - *(t + j) * coef;
|
||||
MoveToEx(hdcg, x, y, NULL);
|
||||
|
||||
FillRect(this->m_dcGrid, &this->m_rectClient, this->m_brushBack);
|
||||
|
||||
nCharacters = abs((int)log10(fabs(this->m_dUpperLimit)));
|
||||
nCharacters = max(nCharacters, abs((int)log10(fabs(this->m_dLowerLimit))));
|
||||
nCharacters = nCharacters + 4 + this->m_nYDecimals;
|
||||
|
||||
this->m_rectPlot.left = this->m_rectClient.left;
|
||||
this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;
|
||||
|
||||
oldPen = (HPEN)SelectObject(this->m_dcGrid, solidPen);
|
||||
MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top, NULL);
|
||||
LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.top);
|
||||
LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.bottom+1);
|
||||
LineTo(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.bottom+1);
|
||||
|
||||
for (i = this->m_rectPlot.top; i < this->m_rectPlot.bottom; i += 12)
|
||||
for (i = 0; i < inst->NumberOfPoints; i++)
|
||||
{
|
||||
MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top + i, NULL);
|
||||
LineTo(this->m_dcGrid, this->m_rectPlot.right, this->m_rectPlot.top + i);
|
||||
}
|
||||
|
||||
for (i = this->m_rectPlot.left; i < this->m_rectPlot.right; i += 12)
|
||||
{
|
||||
MoveToEx(this->m_dcGrid, this->m_rectPlot.left + i, this->m_rectPlot.bottom, NULL);
|
||||
LineTo(this->m_dcGrid, this->m_rectPlot.left + i, this->m_rectPlot.top);
|
||||
}
|
||||
|
||||
SelectObject(this->m_dcGrid, oldPen);
|
||||
DeleteObject(solidPen);
|
||||
|
||||
if (this->m_dcPlot == NULL)
|
||||
{
|
||||
this->m_dcPlot = CreateCompatibleDC(dc);
|
||||
this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
|
||||
this->m_bitmapOldPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapPlot);
|
||||
}
|
||||
else if(bResize)
|
||||
{
|
||||
if(this->m_bitmapPlot != NULL)
|
||||
{
|
||||
this->m_bitmapPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapOldPlot);
|
||||
DeleteObject(this->m_bitmapPlot);
|
||||
this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
|
||||
SelectObject(this->m_dcPlot, this->m_bitmapPlot);
|
||||
}
|
||||
}
|
||||
|
||||
SetBkColor(this->m_dcPlot, this->m_crBackColor);
|
||||
FillRect(this->m_dcPlot, &this->m_rectClient, this->m_brushBack);
|
||||
|
||||
InvalidateRect(this->m_hParentWnd, &this->m_rectClient, TRUE);
|
||||
ReleaseDC(this->m_hParentWnd, dc);
|
||||
}
|
||||
|
||||
double GraphCtrl_AppendPoint(TGraphCtrl* this,
|
||||
double dNewPoint0, double dNewPoint1,
|
||||
double dNewPoint2, double dNewPoint3)
|
||||
{
|
||||
double dPrevious;
|
||||
|
||||
dPrevious = this->m_dCurrentPosition[0];
|
||||
this->m_dCurrentPosition[0] = dNewPoint0;
|
||||
this->m_dCurrentPosition[1] = dNewPoint1;
|
||||
this->m_dCurrentPosition[2] = dNewPoint2;
|
||||
this->m_dCurrentPosition[3] = dNewPoint3;
|
||||
GraphCtrl_DrawPoint(this);
|
||||
return dPrevious;
|
||||
}
|
||||
|
||||
void GraphCtrl_Paint(TGraphCtrl* this, HWND hWnd, HDC dc)
|
||||
{
|
||||
HDC memDC;
|
||||
HBITMAP memBitmap;
|
||||
HBITMAP oldBitmap;
|
||||
|
||||
memDC = CreateCompatibleDC(dc);
|
||||
memBitmap = (HBITMAP)CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight);
|
||||
oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap);
|
||||
|
||||
if (memDC != NULL)
|
||||
{
|
||||
BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcGrid, 0, 0, SRCCOPY);
|
||||
BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcPlot, 0, 0, SRCPAINT);
|
||||
BitBlt(dc, 0, 0, this->m_nClientWidth, this->m_nClientHeight, memDC, 0, 0, SRCCOPY);
|
||||
}
|
||||
SelectObject(memDC, oldBitmap);
|
||||
DeleteObject(memBitmap);
|
||||
DeleteDC(memDC);
|
||||
}
|
||||
|
||||
void GraphCtrl_DrawPoint(TGraphCtrl* this)
|
||||
{
|
||||
int currX, prevX, currY, prevY;
|
||||
HPEN oldPen;
|
||||
RECT rectCleanUp;
|
||||
int i;
|
||||
|
||||
if (this->m_dcPlot != NULL)
|
||||
{
|
||||
BitBlt(this->m_dcPlot, this->m_rectPlot.left, this->m_rectPlot.top+1,
|
||||
this->m_nPlotWidth, this->m_nPlotHeight, this->m_dcPlot,
|
||||
this->m_rectPlot.left+this->m_nShiftPixels, this->m_rectPlot.top+1,
|
||||
SRCCOPY);
|
||||
|
||||
rectCleanUp = this->m_rectPlot;
|
||||
rectCleanUp.left = rectCleanUp.right - this->m_nShiftPixels;
|
||||
|
||||
FillRect(this->m_dcPlot, &rectCleanUp, this->m_brushBack);
|
||||
|
||||
for (i = 0; i < MAX_PLOTS; i++)
|
||||
{
|
||||
oldPen = (HPEN)SelectObject(this->m_dcPlot, this->m_penPlot[i]);
|
||||
|
||||
prevX = this->m_rectPlot.right-this->m_nPlotShiftPixels;
|
||||
prevY = this->m_rectPlot.bottom -
|
||||
(long)((this->m_dPreviousPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor);
|
||||
MoveToEx(this->m_dcPlot, prevX, prevY, NULL);
|
||||
|
||||
currX = this->m_rectPlot.right-this->m_nHalfShiftPixels;
|
||||
currY = this->m_rectPlot.bottom -
|
||||
(long)((this->m_dCurrentPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor);
|
||||
LineTo(this->m_dcPlot, currX, currY);
|
||||
|
||||
SelectObject(this->m_dcPlot, oldPen);
|
||||
|
||||
if ((prevY <= this->m_rectPlot.top) || (currY <= this->m_rectPlot.top))
|
||||
{
|
||||
RECT rc;
|
||||
rc.bottom = this->m_rectPlot.top+1;
|
||||
rc.left = prevX;
|
||||
rc.right = currX+1;
|
||||
rc.top = this->m_rectClient.top;
|
||||
FillRect(this->m_dcPlot, &rc, this->m_brushBack);
|
||||
}
|
||||
if ((prevY >= this->m_rectPlot.bottom) || (currY >= this->m_rectPlot.bottom))
|
||||
{
|
||||
RECT rc;
|
||||
rc.bottom = this->m_rectClient.bottom+1;
|
||||
rc.left = prevX;
|
||||
rc.right = currX+1;
|
||||
rc.top = this->m_rectPlot.bottom+1;
|
||||
FillRect(this->m_dcPlot, &rc, this->m_brushBack);
|
||||
}
|
||||
|
||||
this->m_dPreviousPosition[i] = this->m_dCurrentPosition[i];
|
||||
}
|
||||
j = (j ? j : inst->NumberOfPoints) - 1;
|
||||
y = h - *(t + j) * coef;
|
||||
x -= PLOT_SHIFT;
|
||||
LineTo(hdcg, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphCtrl_Resize(TGraphCtrl* this)
|
||||
inline void GraphCtrl_RedrawOnHeightChange(PTGraphCtrl inst, INT nh)
|
||||
{
|
||||
GetClientRect(this->m_hWnd, &this->m_rectClient);
|
||||
HDC hdc;
|
||||
HBITMAP hbmOld;
|
||||
|
||||
this->m_nClientHeight = this->m_rectClient.bottom - this->m_rectClient.top;
|
||||
this->m_nClientWidth = this->m_rectClient.right - this->m_rectClient.left;
|
||||
inst->BitmapHeight = nh;
|
||||
inst->ftPixelsPerPercent = (FLOAT)nh / 100.00f;
|
||||
|
||||
this->m_rectPlot.left = 0;
|
||||
this->m_rectPlot.top = -1;
|
||||
this->m_rectPlot.right = this->m_rectClient.right;
|
||||
this->m_rectPlot.bottom = this->m_rectClient.bottom;
|
||||
hdc = GetDC(inst->hParentWnd);
|
||||
hbmOld = inst->hbmGraph;
|
||||
inst->hbmGraph = CreateCompatibleBitmap(hdc, inst->BitmapWidth, nh);
|
||||
SelectObject(inst->hdcGraph, inst->hbmGraph);
|
||||
DeleteObject(hbmOld);
|
||||
ReleaseDC(inst->hParentWnd, hdc);
|
||||
|
||||
this->m_nPlotHeight = this->m_rectPlot.bottom - this->m_rectPlot.top;
|
||||
this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;
|
||||
|
||||
this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange;
|
||||
GraphCtrl_RedrawBitmap(inst, nh);
|
||||
}
|
||||
|
||||
extern TGraphCtrl PerformancePageCpuUsageHistoryGraph;
|
||||
|
@ -321,6 +262,7 @@ extern HWND hPerformancePageMemUsageHistoryGraph;
|
|||
INT_PTR CALLBACK
|
||||
GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
PTGraphCtrl graph;
|
||||
RECT rcClient;
|
||||
HDC hdc;
|
||||
PAINTSTRUCT ps;
|
||||
|
@ -371,24 +313,32 @@ GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
case WM_NCCALCSIZE:
|
||||
return 0;
|
||||
case WM_SIZE:
|
||||
if (hWnd == hPerformancePageMemUsageHistoryGraph)
|
||||
{
|
||||
GraphCtrl_Resize(&PerformancePageMemUsageHistoryGraph);
|
||||
GraphCtrl_InvalidateCtrl(&PerformancePageMemUsageHistoryGraph, TRUE);
|
||||
}
|
||||
if (hWnd == hPerformancePageCpuUsageHistoryGraph)
|
||||
{
|
||||
GraphCtrl_Resize(&PerformancePageCpuUsageHistoryGraph);
|
||||
GraphCtrl_InvalidateCtrl(&PerformancePageCpuUsageHistoryGraph, TRUE);
|
||||
}
|
||||
graph = &PerformancePageCpuUsageHistoryGraph;
|
||||
else if (hWnd == hPerformancePageMemUsageHistoryGraph)
|
||||
graph = &PerformancePageMemUsageHistoryGraph;
|
||||
else
|
||||
return 0;
|
||||
if (HIWORD(lParam) != graph->BitmapHeight)
|
||||
GraphCtrl_RedrawOnHeightChange(graph, HIWORD(lParam));
|
||||
InvalidateRect(hWnd, NULL, FALSE);
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
if (hWnd == hPerformancePageCpuUsageHistoryGraph)
|
||||
graph = &PerformancePageCpuUsageHistoryGraph;
|
||||
else if (hWnd == hPerformancePageMemUsageHistoryGraph)
|
||||
graph = &PerformancePageMemUsageHistoryGraph;
|
||||
else
|
||||
return 0;
|
||||
hdc = BeginPaint(hWnd, &ps);
|
||||
GetClientRect(hWnd, &rcClient);
|
||||
if (hWnd == hPerformancePageMemUsageHistoryGraph)
|
||||
GraphCtrl_Paint(&PerformancePageMemUsageHistoryGraph, hWnd, hdc);
|
||||
if (hWnd == hPerformancePageCpuUsageHistoryGraph)
|
||||
GraphCtrl_Paint(&PerformancePageCpuUsageHistoryGraph, hWnd, hdc);
|
||||
BitBlt(hdc, 0, 0,
|
||||
rcClient.right,
|
||||
rcClient.bottom,
|
||||
graph->hdcGraph,
|
||||
graph->BitmapWidth - rcClient.right,
|
||||
0,
|
||||
SRCCOPY);
|
||||
EndPaint(hWnd, &ps);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue