?? form1.h
字號:
#pragma once
#include "stdafx.h"
#define LINE_LEN 60
#define MAX_RECT_HEIGHT 100
#define MIN_RECT_WIDTH 30
#define MIN_RECT_HEIGHT 30
#define MAX_RECT_WIDTH 100
using namespace System::Drawing;
namespace memadim {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此類的名稱,則需要更改
/// 與此類所依賴的所有 .resx 文件關聯的托管資源編譯器工具的
/// “資源文件名”屬性。否則,
/// 設計器將不能與此窗體的關聯
/// 本地化資源正確交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
_myGraphics = this->pictureBox1->CreateGraphics();
}
protected:
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Button^ Init_Memory;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::GroupBox^ groupBox1;
protected:
#pragma region 許暉冬自定的變量
public:
char *G_TestMem;
private:
int G_FontLineSpace;
int G_TestMemLen;
char **Test_sp; //用于保存分配出去的測試指針
int Test_sp_num; //已經分配的指數數目
int Test_Alloc_Mem; //已經分配出去的內存大小
int *Test_Space; //保存相應的分配出去的大小
int G_Width;
int G_Height;
int Org_X;
int Org_Y;
array<Rectangle, 1>^ _BusyItem; //忙鏈表中的表項數組
array<Point, 2>^ _BusyItemPoint; //忙鏈表中的表項的4個關鍵點next,prev, next, prev
array<String^, 2>^ _BusyItemInfo; //忙鏈表中的表項的關鍵信息
Pen^ _BusyPen; //忙鏈表使用Pen
SolidBrush^ _BusyBrush; //忙鏈表使用Bursh
System::Drawing::Font^ _BusyFont; //忙鏈表使用Font
int _BusyItemSum; //忙鏈表的總共塊數
array<Rectangle, 1>^ _IdleItem; //空鏈表中的表項數組
array<Point, 2>^ _IdleItemPoint; //空鏈表中的表項的4個關鍵點next,prev, next, prev
array<String^, 2>^ _IdleItemInfo; //空鏈表中的表項的關鍵信息
Pen^ _IdlePen; //空鏈表使用Pen
SolidBrush^ _IdleBrush; //空鏈表使用Bursh
int _IdleItemSum; //空鏈表的總共塊數
array<Rectangle, 1>^ _ErrItem; //鏈表中出錯的表項數組
array<Point, 2>^ _ErrItemPoint; //鏈表中出錯的表項的4個關鍵點next,prev, next, prev
array<String^, 2>^ _ErrItemInfo; //鏈表中出錯的表項的關鍵信息
Pen^ _ErrPen; //鏈表出錯表項使用Pen
SolidBrush^ _ErrBrush; //鏈表出錯表項使用Bursh
int _ErrCount; //出錯的個數
array<Rectangle, 1>^ _PhyItem; //物理鏈表中的表項數組
array<Point, 2>^ _PhyItemPoint; //物理鏈表中的表項的4個關鍵點next,prev, next, prev
array<String^, 2>^ _PhyItemInfo; //物理鏈表中的表項的關鍵信息
Pen^ _PhyPen; //物理鏈表中項使用Pen
SolidBrush^ _PhyBrush; //物理鏈表中項使用Bursh
int _PhyCount; //物理的個數
Graphics^ _myGraphics; //要使用的畫布
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::CheckBox^ checkBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::CheckBox^ checkBox2;
private: System::Windows::Forms::CheckBox^ checkBox3;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::CheckBox^ checkBox4;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox1;
#pragma endregion
/// <summary>
/// 畫出Rect數組。
/// _DestRectArray 要畫出的矩形數組的數目
/// _DestRectKeyPoint 矩形所對應的關鍵點的坐標
/// _DrawPen 要使用的畫筆
/// _DrawBrush 填矩形框用的畫刷
/// _RectNum 矩形的數目
/// </summary>
private: System::Void Sub_DrawList(array<Rectangle, 1>^ _DestRectArray, array<Point, 2>^ _DestRectKeyPoint, Pen^ _DrawPen, SolidBrush^ _DrawBrush, array<String^, 2>^ _DrawInfo, System::Drawing::Font^ _DrawFont, int _RectNum)
{
int i;
_myGraphics->FillRectangles(_DrawBrush, _DestRectArray);
for(i = 1; i <= _RectNum - 1; i++)
{
if(_DestRectKeyPoint[i - 1, 0].Y == _DestRectKeyPoint[i, 0].Y)
{
_myGraphics->DrawLine(_DrawPen, _DestRectKeyPoint[i - 1, 2], _DestRectKeyPoint[i, 0]);
_myGraphics->DrawLine(_DrawPen, _DestRectKeyPoint[i, 1], _DestRectKeyPoint[i - 1, 3]);
}
else
{
_myGraphics->DrawLine(_DrawPen, _DestRectKeyPoint[i - 1, 2].X, _DestRectKeyPoint[i - 1, 2].Y, G_Width, _DestRectKeyPoint[i - 1, 2].Y);
_myGraphics->DrawLine(_DrawPen, G_Width, _DestRectKeyPoint[i - 1, 3].Y, _DestRectKeyPoint[i - 1, 3].X, _DestRectKeyPoint[i - 1, 3].Y);
}
}
for(i = 0; i < _RectNum; i++)
{
_myGraphics->DrawString(_DrawInfo[i, 0], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height);
_myGraphics->DrawString(_DrawInfo[i, 1], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 15);
//_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 7], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 6], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 60);
}
}
///<summary>
///_DestRectArray 要計算的目標Rect
///_DestRectKeyPoint 要計算的目標Point
///Start_X 開始的X坐標
///Start_Y 開始的Y坐標
///Num Rect的數目
///</summary>
private:System::Void Sub_ComputerRectAndPoint(array<Rectangle, 1>^ _DestRectArray, array<Point, 2>^ _DestRectKeyPoint, int Start_X, int Start_Y, int Num)
{
int i;
int j;
int rect_width, rect_height;
int x;
i = Num;
j = G_Width - LINE_LEN * (i - 1);
if((j / i) > MAX_RECT_WIDTH)
{
rect_width = MAX_RECT_WIDTH;
}
else if((j / i) < MIN_RECT_WIDTH)
{
rect_width = MIN_RECT_WIDTH;
}
else
{
rect_width = j / i;
}
rect_height = MIN_RECT_HEIGHT;
_DestRectArray[0].X = Org_X;
_DestRectArray[0].Y = Org_Y;
_DestRectArray[0].Width = rect_width;
_DestRectArray[0].Height = rect_height;
//可能要出現換行
if((rect_width * i) > (G_Width - LINE_LEN * (i - 1)))
{
//要換行
for(j = 1; j < i; j++)
{
if((_DestRectArray[j - 1].X + rect_width + LINE_LEN) > (G_Width - LINE_LEN))
{
_DestRectArray[j].X = Org_X;
_DestRectArray[j].Y = _DestRectArray[j - 1].Y + _DestRectArray[j - 1].Height + G_FontLineSpace * 5 + 5; //加上5的分格
}
else
{
_DestRectArray[j].X = _DestRectArray[j - 1].X + rect_width + LINE_LEN;
_DestRectArray[j].Y = _DestRectArray[j - 1].Y;
}
_DestRectArray[j].Width = rect_width;
_DestRectArray[j].Height = rect_height;
}
}
else
{
//要把矩形框平均地分布在平面內
j = G_Width - i * rect_width;
if(i == 1)
x = j;
else
x = j / (i - 1);
for(j = 1; j < i; j++)
{
_DestRectArray[j].X = _DestRectArray[j - 1].X + rect_width + x;
_DestRectArray[j].Y = _DestRectArray[j - 1].Y;
_DestRectArray[j].Width = rect_width;
_DestRectArray[j].Height = rect_height;
}
}
for(j = 0; j < i; j++)
{
_DestRectKeyPoint[j,0].X = _DestRectArray[j].X;
_DestRectKeyPoint[j,0].Y = _DestRectArray[j].Y + 5;
_DestRectKeyPoint[j,1].X = _DestRectArray[j].X;
_DestRectKeyPoint[j,1].Y = _DestRectArray[j].Height + _DestRectArray[j].Y - 5;
_DestRectKeyPoint[j,2].X = _DestRectArray[j].X + _DestRectArray[j].Width;
_DestRectKeyPoint[j,2].Y = _DestRectArray[j].Y + 5;
_DestRectKeyPoint[j,3].X = _DestRectArray[j].X + _DestRectArray[j].Width;
_DestRectKeyPoint[j,3].Y = _DestRectArray[j].Height + _DestRectArray[j].Y - 5;
}
}
///<summary>
///畫出物理內存塊
/// _DestRectArray 要畫出的矩形數組的數目
/// _DestRectKeyPoint 矩形所對應的關鍵點的坐標
/// _DrawBusyPen 用于畫忙的Pen
/// _DrawBusyBrush 用于畫忙的Brush
/// _DrawIdlePen 用于畫空的Pen
/// _DrawIdleBrush 用于畫空的Brush
/// _DrawInfo 要顯示的信息
/// _DrawFont 用于顯示信息的Font
/// _RectNum 矩形的數目
///</summary>
private:virtual System::Void Sub_DrawPhyListItem(array<Rectangle, 1>^ _DestRectArray, array<Point, 2>^ _DestRectKeyPoint, Pen^ _DrawBusyPen, SolidBrush^ _DrawBusyBrush, Pen^ _DrawIdlePen, SolidBrush^ _DrawIdleBrush, array<String^, 2>^ _DrawInfo, System::Drawing::Font^ _DrawFont, int _RectNum)
{
int i;
UInt32 x1, AllSpace;
array<Char>^ xu_str = gcnew array<Char>(256);
String^ temp_str;
AllSpace = 0;
for(i = 0; i < _RectNum; i++)
{
xu_str->Clear(xu_str, 0, xu_str->GetLength(0));
_DrawInfo[i, 3]->CopyTo(5, xu_str, 0, _DrawInfo[i, 3]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::UInt32::Parse(temp_str, System::Globalization::NumberStyles::Integer);
AllSpace += x1;
xu_str->Clear(xu_str, 0, xu_str->GetLength(0));
_DrawInfo[i, 7]->CopyTo(5, xu_str, 0, _DrawInfo[i, 7]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::UInt32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
if(x1 == 0xaa)
{
_myGraphics->FillRectangle(_DrawBusyBrush, _DestRectArray[i]);
_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height);
_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 15);
//_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 6], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 60);
}
else
{
_myGraphics->FillRectangle(_DrawIdleBrush, _DestRectArray[i]);
_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height);
_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 15);
//_myGraphics->DrawString(_DrawInfo[i, 2], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 3], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 30);
_myGraphics->DrawString(_DrawInfo[i, 6], _DrawFont, _DrawIdleBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 4], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 45);
//_myGraphics->DrawString(_DrawInfo[i, 5], _DrawFont, _DrawBusyBrush, _DestRectArray[i].X, _DestRectArray[i].Y + _DestRectArray[i].Height + 60);
}
if((i != 0) )//&& (i != (_RectNum - 1)))
{
if(_DestRectKeyPoint[i - 1, 0].Y == _DestRectKeyPoint[i, 0].Y)
{
if(x1 == 0xaa)
{
_myGraphics->DrawLine(_DrawBusyPen, _DestRectKeyPoint[i - 1, 2], _DestRectKeyPoint[i, 0]);
_myGraphics->DrawLine(_DrawBusyPen, _DestRectKeyPoint[i, 1], _DestRectKeyPoint[i - 1, 3]);
}
else
{
_myGraphics->DrawLine(_DrawIdlePen, _DestRectKeyPoint[i - 1, 2], _DestRectKeyPoint[i, 0]);
_myGraphics->DrawLine(_DrawIdlePen, _DestRectKeyPoint[i, 1], _DestRectKeyPoint[i - 1, 3]);
}
}
else
{
if(x1 == 0xaa)
{
_myGraphics->DrawLine(_DrawBusyPen, _DestRectKeyPoint[i - 1, 2].X, _DestRectKeyPoint[i - 1, 2].Y, G_Width, _DestRectKeyPoint[i - 1, 2].Y);
_myGraphics->DrawLine(_DrawBusyPen, G_Width, _DestRectKeyPoint[i - 1, 3].Y, _DestRectKeyPoint[i - 1, 3].X, _DestRectKeyPoint[i - 1, 3].Y);
}
else
{
_myGraphics->DrawLine(_DrawIdlePen, _DestRectKeyPoint[i - 1, 2].X, _DestRectKeyPoint[i - 1, 2].Y, G_Width, _DestRectKeyPoint[i - 1, 2].Y);
_myGraphics->DrawLine(_DrawIdlePen, G_Width, _DestRectKeyPoint[i - 1, 3].Y, _DestRectKeyPoint[i - 1, 3].X, _DestRectKeyPoint[i - 1, 3].Y);
}
}
}
}
_myGraphics->DrawString("總共內存大小:" + AllSpace.ToString(), _DrawFont, _DrawBusyBrush, 50, _DestRectArray[_RectNum - 1].Y + _DestRectArray[_RectNum - 1].Height + 100);
}
///<summary>
///_AnalyseInfo 要分析的鏈表的相關信息
///_Num 表項的個數
///_AnalyseErr 出錯的矩形框
///_AnalyseErrInfo 出錯的表項的信息
///_AnalyseItemPoint 出錯表項的關鍵點
///</summary>
private:System::UInt32 Fun_AnalyseList(array<String^, 2>^ _AnalyseInfo, int Num, array<Rectangle, 1>^ _AnalyseErr, array<String^, 2>^ _AnalyseErrInfo, array<Point, 2>^ _AnalyseItemPoint)
{
int count;
unsigned int x1, x2, j;
int *errarray;
count = 0;
array<Char>^ xu_str = gcnew array<Char>(256);
String^ temp_str;
errarray = new int [Num];
for(j = 1; j < Num; j++)
{
_AnalyseInfo[j - 1, 0]->CopyTo(5, xu_str, 0, _AnalyseInfo[j - 1, 0]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
_AnalyseInfo[j, 6]->CopyTo(5, xu_str, 0, _AnalyseInfo[j, 6]->Length - 5);
temp_str = gcnew String(xu_str);
x2 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
if(x1 != x2)
{
errarray[j] = 1;
count += 1;
}
else
{
_AnalyseInfo[j, 1]->CopyTo(5, xu_str, 0, _AnalyseInfo[j, 1]->Length - 5);
temp_str = gcnew String(xu_str);
x1 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
_AnalyseInfo[j - 1, 6]->CopyTo(5, xu_str, 0, _AnalyseInfo[j - 1, 6]->Length - 5);
temp_str = gcnew String(xu_str);
x2 = System::Int32::Parse(temp_str, System::Globalization::NumberStyles::AllowHexSpecifier);
if(x1 != x2)
{
errarray[j] = 1;
count += 1;
}
else
{
errarray[j] = 0;
}
}
}
if(count == 0)
{
return count;
}
_AnalyseErr = gcnew array<Rectangle, 1>(count);
_AnalyseErrInfo = gcnew array<String^, 2>(count, 7);
_AnalyseItemPoint = gcnew array<Point, 2>(count, 4);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -