/*****************************************************************************
创建时间 :2022年10月01日
文件名 :log_.h
功能 :模拟 Android Studo,Eclipse 的 LogCat
作者 :李锋
微信号 :lifengwx2005
Email :[email protected]
联系电话 :1382877886(移动),18924615309(电信)
----------------------最后一次修改时间:2022年10月08日
*******************************************************************************/
#ifndef _LOG__H_
#define _LOG__H_
#include "X:\Work\Share\CCode\CPlatform\list_.h"
_LF_BEGIN_
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
ref class log_
{
public:
static RichTextBox^ rtb = null;
static String^ sMessage = L"";
static String^ sTag = L"";
delegate void InvokeCallback();
public:
void setText();
log_();
~log_();
void Invoke();
static void d(const _string& sMessage, const _string& sTag);
//static string_ findTag(const char_* pwszFindMessage, const char_* pwszFindTag);
//static string_ findTag(const String^ csharpFindMessage, const String^ csharpFindTag);
static String^ findTag(String^ sFindMessage, String^ sFindTag);
};
_LF_END_
#endif //------------------------------------------#ifndef _LOGCAT__H_
#include "log_.h"
#include "..\..\CPlatform\global_c_.h"
_LF_BEGIN_
void log_::setText()
{
/*
/this.Invoke(new MethodInvoker(delegate
m_RichEdit.Invoke(new MethodInvoker(
delegate
{
m_RichEdit.Text = lf.lg.Logcat.FindTag(cb_内容过虑.Text, cb_标题过虑.Text);
}
));
*/
_string s = findTag(sMessage, sTag);
rtb->Text = gcnew String(s.c_str());
}
log_::log_()
{
}
log_::~log_()
{
}
void log_::Invoke()
{
InvokeCallback^ ic = gcnew InvokeCallback(this, &log_::setText);
if (rtb != null)
rtb->Invoke(ic);
}
void log_::d(const _string& sMessage, const _string& sTag)
{
if (gc.slLog.count() > 100000) //10万
{
throw L"错误:日志文件太大了!";
}
_string sInfo(L"", 300);
if (sMessage.length() > 0)
{
sInfo.add(_string::java_valueOf(gc.slLog.count() + 1).intStrFillUp(4));
sInfo.add(L" ");
sInfo.add(DateTime::Now.ToString());
sInfo.add(L"\t\tsTag = (");
sInfo.add(sTag);
sInfo.add(L")\t\tsMessage = (");
sInfo.add(sMessage);
sInfo.add(L")");
}
else
{
sInfo.add(_string::java_valueOf(gc.slLog.count() + 1).intStrFillUp(4));
sInfo.add(L" ");
sInfo.add(DateTime::Now.ToString());
sInfo.add(L"\t\tsTag = (");
sInfo.add(sTag);
sInfo.add(L")\t\tsMessage = (");
sInfo.add(sMessage);
sInfo.add(L")");
}
gc.slLog.add(sInfo);
(gcnew log_())->Invoke();
}
String^ log_::findTag(String^ sFindMessage, String^ sFindTag)
{
/* C#--------------------------------------------------------------代码
string sResult = "";
DListNote_ pNote = _LogcatList.Last;
while (pNote != null)
{
StringList_ sTemp = pNote.Data._Split("\t\t", true);
if(sFindMessage.Trim().Length > 0)
{
if(sTemp.Count == 3)
{
if(sTemp[2].ToLower().IndexOf(sFindMessage.ToLower().Trim()) != -1)
{
if(sFindTag.Trim().Length > 0)
{
if (sTemp[1].ToLower().IndexOf(sFindTag.ToLower().Trim()) != -1)
{
sResult += pNote.Data;
sResult += "\n";
}
}
else
{
sResult += pNote.Data;
sResult += "\n";
}
}
}
else
{
}
}
else
{
if (sFindTag.Trim().Length > 0)
{
if (sTemp[1].ToLower().IndexOf(sFindTag.ToLower().Trim()) != -1)
{
sResult += pNote.Data;
sResult += "\n";
}
}
else
{
sResult += pNote.Data;
sResult += "\n";
}
}
pNote = pNote.Prev;
}
return sResult;
*/
_string sResult(L"", 5000);
dnote_<_string>* pNote = gc.slLog.Last();
_string sFmTrl = sFindMessage->Trim()->ToLower();//sFindMessage.csharp_Trim().csharp_ToLower();
_string sFtTrl = sFindTag->Trim()->ToLower();//sFindTag.csharp_Trim().csharp_ToLower();
while (pNote != null)
{
stringList_ sl(pNote->Data.c_str(), L"\t\t", true);
if (sFmTrl.csharp_Length() > 0)
{
if (sl.csharp_Count() == 3)
{
if (sl[2].csharp_ToLower().csharp_IndexOf(sFmTrl) != -1)
{
if (sFtTrl.csharp_Length() > 0)
{
if (sl[1].csharp_ToLower().csharp_IndexOf(sFtTrl) != -1)
{
sResult += pNote->Data;
sResult += L"\n";
}
}else{
sResult += pNote->Data;
sResult += L"\n";
}
}
}else{
}
}else
{
if (sFtTrl.csharp_Length() > 0)
{
if (sl[1].csharp_ToLower().csharp_IndexOf(sFtTrl) != -1)
{
sResult += pNote->Data;
sResult += L"\n";
}
}else{
sResult += pNote->Data;
sResult += L"\n";
}
}
pNote = pNote->Prev;
}
//Windows::Forms::MessageBox::Show(gcnew String(sResult.c_str()));
return gcnew String(sResult.c_str());
}
_LF_END_
窗体设计
代码:
#pragma once
#include "X:\Work\Share\CCode\WindowsPlatform\CLR\gw.h"
using namespace lf;
public delegate void MyDel();
namespace MyOffice {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
/// LogcatForm 摘要
///
public ref class LogcatForm : public System::Windows::Forms::Form
{
public:
LogcatForm(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
log_::rtb = m_RichEdit;
}
protected:
///
/// 清理所有正在使用的资源。
///
~LogcatForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Panel^ panel1;
protected:
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::ComboBox^ cb_内容过虑;
private: System::Windows::Forms::ComboBox^ cb_标题过虑;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::ComboBox^ cb_调试类型;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::ComboBox^ cb_日志文件;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::ContextMenuStrip^ m_contextMenuStrip;
private: System::Windows::Forms::ToolStripMenuItem^ tsmi_清除内容;
private: System::Windows::Forms::RichTextBox^ m_RichEdit;
private: System::ComponentModel::IContainer^ components;
private:
///
/// 必需的设计器变量。
///
#pragma region Windows Form Designer generated code
///
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
///
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->label4 = (gcnew System::Windows::Forms::Label());
this->cb_内容过虑 = (gcnew System::Windows::Forms::ComboBox());
this->cb_标题过虑 = (gcnew System::Windows::Forms::ComboBox());
this->label3 = (gcnew System::Windows::Forms::Label());
this->cb_调试类型 = (gcnew System::Windows::Forms::ComboBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->cb_日志文件 = (gcnew System::Windows::Forms::ComboBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->m_contextMenuStrip = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));
this->tsmi_清除内容 = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->m_RichEdit = (gcnew System::Windows::Forms::RichTextBox());
this->panel1->SuspendLayout();
this->m_contextMenuStrip->SuspendLayout();
this->SuspendLayout();
//
// panel1
//
this->panel1->Controls->Add(this->label4);
this->panel1->Controls->Add(this->cb_内容过虑);
this->panel1->Controls->Add(this->cb_标题过虑);
this->panel1->Controls->Add(this->label3);
this->panel1->Controls->Add(this->cb_调试类型);
this->panel1->Controls->Add(this->label2);
this->panel1->Controls->Add(this->cb_日志文件);
this->panel1->Controls->Add(this->label1);
this->panel1->Dock = System::Windows::Forms::DockStyle::Top;
this->panel1->Location = System::Drawing::Point(0, 0);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(1851, 41);
this->panel1->TabIndex = 2;
//
// label4
//
this->label4->AutoSize = true;
this->label4->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->label4->Location = System::Drawing::Point(780, 9);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(130, 24);
this->label4->TabIndex = 13;
this->label4->Text = L"标题过虑:";
//
// cb_内容过虑
//
this->cb_内容过虑->BackColor = System::Drawing::Color::White;
this->cb_内容过虑->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->cb_内容过虑->ForeColor = System::Drawing::Color::Black;
this->cb_内容过虑->FormattingEnabled = true;
this->cb_内容过虑->Location = System::Drawing::Point(1418, 5);
this->cb_内容过虑->Name = L"cb_内容过虑";
this->cb_内容过虑->Size = System::Drawing::Size(354, 32);
this->cb_内容过虑->TabIndex = 12;
this->cb_内容过虑->SelectedIndexChanged += gcnew System::EventHandler(this, &LogcatForm::cb_内容过虑_SelectedIndexChanged);
this->cb_内容过虑->TextChanged += gcnew System::EventHandler(this, &LogcatForm::cb_内容过虑_TextChanged);
//
// cb_标题过虑
//
this->cb_标题过虑->BackColor = System::Drawing::Color::White;
this->cb_标题过虑->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->cb_标题过虑->ForeColor = System::Drawing::Color::Black;
this->cb_标题过虑->FormattingEnabled = true;
this->cb_标题过虑->Location = System::Drawing::Point(916, 5);
this->cb_标题过虑->Name = L"cb_标题过虑";
this->cb_标题过虑->Size = System::Drawing::Size(354, 32);
this->cb_标题过虑->TabIndex = 11;
this->cb_标题过虑->SelectedIndexChanged += gcnew System::EventHandler(this, &LogcatForm::cb_标题过虑_SelectedIndexChanged);
this->cb_标题过虑->TextChanged += gcnew System::EventHandler(this, &LogcatForm::cb_内容过虑_TextChanged);
//
// label3
//
this->label3->AutoSize = true;
this->label3->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->label3->Location = System::Drawing::Point(1276, 7);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(130, 24);
this->label3->TabIndex = 10;
this->label3->Text = L"内容过虑:";
//
// cb_调试类型
//
this->cb_调试类型->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->cb_调试类型->FormattingEnabled = true;
this->cb_调试类型->Location = System::Drawing::Point(615, 3);
this->cb_调试类型->Name = L"cb_调试类型";
this->cb_调试类型->Size = System::Drawing::Size(154, 32);
this->cb_调试类型->TabIndex = 9;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->label2->Location = System::Drawing::Point(497, 8);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(130, 24);
this->label2->TabIndex = 8;
this->label2->Text = L"调试类型:";
//
// cb_日志文件
//
this->cb_日志文件->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->cb_日志文件->FormattingEnabled = true;
this->cb_日志文件->Location = System::Drawing::Point(144, 3);
this->cb_日志文件->Name = L"cb_日志文件";
this->cb_日志文件->Size = System::Drawing::Size(347, 32);
this->cb_日志文件->TabIndex = 7;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Consolas", 7.875F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->label1->Location = System::Drawing::Point(5, 7);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(130, 24);
this->label1->TabIndex = 6;
this->label1->Text = L"日志文件:";
//
// m_contextMenuStrip
//
this->m_contextMenuStrip->ImageScalingSize = System::Drawing::Size(32, 32);
this->m_contextMenuStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) { this->tsmi_清除内容 });
this->m_contextMenuStrip->Name = L"m_contextMenuStrip";
this->m_contextMenuStrip->Size = System::Drawing::Size(185, 42);
//
// tsmi_清除内容
//
this->tsmi_清除内容->Name = L"tsmi_清除内容";
this->tsmi_清除内容->Size = System::Drawing::Size(184, 38);
this->tsmi_清除内容->Text = L"清除内容";
//
// m_RichEdit
//
this->m_RichEdit->BackColor = System::Drawing::SystemColors::Desktop;
this->m_RichEdit->ContextMenuStrip = this->m_contextMenuStrip;
this->m_RichEdit->Dock = System::Windows::Forms::DockStyle::Fill;
this->m_RichEdit->Font = (gcnew System::Drawing::Font(L"Consolas", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->m_RichEdit->ForeColor = System::Drawing::Color::Lime;
this->m_RichEdit->Location = System::Drawing::Point(0, 41);
this->m_RichEdit->Name = L"m_RichEdit";
this->m_RichEdit->Size = System::Drawing::Size(1851, 455);
this->m_RichEdit->TabIndex = 4;
this->m_RichEdit->Text = L"Line Text";
//
// LogcatForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(12, 24);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(1851, 496);
this->Controls->Add(this->m_RichEdit);
this->Controls->Add(this->panel1);
this->Name = L"LogcatForm";
this->Text = L"LogcatForm";
this->Load += gcnew System::EventHandler(this, &LogcatForm::LogcatForm_Load);
this->panel1->ResumeLayout(false);
this->panel1->PerformLayout();
this->m_contextMenuStrip->ResumeLayout(false);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void LogcatForm_Load(System::Object^ sender, System::EventArgs^ e) {
//System::Object ^System::Windows::Forms::Control::Invoke(System::Delegate ^method)
//System::Delegate::CreateDelegate(System::Type^, System::Object^, System::Reflection::MethodInfo^)
m_RichEdit->Multiline = true;
m_RichEdit->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::Both;
}
public: RichTextBox^ getRichTextBox() { return m_RichEdit; }
private: System::Void cb_内容过虑_TextChanged(System::Object^ sender, System::EventArgs^ e) {
m_RichEdit->Text = log_::findTag(cb_内容过虑->Text,cb_标题过虑->Text);
}
private: System::Void cb_标题过虑_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void cb_内容过虑_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
};
}
窗体设计
MainForm_Load代码:
/*****************************************************************************
创建时间 :2022年10月07日
文件名 :gw.h
功能 :C++ CLR 全局类
作者 :李锋
微信号 :lifengwx2005
Email :[email protected]
联系电话 :1382877886(移动)
----------------------最后一次修改时间:2022年10月07日
*******************************************************************************/
#ifndef _GW_H_
#define _GW_H_
#include "X:\Work\Share\CCode\CPlatform\global_c_.h"
#include "keyBinaryFile_.h"
#include "IniFile_.h"
#include "log_.h"
_LF_BEGIN_
using namespace System;
using namespace System::Drawing;
using namespace System::Windows;
using namespace System::Windows::Forms;
using namespace System::IO;
ref class Theme_
{
public:
Font^ TextFont;
Color ForeColor;
Color BackColor;
///
/// /苹果绿
///
static Color AppleGreen = Color::FromArgb(204, 255, 204);
///
/// 杏仁黄
///
static Color AlmondYellow = Color::FromArgb(250, 249, 222);
///
/// 秋叶褐
///
static Color AutumnLeafBrown = Color::FromArgb(255, 242, 226);
///
/// 胭脂红
///
static Color Carminum = Color::FromArgb(253, 230, 224);
///
/// 青草绿
///
static Color GreenGrass = Color::FromArgb(227, 237, 205);
///
/// 青草绿 2
///
static Color GreenGrass2 = Color::FromArgb(220, 255, 205);
///
/// 海天蓝
///
static Color SeaAndSkyBlue = Color::FromArgb(220, 226, 241);
///
/// 葛巾紫
///
static Color PuerariaPurple = Color::FromArgb(233, 235, 254);
///
/// 极光灰
///
static Color AuroralAsh = Color::FromArgb(234, 234, 239);
Theme_(Color textColor, Color backColor, Font^ f)
{
TextFont = f;
ForeColor = textColor;
BackColor = backColor;
}
Theme_()
{
TextFont = gcnew Font("微软雅黑", 11);
ForeColor = Color::FromKnownColor(KnownColor::Black);
BackColor = Color::FromKnownColor(KnownColor::White);
}
};
static ref class gw
{
private:
static Theme_^ _theme;
public:
///
/// 获取应用程序的全路径
///
///
static property String^ exeFullPathName{
String^ get()
{
return Application::StartupPath + L"\\" + Application::ProductName + L".exe";
}
}
static property String^ dataPath {
String^ get() {
if (gc.dataPath.length() == 0) {
String^ tmpPath;
tmpPath = Path::GetDirectoryName(gw::exeFullPathName) + "\\Data\\";
if (!Directory::Exists(tmpPath))
{
if (Directory::CreateDirectory(tmpPath)->Exists)
{
}
else
{
gc.p(L"创建数据文件夹Data失败!", L"gw::property String^ dataPath");
}
}
gc.dataPath = tmpPath;
return tmpPath;
}
else {
return gc.dataPath;
}
}
}
///
/// 应用程序名
///
static property String^ exeOnlyName
{
String^ get()
{
return Path::GetFileNameWithoutExtension(exeFullPathName);
}
}
static property IniFile_^ iniFile{
IniFile_^ get(){
if (_iniFile == null)
{
_iniFile = gcnew IniFile_(gw::dataPath + gw::exeOnlyName + L".ini");
}
return _iniFile;
}
}
static property Theme_^ theme{
Theme_^ get() {
if (_theme == null)
{
_theme = gcnew Theme_();
}
return _theme;
}
}
public:
gw();
~gw();
static void SetThemeALL(Theme_^ theme);
static void SetThemeForm(Form^ f);
static void SetControlBackColor(Control^ control, Color c);
static void SetMenuStripBackcolor(MenuStrip^ ms, Color c);
static void SetToolStripItemBackcolor(ToolStripItem^ tsi, Color c);
private:
static IniFile_^ _iniFile;
};
_LF_END_
#endif // ! _GW_H_
#include "gw.h"
#include "X:\Work\Share\CCode\CPlatform\global_c_.h"
_LF_BEGIN_
gw::gw()
{
}
gw::~gw()
{
}
///
/// 设置皮肤背景
///
///
/// 创建时间: 2022-10-08 最后一次修改时间:2022-10-08
void gw::SetThemeALL(Theme_^ theme)
{
if (theme != null)
{
_theme = theme;
}
FormCollection^ fc = Application::OpenForms;
for (int i = 0; i < fc->Count; ++i)
{
Form^ f = fc[i];
SetThemeForm(f);
}
}
///
/// 设置单个窗体的皮肤
///
///
/// 创建时间: 2022-10-08 最后一次修改时间:2022-10-08
void gw:: SetThemeForm(Form^ f) {
SetControlBackColor(f, theme->BackColor);
SetMenuStripBackcolor(f->MainMenuStrip, theme->BackColor);
}
///
///
///
///
///
/// 创建时间: 2022-10-08 最后一次修改时间:2022-10-08
void gw::SetControlBackColor(Control^ control, Color c)
{
control->BackColor = c;
for (int i = 0; i < control->Controls->Count; ++i)
{
Control^ con = control->Controls[i];
log_::d(con->Name, L"void gw::SetControlBackColor");
SetControlBackColor(con, c);
}
}
///
///
///
/// 创建时间: 2022-09-08 最后一次修改时间:2022-10-08
void gw::SetMenuStripBackcolor(MenuStrip^ ms, Color c){
if (ms == null) return;
ms->BackColor = c;
for (int i = 0; i < ms->Items->Count; ++i) {
ToolStripItem^ tsi = (ms->Items[i]);
SetToolStripItemBackcolor(tsi,c);
}
}
///
/// 设置ToolStripItem的背景颜色
///
/// 创建时间: 2022-10-08 最后一次修改时间:2022-10-08
void gw::SetToolStripItemBackcolor(ToolStripItem^ tsi, Color c)
{
if (tsi == null) return;
ToolStripMenuItem^ tsmi = (ToolStripMenuItem^)(tsi);
tsmi->BackColor = c;
for (int j = 0; j < tsmi->DropDownItems->Count; ++j) {
ToolStripMenuItem^ tmp = (ToolStripMenuItem^)tsmi->DropDownItems[j];
SetToolStripItemBackcolor(tmp, c);
}
}
_LF_END_