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

📄 mainform.cpp

📁 C++Builder程序员编程手记《配书光盘》
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#pragma resource "MyCursor.res"
TForm1 *Form1;
HICON Large[50],Small[50];
int IconNum,IconCount=0,AniCurCount=11;
bool MyCur=false,AniCur=false;
TIcon *TempLargeIcon[50],*TempSmallIcon;
AnsiString CursorID[22]={"crDefault","crNonecrArrow","crArrow","crCross","crIBeam","crSizeNESW",
                      "crSizeNS","crSizeNWSE","crSizeWE","crUpArrow","crHourGlass",
                      "crDrag","crNoDrop","crHSplit","crVSplit","crMultiDrag","crSQLWait",
                      "crNo","crAppStart","crHelp","crHandPoint","crSizeAll"};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::OpenButtonClick(TObject *Sender)
{
  Graphics::TBitmap *TempBitmap;
  int cbfileinfo;


  Timer1->Enabled=false;
  if(OpenDialog1->Execute())
  {
    for(int j=0;j<50;j++)
    {
      Large[j]=Small[j]=NULL;
      TempLargeIcon[j]=new TIcon;
    }
    TempSmallIcon=new TIcon;
    TempBitmap=new Graphics::TBitmap;
    TempBitmap->Width=Image1->Width;
    TempBitmap->Height=40*30+20;
    ExtractIconEx(OpenDialog1->FileName.c_str(),0,Large,Small,30);
    int i=0;
    do{
      TempLargeIcon[i]->Handle=Large[i];
      TempSmallIcon->Handle=Small[i];
      TempBitmap->Canvas->Draw(10,10+i*40,TempLargeIcon[i]);
      TempBitmap->Canvas->Draw(150,10+i*40,TempSmallIcon);
      i++;
    }while(Large[i]!=NULL&&Small[i]!=NULL);
    IconNum=i-1;
    Image1->Picture->Bitmap->Assign(TempBitmap);
    Timer1->Enabled=true;
    delete TempSmallIcon;
    delete TempBitmap;
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{

  Image2->Picture=NULL;
  if(IconCount<IconNum)
  {
    Image2->Canvas->Draw(0,0,TempLargeIcon[IconCount]);
    IconCount++;
  }
  else
    IconCount=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  HCURSOR NewCursor,AniCursor[9];

  Timer2->Enabled=false;
  if(MyCur)
    DestroyCursor(NewCursor);
  if(AniCur)
    for(int i=11;i<9;i++)
      DestroyCursor(Screen->Cursors[i]);
  switch(ComboBox1->ItemIndex)
  {
    case 0:
    case 2:
      Screen->Cursors[1]=LoadCursor(HInstance,"NORMAL");
      Screen->Cursor=(TCursor)1;
      NewCursor=GetCursor();
      MyCur=true;
      break;
    case 3:
      Screen->Cursors[3]=LoadCursor(HInstance,"CROSS");
      Screen->Cursor=(TCursor)3;
      NewCursor=GetCursor();
      MyCur=true;
      break;
    case 4:
      Screen->Cursors[4]=LoadCursor(HInstance,"IBEAM");
      Screen->Cursor=(TCursor)4;
      NewCursor=GetCursor();
      MyCur=true;
      break;
    case 10:
      Screen->Cursors[10]=LoadCursor(HInstance,"WAIT");
      Screen->Cursor=(TCursor)10;
      MyCur=true;
      break;
    case 18:
      for(int i=0;i<9;i++)
      {
        AnsiString CurName="WAIT"+IntToStr(i);
        Screen->Cursors[11+i]=LoadCursor(HInstance,CurName.c_str());
      }
      Timer2->Enabled=true;
      AniCur=true;
      break;
    default:
      MyCur=false;
      break;
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  int i=0;
  for(i=0;i<22;i++)
    ComboBox1->Items->Add(CursorID[i]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
  if(ComboBox1->ItemIndex<5)
    Screen->Cursor=(TCursor)(-(ComboBox1->ItemIndex));
  else
    Screen->Cursor=(TCursor)-((ComboBox1->ItemIndex+1));
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
  Screen->Cursor=(TCursor)AniCurCount;
  AniCurCount++;
  if(AniCurCount>19)
    AniCurCount=11;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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