📄 infoform3.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "InfoForm3.h"
#include "MainForm1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TInfoForm *InfoForm;
//---------------------------------------------------------------------------
__fastcall TInfoForm::TInfoForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
/*
在InfoForm还没有显示之前进行一些操作,就需要重载Loaded()函数。
具体做法是:
首先,调用基类的Loaded()函数,以保证基类的动作被继承。然后,
设置Form的一些属性,SetBounds()设置窗体的边框大小。
*/
void __fastcall TInfoForm::Loaded()
{
TForm::Loaded();
Visible = false;
Position = poDefault;
BorderIcons = TBorderIcons();
BorderStyle = bsNone;
Color=clMenu;
HandleNeeded();
int X = MainForm->Width/2;
int Y = 0;
int H =MainForm->Height ;
int W = MainForm->Width/2;
SetBounds(X,Y,W,H);
}
//---------------------------------------------------------------------------
/*
当VCL要构造元件的窗口类时,就会调用CreateParams()函数。
CreateParams()函数声明如下:
virtual void __fastcall CreateParams(TCreateParams& Params);
唯一的参数是一个 TCreateParams结构。TCreateParams声明如下:
struct TCreateParams
{
char *Caption;
int Style;
int ExStyle;
int X;
int Y;
int Width;
int Height;
HWND WndParent;
void *Param;
tagWNDCLASSA WindowClass();
char WinClassName[64];
};
大多数情况下需要重载CreateParams()函数,以便改变元件的窗口风格。
具体做法是:
首先,调用基类的CreateParams()函数,以便继承默认的行为。然后,
在原有的窗口风格基础上加上WS_CHILD | WS_CLIPSIBLINGS。
*/
void __fastcall TInfoForm::CreateParams(TCreateParams& Params)
{
TForm::CreateParams(Params);
TForm* owner = dynamic_cast<TForm*>(Owner);
Params.WndParent = owner->Handle;
Params.Style = WS_CHILD | WS_CLIPSIBLINGS;
Params.X = 0;
Params.Y = 0;
}
//---------------------------------------------------------------------------
/*
公有自定义函数
初始化静态文本框中的文本。 AnsiString类的文本赋值采用等号。
*/
void TInfoForm::Reset()
{
Timer->Caption="时间:";
Color1->Caption="红方:";
RedInfo->Caption="红方:";
BlackInfo->Caption="黑方:";
Level2->Caption="级别:";
Value->Caption="值:";
Nodes->Caption="节点:";
Seconds->Caption="步/秒:";
Depth->Caption="深度:";
BestPath->Caption="";
Message->Caption="";
}
//---------------------------------------------------------------------------
/*
设置信息窗体背景
采用文件方式载入位图。
如果位图没有保存在资源文件(.res)内,C++ Builder不能把从文件装入的位图
连接入最后的可执行文件。因此,必须确保在c:\BcbChess下有必需的位图文件。
很明显,使用VCL函数比原始的API函数要方便得多。
使用后,应将Canvas->Brush->Bitmap这个特性设为NULL,以释放位图。
如果不删除位图,将导致程序内存不足。
*/
void TInfoForm::SetInfoWindowBk()
{
Graphics::TBitmap *BLKBrushBmp = new Graphics::TBitmap();
BLKBrushBmp->LoadFromFile("BKBrush.bmp");
//BLKBrushBmp->LoadFromFile("c:\\BcbChess\\BKBrush.bmp");
InfoForm->Canvas->Brush->Bitmap=BLKBrushBmp;
InfoForm->Canvas->FillRect(InfoForm->GetClientRect());
InfoForm->Canvas->Brush->Bitmap=NULL;
delete BLKBrushBmp;
}
//---------------------------------------------------------------------------
/*
公有自定义函数
AnsiString类的文本赋值采用等号,非常方便。
*/
void TInfoForm::IterReset()
{
Color1->Caption="红方";
Value->Caption="";
Nodes->Caption="";
Seconds->Caption="";
BestPath->Caption="";
}
//---------------------------------------------------------------------------
/*
信息窗体重画函数。其背景用位图填充。注意,由于位图采用文件方式载入,
不能链接入可执行文件中,请确保c:\BcbChess下有需要的位图文件。
*/
void __fastcall TInfoForm::InfoPaint(TObject *Sender)
{
SetInfoWindowBk();
HDC PaintDC=GetDC(InfoForm->Handle);
DrawInfoFrame(PaintDC);
ReleaseDC(InfoForm->Handle, PaintDC);
}
//---------------------------------------------------------------------------
/*
公有自定义函数
绘制信息窗体凸起来的三维边框
*/
void TInfoForm::DrawInfoFrame(HDC hDC)
{
DrawFrame(hDC, InfoRect);
}
//---------------------------------------------------------------------------
/*
信息窗体显现事件处理函数
窗体显现时获取信息窗体的矩形框大小
*/
void __fastcall TInfoForm::FormShow(TObject *Sender)
{
InfoRect.right = MainForm->ClientWidth/2;
InfoRect.bottom = MainForm->ClientHeight;
InfoRect.left = 0 ;
InfoRect.top = 0 ;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -