- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
/ @( F" {3 I; O' Vfile://------------------------------------------------------------------------
' A g4 Q- Y/ B' @<a>file://Unit1.h</A></P>$ B- o8 `1 Z! W* W( A6 K
< >#ifndef Unit1H. o0 {+ _, ~. G$ l! ]
#define Unit1H
+ D% A0 s9 Z- ~8 }: C Rfile://------------------------------------------------------------------------" g) Z) @! \! ?0 V, S r
#include <Classes.hpp>) U$ K" B2 W, X7 K' i- k
#include <Controls.hpp>, q6 v8 S; n* z0 k9 E! I( u/ `" p
#include <StdCtrls.hpp>- @% L1 p) x% b" t
#include <Forms.hpp>: `* J# b6 n3 ]4 C
#include <ExtCtrls.hpp>) A/ c0 ]0 U. S& [$ k7 \
#include <Graphics.hpp>" k( D( D; p, _2 h9 X
#include <Menus.hpp>% y, I2 L+ d( _
#include <Dialogs.hpp># o- `7 M3 M* F w; B
#include <ExtDlgs.hpp>
! {2 n5 {, |$ n$ ^( A5 Gfile://---------------------------------------------------------------------------
( f) p5 {! S& Xclass TForm1 : public TForm
5 e' C8 F J& l j- [" f{
' G! C: \2 X8 n__published: // IDE-managed Components
! E5 t5 @5 g; j( s5 ~ TImage *Image1;- f9 u: Z4 j) Y! q7 O; w. P8 r4 U
TPopupMenu *PopupMenu1;
( d+ m5 _6 X }8 G9 t# U TMenuItem *Exit1;
6 C/ s# b S% f TOpenPictureDialog *OpenPictureDialog1;
' v& _& ]7 R& u TMenuItem *Open1;
* F4 G' W K" h$ s: A void __fastcall Exit1Click(TObject *Sender);% _& X! y8 s; O. h
void __fastcall FormCreate(TObject *Sender);. t, n' @2 S; ^& g$ ?0 b |, j
void __fastcall Image1MouseDown(TObject *Sender,
* _; T* x1 I6 H1 f) ~! a TMouseButton Button, TShiftState Shift, int X, int Y);
( c: }" T5 F6 ?4 ?, K0 z3 g$ | void __fastcall Open1Click(TObject *Sender);
% V2 |/ d) k0 i Aprivate: // User declarations4 X9 U, O% j" V S
void __fastcall BmpToRgn();
6 E8 X; q5 N$ k, \1 e1 @& P% h+ a+ Spublic: // User declarations
3 V9 Y8 D2 }1 S' K" a8 V' T$ B __fastcall TForm1(TComponent* Owner);' F' g5 ?) h" x1 @) r, Y% \- f6 X
};
8 r0 W# A; Z9 u. I, U5 Rfile://---------------------------------------------------------------------------' K" n- U/ C) g! a" \
extern PACKAGE TForm1 *Form1;
0 \) P# S- m$ N( Y lfile://---------------------------------------------------------------------------
' X; W6 a" @, g) D#endif</P>
. g, u( b3 b5 Z: T5 s' N* b< >
: k+ @8 [! f! P! W<a>file://unit1.cpp</A>; m0 \1 R1 m9 {4 Q S( f
file://---------------------------------------------------------------------------</P>3 n1 t4 V: N# a/ d- B
< >#include <vcl.h> Z" R7 S' @# `% l' a2 B
#pragma hdrstop</P>' h+ X+ y( w! }: Z0 F, g. c
< >#include "Unit1.h"5 p2 m. @2 T7 ^/ T* \* P
file://---------------------------------------------------------------------------4 S: `9 R" O5 ~
#pragma package(smart_init)
6 L6 L6 `* K0 r$ }% G/ i#pragma resource "*.dfm". x e' j5 `: w* }0 S& h5 H
TForm1 *Form1;7 i! T& i1 I5 L8 N* h$ |% y- f1 S
file://---------------------------------------------------------------------------& q8 f' l/ V+ }/ r) t
__fastcall TForm1::TForm1(TComponent* Owner)
- Y, x# e9 o4 Y : TForm(Owner)
& c4 V5 t1 p, p) B( \6 d+ @' w b9 _! t{
- i5 Y$ b; h- V" H}
" x8 a" J1 l- s- g lfile://---------------------------------------------------------------------------
, N6 B! W4 v# R/ J ivoid __fastcall TForm1::Exit1Click(TObject *Sender)
/ V/ w* }6 W7 a2 l4 G{1 h8 {( [3 V/ C$ _& T8 {
Close();
* ~7 f* J5 e6 r) b) C}: e! m0 q' ~ [7 R
file://---------------------------------------------------------------------------</P>0 F1 d$ r2 ]9 p
< >void __fastcall TForm1::FormCreate(TObject *Sender)
! N6 L" N$ \9 L8 L$ m$ T8 x{</P>. D1 p5 z# V$ o* Q
< >BmpToRgn();! ?6 y; V k9 Q3 E% h% u
}
- w0 k7 x7 i, e% _, u' F& Z) j Bfile://---------------------------------------------------------------------------</P>5 x& |; N/ H* Z. v' K/ J0 b
< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,% ?) O0 K9 W. k/ c
TMouseButton Button, TShiftState Shift, int X, int Y)
& O# c( d( ~8 ^% G$ { t% [. |{
' _9 W# G4 b6 x* Aif(Button == mbLeft)
$ S. C0 H& O4 H7 T5 p B" a {3 N: o, h9 j, }, N
ReleaseCapture();
* y% p# N; Z6 o+ h, P, a& H* m) E Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);
2 \" ? s# X( T8 E }
/ y; O# {/ [! h$ \% D}: H* @8 i! [8 Z
file://---------------------------------------------------------------------------
0 ~9 h, B9 U8 j& K" v" Evoid __fastcall TForm1::BmpToRgn()
! b W% Z/ w; l4 e( E6 Q% S3 J{
* ^, i0 U/ C1 H" W# FImage1->AutoSize=true;
* d7 F8 }, M$ v# uForm1->AutoSize=true;0 V6 X7 o/ U8 {
Form1->BorderStyle=bsNone;; X) d1 X4 O* q- D. S! Y4 h5 f
TColor ColorKey=Image1->Canvas-> ixels[0][0];% k% O/ U9 U5 Z( A
int x,y;+ e7 a7 {! r5 j" L& B3 U% E
int l,r;
: n6 I% S# s/ s4 P& |POINT *a;5 V* z1 b" @2 {( g
bool lb,rb;2 V# S {/ H3 j8 ]8 e) I; n
HRGN WndRgn,TempRgn;</P>
( l& q) |: F2 I h< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)
. ]. j- j9 ~& B3 l% P& d8 q7 @2 ~{
/ O+ f4 l3 M; M. s ShowMessage("申请内存失败!");1 ~2 {1 q4 g5 ^, s3 f
exit(0);
! u2 X$ s4 y/ u}</P>
# C" U; _/ k" v5 L< >l=0;r=Image1->Height*2-1;5 Y/ m& C' `& r# ~
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>5 h, ^8 y* X4 ? P7 U" p; t
< >for(y=0;y<Image1->Height;y++)3 e/ |( d3 w) v' b% |
{7 Z% T7 x. W" g8 B6 K& c
lb=true;) E3 Z* E- s4 k; T! w
for(x=0;x<Image1->Width+1;x++), c9 W2 f+ \8 E4 X, k5 ~
if(Image1->Canvas-> ixels[x][y]!=ColorKey)* g8 y. Y8 H1 J. |( `6 M
{
, U8 W* c; Z( d" B$ V4 \: I a[l].x=x;
" s* f) _6 l) q$ R/ l- g; H1 l( U a[l].y=y;; Q4 z8 w& r2 K4 X; C, h9 ]
lb=false;
' W! \# P" T6 ^2 G# O" A5 _1 W break;2 X+ |! f/ t- J: k
}</P>
h) H% |/ w- j5 g) C< > if(lb) a[l]=a[l-1];% _. F0 B- {; H! `' l, E) j
l++;2 j) O: p6 k0 f2 L7 u) k* m+ {
rb=true;</P>+ p; z7 c( \9 o% N7 v8 V
< > for(x=Image1->Width;x>=0;x--)1 m/ @! G) L( y' f; i
if(Image1->Canvas-> ixels[x][y]!=ColorKey)! u2 d8 Z, H* }) Q) v |* G6 P3 J
{
) i" w$ N3 z. S/ u a[r].x=x;8 |. ^* V/ @6 z. e. e6 ]
a[r].y=y;
) l) k- q* C: W1 ~4 t rb=false;) F& M$ V# H, |/ ?8 w
break;& b; T" z. H' h( q& m
}
+ A+ p1 [' a! M$ o if(rb) a[r]=a[r+1];
1 H& U6 u5 S" ~% \# F r--;
; \* f. M2 G8 c5 L- x$ ?: Z}</P>
$ Y9 i; H% T1 x1 C* z/ d+ ~; G0 J4 C7 N< >r=Image1->Height*2-1;3 d# z# P5 q+ ?& Y0 K
for(y=0;y<Image1->Height-1;y++)
9 Z1 I3 [- E# [' U) H4 a{
4 F& r7 R$ i1 v8 G) k1 y for(x=a[y].x;x<=a[r].x;x++); I% M( o. H$ F* C! p" ~
if(Image1->Canvas-> ixels[x][y]==ColorKey)* d- [* u+ n; U/ y5 k
{. Z# w% H, c4 d: @: z# w4 W3 q$ y
TempRgn=CreateRectRgn(x,y,x+1,y+1);1 o4 [+ x8 v) T( s4 h* q
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);
8 j4 E" y! `7 C0 W3 @ DeleteObject(TempRgn);
7 y$ W% j# U2 P4 s7 V }
: M" _. w h b+ Z r--;/ `: @" l2 W' B) }5 \+ z
}</P>. t( i, S" |, C4 f* F2 T, C9 V4 y
< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
" j- @" ?$ T7 l/ O- q" Y- ~4 QTempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);
( w' U" R2 N. C$ S$ H. L0 {CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND); m+ N! ?2 F9 V" Z6 x
DeleteObject(TempRgn);& _) s! Y& ?* c9 g3 s' n
delete a;
% x* W# d- O: S2 m) W: D* Y- xSetWindowRgn(Handle,WndRgn,true);
2 U- U8 ]) ^. N}</P>5 U: K3 _- L# _
< >void __fastcall TForm1::Open1Click(TObject *Sender)
; P+ Q& F! V8 W4 |{
) B7 C4 W: S% l8 A- |$ i if(OpenPictureDialog1->Execute())4 K O# J4 w" e/ w! C
{
( d8 ~) k; Q! h5 ^ H/ o Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);
3 G' ?; ~* k# w( Y4 R! H6 B# Z BmpToRgn();
# L6 K! _5 Z/ D/ ^1 E6 y }$ ?+ b" ]! ~" s2 J1 m
}
- a+ \, p! T7 \% E9 l; S# V9 Vfile://---------------------------------------------------------------------------</P>+ P5 E( G u# i/ }. m) O& l# P: A
< >对啦,图片的背景色要相同。
. j- v1 z/ R* ^7 e图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>
7 B- u5 L' L9 M' m. Y U, E# v' M< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------1 a$ }" C/ [5 E! Y# c9 T3 a. \2 M
void __fastcall TForm1::FormPaint(省略)( i) u F! b0 O% P% \1 [3 H
{
2 h( _/ M4 L8 a. K8 D3 Z AnsiString ww;int bb;
' Z% l8 Z; A+ s% j& F+ c$ i ww=AnsiString(Form1->Width/256);
- O& m- A9 O" J, O. l' q7 ? TRect MyRect;
% `4 ]+ t# f1 D& b) A, x MyRect.left=0;
% i( D e% S1 n% L1 s8 t) R, C9 |$ O- W) a for(bb=0;bb<255;bb++)
' `! l6 ~4 f+ R- a' y {9 {2 B# l: ]' I- g, L
Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);
0 ?+ i/ H' Q" S' u _* t MyRect.top=bb*(ww.ToInt());) W( M& C, d4 y0 J9 E$ J& L4 V
MyRect.right=Form1->Width;, L8 D, p2 G/ V/ r V
MyRect.bottom=(bb+1)*(ww.ToInt());6 ]9 a5 H: m* D7 ]$ O& m
Form1->Canvas->FillRect(MyRect);
% |! |1 A, b9 W3 t }6 c9 r3 f1 I. R/ v- A# y
} </P>3 x! @8 B, p9 f% g% m% g4 j
< >file://---------------透明窗体--------------------------
z: _* F9 _3 G+ E8 z6 mvoid __fastcall TForm1::Button1Click(TObject *Sender)& g' p# |+ T' C x( \( |# c! f2 J
{
t* X; i6 H. V6 r6 e TRect *rctClient,*rctFrame;
) L t- x+ K1 w8 s4 u0 ^* m+ r$ a) T4 { HRGN hClient,hFrame;! e+ I3 L# l X" k0 G# j U9 w
POINT *lpTL,*lpBR;
3 e! C$ z3 c0 E# U5 Q) ^8 s rctFrame=new TRect;' c8 s9 U4 H5 l& o
rctClient=new TRect;4 I1 l7 }/ k$ k3 d
lpTL=new POINT;
2 {2 M: s3 h4 n+ l+ d lpBR=new POINT;
2 j) n/ T4 S4 G, \0 V8 q8 n& K4 q GetWindowRect(Form1->Handle,rctFrame);
5 N3 W5 \7 P% b' c. ^8 M ::GetClientRect(Form1->Handle,rctClient);# u1 W6 e8 w2 Q: M4 @/ d5 N( m
lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;
2 q' `" s) c$ F8 C/ m# Q lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>8 R! l$ D; a8 C/ A, u- `
< > ::ScreenToClient(Form1->Handle,lpTL);" v/ a; m- K& {/ L4 F
::ScreenToClient(Form1->Handle,lpBR);, L o7 K9 X6 d" i2 G' k# _
rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;
, Z' d2 l7 Z- D' R P) s( D u rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;( h7 x% a; B1 L! c8 q/ U* P' `) o3 M
rctClient->Left=abs(rctFrame->Left);
+ _1 R$ Z; _) O# _- }: w* \ rctClient->Top=abs(rctFrame->Top);4 q6 `- {" S3 k. o* ]
rctClient->Right=rctClient->Right+
- T a) O' |/ \; E1 K/ ~ abs(rctFrame->Left);
' b: T4 G. C: ^" N1 e rctClient->Bottom=rctClient->Bottom+
3 J; |: `- I0 m( |# v abs(rctFrame->Top);
Q0 N, u6 }0 S! u+ m1 j rctFrame->Right=rctFrame->Right+1 |3 P# C; N8 h h; N: K. }
abs(rctFrame->Left);
+ T2 U% G" Z0 z rctFrame->Bottom=rctFrame->Bottom+
+ w& m4 U& Q! X7 Z- ] abs(rctFrame->top);+ ?) _* r/ ]3 m- M$ _
rctFrame->Top=0;rctFrame->Left=0;</P>
9 u/ ~5 ]- b$ Y2 `& i< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,
/ p1 _) P3 ]( r+ u3 B rctClient->Right,rctClient->Bottom);
8 j0 L& O- B" Z hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,
, N1 s" A; ~4 x3 f) W% f6 e! K# @ rctFrame->Right,rctFrame->Bottom);
0 } d! n7 L8 e1 a CombineRgn(hFrame,hClient,hFrame,RGN_XOR);
, @2 u4 o; {& r& ]0 `7 s$ @ SetWindowRgn(Form1->Handle,hFrame,true);</P>2 g3 |/ E" R' p2 y7 _
< >
- L+ l* W7 Z! s, c delete rctFrame;
& k7 Y4 r4 _& E delete rctClient;$ Y6 Z5 l& W& T2 X f
delete lpTL,lpBR;</P>4 s9 L& Z2 V* t; Q) Q+ ?2 d. w2 `
< >} </P> |
zan
|