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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
8 s( w: e: y* q3 i1 V: S+ mfile://------------------------------------------------------------------------
* n2 x% w! x& n! s$ o X! E<a>file://Unit1.h</A></P>9 K- X6 |$ D$ A; {2 _/ G
< >#ifndef Unit1H8 e5 S& c6 `5 }/ J
#define Unit1H
" s: g6 e( W2 ^# D- z( Nfile://------------------------------------------------------------------------: v+ J- i) b1 g$ G
#include <Classes.hpp>
5 m* d/ ^/ M1 n8 I#include <Controls.hpp>
0 D- Y; j5 W$ a* l#include <StdCtrls.hpp>. d) K+ s& g0 e/ g
#include <Forms.hpp>* }' @! x& ^7 J( L6 F
#include <ExtCtrls.hpp>0 r, F c& V! g3 R" ?5 s' Z" n
#include <Graphics.hpp>
3 T3 B2 S3 G1 `- R/ `: B! n/ i#include <Menus.hpp>
7 x9 [' f6 `' t) w! S#include <Dialogs.hpp>; v- g" T& C$ p' t
#include <ExtDlgs.hpp>
$ I4 T$ k+ X0 u; Lfile://---------------------------------------------------------------------------9 c4 t/ A# s1 `# @6 L
class TForm1 : public TForm2 I+ q! I; d8 q: l
{( f& a% w2 r4 e/ ~4 R
__published: // IDE-managed Components7 N( T& _% ~9 s' k% y& L
TImage *Image1; @) s) K; n) y6 {+ K" d4 x
TPopupMenu *PopupMenu1;! g/ L- I+ O7 x6 P b' o
TMenuItem *Exit1;
4 x( R5 e" o5 R/ ]2 \& c, r, R% | TOpenPictureDialog *OpenPictureDialog1;) Y: j* |( g8 H. B {
TMenuItem *Open1;! _+ s' ^) c; C+ J; J u+ m
void __fastcall Exit1Click(TObject *Sender);: e- K/ \9 x% e# N- q
void __fastcall FormCreate(TObject *Sender);
. h0 c! z9 F6 f, n8 | void __fastcall Image1MouseDown(TObject *Sender,% p& V7 V4 U& ~, s1 L
TMouseButton Button, TShiftState Shift, int X, int Y);& v6 m5 x' ~: Y
void __fastcall Open1Click(TObject *Sender);
: k2 e6 S/ n* j/ n6 tprivate: // User declarations( y) Z/ H+ ?- B+ {% \' w9 d, q
void __fastcall BmpToRgn();7 y$ _* a9 o9 Z8 _0 c( @. a
public: // User declarations
& W( ~' f- o" v$ ^! X2 V __fastcall TForm1(TComponent* Owner);
/ M6 O5 [3 V. F3 M, [};* p3 n& N- e0 T: T2 l$ ?
file://---------------------------------------------------------------------------- ^" d& C" o& C ^, B4 `6 T6 Y! w6 n
extern PACKAGE TForm1 *Form1;
! E2 f! M8 }% i) e& F* [3 y5 Ofile://---------------------------------------------------------------------------9 v, q) i' v' O: t" W1 p6 r
#endif</P>( {+ P0 F5 Z/ V/ `. h* E4 p! E0 b: s
< >0 H9 J0 b$ y7 o% K
<a>file://unit1.cpp</A>
+ h; T j2 K# ^) p1 w1 E: _& Ffile://---------------------------------------------------------------------------</P>
! B- k6 f# k) t8 g< >#include <vcl.h>) ]2 G1 B+ X9 m) k% M; \" |7 n
#pragma hdrstop</P>
, p# U0 f8 @% ^$ D/ D B% g: b< >#include "Unit1.h"8 D4 S& l( ^4 S \$ r2 ^5 k
file://---------------------------------------------------------------------------
3 [# u( ~* q4 H* G, \#pragma package(smart_init)
( T0 L5 D8 i: [; \#pragma resource "*.dfm"
- ]: q" J; [( r' i* M) U- A7 fTForm1 *Form1;/ l3 ^& g3 w6 W4 ]
file://---------------------------------------------------------------------------. e5 Y% s* v8 s6 B
__fastcall TForm1::TForm1(TComponent* Owner)
7 a9 q2 f! c9 b! o) J9 A : TForm(Owner)) w- J Y& Y2 v1 O% [
{1 ~* B# |- w; g0 W1 E) e* f
}
0 p! N6 w: a+ Sfile://---------------------------------------------------------------------------
: h$ u# R! f, ?9 ? S" H/ n5 Yvoid __fastcall TForm1::Exit1Click(TObject *Sender)
]) G/ D3 y+ }6 i2 d{) {7 z/ h' d9 K
Close();
: I: z, m6 I4 k0 ]9 ]}
' N4 B+ `( y3 c# tfile://---------------------------------------------------------------------------</P>- r0 R% N0 a% B
< >void __fastcall TForm1::FormCreate(TObject *Sender)& ^' N% j7 o- j' z1 g% X
{</P>
: I& m7 p* t; f. `6 M< >BmpToRgn();) R$ L9 a7 F$ z; {) O/ N" w0 j: M
}
( o9 u: a! p1 tfile://---------------------------------------------------------------------------</P>
8 }, m8 v) G7 \3 L# }2 l7 X. k" p< >void __fastcall TForm1::Image1MouseDown(TObject *Sender, F" R# v( h/ g+ }* B3 a: m
TMouseButton Button, TShiftState Shift, int X, int Y)
( ], c' \8 @ F. m{1 z9 b' k4 r6 A! m
if(Button == mbLeft). P5 C9 h: ?4 z# H
{
( [3 N n. B! p5 k6 d ReleaseCapture();
9 l' r. a. L) j4 _ Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);: p7 Y3 C5 e& c! ~2 A% d4 h% O/ `
}4 X H" A, ]& {5 r
}
o; ?9 l6 X& o q/ xfile://---------------------------------------------------------------------------
# j; ? K: k" {void __fastcall TForm1::BmpToRgn() s- e$ O; J9 d* `. o* L( {, L& t
{
1 _' Q( }; |% `4 J; gImage1->AutoSize=true;
+ C0 K; c5 F6 |% K; T6 U6 YForm1->AutoSize=true;
9 x% @4 ] j( F. x2 k6 R5 y7 _Form1->BorderStyle=bsNone;
. a. V3 I" Z/ U- yTColor ColorKey=Image1->Canvas-> ixels[0][0];
: H" J" O {/ I& `/ J1 x/ m- cint x,y;# R* y% X* q. w' h z, ~ L# E* ?
int l,r;
; }# B. _: V1 j8 zPOINT *a;
. Q3 d t! m5 Q9 T* \" qbool lb,rb;
5 R0 Y% H+ c' F1 u! ~; t" C7 \HRGN WndRgn,TempRgn;</P>9 H0 A" P6 l# y
< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL), X- [* ^" S6 O s5 o
{# r2 ^% n5 X' M, c
ShowMessage("申请内存失败!");" Z1 H" M T) d6 c- B/ y% ^: x
exit(0);" j. d/ Q7 c; Y N
}</P>. y+ X# ^8 P; l$ Z) l7 L
< >l=0;r=Image1->Height*2-1;
& t( T( r: N# {4 R" pWndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>& U7 ?6 \. A! D
< >for(y=0;y<Image1->Height;y++)
4 d; E. S6 t: x; t. J" ^{% O4 b* E4 u0 _: h! ~- O
lb=true;
( Z$ m! k S0 X; F% U for(x=0;x<Image1->Width+1;x++)
* v9 }: ~4 e: | if(Image1->Canvas-> ixels[x][y]!=ColorKey)
2 ^, G- f9 d: U2 U' m' b {
+ e. A+ U7 q$ ]0 X0 t0 a$ r$ e* R a[l].x=x;
% F( V; C' {- L7 Z2 M) o! k a[l].y=y;" A! m3 R; V" t6 @" l5 \
lb=false;! n$ y: S e6 Q
break;5 z ?* R! s" [7 ~5 ~* t" J
}</P>9 l j9 ?" V& P# z3 s1 t
< > if(lb) a[l]=a[l-1];' l% c; c( \8 A* m1 f/ V
l++;( E" m/ z: w7 D- Y8 U- N) ?+ u
rb=true;</P>
' ~0 N+ ~0 m D; K6 u, x, L< > for(x=Image1->Width;x>=0;x--)
% L& K' T& [- i8 C, J if(Image1->Canvas-> ixels[x][y]!=ColorKey)# Z8 P% x3 k& l$ R7 ~/ |
{
7 q: q" w1 J' m9 J/ a- g2 `. v a[r].x=x;
8 i: B9 @1 I! @5 V3 r a[r].y=y;
, G* K5 {% r5 Q9 G2 | rb=false;
% r' r7 O& m& H" e break;* _( y% A. k" ~- N G
} t# l8 A' q6 w4 M# G, a& U
if(rb) a[r]=a[r+1];4 ^7 Z3 x: \: \1 ~
r--;8 F2 t$ C$ X5 m
}</P>
+ R O6 o3 p) W. V9 N0 c< >r=Image1->Height*2-1;
7 `! y8 [* ?( G& n. G4 ]; ~for(y=0;y<Image1->Height-1;y++)
, ?+ @% _( p" w0 L$ E9 q0 A{" Y7 p( T4 I* {
for(x=a[y].x;x<=a[r].x;x++)3 g- g& [: e- k# ]1 \9 k
if(Image1->Canvas-> ixels[x][y]==ColorKey)
% s& t6 k( P: A6 t {
& ]5 B r" S# U TempRgn=CreateRectRgn(x,y,x+1,y+1);
4 c( j$ {9 b, b7 v6 K CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);, l$ M6 c' x$ m# p- @* N1 |
DeleteObject(TempRgn);) d. ^- E# F/ W& p6 \
}
0 s' Y' B+ |( m( h$ X6 ^ r--; M# y9 B2 l$ Q7 m6 f4 ^) X
}</P># s8 Z) b* C: F% p6 \+ a
< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
* {. f* m2 S" C8 i9 T$ YTempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);& C7 S) r H3 n: L
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);' h% g4 L# m( [4 {2 L
DeleteObject(TempRgn);
7 G, K5 Y* l) O! @! L2 X2 }. ^# Cdelete a;
5 _/ e5 P, S6 x9 dSetWindowRgn(Handle,WndRgn,true);
3 s, \5 Q; @8 o0 x) ^, ~1 d}</P>8 G, ]/ T9 R" o! n) H4 |0 N; t# k5 a
< >void __fastcall TForm1::Open1Click(TObject *Sender)& g: O4 }2 p" k# K) w
{
/ F0 o7 j( Y d' K' ^2 B0 }+ o if(OpenPictureDialog1->Execute())4 C: M, V7 D! @2 G% X1 B
{" o0 e- i9 q( `( b6 A6 b
Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);1 D/ E# ]+ V6 W& t
BmpToRgn();, r& {" ? ?0 P
}1 x: h' w9 s0 Q+ P0 G W
}8 a, K3 n$ |% h/ c3 l
file://---------------------------------------------------------------------------</P>1 l% D2 H3 E; L- N' ]+ [; B( g
< >对啦,图片的背景色要相同。
/ U8 b. {/ } B" M# ]3 W图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>, D; g& {! j+ A6 h) F- _3 z
< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------
8 \/ ^8 \' w9 U8 D/ Lvoid __fastcall TForm1::FormPaint(省略); l) Q9 o& P: o# J) }/ }
{6 g5 o) s% I8 t+ H* k$ n
AnsiString ww;int bb;7 [. x( d. d, f' ?& C
ww=AnsiString(Form1->Width/256);5 f* c8 c9 e0 i+ l1 P, F
TRect MyRect;8 P! A' a$ y1 d* w! y
MyRect.left=0;! }5 ]6 k- w9 c" d' M
for(bb=0;bb<255;bb++)
) e2 u$ K/ N6 h% r A0 @+ n5 c& g2 A {
7 U4 j7 W) q( p c0 a( L) N Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);
) ~! Q# q9 e; p6 P* K% @& z MyRect.top=bb*(ww.ToInt());7 K5 a C' E' W
MyRect.right=Form1->Width;
. h. v3 Q* H+ F" b1 H4 z! e* n MyRect.bottom=(bb+1)*(ww.ToInt());
- v5 _' z, |5 t$ r. c Form1->Canvas->FillRect(MyRect);1 S; A% U; N% E
}
S8 I+ \' W9 s# |5 Q% Q} </P>
" ~ _) g8 n3 i! a: J- S/ y l. v< >file://---------------透明窗体--------------------------
) |/ x/ ]" |4 c2 Wvoid __fastcall TForm1::Button1Click(TObject *Sender)7 e4 s6 f% q1 R* a; C) [( C
{$ X: ?" ]3 y+ L; [% W! n
TRect *rctClient,*rctFrame;) A Q. I7 ?3 l$ [, m
HRGN hClient,hFrame;
# @; p9 g \5 M6 R5 Z; M POINT *lpTL,*lpBR;& H$ r& x8 M% K* N6 c0 a! U
rctFrame=new TRect;
0 o9 F8 h0 J9 C A rctClient=new TRect; N" O9 c+ H3 l
lpTL=new POINT;2 C, w% Z! [9 X! ~1 O
lpBR=new POINT;$ ^0 d# v* F: A' ^ ^9 [6 E
GetWindowRect(Form1->Handle,rctFrame);
( p% K8 Z* X! c+ \0 @7 n ::GetClientRect(Form1->Handle,rctClient);( @$ ^: e' S& R" h; g
lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;' ^* p) x) E% R) v4 D
lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>
* h$ ~- | j4 Y/ \7 C# X< > ::ScreenToClient(Form1->Handle,lpTL);
" f' w4 ^+ a% x# K! x/ K4 q/ x ::ScreenToClient(Form1->Handle,lpBR);
9 R+ x, _3 N9 e/ N rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;
& O8 w9 k H; t; n- J+ m" d. D% e+ g rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;
6 r% f' X, _% Z9 n& q rctClient->Left=abs(rctFrame->Left);7 [$ T4 G! D* A$ q5 J7 K
rctClient->Top=abs(rctFrame->Top);
2 a; _3 c9 {2 g9 \! R rctClient->Right=rctClient->Right+! X% ]" y* W! J {
abs(rctFrame->Left);
- p0 n8 d$ r# p4 s! c: V2 u rctClient->Bottom=rctClient->Bottom+
) N6 N' l6 x; {5 ~% O$ J# n2 Y abs(rctFrame->Top);% q; N/ k( C7 G8 x- |
rctFrame->Right=rctFrame->Right+. C5 n' |3 d) ?2 w# q) j; s
abs(rctFrame->Left);1 E& H7 W0 T! s: ~ P
rctFrame->Bottom=rctFrame->Bottom+
' k4 V* O7 U- F, `+ Q* z; z9 \2 C abs(rctFrame->top);9 l d$ J8 S1 ]; A# x$ X8 y' A% i0 I
rctFrame->Top=0;rctFrame->Left=0;</P>0 S7 p5 _( ]$ l1 K8 P7 R
< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,
( v" ?5 u7 g4 [& J4 F9 W5 T8 F rctClient->Right,rctClient->Bottom);
8 q7 `$ Z5 V* P hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,
. q/ r" L# o% y$ Q# p rctFrame->Right,rctFrame->Bottom);2 P, P# K6 `: `: B3 }$ W$ J1 X
CombineRgn(hFrame,hClient,hFrame,RGN_XOR); |+ y+ w8 O3 l V3 b$ [
SetWindowRgn(Form1->Handle,hFrame,true);</P>
: j* x m/ o8 U) n! |7 N. ~< >
7 J1 ?$ F. O2 @% s1 G: J delete rctFrame;
; t8 B" m* x V) N7 ` delete rctClient;
, e$ Q% U5 n" V$ g+ ?9 B, e H( T delete lpTL,lpBR;</P>
) w; G; i$ e+ z2 C& u! n< >} </P> |
zan
|