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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
: l+ V# v) ]6 bfile://------------------------------------------------------------------------6 G( }* s/ ~' f; c: i9 w/ q
<a>file://Unit1.h</A></P>) q) j4 J9 t+ B4 r* W3 O( @
< >#ifndef Unit1H
! [- I& O! H v. Y' K4 P0 B- F#define Unit1H
/ z' Y Z# i' _5 g6 ~/ E) @3 ufile://------------------------------------------------------------------------
+ @) J1 o* V' @; M' J0 Z: t3 r#include <Classes.hpp>
2 S* L# k9 ^; A5 D p#include <Controls.hpp>
3 M% |4 A ~2 ?. I: z4 G& L% I#include <StdCtrls.hpp>, U) l, [8 v/ i3 _: M, o
#include <Forms.hpp>3 a C% R/ h: v* w$ K
#include <ExtCtrls.hpp>
8 j- d2 i" y* K5 h7 h#include <Graphics.hpp>
; E+ K# ^+ u& n' U, ^7 o. @% M#include <Menus.hpp>
0 W: ~8 X0 }2 K4 G7 H. r" j) \#include <Dialogs.hpp>) j' V' [( |4 e3 j% l
#include <ExtDlgs.hpp>( l O7 S/ i; x; E
file://---------------------------------------------------------------------------1 F* k) R8 X+ d4 Y
class TForm1 : public TForm
4 X: L% ~2 R% k$ ?, J$ ^% r{
+ \: d8 C0 y6 F3 H5 y__published: // IDE-managed Components
, g' R2 u- ?$ \! A& Z4 Z! ?1 U TImage *Image1;' m) d, [8 a1 u4 h* J; [# ?, \
TPopupMenu *PopupMenu1;
1 V$ o: i) ]& U& c# E" z% s a TMenuItem *Exit1;
Y$ G5 a; f0 ? A' t6 Y. o* l% v TOpenPictureDialog *OpenPictureDialog1;# y# y' \+ n1 e# a7 @/ e: n( d
TMenuItem *Open1;' }6 z" P8 b/ l8 }
void __fastcall Exit1Click(TObject *Sender);
: E: v) K# u2 r& ` void __fastcall FormCreate(TObject *Sender);! h. A! n4 Q. Y
void __fastcall Image1MouseDown(TObject *Sender,
1 h' r9 _) Q0 ?9 ?, O2 u TMouseButton Button, TShiftState Shift, int X, int Y);! n! C' H+ ^- P; J4 |+ z
void __fastcall Open1Click(TObject *Sender);
! s! {) T# c; H$ s1 U9 dprivate: // User declarations
/ E7 r, |7 l( j7 p7 q void __fastcall BmpToRgn();' O+ `! [( j9 }9 a. B
public: // User declarations# G! P% p) Q0 k# @5 h% w( u$ n, p& O9 u
__fastcall TForm1(TComponent* Owner);
. w6 {9 E" N2 y4 Q; n: j};
% ?/ b0 K0 T% \% |' ^6 |9 ]* pfile://---------------------------------------------------------------------------' D# d$ ~2 y. l! r
extern PACKAGE TForm1 *Form1;
1 }+ D9 `. o( m) R. w& ufile://---------------------------------------------------------------------------- m6 @" E2 ?6 q/ F8 b) U+ L' v& ~# m
#endif</P>
& u e, z6 ~1 O) P. K< >' r5 b- U/ Y a0 ]( D6 [
<a>file://unit1.cpp</A>
/ n& r: z( _6 lfile://---------------------------------------------------------------------------</P>7 A& w- n" w/ q; l* }* n; ?) f
< >#include <vcl.h>" x4 K9 x0 E0 Q3 b2 I) `6 ^ m
#pragma hdrstop</P>" w4 m: G) |& b: T( ^3 V$ u5 r7 z
< >#include "Unit1.h"
: T0 [0 W$ X2 O4 p. mfile://---------------------------------------------------------------------------
% s; }4 t+ X- ~' t P#pragma package(smart_init)
/ ^. k8 s4 P" L0 \# Y, n, S# H#pragma resource "*.dfm"
3 ]& h4 V5 ], c4 q8 O' DTForm1 *Form1;) t* _) A' M f% [1 o& r
file://---------------------------------------------------------------------------+ E/ _" ]4 \9 H
__fastcall TForm1::TForm1(TComponent* Owner)4 X" ^$ T$ K& l
: TForm(Owner)1 \( j5 K6 o# P$ @9 v9 S
{
* B( H3 Z1 u5 M7 e! R! P1 m0 H}
3 a% E" n" u* h2 u) ]1 mfile://---------------------------------------------------------------------------# V- W& a+ g2 F
void __fastcall TForm1::Exit1Click(TObject *Sender)+ b2 J6 n; {& ^2 Q9 i2 h
{
9 [+ ~# L$ }8 P1 c# ` Close();- o5 v8 L4 p {% R5 d. t$ l
}
. i8 V5 g) D- j6 T. }file://---------------------------------------------------------------------------</P>
4 x6 l( K9 I8 J8 p7 q$ Y< >void __fastcall TForm1::FormCreate(TObject *Sender)
7 `0 a% s1 q( |/ b) l{</P>% o2 H9 c3 P: y6 d- m! G
< >BmpToRgn();
- p5 N4 r: K! F {}
5 |* Z. ^1 `4 P7 J jfile://---------------------------------------------------------------------------</P>
6 b, A- N6 y6 e! r1 w< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,
2 x3 r: Y$ G% W* e TMouseButton Button, TShiftState Shift, int X, int Y)
+ ]) E& v: y6 J0 \/ j{
^" d h% r, Tif(Button == mbLeft)
; ] _& |% W6 h( N1 u3 P; k0 W {8 F6 j1 Z x( U: ?, L
ReleaseCapture();
% e+ A0 x* q+ C- t1 j8 A Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);- f9 U. c5 r: s3 w4 P: |6 ~
}
! ~! \ F- B# I' A}
7 x% x0 f! x$ q9 K& E/ x) I4 G V; `file://--------------------------------------------------------------------------- Y$ u5 ?' m* I8 O
void __fastcall TForm1::BmpToRgn()
( `# @1 E# ], A{
- o; ~( ^% l2 p) WImage1->AutoSize=true;+ S7 _+ n# c9 w4 b! m) G, }
Form1->AutoSize=true;% }& O5 e4 h9 E8 v. ^4 S; t- b
Form1->BorderStyle=bsNone;
9 m+ h8 {/ V! q0 F4 X# aTColor ColorKey=Image1->Canvas-> ixels[0][0];# D0 D# g/ C- [* [5 d5 j) f9 O/ U1 L$ r
int x,y;7 @8 s6 H0 q$ Z; E
int l,r;
5 m- G6 i: ~6 ?( BPOINT *a;1 r; d. _' H$ p L1 Z8 a6 ], ^
bool lb,rb;9 K4 a8 [& B; M1 t( j( Q
HRGN WndRgn,TempRgn;</P>; P- s' i/ N* V, y {% I) k
< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)
$ B$ J9 \/ A& @' c{8 ^3 @ x3 I: G U( t" d) r
ShowMessage("申请内存失败!");
7 ^& p% ~2 F* x/ m; Q exit(0);' f: C, B3 v1 b3 x! S# R/ Z" A' T
}</P>
6 R/ H4 m: K( E* N* x* d< >l=0;r=Image1->Height*2-1;; J% j' i K$ e
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>% k4 K8 b2 |7 H# c
< >for(y=0;y<Image1->Height;y++)# O" @+ N1 l7 C+ ^
{
7 z1 C5 L3 B6 X1 q9 t lb=true;
8 G2 h, m( D O1 O for(x=0;x<Image1->Width+1;x++)
J' V. _3 q" V/ R" i- l if(Image1->Canvas-> ixels[x][y]!=ColorKey)5 a g8 I0 ^4 I
{7 L+ K0 w1 Q5 b7 r0 K6 G' \
a[l].x=x;1 F& }* _: H9 I5 t. r# t
a[l].y=y;
: P( h; O- p4 n- e4 j$ |# P8 s lb=false;3 D# { ^( |" _' u/ x
break;
/ @8 a3 m$ r" `# r) f }</P>
& C' F5 ]% E: p* s3 b< > if(lb) a[l]=a[l-1];
0 ~: ]& d; |* x" T# e% s3 b l++;3 y7 i( b. ?- u7 E! G
rb=true;</P>
; v+ C2 o6 K4 P& `< > for(x=Image1->Width;x>=0;x--) l# ?; r5 a4 }. a; K- W- s, N2 a# _; n
if(Image1->Canvas-> ixels[x][y]!=ColorKey)
( T8 }/ h- v& D4 d9 U t) t, ~% T {1 P( K' u" [) z% m, V. w3 [, C
a[r].x=x;
7 N" y- A+ W" I) ?% { a[r].y=y;5 P, {; L' y- |( c% Y* N+ D
rb=false;
9 l' K8 R0 K0 H; M* |7 o. h- z break;
5 U- R, ?% p& n, @$ W) s/ J }1 A$ k+ h/ ^( n1 o. A* z% n3 a( X
if(rb) a[r]=a[r+1];8 H% O4 H+ t9 R! {# Z6 `0 G
r--;# Z8 X% D. w4 @. Z2 P, S3 {4 E! ^" B
}</P>
* `# o( h! j) E7 Y2 N< >r=Image1->Height*2-1;
- r1 e2 l4 z& P2 ofor(y=0;y<Image1->Height-1;y++)6 K0 Y) T8 a+ C. K# [; N
{9 h8 i0 W7 T/ B
for(x=a[y].x;x<=a[r].x;x++)" |1 X3 [: _) m7 F) N
if(Image1->Canvas-> ixels[x][y]==ColorKey)2 C1 M/ @- l6 G9 i& k3 ~
{- o% z( L6 [& j+ }. N- |8 e2 l
TempRgn=CreateRectRgn(x,y,x+1,y+1);
/ B5 }8 c; t- l$ x- \$ [4 p; a( b CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);
+ O: b1 d5 i6 g) B9 D# M DeleteObject(TempRgn);
* x4 p2 P$ W6 }% [+ O4 Z5 [ }4 H' E& d% @' O" T; T9 D
r--;( @; A$ [# Y9 V
}</P>
( @8 @9 p# u6 T< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
0 V7 ?! F" M) E6 j' b U& {TempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);
^/ ~5 P+ G" R$ Z% X( F5 RCombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);- S) |& f6 U* q0 l
DeleteObject(TempRgn);
- r) d, h; ^6 \0 P3 J. z; Jdelete a;! u* F/ m3 \3 ^: W; R6 `$ `% i. h
SetWindowRgn(Handle,WndRgn,true);
1 e$ L( ~( ~. Q}</P>
* b- H5 x1 w9 A0 d6 I< >void __fastcall TForm1::Open1Click(TObject *Sender)1 e$ }# w7 k: v% @) r% b
{) Z) L* z/ h+ E+ M" m* b; Y
if(OpenPictureDialog1->Execute())" o, V6 L' v: L1 J1 F
{
Z9 V1 o7 T" X) R Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);
9 n+ k. l0 @1 s BmpToRgn();% A2 P9 u- {5 y, i5 `* v: ~- t
}6 a$ v, |) o3 O
}
9 |5 @+ Q: o' `9 Lfile://---------------------------------------------------------------------------</P>
9 \$ H: T# v% z3 B) z7 T< >对啦,图片的背景色要相同。
$ O# u# J2 [: }& y8 e图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>- P' U, ~* e1 o+ J
< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------" }- a$ {( q0 i5 J# E) |
void __fastcall TForm1::FormPaint(省略)" m' E/ r! \4 Q- {7 A% s9 }8 }
{
/ R$ u# N. n2 m AnsiString ww;int bb;7 y9 z( W6 U5 V/ H# Y4 o
ww=AnsiString(Form1->Width/256);
5 H- ^9 R' ]) S* o1 @ TRect MyRect;
4 @/ \1 W/ t: F! s5 o5 s MyRect.left=0;" {+ R. m6 a7 e. d: j2 V7 }
for(bb=0;bb<255;bb++)
: i) o9 K! v8 V$ ~) E# x {' w. _1 q6 |+ Q1 x
Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);
# N2 K/ Y7 ?* u MyRect.top=bb*(ww.ToInt());
v0 B2 H8 ^) U) ^% W+ ~ MyRect.right=Form1->Width;+ b2 ?# k& ?5 v, S9 d
MyRect.bottom=(bb+1)*(ww.ToInt());3 M* ?4 P3 D! ~ @7 x* T
Form1->Canvas->FillRect(MyRect);
& c1 D& D6 U9 h" L }+ r" k) t9 [- a
} </P>! I4 b3 a* P" q) S
< >file://---------------透明窗体--------------------------
5 b. q; I+ E; k, m# Yvoid __fastcall TForm1::Button1Click(TObject *Sender)' g7 J9 B1 Y' E
{
2 I! f1 Y" D" b8 K; S$ ]' E& o TRect *rctClient,*rctFrame;* f9 r$ X8 `' p5 k
HRGN hClient,hFrame;
% t5 M! X; h4 H! a2 ]- o, ~3 @3 w POINT *lpTL,*lpBR;
2 r. J5 o5 n- r8 u/ e/ Q6 ]4 T rctFrame=new TRect;
/ G1 f2 P8 w$ N rctClient=new TRect;+ x0 }% |( U6 O" I J
lpTL=new POINT;( o2 s% v/ d( b: i
lpBR=new POINT;
( c6 ^9 Y/ X# T) }* z, s7 z$ C# F( W GetWindowRect(Form1->Handle,rctFrame);7 H3 J t. x: g: w- M
::GetClientRect(Form1->Handle,rctClient);
* x, p' V( Y! e! l: m lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;& @/ o- i3 y" g$ C9 k
lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>
% v# W7 g4 U. D8 l& F: j0 K+ M X1 D< > ::ScreenToClient(Form1->Handle,lpTL);
S3 `. C& B8 c3 Q3 h+ f+ e ::ScreenToClient(Form1->Handle,lpBR);9 I" L: y9 m' {" S# h5 p/ K
rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;
( Q, q9 R8 ~9 Q% x* h rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;
% E4 Q+ U" w8 J& G5 ~2 M rctClient->Left=abs(rctFrame->Left);
{! I! ^3 s7 U2 V \ rctClient->Top=abs(rctFrame->Top);
2 E6 A, y+ ^1 \+ p5 @; W3 _- d rctClient->Right=rctClient->Right+
( G% Q8 J; n! ?, L7 U6 t abs(rctFrame->Left);0 m: [+ g) [, J' W3 O9 u
rctClient->Bottom=rctClient->Bottom+- r6 y1 I2 | Y5 b! a9 F2 s
abs(rctFrame->Top);8 C" [% Y4 W1 s: z! S
rctFrame->Right=rctFrame->Right+
. L9 d1 g; ^; q' c. j4 G abs(rctFrame->Left);0 a# m9 ^: G' q& u+ P. v" L1 U0 U
rctFrame->Bottom=rctFrame->Bottom+
. s7 D" P5 D/ Y; g+ T abs(rctFrame->top);
+ r! q. S& }' j" W4 Z rctFrame->Top=0;rctFrame->Left=0;</P>$ w8 [6 ?& W% @0 S
< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,1 P! z) d7 [ D' s, w
rctClient->Right,rctClient->Bottom);3 G* Q# I: \8 o `6 I
hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,
7 ^" R. ?* I8 l rctFrame->Right,rctFrame->Bottom);, i" k9 c6 G7 \, K' F& G9 [+ O
CombineRgn(hFrame,hClient,hFrame,RGN_XOR);! l9 y3 W# F# b( C
SetWindowRgn(Form1->Handle,hFrame,true);</P>
# [4 F( z' F" @* |4 D6 I! _3 R; k< >9 d) i* V8 N% B* T( @6 [- T/ W
delete rctFrame;
3 N; i1 D* l* K7 E, _: Z delete rctClient;
5 s, Z& n2 Q9 O delete lpTL,lpBR;</P>
, P! @( l6 j3 P2 X< >} </P> |
zan
|