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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
$ E* v+ Z/ H. P6 G; K) K4 h ?7 I Yfile://------------------------------------------------------------------------2 h( M8 d. _% Z2 W' g r2 ]
<a>file://Unit1.h</A></P>
6 P! }1 e P4 ~- t# O< >#ifndef Unit1H
# `' i0 f5 ^2 {7 |#define Unit1H8 G U8 T' N' a, ] I+ J" ?0 S3 f; O
file://------------------------------------------------------------------------4 c& s3 K( ? H
#include <Classes.hpp>
) j, s. b5 V7 {" @- _#include <Controls.hpp>' o) w, z" Z$ _( V
#include <StdCtrls.hpp>9 u( U" k v0 ?. U
#include <Forms.hpp>
2 i7 f6 _2 M6 N7 D#include <ExtCtrls.hpp>
9 C/ a$ c8 x$ x: f2 ?#include <Graphics.hpp>: F5 |, B# N4 z8 D0 I# o
#include <Menus.hpp>
$ y: ?% t; W3 J* |& z+ G M#include <Dialogs.hpp>
' a+ k/ q) _4 M* _2 W8 ^9 L! d#include <ExtDlgs.hpp>
6 W: M% o' s: }* U7 sfile://---------------------------------------------------------------------------' o$ E7 G& j O: E) [
class TForm1 : public TForm
6 k& r4 U* i% j, `( D{5 a* s: V& I. t3 n
__published: // IDE-managed Components
9 f) o4 o- A0 X* Q- t0 C TImage *Image1;' |/ E1 I3 X: X: g( I2 v6 v
TPopupMenu *PopupMenu1;- z K$ ~0 |% {1 t/ e
TMenuItem *Exit1;. r @# J7 p* S# L9 ?9 b# C
TOpenPictureDialog *OpenPictureDialog1;
1 ?% d4 u# k3 ^9 V8 M: M TMenuItem *Open1;; l+ S+ q {* y, H# N* Z! x' N, S
void __fastcall Exit1Click(TObject *Sender);1 g: I D8 A. W+ t% y! x! x
void __fastcall FormCreate(TObject *Sender);
j$ G7 q" ^7 {3 k0 c" r7 o( \ void __fastcall Image1MouseDown(TObject *Sender,
+ H2 _/ Z; _' f$ T* ] TMouseButton Button, TShiftState Shift, int X, int Y);% c- q# C @3 X0 n
void __fastcall Open1Click(TObject *Sender);
$ a, N& D8 M4 ]% h" S( cprivate: // User declarations. s. g) O9 p1 V) T) ?4 Q
void __fastcall BmpToRgn();
6 t7 F9 A, m5 t: y6 K9 N& t( V* upublic: // User declarations
: @4 C( B, E& x% ?0 s$ O, u8 a1 Z __fastcall TForm1(TComponent* Owner);
7 H& e2 I, Y$ q3 z};, {6 H* \8 L6 a
file://---------------------------------------------------------------------------6 C- Q' u1 V5 ]: C, T
extern PACKAGE TForm1 *Form1;
$ t" g/ ^# a/ V; n; m! \file://---------------------------------------------------------------------------
4 t; r, Y1 F5 H; I7 n#endif</P>
% N5 Y d0 L- S4 M< >
1 @5 }2 d( ^) W+ q2 h<a>file://unit1.cpp</A>3 H5 j. s' m4 ~2 e
file://---------------------------------------------------------------------------</P>
`8 x3 b1 N! ?1 t/ c! U< >#include <vcl.h>0 y$ s2 D0 o* P7 e
#pragma hdrstop</P>" X" Q# d: x& c, A; h
< >#include "Unit1.h"
( j# ~( R8 d* f, ~6 i" Kfile://---------------------------------------------------------------------------
1 R8 m2 D7 ]3 ~& A' i6 V( H#pragma package(smart_init)
8 R) T! u& \" _6 W#pragma resource "*.dfm"
, A8 C1 h* h6 c8 U4 tTForm1 *Form1;9 o) m# g [3 t( \! J m$ l4 B8 x* \
file://---------------------------------------------------------------------------
- O- H: l. i2 x% F1 Y+ O__fastcall TForm1::TForm1(TComponent* Owner)( g" _: z4 p0 c9 r- C- T
: TForm(Owner)
; G4 T$ t8 Z) U$ U{
! f: e) W* e: A6 ~& k}0 u( y, I5 {6 q
file://---------------------------------------------------------------------------- h9 X$ u; N! Y
void __fastcall TForm1::Exit1Click(TObject *Sender)
0 n) ~5 @2 M) V7 L# G; a{9 z* }7 e0 ]' G/ o: D
Close();. w$ K+ D1 p/ [* T! l6 [. [" V
}* ~7 p8 q. H& u) Y( i# w0 @* X7 L# u
file://---------------------------------------------------------------------------</P>" K9 ?% W# \6 }3 g; m5 o3 a
< >void __fastcall TForm1::FormCreate(TObject *Sender)
! i% C3 t4 M, @( B4 I: ?% q# u& Y{</P>
- F+ r2 |$ h* o6 Z5 }4 _, i0 L< >BmpToRgn();
4 X. r# o/ _* K; w L}
/ t! z- P. Z3 g6 H! X( Gfile://---------------------------------------------------------------------------</P># W# ~1 B/ _+ h" m, H; B/ X$ Z
< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,
0 Y6 e+ R% g3 o% t TMouseButton Button, TShiftState Shift, int X, int Y)
+ Z7 f5 c n6 _2 B0 Q' G{
5 \+ ]/ ?7 \' {- L- r8 B$ gif(Button == mbLeft)
/ F5 S; j; W) Q' C {
% a: J6 F+ z" j; O( U+ d4 ^ ReleaseCapture();
7 b2 @5 S. t1 }- B( p1 K$ h Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);' J2 e; l5 F) K& X, v; B+ A
}
" N9 H: S5 l& q! l1 f}
! e8 |6 r% a3 P4 b" Efile://---------------------------------------------------------------------------- \2 k# N$ l& d O
void __fastcall TForm1::BmpToRgn()
5 P: }9 {0 r3 _- W{
' S3 M+ t; ^. i) t% rImage1->AutoSize=true;
& x' t; i9 h. N( Z4 ^' UForm1->AutoSize=true;
, U& I& I( L1 D) K+ {Form1->BorderStyle=bsNone;' v$ Y, X. G4 V1 S* `
TColor ColorKey=Image1->Canvas-> ixels[0][0];( ?7 s2 w! ~+ g0 x, m4 _
int x,y;
; o- l/ \/ g8 P7 v v! D% A3 Y+ Dint l,r;( K) h$ {* p& O- B. l. _
POINT *a;
9 D' {0 X" p8 M% z. ebool lb,rb;- p7 y; f/ C8 z, o+ Z- d
HRGN WndRgn,TempRgn;</P>
% i6 Y6 a! O+ y' B& b- E< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)
% q2 S6 S0 Y+ p{# s3 _; P: T7 g3 i4 Y) P0 w- K
ShowMessage("申请内存失败!");
8 y5 @6 H: V/ z) d exit(0);9 Q+ e1 @8 i6 B, C; U
}</P>
/ H( A5 w: x' O2 ~) W< >l=0;r=Image1->Height*2-1;1 t5 i5 N# z8 Z( H* e
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>- D/ {* ]# n3 m
< >for(y=0;y<Image1->Height;y++)
& Y$ g9 u0 ]' |. V; y& J{
" Y: F' \0 m4 c1 S" ~2 a lb=true;" n+ O6 X8 E- Y8 I
for(x=0;x<Image1->Width+1;x++); B5 t& k8 y/ O
if(Image1->Canvas-> ixels[x][y]!=ColorKey)+ d# N/ m( [3 c% h' Z; o
{. Z8 e* F$ L* M3 m, {
a[l].x=x;
6 k Z4 V+ O" P2 d/ o a[l].y=y;5 F8 L. _& A+ Q1 z' z$ j6 V
lb=false;
4 w, }$ R$ |- M/ l" j! G2 L break;
! G- l; {2 P, Z, g# V4 B }</P>% h% g+ p- h6 L3 g4 ?, Z. ]2 [- j
< > if(lb) a[l]=a[l-1];
* r) |0 z g* v* E2 f7 ~5 M& @" ` l++;
7 O7 `' ?( m* i7 } rb=true;</P>
' P0 _. X1 {5 O1 k* E& b" ~< > for(x=Image1->Width;x>=0;x--)0 A0 x. S: N0 A/ L$ h; _6 h1 ?
if(Image1->Canvas-> ixels[x][y]!=ColorKey)8 b" f- G2 K6 q: D+ J
{% P9 o, c: U3 U) `
a[r].x=x;9 ]1 _' A. Y6 B& @2 g
a[r].y=y;+ ~8 Q* m; A6 P# |, K" ]6 O$ X
rb=false;
7 a% m7 S/ n9 h3 N6 _5 G4 U1 b break;
9 {2 R6 f) K- t8 d0 x I }# R$ e, f; p! ^( D
if(rb) a[r]=a[r+1];7 w+ v- p' ?- C2 ?/ G* I
r--;
" q% Z9 d) {- E0 z4 `+ v- o4 {}</P>1 X4 B' o9 W* q. m2 O/ p
< >r=Image1->Height*2-1;3 A) q( b, G( z7 d6 N2 p+ g
for(y=0;y<Image1->Height-1;y++)1 ?+ ^* X* b9 v7 ^6 ^1 F
{" r3 q4 {/ L) A* c
for(x=a[y].x;x<=a[r].x;x++)
% B6 c. X: m1 |# Q if(Image1->Canvas-> ixels[x][y]==ColorKey)
) x$ B X" m% C: v8 w {
+ P) {& Q* k. H0 v& ^/ P5 o TempRgn=CreateRectRgn(x,y,x+1,y+1);
6 P3 K3 w& X/ N9 F CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);
* r& Q9 V: j1 w! l' V, d" b8 j' e DeleteObject(TempRgn);
9 K8 j8 q: N/ @ }- O1 U; c. N3 n& a7 d
r--;
9 y3 F: t# K( H3 Y x. c2 ^}</P># [( H2 t( @- S' k
< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);/ O! X. \3 X; u& c7 }9 n0 X
TempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);3 |( Y* y) F* I$ O
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);
/ s5 |* q1 n+ U( pDeleteObject(TempRgn);
" m2 @& x/ s% W& z( P6 ]# ]0 tdelete a;
1 {, |3 @3 d$ N( p$ D/ K* l* J5 mSetWindowRgn(Handle,WndRgn,true);. f$ B- z; `7 v8 A* T# O$ U
}</P>+ N8 x6 f# y6 @* a
< >void __fastcall TForm1::Open1Click(TObject *Sender)
: f( V5 `, D6 M5 K& O7 H{5 u" Y. D: I7 M1 i
if(OpenPictureDialog1->Execute())% _! A3 A9 J& ]1 b/ H' ]
{
) ?& h! O3 n) J4 j/ | Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);" f/ I( s q% i3 w
BmpToRgn();2 T. ]' b9 k3 Z, D$ ~* T) E5 m0 r
}; k! u* N/ {% `) f$ A$ W
}1 k* `; v' q8 U2 v, ~- A5 _* I( ^/ y
file://---------------------------------------------------------------------------</P>
& J2 U* |2 c) c' y8 v< >对啦,图片的背景色要相同。; a# K: P! R& t f) x
图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>$ f- H" p3 y, {: I; H
< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------
7 |( y! G) {" Y2 @- J* Y* e- g7 Qvoid __fastcall TForm1::FormPaint(省略)
3 q7 k4 j/ n1 g) v/ f{+ I, l; J8 x% v4 I6 t$ H, B: c
AnsiString ww;int bb;
7 T# o& E) D3 \# q ww=AnsiString(Form1->Width/256);& D# e g S2 ^2 M
TRect MyRect; ~! Z3 F! q! L, [! r$ y) j
MyRect.left=0;% j4 G2 d1 ` {& o. {+ C A9 O ~7 ^0 \
for(bb=0;bb<255;bb++)7 S! z& N2 D% ^8 g( E' ]8 G
{
" `3 W* B' ^' ?" i( D Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);2 P% o6 X% z3 x- C
MyRect.top=bb*(ww.ToInt());
8 u# B$ ~9 m4 \2 _6 s MyRect.right=Form1->Width;
1 n# o- o# o3 X/ y# f1 \ P MyRect.bottom=(bb+1)*(ww.ToInt());7 F4 G+ `2 B6 e5 w; z4 U
Form1->Canvas->FillRect(MyRect);
3 [% B3 B N" G7 k }
% s$ T" m$ \* f. l, Y} </P>
! m# [. F; c6 K8 j< >file://---------------透明窗体--------------------------4 q+ b! {6 C/ e5 C0 G+ y; L
void __fastcall TForm1::Button1Click(TObject *Sender)' }9 \' P7 l* g0 A! P; k( |5 O$ }
{: P$ _' n# E2 s; b4 }/ X5 w
TRect *rctClient,*rctFrame;" @9 y8 m) S: h
HRGN hClient,hFrame;
! P. z! s/ A* N4 _6 }# Y* X7 o POINT *lpTL,*lpBR;; M q" o6 |3 I; w9 a
rctFrame=new TRect;' X9 |; i9 `$ u3 e# T3 a
rctClient=new TRect;- }* K6 c; U8 W* v7 d1 Q
lpTL=new POINT;
1 k/ S8 n K" X5 W. V" O% U; P5 f lpBR=new POINT;
7 p# M4 ^, B, {* ]2 X GetWindowRect(Form1->Handle,rctFrame);$ K! n7 q1 n$ G! f
::GetClientRect(Form1->Handle,rctClient);
) l% c& }+ H# y" l! I lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;- M, @% J- r: V) E
lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>
7 B/ G2 q4 _4 o5 Z< > ::ScreenToClient(Form1->Handle,lpTL);
+ l" @5 y8 j b4 Z) p% n- i2 Q ::ScreenToClient(Form1->Handle,lpBR);
# u0 y0 F& `! L rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;4 N+ U7 K' P" d/ }; l9 d; {8 c
rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;+ W1 j% Y0 G2 D, H1 Q3 ]
rctClient->Left=abs(rctFrame->Left);! O* M( e0 }8 t+ k! ]$ ^% `
rctClient->Top=abs(rctFrame->Top);
$ \/ Q4 t2 }/ o) p+ s9 O* O rctClient->Right=rctClient->Right+$ U3 G- W- l; ^ d, L! V Y
abs(rctFrame->Left);
( w4 G( P+ D: n, e rctClient->Bottom=rctClient->Bottom+* c7 w: N7 Q% e$ k/ R* S% @' d
abs(rctFrame->Top);- W, O# t- B) O' r% R
rctFrame->Right=rctFrame->Right+( c6 h3 t0 D: H
abs(rctFrame->Left);4 ?0 \) A5 y3 v1 R& o3 R: ` y0 W
rctFrame->Bottom=rctFrame->Bottom+
6 A9 q; k; u; V$ N9 S e4 f abs(rctFrame->top);3 Q* ^, L; v2 z0 g- R( {
rctFrame->Top=0;rctFrame->Left=0;</P>4 M- \ } X: B+ O7 O0 ?
< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,
2 U, i( P# E# M+ S4 m" h( t7 g rctClient->Right,rctClient->Bottom);
( A1 A% ~% v, d P! H# A+ |3 } hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,- t( p9 P: e+ p0 u2 H/ `" L( L
rctFrame->Right,rctFrame->Bottom);5 g2 W& y: E/ A
CombineRgn(hFrame,hClient,hFrame,RGN_XOR);/ }3 Z; Y; ]: f7 |1 r2 ~) @
SetWindowRgn(Form1->Handle,hFrame,true);</P>/ g( s% a' V# u+ U- D1 P; K! \
< >
0 I8 M1 b- Q0 t" l delete rctFrame;
6 C/ q+ ~8 o6 M+ P8 L1 q" X3 ~ delete rctClient;9 c& ~! s5 `* @
delete lpTL,lpBR;</P>
) v* b& A7 X' U0 s< >} </P> |
zan
|