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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
/ h. ~# ]9 S [( cfile://------------------------------------------------------------------------
1 O6 H4 t) |7 K% P2 r5 O: i<a>file://Unit1.h</A></P>
5 Z/ O- W, g! j. | ]< >#ifndef Unit1H7 o: x0 l% D/ K$ J2 k" h8 K/ s
#define Unit1H
7 `& O3 f8 P; G# P( D: ?, M4 `file://------------------------------------------------------------------------
6 p" X3 u a( _1 n" B#include <Classes.hpp>: E" |! P: P# A: I, ^0 y
#include <Controls.hpp>
0 ^9 U( q# S1 F#include <StdCtrls.hpp>; {: @ n" [( f& j6 }
#include <Forms.hpp>
8 m4 E1 N. }; ]5 H* @$ U- K#include <ExtCtrls.hpp>, I* @: Z8 i/ W) S) ~
#include <Graphics.hpp>: |5 x- K0 J2 n% g
#include <Menus.hpp>
0 k2 S U6 ^8 H D1 f# t3 U1 F#include <Dialogs.hpp>% M+ B* P9 s4 d2 L: B/ E9 s+ c, o
#include <ExtDlgs.hpp>
# q1 n L2 G5 Z! p* a; a% pfile://---------------------------------------------------------------------------
' O$ B8 ]# I; \class TForm1 : public TForm" F& \# V2 X" `% \/ U" X. _( E
{. a6 Z( l: G/ A$ `$ j( L! _
__published: // IDE-managed Components4 ~7 g5 R: z& I; E. H8 y7 J
TImage *Image1;
& ~- Y0 d' ?0 X% @- J TPopupMenu *PopupMenu1;6 m8 }# `1 w. B/ }$ D/ F1 d
TMenuItem *Exit1;
" v/ L% g8 D% m- e. P. k TOpenPictureDialog *OpenPictureDialog1;
8 C# e& z0 J: |* m5 f4 K2 @. I TMenuItem *Open1;
0 `" i- B( O0 D6 E8 k4 q" x) D void __fastcall Exit1Click(TObject *Sender);
) j0 [! L$ V9 b7 s1 q void __fastcall FormCreate(TObject *Sender);
! r, f1 J( b2 T8 U, K& z/ F# ]9 f void __fastcall Image1MouseDown(TObject *Sender,
- ?/ ?- l5 I0 t TMouseButton Button, TShiftState Shift, int X, int Y); n: \2 }) q- q4 ^8 V4 i5 z5 Y1 R
void __fastcall Open1Click(TObject *Sender);2 v+ P( G; e0 [; T! l7 h5 ~
private: // User declarations8 Y( ]% K' g) H$ l7 b
void __fastcall BmpToRgn();
8 A' w. u! \7 E# mpublic: // User declarations
- E: K& S$ Y) @. O e __fastcall TForm1(TComponent* Owner);! A O4 N g0 p7 B r
};' N$ B( O1 Q: ?% ` {
file://---------------------------------------------------------------------------' q Z" F& A! {4 b
extern PACKAGE TForm1 *Form1;8 V8 A0 l0 S P! x# X4 D# M- p
file://---------------------------------------------------------------------------! p* ~* q9 {' X! e5 {
#endif</P>, T" V* ~9 j; s5 B
< >
! p: f, O8 W2 X; O* ?<a>file://unit1.cpp</A>" V; J. `- [8 h. z: V7 u2 x. X
file://---------------------------------------------------------------------------</P>
+ `: Z2 f3 l+ ~5 l+ i* f< >#include <vcl.h>
$ E4 z! a H4 [4 ]#pragma hdrstop</P>, U) A7 g" R7 c2 ?+ p, {; [
< >#include "Unit1.h"8 Q! w( U# f6 D0 o& r; ]9 \+ K
file://---------------------------------------------------------------------------* _5 z1 r Y+ d5 R& L; Y+ P& l* r
#pragma package(smart_init)2 W2 d! n3 H. |
#pragma resource "*.dfm"& M! \7 |5 P1 V }. e% @
TForm1 *Form1;
2 i, D0 G' N& `7 I$ m4 d- Pfile://---------------------------------------------------------------------------
1 L/ M% p7 U9 H9 w! a* i. @, A9 E__fastcall TForm1::TForm1(TComponent* Owner)' a' W" J5 N7 U+ T' b9 x4 ?
: TForm(Owner)
$ p- m9 t6 r" E( O3 S{
. t3 m: ?7 ]0 _* b& x# H6 m}
( f2 B) B6 ^& ^" [# d& X% `file://---------------------------------------------------------------------------' O/ u/ i+ O% ^9 L: S
void __fastcall TForm1::Exit1Click(TObject *Sender)
$ K- p5 I2 \' H4 n) y) g{
+ C, ]+ n1 J1 }1 S( _ Close();
% \* h$ U1 ~9 {4 L6 k& S" e}& F" j6 r8 \* i+ f
file://---------------------------------------------------------------------------</P>
6 H/ }) {9 p9 j# C( `# g8 Q< >void __fastcall TForm1::FormCreate(TObject *Sender)/ S3 \# p8 S) _: C4 X
{</P>
* G1 T: G* l5 v< >BmpToRgn();
0 C: I' g) I0 @4 u5 h6 |}) }8 d, N& K9 \, A H; ?" W g
file://---------------------------------------------------------------------------</P>
( A" h& {, c4 k; I< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,; M) ?/ q! k9 W) V5 h7 N4 k# K
TMouseButton Button, TShiftState Shift, int X, int Y)
2 r! s; f3 P8 D+ C" n5 {{: O) k! I9 t- {9 U8 X ]. e1 {
if(Button == mbLeft)/ z/ ]; x( u0 n" t& h4 H
{
1 V9 m) Q( |- c, U0 l% ?5 ~ ReleaseCapture();4 u& B' O' o1 A
Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);
E5 u2 B- s- ]" j9 [7 ` }
7 t4 P7 a( u# e) c6 D: L- P}
; k$ y7 u1 z6 ], ^file://---------------------------------------------------------------------------
3 \" d$ `' \# r. G1 T) F/ G, cvoid __fastcall TForm1::BmpToRgn()
% P& q; ^' s' ]/ V{) u" U* R9 H2 M$ F/ [
Image1->AutoSize=true;
; P* R. M" N0 p( b! Q( B$ OForm1->AutoSize=true;( A$ G4 U- l) ~4 [7 K5 i8 S
Form1->BorderStyle=bsNone;7 O# K) v9 i G" e8 p
TColor ColorKey=Image1->Canvas-> ixels[0][0];
2 e1 n, R/ F sint x,y;
0 I7 g) i0 ` q' i+ Jint l,r;
. c! g3 S4 P1 RPOINT *a;. u. w# c/ S. Z8 H1 f
bool lb,rb;$ Z. C5 z A8 F
HRGN WndRgn,TempRgn;</P>8 _9 q9 u! v) H9 r1 \9 ^
< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)! I+ c: P9 k" T; g
{1 O+ L( g2 j, Y# ]3 n, p
ShowMessage("申请内存失败!");, P6 A& h# B9 H2 m, d2 i( e
exit(0);
1 H$ p( c9 _. }$ T9 O8 A}</P>) I% V/ j) H" M) I. [
< >l=0;r=Image1->Height*2-1;
. ?3 |* J/ g6 c$ ]WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>
! M" f$ X5 J+ l8 B: t+ q# x< >for(y=0;y<Image1->Height;y++)
' [& b" t z% E, t3 L% S{& p/ L7 e# [4 J7 D. \! ^
lb=true;1 d' d6 b0 e4 p% J
for(x=0;x<Image1->Width+1;x++)
: j/ }. j" G4 r+ R if(Image1->Canvas-> ixels[x][y]!=ColorKey). X+ f o! V( c2 O. i1 O: ?! X2 b
{
6 J; C7 z: w) M+ D* j f a[l].x=x;/ L( n! b" t* g7 Q6 N" ^/ g
a[l].y=y;$ v3 u9 x) t9 [: N. f) a: u8 o! s( i
lb=false;) `$ h% t; a, w4 h1 n1 b, s
break;+ h2 Y- W2 D! o% v, c; A6 R0 A3 S8 E
}</P>
- Z- _3 L7 X$ y" _# r7 X< > if(lb) a[l]=a[l-1];
4 [( p5 Y$ d2 J3 H l++;) e$ H4 O# r# q, ~0 H
rb=true;</P>+ S* _) d$ C5 K! Y1 m5 O/ P, w' ^
< > for(x=Image1->Width;x>=0;x--)
6 U& u. T1 i" E7 G5 f4 j' @( @. d+ c if(Image1->Canvas-> ixels[x][y]!=ColorKey)
1 U* `: E4 `2 ^% z {
! z" y* q. t1 }7 f/ V3 R, I a[r].x=x; T6 C" S1 \" [, L3 O
a[r].y=y;; W9 q1 C1 g" o% c
rb=false;
6 P% [" Z. y, R( I9 t* C break;0 T+ N0 e, [9 b! ~7 `" l
}
( p$ U$ i, r* u6 q4 ~! k5 e( Q if(rb) a[r]=a[r+1];
# _+ Q" f/ y3 Q+ l" | r--;
$ H, w8 M6 b( n& f1 t}</P>
. ]/ S( f. s2 n< >r=Image1->Height*2-1;5 x4 B! r( E+ `/ S) |
for(y=0;y<Image1->Height-1;y++)% f7 X" \+ W ^% }$ N
{
0 n$ f0 ?% b. N+ r) L for(x=a[y].x;x<=a[r].x;x++)
& ~1 ~! V( [! c- O9 b2 w if(Image1->Canvas-> ixels[x][y]==ColorKey)
0 ^* @/ ]) p4 [8 n1 X5 Z& W( v3 g {5 o2 f! J8 G' z1 s P# I
TempRgn=CreateRectRgn(x,y,x+1,y+1);0 \! v5 K% N2 P
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);
. R+ T$ J2 _+ x9 o2 t/ G$ ?0 C0 U' [ DeleteObject(TempRgn);& j; w- D$ y7 K$ m
}' `& `% b; N% i
r--;
' J9 |% g9 O1 ^" `; J+ K' @$ `}</P>
# J6 W" G+ _) J+ b< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
% F8 D0 R6 u& q B) N! OTempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);% `3 e9 ]/ O, ^
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);: [3 [* g3 n) J3 g B u
DeleteObject(TempRgn);
+ C+ G; \9 `: q5 w( Sdelete a;
# e, y1 ~$ J, [& jSetWindowRgn(Handle,WndRgn,true);
0 @8 ]4 h+ W+ d* C8 P}</P>
6 e6 k: k6 W# ^' {9 C7 r% [< >void __fastcall TForm1::Open1Click(TObject *Sender)) S2 x) e: o( Z( _5 h
{
( i% K% l( b. W, s! V if(OpenPictureDialog1->Execute()). S( c3 N8 @9 i B
{
& | K6 l0 a5 v1 N Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);
1 z5 m* M6 Q' A BmpToRgn();
+ `3 Q, p- u Q4 [" P }
5 |0 n' X2 x8 Y7 E}9 A: c2 P: b% r1 g. p* b
file://---------------------------------------------------------------------------</P>% M# \/ E9 Q7 K B( o
< >对啦,图片的背景色要相同。
" o, }7 G7 Z2 d8 A" D% I图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>4 q% T {8 h) Q
< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------* Q( ^' F# X3 G4 G
void __fastcall TForm1::FormPaint(省略)% l* u3 k, c( m1 `5 B5 k
{& Y' X6 ] h4 T; h: t- r5 t( B
AnsiString ww;int bb;
) o- K0 z" T% |8 \6 k8 w ww=AnsiString(Form1->Width/256);
1 Z$ Y" W; J& G% @5 R6 G) h TRect MyRect;
K+ M6 s' j7 f+ W3 s2 m2 n MyRect.left=0;
5 H- C/ T0 o, S9 b; e! ?, @ for(bb=0;bb<255;bb++) w* l3 x5 g% @# j
{
B$ l& k& b3 i/ Y3 ? H Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);9 G. v$ B4 |5 ^/ Y' }7 I- R6 I
MyRect.top=bb*(ww.ToInt());
6 c: A6 U9 B7 N3 w4 Z% e MyRect.right=Form1->Width;
9 l" d! h5 }) p, [! [ MyRect.bottom=(bb+1)*(ww.ToInt());2 x- j0 z: M7 B' m: {! ]( g
Form1->Canvas->FillRect(MyRect);+ w, @& M0 O8 J F9 w
}
+ K2 {, [: I" b/ x2 G} </P>; ~0 r1 }0 ^/ X$ }
< >file://---------------透明窗体--------------------------8 w3 j; K4 i) X4 ?! _# |; a' @! K
void __fastcall TForm1::Button1Click(TObject *Sender), c1 w4 B/ K1 S" O
{
0 i1 r3 p: a5 _ TRect *rctClient,*rctFrame;: o8 a$ l2 i4 L. [$ N5 ^. `; t# w
HRGN hClient,hFrame;
5 @ P7 P: h1 ^+ a$ @: M8 J ? POINT *lpTL,*lpBR;
) i+ }& K' F$ ] rctFrame=new TRect;
" C% K# \+ b' \ rctClient=new TRect;
& d" K4 M- F! h lpTL=new POINT;) T6 z5 I5 e% | Z8 f# Z" O- e- E
lpBR=new POINT;
+ w. \6 l' o' U4 | GetWindowRect(Form1->Handle,rctFrame);
, D* H- q# l" t* v( V0 d ::GetClientRect(Form1->Handle,rctClient);$ q( M J0 a: Z9 _8 T8 i
lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;( N6 ?6 D% G9 S1 \1 |- E) g0 z% j" a
lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>4 U5 N+ p5 `( ]. F3 R) t5 c
< > ::ScreenToClient(Form1->Handle,lpTL);
0 p+ E- A+ p5 L/ Y0 h2 [ ::ScreenToClient(Form1->Handle,lpBR);
4 Z# s/ Y) m6 _$ ~" ~1 L rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;
% x8 q1 _1 L- d& E rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;8 R8 f+ U T( c) R7 ]
rctClient->Left=abs(rctFrame->Left);6 t; b; m/ e5 o C. }
rctClient->Top=abs(rctFrame->Top);; Q) G! R. \1 U4 d. t
rctClient->Right=rctClient->Right+/ M& v( Y& F6 [' q6 `/ s( ~$ [
abs(rctFrame->Left);! H! Q4 A% R/ K$ ]9 X( Y
rctClient->Bottom=rctClient->Bottom+3 ?0 H/ @/ }2 b3 b n
abs(rctFrame->Top);
8 u$ d0 o4 s. t1 w rctFrame->Right=rctFrame->Right+
7 e; P2 S, {/ m abs(rctFrame->Left);
! G3 \ v2 r F$ @) i- G rctFrame->Bottom=rctFrame->Bottom+7 U: m2 p* Y. \( `% O) {. p
abs(rctFrame->top);
( [( c6 D. V) h rctFrame->Top=0;rctFrame->Left=0;</P>0 ]) Y6 |! q0 z. c5 F) c
< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top, J2 h* q: d9 I' ]
rctClient->Right,rctClient->Bottom);
, }) g8 h6 b8 B# {$ y hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,
1 i. w1 K0 v& H }# W rctFrame->Right,rctFrame->Bottom);
& ]) D: T. h4 U& d CombineRgn(hFrame,hClient,hFrame,RGN_XOR);" y6 [2 {' Q$ T' a) c ^: g
SetWindowRgn(Form1->Handle,hFrame,true);</P>
; Q5 ^0 k/ D: N$ h4 M< >
7 |1 T/ E# O& I! j, C delete rctFrame;$ z' C( i0 ^; t8 ^$ u
delete rctClient;
! n+ Q, A* c; A; T delete lpTL,lpBR;</P>
" M5 o$ z& ]# @) N: k( N< >} </P> |
zan
|