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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。/ _% m2 M+ g2 `; n
file://------------------------------------------------------------------------2 k$ O0 `4 g0 p* G1 H( d% ?% p
<a>file://Unit1.h</A></P>
2 S9 V& x2 U3 W% V9 T l$ `< >#ifndef Unit1H
9 I3 ^8 {/ J' o+ ?* e#define Unit1H
# p3 v+ s b% N( C7 y' Sfile://------------------------------------------------------------------------
# s& Y* Q4 H6 ~#include <Classes.hpp>
! X7 Z' a8 T3 Y. ]% S: w#include <Controls.hpp>
, J/ u" x5 M8 S; o#include <StdCtrls.hpp>$ \8 T0 b& m# m* Y9 z- R3 u6 s& C
#include <Forms.hpp>* @- ~, p1 V0 }* K, M* f9 n
#include <ExtCtrls.hpp>& e9 `3 J) M: E3 ]& f5 `( X
#include <Graphics.hpp>
: ~) Y. ]5 c7 d$ S/ B% U, s#include <Menus.hpp>2 ?7 w) F I V3 [. f
#include <Dialogs.hpp>
1 O) n& Y% [% G- t$ q5 k#include <ExtDlgs.hpp>; N- z" f) g$ f- d1 h6 b# N. S0 A( b
file://---------------------------------------------------------------------------% m. U% X$ V, w F [
class TForm1 : public TForm
/ U: C5 f8 d8 l+ O) F{+ l% Z& X7 ~" T. B3 p% |! h
__published: // IDE-managed Components
0 p! {& O& M K4 ~0 x* y0 n TImage *Image1;4 i x1 _1 I1 f- v( |) `
TPopupMenu *PopupMenu1;
, s# v6 {" }; p9 e$ a TMenuItem *Exit1;- L8 s o! [% P
TOpenPictureDialog *OpenPictureDialog1;2 G6 u& O0 g: m7 R( m
TMenuItem *Open1;% z$ j% D3 S9 x
void __fastcall Exit1Click(TObject *Sender);
" p! T: ^; }" _8 C5 K7 i void __fastcall FormCreate(TObject *Sender);
; t! r4 A4 O p* _ void __fastcall Image1MouseDown(TObject *Sender,
( B, w+ J2 M I+ Q TMouseButton Button, TShiftState Shift, int X, int Y);
7 ~ W- m0 W2 L0 z" p void __fastcall Open1Click(TObject *Sender);
3 A" }. A7 C4 c. Uprivate: // User declarations8 M( e# J/ b& P' x" v, ]
void __fastcall BmpToRgn();
6 E" a2 \8 w7 Rpublic: // User declarations
. d9 Z+ p: b% F __fastcall TForm1(TComponent* Owner);+ S2 u( i$ ]: f; ~
};! ^* [' B: z& e; ]) I3 `6 n& m
file://---------------------------------------------------------------------------! [4 j5 f9 O6 k, q8 b6 }) E( w7 A& F0 D
extern PACKAGE TForm1 *Form1;- A, k' n) s" |* k0 V* p
file://---------------------------------------------------------------------------: }$ g- k7 V/ F0 f
#endif</P>
6 n/ R9 B% t Q1 y( l* X< >
+ z# e: D X3 w9 ]- _<a>file://unit1.cpp</A>
3 i; e1 ^1 {4 @ `file://---------------------------------------------------------------------------</P> u; r% j0 e d3 j( T- M
< >#include <vcl.h>0 ~; U* Q/ S# {+ |* `
#pragma hdrstop</P>% ]; H c6 E; Q6 g1 l2 O: B
< >#include "Unit1.h"/ c) W/ B) V" J5 ^" R) a! O3 m
file://---------------------------------------------------------------------------
" K3 H/ |! o, t+ R+ y. I#pragma package(smart_init)' ?" T) l) Z# q: F. z8 m
#pragma resource "*.dfm"
8 W. }2 O/ w D/ fTForm1 *Form1;# I+ G* A% b2 u. F. F
file://---------------------------------------------------------------------------' ~8 I( [) E- ^3 W9 s- H
__fastcall TForm1::TForm1(TComponent* Owner)
- p: r. d9 h n/ c* O6 ` : TForm(Owner)
) y7 g7 S: f3 R0 t{, T: A$ Z5 A: L3 m! A4 N
}
: |, U7 ]+ H' Z; J2 g7 k* Q" s4 ^' qfile://---------------------------------------------------------------------------
$ Z( E/ T% k$ x* i5 @void __fastcall TForm1::Exit1Click(TObject *Sender)
+ H7 z& u+ p5 K3 H7 l( I) I# l7 @5 G{
5 Q R5 w, x" o7 p Close();
' w5 a; @8 I+ A. @}
8 O) R6 C/ {" t% x6 G8 T6 Kfile://---------------------------------------------------------------------------</P>9 H% D, U: l! o3 k
< >void __fastcall TForm1::FormCreate(TObject *Sender)8 W! n3 |' Q9 ]9 F
{</P>
* R/ G! ^& O7 p9 z6 w Q- v< >BmpToRgn();
5 S$ q e+ b6 v& Y}; i f4 i1 `) E/ l; U
file://---------------------------------------------------------------------------</P>! U% h" N# K0 h* G
< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,
# x, f( k* S% `' S2 a' E TMouseButton Button, TShiftState Shift, int X, int Y)
3 U% F; F1 W8 b, @/ @{: M! t* e( Q5 G+ G
if(Button == mbLeft)
, I3 Q+ b# H# D% z0 p {
J- l. b1 j, A; Z ReleaseCapture();1 b3 t% m! ~" Q6 u
Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);9 p% _; v6 b% u' K( S
}
7 r8 L4 y# a5 R# r& ^}
" l0 O5 v3 o. }) _file://---------------------------------------------------------------------------
+ _! ]8 K9 }9 K# R8 hvoid __fastcall TForm1::BmpToRgn()
/ O0 U( |; G$ j y6 [4 ~0 L{
% S5 l! ~* O: d# a: bImage1->AutoSize=true;4 H5 t ~# }1 i! I1 L! \; U5 S9 _
Form1->AutoSize=true;
9 o7 N% B4 K: `' H8 cForm1->BorderStyle=bsNone;5 w; o6 q' @; ?) c `7 D
TColor ColorKey=Image1->Canvas-> ixels[0][0];4 K( t' _6 S3 q: m
int x,y;" c: m0 N6 u: z6 w) Q
int l,r;
# @" y* {' V. Z# dPOINT *a;
% A, L$ G8 m3 E8 U6 ` Xbool lb,rb;
0 R% Q1 ^# h7 H& j" Z8 U- ^. x# KHRGN WndRgn,TempRgn;</P>
6 H, I8 W: o. ?% v8 h0 B# P: ?; A3 F< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)0 A/ B) r* J4 }- l/ ?
{
: C7 W4 M. n9 C ShowMessage("申请内存失败!");
( d) j C/ a5 g- O$ r: K* e: V: ? exit(0);
7 r$ K7 S! ^3 Q, ~) D; R- E}</P>& T8 x, K8 G: L) K6 b3 r) k
< >l=0;r=Image1->Height*2-1;. D( o; g: g, l/ [+ X( {% r
WndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>9 q2 w2 V5 {- @) O1 {8 ]1 g8 E
< >for(y=0;y<Image1->Height;y++)
; u% b8 U+ S# V9 Y{- t$ |; Y* a) c1 Y! h
lb=true;# A6 R$ ^, T+ F- [" Z( c
for(x=0;x<Image1->Width+1;x++)
( U, ], L- A/ t+ w if(Image1->Canvas-> ixels[x][y]!=ColorKey)" C1 p/ X: L# z" Q8 H* K- v, D
{& i% u# w/ i% i8 ?. u U
a[l].x=x;
* @& Y2 |% e3 r: M a[l].y=y;
( V: e+ L8 G1 S7 n6 c lb=false;9 `. O; ]! T. v4 D0 j
break;8 e; ?& u) b/ P3 C" i1 n& t" U% a' B
}</P>
( q. P0 c' J. C, e, k* O1 _% N, E< > if(lb) a[l]=a[l-1];
' i% R# q! v! P l++;3 z% J/ k& F4 X4 D6 i
rb=true;</P>0 l: f# I/ L5 w R5 L
< > for(x=Image1->Width;x>=0;x--)
; h' Q1 o$ g8 Q" C/ f, N4 R. g if(Image1->Canvas-> ixels[x][y]!=ColorKey)
& {3 N/ u; x" G7 j( k( v {; `. a, {7 y- V" M4 `+ ^
a[r].x=x;
/ [% t5 X# K3 B8 c. m9 \ a[r].y=y;
5 Z; @! L7 I* j/ J* o+ E# d rb=false;6 A" P, V5 ^8 z( T) E# x
break;
8 k2 ]3 f- Y- Y8 z! V/ _ }: T4 n& m: B5 l {7 k9 S0 I0 |5 G
if(rb) a[r]=a[r+1];
& o H' Y7 y) J" R; F v r--;2 ]! A9 B3 S$ Z7 Q$ \3 }4 @
}</P>0 {$ b9 c) N* K/ E+ n5 j
< >r=Image1->Height*2-1;
6 e' {7 a9 G1 o- Y1 B3 s+ `for(y=0;y<Image1->Height-1;y++)
# E7 e1 h/ F7 H0 G: B{1 i$ z" j$ d" h) A' y
for(x=a[y].x;x<=a[r].x;x++)
/ w& z2 \( ^2 L6 c. s/ r" m if(Image1->Canvas-> ixels[x][y]==ColorKey)! _# ^. g5 l l1 X
{" }& n% t# A3 R% ]
TempRgn=CreateRectRgn(x,y,x+1,y+1);! {: l1 `, C/ O/ j; d- T
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);5 m' }& d& K0 b; f, ~9 U+ K2 f
DeleteObject(TempRgn);
& T5 T+ P; }1 }: y1 X; l }$ O6 D) l$ E* V9 b2 ?
r--;1 ~* `0 d; m5 Y( C. L
}</P>/ ~5 W/ h4 y: h; [) ?7 O
< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
. _6 r4 b. w" o+ }, D& {TempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);
- g. e0 P, \! p3 F. C7 `9 [CombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);
3 T- c4 h; a9 o. V3 }, A0 A) H( \6 PDeleteObject(TempRgn);
% n( w& y3 Z, M/ ]+ f- xdelete a;5 B" ^& b" X% {8 ~; Q( X0 L
SetWindowRgn(Handle,WndRgn,true);
) g9 I0 H, e& n5 n' R}</P>
* h4 K6 t+ C+ K, k4 n! P< >void __fastcall TForm1::Open1Click(TObject *Sender)
% X7 q7 u8 k p$ T% n) w0 ~* F{
# q& q. B) E3 K! l4 W* o if(OpenPictureDialog1->Execute())
7 M) O; Y0 V* V- \2 @" { {- ^6 z; X/ l& T9 Z6 v( w! C7 v( o
Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);, h( ?( e5 n: {* d) v
BmpToRgn();
. U1 W( n1 T! X+ V* j, N }
5 c$ o% x( \5 N d}
) G' E2 |2 Q* W8 O3 ifile://---------------------------------------------------------------------------</P>
! q2 c: ^6 T$ q" _< >对啦,图片的背景色要相同。% N7 ?' y. S* U
图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>
. d' a* G: ~9 F9 Q< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------
% }2 F9 k1 r5 Uvoid __fastcall TForm1::FormPaint(省略)
& N/ y; f, G) z9 m{
6 x2 r: X$ u3 @2 e5 Z AnsiString ww;int bb;: F9 n; R' j9 V; @
ww=AnsiString(Form1->Width/256);
# S o2 ?: c1 q: L Z z! R TRect MyRect;
. K, \" D% U' f- u' b" o9 t, Y8 c MyRect.left=0;1 R$ ^& q$ I1 T6 Y
for(bb=0;bb<255;bb++)
2 ]% i3 n- Y0 C: p {
3 ?) e) J% V! G Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);. a+ x8 q9 c# o( Y" F
MyRect.top=bb*(ww.ToInt());$ L! Y* j8 G& |$ E
MyRect.right=Form1->Width;
+ Z, b: R U. { MyRect.bottom=(bb+1)*(ww.ToInt());) A5 Z J: F W ]) l8 Y& K# Y
Form1->Canvas->FillRect(MyRect);, c' V- a( ^$ [9 ?. Z
}
: T" W0 z' R9 x+ S! @3 v- d} </P>4 e% \3 {% }* H& H/ N5 ^5 K
< >file://---------------透明窗体--------------------------4 p* z9 R0 F% E0 w. J6 a: ?# X
void __fastcall TForm1::Button1Click(TObject *Sender)
/ t9 |3 ]' y1 C. x: J{: A. V. c ?+ @/ m/ Y
TRect *rctClient,*rctFrame;
. I. t0 s; k* B4 s HRGN hClient,hFrame;
+ c' ]6 A5 F: x; F* M+ m( Z( \ POINT *lpTL,*lpBR;% L2 Q# j% i( l/ y/ _# I
rctFrame=new TRect;% X2 B, B2 d$ Q0 a M* T
rctClient=new TRect;, z, a' i( B2 d- A. \
lpTL=new POINT;- v( Y" d# e) P3 n- F( I
lpBR=new POINT;* f# ?4 {4 H: }& P& o5 d, `- M
GetWindowRect(Form1->Handle,rctFrame);9 q+ R$ N, y0 v3 J
::GetClientRect(Form1->Handle,rctClient);, _7 x7 z' x. [: Z+ V
lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;0 h3 S$ w6 v" k/ X
lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>' Z0 S r1 R9 N$ l
< > ::ScreenToClient(Form1->Handle,lpTL);# c1 w$ ^( N1 H. g
::ScreenToClient(Form1->Handle,lpBR);7 x- g" L" c; k8 d
rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;: r S! Y9 t5 p% q! M
rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;; A4 ^" l4 L' `' I! W
rctClient->Left=abs(rctFrame->Left);. k: l9 I$ Q* Q# [+ m
rctClient->Top=abs(rctFrame->Top);
2 A3 C8 P& s7 U6 u4 `% f rctClient->Right=rctClient->Right+! y, G) y, Y8 K8 x3 u0 M7 O
abs(rctFrame->Left);
! o- k) n8 Q) w$ P/ \# Y rctClient->Bottom=rctClient->Bottom+
B3 G: P& w9 ~7 L abs(rctFrame->Top);- z5 W- x4 W9 X: ]1 \6 @$ A# |8 w
rctFrame->Right=rctFrame->Right+2 `& n- p" |. \9 G6 }) ?$ g0 ]
abs(rctFrame->Left);9 P; d0 V& {( D; w; I7 t& p
rctFrame->Bottom=rctFrame->Bottom+
7 G4 `0 c) b: r& ?3 P abs(rctFrame->top);% c% {* e/ Y. i* I4 L; r
rctFrame->Top=0;rctFrame->Left=0;</P>: m4 p* L1 j8 K* u+ W$ A
< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,* h' f$ u% A4 ?8 l/ ^
rctClient->Right,rctClient->Bottom);
H+ h2 r: S9 u) s6 M* {1 [ hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,
* g! h* g+ t4 I8 u" A1 Z- y rctFrame->Right,rctFrame->Bottom);8 e l! k1 Z! F% c8 B
CombineRgn(hFrame,hClient,hFrame,RGN_XOR);
) ^ A% }7 C ^5 h7 u SetWindowRgn(Form1->Handle,hFrame,true);</P>9 x: P! Y4 O1 z2 B
< >/ z* d& g: f' \2 h; i$ I
delete rctFrame;2 x/ S0 t) z- }8 e$ q
delete rctClient;) O; A3 a, j4 i6 I, u3 C, L
delete lpTL,lpBR;</P>
4 E X& @3 o8 P< >} </P> |
zan
|