⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cpp

📁 C++ BUILDER精彩编程实例集锦(源码) 第一部分 界面设计 第二部分 程序设置
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Mainform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  iIndex=0;
  iCount=0;
  StrFileName="";
}
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
   this->OpenDialog1->Options.Clear();
   this->OpenDialog1->Filter= "执行文件 (*.exe)|*.exe|动态链接库文件(*.dll)|*.dll|图标文件(*.ico)|*.ico";
   this->OpenDialog1->InitialDir="C:\\";
   if(OpenDialog1->Execute())
   { //获得打开的文件名
     StrFileName=OpenDialog1->FileName;
     //得到此文件所含的图标数目
     iCount=(int)ExtractIcon(HInstance,StrFileName.c_str(),-1);
     //根据index值,得到当前的图标,将索引图标的句柄赋给Image1显示此icon
     Image1->Picture->Icon->Handle=ExtractIcon(HInstance,StrFileName.c_str(),iIndex);
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
  if(++iIndex<iCount-1)
    Image1->Picture->Icon->Handle=ExtractIcon(HInstance,StrFileName.c_str(),iIndex);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
  if(--iIndex<iCount-1)
    Image1->Picture->Icon->Handle=ExtractIcon(HInstance,StrFileName.c_str(),iIndex);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{//保存图标为图标文件
  if(this->SavePictureDialog1->Execute())
  {
    AnsiString StrPath=SavePictureDialog1->FileName;
    AnsiString StrFile=StrPath+".ico";
    Image1->Picture->SaveToFile(StrFile);
  }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -