以下源码是快速创建不规则窗体的,还可以移动。
file://------------------------------------------------------------------------
file://Unit1.h
#ifndef Unit1H
#define Unit1H
file://------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
#include <Menus.hpp>
#include <Dialogs.hpp>
#include <ExtDlgs.hpp>
file://---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
TPopupMenu *PopupMenu1;
TMenuItem *Exit1;
TOpenPictureDialog *OpenPictureDialog1;
TMenuItem *Open1;
void __fastcall Exit1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall Open1Click(TObject *Sender);
private: // User declarations
void __fastcall BmpToRgn();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
file://---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
file://---------------------------------------------------------------------------
#endif
file://unit1.cpp
file://---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include \"Unit1.h\"
file://---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource \"*.dfm\"
TForm1 *Form1;
file://---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
file://---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
Close();
}
file://---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
BmpToRgn();
}
file://---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Button == mbLeft)
{
ReleaseCapture();
Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
file://---------------------------------------------------------------------------
void __fastcall TForm1::BmpToRgn()
{
Image1->AutoSize=true;
Form1->AutoSize=true;
Form1->BorderStyle=bsNone;
TColor ColorKey=Image1->Canvas->Pixels[0][0];
int x,y;
int l,r;
POINT *a;
bool lb,rb;
HRGN WndRgn,TempRgn;
if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)
{
ShowMessage(\"申请内存失败!\");
exit(0);
}
l=0;r=Image1->Height*2-1;
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);
for(y=0;y<Image1->Height;y++)
{
lb=true;
for(x=0;x<Image1->Width+1;x++)
if(Image1->Canvas->Pixels[x][y]!=ColorKey)
{
a[l].x=x;
a[l].y=y;
lb=false;
break;
}
if(lb) a[l]=a[l-1];
l++;
rb=true;
for(x=Image1->Width;x>=0;x--)
if(Image1->Canvas->Pixels[x][y]!=ColorKey)
{
a[r].x=x;
a[r].y=y;
rb=false;
break;
}
if(rb) a[r]=a[r+1];
r--;
}
r=Image1->Height*2-1;