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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
! \; l8 P% G0 i9 j1 L5 }: w% mfile://------------------------------------------------------------------------
4 w9 C3 N: R2 v H5 L5 _# A<a>file://Unit1.h</A></P>) z$ \ v0 }1 I+ w/ w
< >#ifndef Unit1H
! a# [2 b6 Z7 @" h#define Unit1H
8 y1 `) _& Z, ^* r" k1 r1 s% \8 gfile://------------------------------------------------------------------------
3 A% l4 q$ y7 q#include <Classes.hpp>
9 p: D+ i' W, [* I; l$ _0 f+ I) g#include <Controls.hpp>
2 J3 @: z% z2 F* P$ }& Z% e#include <StdCtrls.hpp>
+ j0 U# f) c# u#include <Forms.hpp>
/ b: E$ i; U V" l#include <ExtCtrls.hpp>8 f. @/ z0 q$ g5 p" [' L# a
#include <Graphics.hpp>
, ?2 Y# {; Q. Q y$ }#include <Menus.hpp>8 z! H- E2 P% D1 Y* d) d2 `% s
#include <Dialogs.hpp>
, o, n7 y0 H6 t, i" ^#include <ExtDlgs.hpp>
5 E% a8 V* B* z4 d# A" h {; ^file://---------------------------------------------------------------------------
( G% `' V# J; B! a/ e$ uclass TForm1 : public TForm
7 h* O H# e/ Q; Z& K{
0 z6 J( ` X! o- |2 K- _* a__published: // IDE-managed Components
" _! }! T& K' Z& t3 j* S. M TImage *Image1;
; ?9 ?! \/ i& ?% V& b% q TPopupMenu *PopupMenu1;) i3 [0 o2 U: X$ ]
TMenuItem *Exit1;; [5 J7 x; }$ d0 n* z
TOpenPictureDialog *OpenPictureDialog1;
" c r! b* V8 \, w; q TMenuItem *Open1;9 w" v. B) i8 n: w% D, \( V
void __fastcall Exit1Click(TObject *Sender);
* W; R$ ?! S. A/ _1 S void __fastcall FormCreate(TObject *Sender);
; r6 ~; W) G: _7 Y6 e1 I8 ]% S void __fastcall Image1MouseDown(TObject *Sender,
4 I! }$ Y" w. C! T TMouseButton Button, TShiftState Shift, int X, int Y);, f4 u3 c5 w: j, J7 B! { }" E
void __fastcall Open1Click(TObject *Sender);
! L, g/ J& a" Iprivate: // User declarations
9 e+ @0 [. y* M# ] void __fastcall BmpToRgn();5 y4 n- t$ J' W/ m# h( M; v
public: // User declarations
2 @5 c" `" d( B3 {/ u( U __fastcall TForm1(TComponent* Owner);1 s- }/ W3 E! l
};4 [ a) P& C& G! ^4 \8 e
file://---------------------------------------------------------------------------
1 s. z4 W) S' S; B" d1 E" Xextern PACKAGE TForm1 *Form1;- e( R3 J+ j$ c1 a' h9 v' m
file://---------------------------------------------------------------------------: f, I1 G3 R: x. W/ Z
#endif</P>
7 c9 N' m2 g2 d+ d+ [< >
& n3 \5 j, _2 D5 |4 f& c2 K4 C2 O$ [/ i, x<a>file://unit1.cpp</A>
& a# P4 s, t& S) M! s8 G# Y3 Ffile://---------------------------------------------------------------------------</P>1 L1 J4 t3 F% p- F! ~
< >#include <vcl.h>4 a0 ^" y( z7 c( X( r
#pragma hdrstop</P>
g# c, t; K) M6 o- z< >#include "Unit1.h"
" h+ E$ i% v9 rfile://---------------------------------------------------------------------------: c. ]" f5 n. Z Q- {6 T
#pragma package(smart_init)
1 y! A% w% j3 Y0 L( o7 ]#pragma resource "*.dfm"
9 |7 \: ^0 ]6 A! a- e3 yTForm1 *Form1;
$ @; {) t" H) T; m; [' R% g& A0 xfile://---------------------------------------------------------------------------: b2 z0 @2 s9 ~* S1 y
__fastcall TForm1::TForm1(TComponent* Owner), ^# ~ n+ p/ j) P% S3 Y; Y8 v+ ^
: TForm(Owner)
* \$ S6 A7 M- P$ l' C. T! f& [{
& s/ m, d) |) [& M; |}
$ u" c/ E5 S5 a9 u3 afile://---------------------------------------------------------------------------# a8 p0 m7 [4 b; J! m: p. I X
void __fastcall TForm1::Exit1Click(TObject *Sender)8 j- h3 E. K5 K2 b) F, U: X
{5 k/ B9 b) E( ~' Q# ~2 ?
Close();
% \1 u3 z( V! G; Q; W8 q}5 p% e. X; ?2 ]8 ]7 r0 T' K
file://---------------------------------------------------------------------------</P>4 ]7 u( l7 [) f9 U
< >void __fastcall TForm1::FormCreate(TObject *Sender)! W( r0 T; p$ y* j1 N4 o
{</P>
1 c- _) C, i0 [( j< >BmpToRgn();! Q* S0 k* \- G8 t/ G' M3 }
}$ I- I2 h6 G ~( M( h/ X" y
file://---------------------------------------------------------------------------</P>
* N6 K z* ?: N6 H; y# A< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,( e/ U# q: a' V' Y3 Z! K
TMouseButton Button, TShiftState Shift, int X, int Y)% p1 R8 Q! n0 V- r. T" H1 g
{
9 L: ^# S( t3 I' f# g% p; Z* c" F: [if(Button == mbLeft)* \- V1 F3 O/ {; ^, w% N u* L
{
) E F7 K0 g$ d1 `+ L' L A ReleaseCapture();% N1 @( x7 J* ^
Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);) s1 P0 k# X% b' v/ ?) O G$ w
}/ Y+ O* F E3 f1 Z' Y) q
}4 ?4 y: f% C2 V( W" ?+ j6 C$ V) k7 @
file://---------------------------------------------------------------------------
$ L& Q' Q( G1 @. pvoid __fastcall TForm1::BmpToRgn()2 z% w z+ }% F
{
9 N6 p! A+ Q1 Z- KImage1->AutoSize=true;
9 e/ q& T5 E$ A9 x3 OForm1->AutoSize=true;
* V/ i' F' ?9 {% lForm1->BorderStyle=bsNone;9 s6 v- E' ?8 E4 k/ H) G! p
TColor ColorKey=Image1->Canvas-> ixels[0][0];$ K0 u4 s( ?6 V% A! M% R
int x,y;$ P1 {( ~4 B; g
int l,r;- ?1 Z1 T" O" H+ B4 g* b
POINT *a;
7 D5 Z% ^- `( k6 r/ l/ Zbool lb,rb;
1 F9 }' m* x7 v9 c! A3 W2 ?HRGN WndRgn,TempRgn;</P>' ?$ c) c; V$ x% X
< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)" j& z0 p4 f/ o: E" _
{1 n& U: n# u0 z$ Y/ G1 K2 x* w' |
ShowMessage("申请内存失败!"); D# P+ y7 r5 P4 n) C( a9 k) H$ p( d
exit(0);
! a) ^+ R$ L+ B; L5 x}</P>: }5 G* V) j! c* l1 {* U T
< >l=0;r=Image1->Height*2-1;
/ Z7 z' }- r3 T& y2 HWndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P># h5 ?4 E% i. g. A
< >for(y=0;y<Image1->Height;y++)' R- u H+ Q9 x; o
{
. {0 U. d* I$ v$ H4 f; Q( d lb=true;1 z% |) [4 v; h3 d* i
for(x=0;x<Image1->Width+1;x++)
( D8 \# U1 y! N if(Image1->Canvas-> ixels[x][y]!=ColorKey)! c9 N) v. X, t6 i5 X/ n+ k
{- I. E6 ~# Z* w* `
a[l].x=x;& t8 V6 w4 S p
a[l].y=y;
* X H$ U/ T" V8 A p4 X5 F8 @ lb=false;0 T" S4 c$ H7 o7 x0 R2 s
break;
/ I* o# y" O1 f }</P>
& k& M6 H z3 m3 O0 D$ l< > if(lb) a[l]=a[l-1];9 j' J" j; L2 ?! b' J
l++;
( A( i7 ^" z/ s- ~- B% B! J6 }" s% ~ rb=true;</P>: J# P# k/ H4 h
< > for(x=Image1->Width;x>=0;x--)
7 a3 h f5 N5 o. w2 |" ^ if(Image1->Canvas-> ixels[x][y]!=ColorKey)
4 e* j$ o7 g/ s; E7 k {' h/ i+ V: t: K: j
a[r].x=x;% j7 s' M% q4 T4 k
a[r].y=y;8 n J& B$ K, m: A0 u
rb=false;! C: `$ w# c9 b6 s
break;
9 m* |/ P5 i2 a {0 p9 x$ w }
6 x" o6 V5 K! O" r5 T if(rb) a[r]=a[r+1];
3 e8 W/ u ]9 n2 G }9 Q, P r--;* S- M1 E7 H% w; Q
}</P>
% B# s& ]5 w8 e6 w< >r=Image1->Height*2-1;, N" p! x$ z, ~& J" i' G. u
for(y=0;y<Image1->Height-1;y++)- g. J2 F! A( I" f/ P/ p; V
{
# a% I9 y5 e2 I+ v9 R+ A for(x=a[y].x;x<=a[r].x;x++)
' K. M$ J2 x8 \& n if(Image1->Canvas-> ixels[x][y]==ColorKey) A3 n3 {' s& K: I$ X- V
{! E# n0 _4 k' k1 N# H
TempRgn=CreateRectRgn(x,y,x+1,y+1);
' A% c& ~8 Z8 X/ R. }2 u4 W; g* B0 ^ CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);
, g- k# V7 |. L1 l7 \0 Z8 M* K DeleteObject(TempRgn);
+ [8 ~" o6 T5 x( m7 z }
/ j5 U3 X7 h* G8 ] r--;( _/ s4 w! X; _7 J4 [8 u" ]
}</P>8 a8 H0 Y- R" m: n0 j
< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
$ E) W+ k# U- w2 j' H- XTempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);
" L) \, d$ v; PCombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);% {4 j+ `2 r- s; s+ f$ `" R& Q
DeleteObject(TempRgn);
" b9 R X1 u5 g, Ldelete a;0 q, K% |% {& V; Z
SetWindowRgn(Handle,WndRgn,true);
( V1 Z% ~; a% e}</P>
( s# J, F$ A. x: R1 F: _4 k< >void __fastcall TForm1::Open1Click(TObject *Sender)
' w1 g! K. i# E, O6 m" J7 o3 M{* |" y5 j2 j& {5 z' `
if(OpenPictureDialog1->Execute()): T. H- Y# n G% {9 @: r
{2 U7 R4 M O( j7 e, Z6 w2 i( T+ P
Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName); ~4 ^* J8 M1 S
BmpToRgn();2 ^# V0 z" ^0 Q( O4 j) E( }
}! I' N& k0 Q* ?6 z
}7 O7 q) ~# ^7 I
file://---------------------------------------------------------------------------</P>
2 J5 v: g& }3 Y$ S* o2 X# R< >对啦,图片的背景色要相同。" j3 P$ V s5 \7 X8 s
图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>- z- u0 t' P4 F9 ?
< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------4 s# n' U+ v" i( B. p- R9 f4 [% k
void __fastcall TForm1::FormPaint(省略)% E! A; m$ l6 J$ z9 b4 V8 _$ y
{
) [6 G$ M' f' ? AnsiString ww;int bb;
# S. @) p7 V: j+ F- ~/ g$ m ww=AnsiString(Form1->Width/256);% t% h& `3 Q1 t) D7 g0 o
TRect MyRect;/ J) O9 _: n5 d
MyRect.left=0;' f+ M! u) o C& r, P
for(bb=0;bb<255;bb++) C0 C$ Z. _: z& B% d( o
{+ I# k* O! o9 |) _% N/ d8 P
Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);
- F' m) P a! p" I9 E MyRect.top=bb*(ww.ToInt());
# Q1 M8 o) K: u( b MyRect.right=Form1->Width;, L( q3 z3 q$ k. N
MyRect.bottom=(bb+1)*(ww.ToInt());
, W- U, k& K- m- b% x Form1->Canvas->FillRect(MyRect);" J2 g" C- S* `) ]- q* }
}0 R5 j) d- W3 P, {" q
} </P>
% c( V& `5 j7 F) O2 T# x/ n< >file://---------------透明窗体--------------------------$ L. I; P# w3 n& H# d" C
void __fastcall TForm1::Button1Click(TObject *Sender)6 I# O6 V0 |1 ^) E8 P
{4 _9 i0 ]: ~9 A$ @. c& G, d3 ^
TRect *rctClient,*rctFrame;
# b( i, v( o6 q* V HRGN hClient,hFrame;" h' J! o5 E- q- [7 m( A
POINT *lpTL,*lpBR;+ i3 L1 |2 C8 Y7 M5 }0 D; j2 f
rctFrame=new TRect;$ W! ]1 C$ I6 B* P
rctClient=new TRect;
, s% O ]$ M+ N! j! S lpTL=new POINT;1 G# ~: X# A \: G& d4 U
lpBR=new POINT;
" F6 G2 g7 _. A. g7 P GetWindowRect(Form1->Handle,rctFrame);! g' j9 N8 c( y) ]# j& R$ j
::GetClientRect(Form1->Handle,rctClient);) h0 x% Z9 T! V! D
lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;0 I: T) e! |* a8 ?0 o4 m
lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>
, H' G: z5 g! \+ s$ y% T+ O< > ::ScreenToClient(Form1->Handle,lpTL);0 t0 W8 x; L6 s% h! W9 z% ?+ k K8 [
::ScreenToClient(Form1->Handle,lpBR);. x. s- F9 b5 U) ], u
rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;" i+ ~, a+ }: w3 J+ G( L8 M* h
rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;
" {6 Q. q, {% o8 ?( O d% \ rctClient->Left=abs(rctFrame->Left);8 Q0 P& x* e6 _9 F
rctClient->Top=abs(rctFrame->Top);
7 _: `) I& x+ X1 ~, p rctClient->Right=rctClient->Right+ q( G3 i2 L" E( y4 x
abs(rctFrame->Left);
. T' m4 X& U/ {' U' i rctClient->Bottom=rctClient->Bottom+7 A, v, B# x0 p# @" B
abs(rctFrame->Top);
+ Q* z( s7 k$ J7 i& @) N6 t rctFrame->Right=rctFrame->Right+
4 P3 J( l2 l% j. H1 U% e" a. [" Y abs(rctFrame->Left);
- c1 F" t# D3 N) ? ]" q& I2 v rctFrame->Bottom=rctFrame->Bottom+& |+ b% K& a [; N' |
abs(rctFrame->top);! U" ]7 `; W% Y: a2 V5 J
rctFrame->Top=0;rctFrame->Left=0;</P>. Y/ U( k2 Z* p4 F' P$ X/ s! x
< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,
% S' H8 }5 Q4 r7 W3 b! i0 { rctClient->Right,rctClient->Bottom);
9 d* ^0 m! M8 j7 u7 o( n hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,$ Y, t, S; |4 {! p
rctFrame->Right,rctFrame->Bottom);/ ] v. l0 a9 g0 h7 j/ X4 q" Q
CombineRgn(hFrame,hClient,hFrame,RGN_XOR);. i& y) f h: I! E! Z& e! V+ Q2 h
SetWindowRgn(Form1->Handle,hFrame,true);</P>3 E1 J$ [ Q# ~- g
< >
% {* p+ u7 h7 M7 n% ^% p delete rctFrame;
+ \- |- I( u2 Z; r delete rctClient;4 W6 Y) o6 ?! @* F* b7 n
delete lpTL,lpBR;</P>+ f4 x* T" n) x) s
< >} </P> |
zan
|