创建一个文本文件扩展名 .rc 加入工程, 内容如下
MYBKGND 是资源名字, 随便起名, MYJPG 是资源类型, 也可以随便起名, 不要与已知类型一致例如 BITMAP
这两个名字在程序里面要用。
MYBKGND MYJPG "PATH/FILENAME.JPG"
在程序里面定义位图:
Form 类的 private 里面
Graphics::TBitmap *BkBmp;
不要忘记这句:
#include
然后在程序里面这样装入内存:
BkBmp = NULL;
try
{
TResourceStream *JpgRes = NULL;
TJPEGImage *JpgImg = NULL;
try
{
JpgRes = new TResourceStream((int)HInstance,"MYBKGND","MYJPG");
JpgImg = new TJPEGImage;
JpgImg->LoadFromStream(JpgRes);
BkBmp = new Graphics::TBitmap;
BkBmp->Assign(JpgImg);
}
__finally
{
if(JpgImg) { delete JpgImg; JpgImg=NULL; }
if(JpgRes) { delete JpgRes; JpgRes=NULL; }
}
}
catch(Exception &e)
{
MessageBox(Handle,e.Message.c_str(),Caption.c_str(),MB_OK|MB_ICONSTOP);
}
这样释放资源:
if(BkBmp)
{
delete BkBmp;
BkBmp = NULL;
}
在 PaintBox 的 OnPaint 事件里面画出你的大位图图像
void __fastcall TForm1::PaintBoxClientPaint(TObject *Sender)
{
TRect rc(0,0,PaintBoxClient->Width,PaintBoxClient->Height);
PaintBoxClient->Canvas->StretchDraw(rc,BkBmp);
DrawEdge(PaintBoxClient->Canvas->Handle,&rc,EDGE_SUNKEN,BF_RECT);
}
--------------------next---------------------
BCB 的帮助里面有啊, 这是帮助里面的程序你可以看看
包括清除所有内容, 添加 item 和 subitem
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TTreeNode *Node1;
TreeView1->Items->Clear(); // remove any existing nodes
// Add a root node
TreeView1->Items->Add(NULL, "RootNode1");
/* Set MyTreeNode to first node in tree view and add a child node to it */
Node1 = TreeView1->Items->Item[0];
TreeView1->Items->AddChild(Node1,"ChildNode1");
// Add another root node
TreeView1->Items->Add(Node1, "RootNode2");
/* Reset Node1 to RootNode2 and add a child node to it */
Node1 = TreeView1->Items->Item[2];
TreeView1->Items->AddChild(Node1,"ChildNode2");
/* Reset Node1 to ChildNode2 and add a child node to it */
Node1 = TreeView1->Items->Item[3];
TreeView1->Items->AddChild(Node1,"ChildNode2a");
/* Add another child to ChildNode2 following ChildNode2a */
TreeView1->Items->AddChild(Node1,"ChildNode2b");
// add another root node
TreeView1->Items->Add(TreeView1->Items->Item[0], "RootTreeNode3");
}
--------------------next---------------------
阅读(1040) | 评论(0) | 转发(0) |