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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。& M+ q( J$ D* N- I4 y8 R6 ?
file://------------------------------------------------------------------------
8 _5 Z+ q* G* y: |! L$ ]<a>file://Unit1.h</A></P>- W( J+ I1 n k# V- K* o, c8 x
< >#ifndef Unit1H
/ o: T7 j* ?# m/ v- y9 @#define Unit1H
* z2 U) b+ Y/ C2 R5 Kfile://------------------------------------------------------------------------
: K4 v, I' B' Z3 A& P* y6 Q4 u#include <Classes.hpp>
+ h$ I( b* Y8 r( F P#include <Controls.hpp>3 a1 n4 l' N, ^5 R8 Y
#include <StdCtrls.hpp>
5 U3 T* W4 d y9 H# Q! o, @#include <Forms.hpp>
# O- B8 S8 E" g Z0 z: e#include <ExtCtrls.hpp>9 b- c7 z& d/ N0 N3 ]9 h" z1 n
#include <Graphics.hpp>5 N, Q9 d6 j- z3 Z1 }
#include <Menus.hpp>- L( M, v3 }) m
#include <Dialogs.hpp>
+ b# X f* L5 m# w `+ N#include <ExtDlgs.hpp>9 j" F2 B) ?% P$ o" a
file://---------------------------------------------------------------------------
2 I, ^3 X5 Z5 ]% i3 zclass TForm1 : public TForm$ f/ H% \' N" x! j) C/ ^% ^2 v# C
{
4 h( X% [( K7 Y, w__published: // IDE-managed Components
. @& @) V c8 t: w( |7 j; h TImage *Image1;
2 ? v& V2 p B# j7 F3 V- \* B* N TPopupMenu *PopupMenu1;- k) C5 V9 j& C( y( h. h
TMenuItem *Exit1;: f0 @4 X. }- T5 Q5 h
TOpenPictureDialog *OpenPictureDialog1;% U; W! V3 V+ O
TMenuItem *Open1;
3 B3 Z3 ~! \6 o5 c: B7 s void __fastcall Exit1Click(TObject *Sender);- L- R4 Q4 G- q$ Q
void __fastcall FormCreate(TObject *Sender);
) \- Z, Q) o+ j+ d% M6 @ void __fastcall Image1MouseDown(TObject *Sender,+ v& Q- L e+ T# _7 f+ a A4 B
TMouseButton Button, TShiftState Shift, int X, int Y);
, M/ q2 W% E: n void __fastcall Open1Click(TObject *Sender);
5 m G) i9 B9 \! j sprivate: // User declarations
) H9 }/ ~0 q' U) N void __fastcall BmpToRgn();
0 V/ w6 A6 R3 \6 s, o6 Dpublic: // User declarations9 v. W1 { t7 _3 v6 r: H# ^* _
__fastcall TForm1(TComponent* Owner);, k" r' ^( l0 J$ k3 G1 F3 ?% {% x
};
& ]3 X8 C1 j1 p8 B* Qfile://---------------------------------------------------------------------------# K) y4 L8 |8 b$ z
extern PACKAGE TForm1 *Form1;
: \ {$ M* H+ r, G( Gfile://---------------------------------------------------------------------------
2 Q: X3 y m+ S7 v: S/ T# `#endif</P>4 K, H! |6 J: _. r# V6 g
< >
3 I# t$ Y) u' q<a>file://unit1.cpp</A>& _( N+ x. r6 D, h4 \
file://---------------------------------------------------------------------------</P>
, ]) ~7 q! y% _. H( B2 f$ ?+ g$ G< >#include <vcl.h>
' \7 A) u) Y' V. h/ g5 g#pragma hdrstop</P>
4 e$ `5 W+ Q# t6 y< >#include "Unit1.h"
p) Z5 [' f; {* c" Lfile://---------------------------------------------------------------------------
& [, X- ^' p, O3 h3 Q! M#pragma package(smart_init)
& N/ X9 k' E7 P! H#pragma resource "*.dfm". y1 `4 y2 Q( Y }1 u
TForm1 *Form1;' h4 w' D; I- B. `# J& D
file://---------------------------------------------------------------------------
, S! o8 U. ?9 w: s2 |' w. Q__fastcall TForm1::TForm1(TComponent* Owner)/ S& K9 f3 B9 w2 E" |
: TForm(Owner)
& X$ e( A5 K, ?: p. z{
7 [" n2 l0 u$ M2 g4 K}
% c1 n# O" F% M- ^file://---------------------------------------------------------------------------& d& ] {" L% {9 b
void __fastcall TForm1::Exit1Click(TObject *Sender)' c4 b$ p0 P6 [1 @
{
& W2 ?6 Z7 m! u1 p2 i; j! F' A* d Close();8 e( O2 G t# }! v6 I2 t' q( W, {( k
}, x( f+ |; I+ \/ R: `' D8 R
file://---------------------------------------------------------------------------</P># a) j# u8 g6 z
< >void __fastcall TForm1::FormCreate(TObject *Sender)
% ~+ [0 e( K, w3 [* d{</P>! Z) z! a! g2 U) W" t& U
< >BmpToRgn();1 e0 a* {0 m% r& {" U
}4 {3 @8 ?8 s+ u4 v0 ` `6 A# {- j
file://---------------------------------------------------------------------------</P>! M' m, g2 H0 d* ^2 @+ M, O( r
< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,! t1 K6 p. Y; x( g( D, |
TMouseButton Button, TShiftState Shift, int X, int Y)
7 _; v3 r$ ?$ \3 G{
# G6 d0 Y( U/ z" w- ~2 r- l9 `if(Button == mbLeft)
; c* d8 _& U1 } { I+ K r/ p B2 U
ReleaseCapture();
5 D6 t, P$ N0 @/ w" ? Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);- y" h3 y/ `: K3 Z$ Y: W& q6 o: r
}
. o+ h6 a* n" I/ O}
' F+ k- o6 w, X0 Q% R. Bfile://---------------------------------------------------------------------------+ w V' a5 y2 t- I- s6 v l2 o
void __fastcall TForm1::BmpToRgn()
, Z$ ]: p7 v$ |, b( w{
0 K( V2 f5 U8 p) [Image1->AutoSize=true;
2 ~) {) |% ]. Q5 P% Z. J9 M8 ^$ vForm1->AutoSize=true;
4 L, H' `+ c9 T4 T) |$ ]2 i4 SForm1->BorderStyle=bsNone;
* {; Y+ g! A+ Q) T5 b6 d! yTColor ColorKey=Image1->Canvas-> ixels[0][0];# m7 ^2 A- N& F6 K, l! M
int x,y;
w3 _- e G+ s1 Y# U% j$ Iint l,r;
3 l, R) S( q/ {POINT *a;& m1 M, k6 C1 a7 _# ~
bool lb,rb;
, a# A7 B% _+ S- THRGN WndRgn,TempRgn;</P>
5 m+ ^) i1 L: I7 x2 h0 Z< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)6 U- \/ S/ D/ g$ j( Y' F$ F' Y
{/ J! R$ X/ L1 I
ShowMessage("申请内存失败!");$ N% t& s" c: y/ Q$ z3 B
exit(0);% t1 @" B( J. |, c9 P
}</P>; W/ j3 a0 l- ^- W
< >l=0;r=Image1->Height*2-1;9 r$ k5 j2 R5 i' X6 y' N0 n& t7 K
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>0 b# q1 P# w" Q. o( E6 z
< >for(y=0;y<Image1->Height;y++)
) X( w: Y- d1 Z, X. i# s+ Q+ O{
0 \8 S- S q; K; k$ B } lb=true;
5 Z% b9 _3 h0 K for(x=0;x<Image1->Width+1;x++)5 R9 ?% O1 n% y. _4 W
if(Image1->Canvas-> ixels[x][y]!=ColorKey): ^7 E5 Y& K) p" y
{
: q" [5 G2 B* X; z1 c' J7 s% B a[l].x=x;
$ }8 z q( e2 ~7 {' ~ a[l].y=y;+ u! x; \8 M. ^ |& j* W6 s
lb=false;" `+ p" G2 Z K0 N) o3 z# _0 D! ]
break;
# |# E9 H% C5 H) I) `8 I( S$ g }</P>
3 Y1 F1 d8 G1 L7 t+ b< > if(lb) a[l]=a[l-1];
: `, G3 u- G, G# v; Z+ s l++;3 I- g5 T4 |5 m) X$ }( W
rb=true;</P>
" Q3 j8 v2 `7 z' W% X< > for(x=Image1->Width;x>=0;x--)
. ^, y5 _5 g3 w/ P2 _8 n if(Image1->Canvas-> ixels[x][y]!=ColorKey)3 V6 R! {1 U! @3 [9 K# F' b- w
{
* v- V" X$ D/ c6 L a[r].x=x;
( T( [) ~5 Q# [! R4 j4 n a[r].y=y;1 b6 x% N3 Q; {# B
rb=false;, K0 r% E' A9 n3 h) S
break;, h' j, h! ]+ [! F
}" }9 R: A% g1 N7 @( Q
if(rb) a[r]=a[r+1];, j! Z1 M8 O4 L. \2 X. f$ W
r--;! o) d- @7 \, s1 o, Z. z6 c* G% p0 A
}</P>
9 U$ A/ J1 d) w5 {% u, E& Y \; H< >r=Image1->Height*2-1;$ t" q, j# _% v7 Y$ a7 T
for(y=0;y<Image1->Height-1;y++)1 g) S3 E9 T3 W* f' S
{
# N6 J8 ]9 @9 y for(x=a[y].x;x<=a[r].x;x++)0 ^3 Q. M) s @6 h ~. x2 w
if(Image1->Canvas-> ixels[x][y]==ColorKey)- y5 q, V5 [8 j7 ^# i: V
{/ D/ ~2 t- b7 m X$ ~5 k) K' B
TempRgn=CreateRectRgn(x,y,x+1,y+1);) R' U' o/ j* i
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);9 B) M8 c7 @5 h7 J) \
DeleteObject(TempRgn);8 ~) D5 d3 }! U% f3 R$ S) Z
}1 s4 A+ u( c5 I
r--;
2 P8 J3 Q2 A- A1 y}</P>$ c* f6 D7 S1 X% N1 d |: E
< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
/ j" N7 k- R) M ]TempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);% @0 Z8 K7 {& a; E* g; ~+ b% ~
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);
7 o3 J" V8 [) y2 S9 G+ ^DeleteObject(TempRgn);
5 Y0 P2 n2 D0 n1 Ydelete a;1 R) c" H) v8 k& h# j3 }3 L
SetWindowRgn(Handle,WndRgn,true);
7 Q1 n$ w9 h5 r+ L}</P>
4 K) V- H$ b. Q) Z+ |< >void __fastcall TForm1::Open1Click(TObject *Sender)4 O* v& N* r" @' O( S) c
{
: E. ~1 O4 t8 C if(OpenPictureDialog1->Execute())7 L% h* @2 {5 I, M w; L$ v
{
6 V; P$ W+ _% [" g7 K3 \3 y Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);. g# b( G7 B% l; m- _( b) T
BmpToRgn();
9 {9 O& T; S% \, C. f2 V }
$ u$ x' x' P- R# H3 r/ k}0 d: P z# o! Q1 ^" m% N$ j8 Z! T; P
file://---------------------------------------------------------------------------</P> V+ h" w! J8 U* d# U$ A, @ R6 ~
< >对啦,图片的背景色要相同。! [/ Z2 G9 J) l! [3 U9 _
图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>
9 V( t8 B9 ~ G< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------
$ s" c6 T9 ]. r9 xvoid __fastcall TForm1::FormPaint(省略)0 W, ], W& t% x; I _ ~2 u+ n
{7 d( P6 ]# c( L# i
AnsiString ww;int bb;4 x4 R. \- l* ^- W0 Z/ x3 b4 ^
ww=AnsiString(Form1->Width/256);
1 r, W! W& ]- W. P8 `5 L' U TRect MyRect;% M( Q o* Q, N' T y
MyRect.left=0;6 }8 Y- S/ E- \2 Y
for(bb=0;bb<255;bb++)1 n; h$ p! b* t9 I) q$ C
{
; n: I6 j( x Y" G8 g: ` Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);0 \0 e8 V! j3 S: o/ ?0 a
MyRect.top=bb*(ww.ToInt());7 N8 s1 [" v. @& U7 ]) d
MyRect.right=Form1->Width;
3 ^9 E1 m1 {% I MyRect.bottom=(bb+1)*(ww.ToInt());! U1 C7 ]) u7 i
Form1->Canvas->FillRect(MyRect);! Y! i: q" u/ q+ {# e# s! }; x
}
/ X l# ?2 h/ T2 X* ?- l5 w} </P>
# x! F2 i& o0 E: e& f. u< >file://---------------透明窗体--------------------------
3 P: f5 B. n0 O( pvoid __fastcall TForm1::Button1Click(TObject *Sender)
# x" | x& U$ c8 u! f{
. w* S. F4 Y* J2 H TRect *rctClient,*rctFrame;
7 E& f' K( l' w0 l9 ` HRGN hClient,hFrame;
+ p7 L6 X" n4 G& W {8 B POINT *lpTL,*lpBR;
! I6 [ t1 F! o0 E4 a7 W rctFrame=new TRect;) q: h5 u1 f6 d$ C4 V$ Z
rctClient=new TRect;
9 G! K5 g- M, |& e lpTL=new POINT;+ D, t8 ^ @/ |$ u. q E' b
lpBR=new POINT;
- u* @# _- D p- w GetWindowRect(Form1->Handle,rctFrame);. l( O0 D4 e6 f4 @- O( K. ]
::GetClientRect(Form1->Handle,rctClient);
" h& y9 M! h" E5 V lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;
3 u) \; }$ r7 B lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>! c1 t' V# J8 V% N) B$ |* ?* c
< > ::ScreenToClient(Form1->Handle,lpTL);
5 e7 u3 u" ]4 I2 x @0 C8 u! x4 k3 y' k ::ScreenToClient(Form1->Handle,lpBR);/ Y0 B2 O0 C; M/ C0 Z" V8 y
rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;7 Q* a$ Z1 r6 X. b2 L
rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;5 B- D& c9 P4 w8 \
rctClient->Left=abs(rctFrame->Left);
; K# l. p* B0 ?/ n rctClient->Top=abs(rctFrame->Top);
$ i, J x: a' F rctClient->Right=rctClient->Right+8 j& Y% c; [5 M
abs(rctFrame->Left);% n! \; n% Z# x7 ]- \+ P! r
rctClient->Bottom=rctClient->Bottom+( \! F% E/ ?, k" {1 e' r; T
abs(rctFrame->Top);
8 q3 H: U! G8 ^& l) d$ ~ rctFrame->Right=rctFrame->Right+
4 A$ q" q: [+ h# a1 H abs(rctFrame->Left);% S' ]/ X4 M5 i2 F: f q
rctFrame->Bottom=rctFrame->Bottom+' U8 D0 L* F0 |" n# P2 z
abs(rctFrame->top);
3 S$ D, b, N1 _5 a/ j' Z rctFrame->Top=0;rctFrame->Left=0;</P>
& d4 H# j+ W* U9 z* q' i< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,
h `' k2 c, I rctClient->Right,rctClient->Bottom);) k& s( E5 y9 |# ]
hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,, f$ ?1 G$ Z/ t7 R3 L
rctFrame->Right,rctFrame->Bottom);
8 t& L+ f9 v2 {5 ?1 W CombineRgn(hFrame,hClient,hFrame,RGN_XOR);
" j) D/ Z: ^, L4 U9 F9 {+ c8 `% K+ t SetWindowRgn(Form1->Handle,hFrame,true);</P>
+ D6 a' r" c/ ]< >3 e! b7 Y- B7 @$ i0 ^' {
delete rctFrame;
$ i& F' u/ e5 i( S* h' x delete rctClient;* i/ D( V5 \2 I# l) V
delete lpTL,lpBR;</P>2 g0 L3 c; U( b- w* _2 E
< >} </P> |
zan
|