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

我的地盘我做主
该用户从未签到
 |
< >以下源码是快速创建不规则窗体的,还可以移动。
6 \$ o/ ^( E/ ~ m" l% t9 Zfile://------------------------------------------------------------------------2 j0 J/ _: U& o# @
<a>file://Unit1.h</A></P>
" ?9 k* Z6 R: X2 E< >#ifndef Unit1H
/ K6 p3 S9 {8 P" L: t7 U#define Unit1H8 Z' Q j! v8 [9 [
file://------------------------------------------------------------------------
0 W3 X/ ~; f4 w" {+ T4 {% B+ A#include <Classes.hpp>8 C( }1 A3 }4 B% v6 i/ J' ]
#include <Controls.hpp>
% f5 Z7 r T& p1 N6 X* E# a5 P#include <StdCtrls.hpp>) @ i" l+ E, U4 J/ V
#include <Forms.hpp>3 I# C3 q7 }! [6 `; }
#include <ExtCtrls.hpp>
, m% ~- Q) m7 `% i) n' F#include <Graphics.hpp>: X' u7 `* L" i; I; ~3 J+ I- M
#include <Menus.hpp>
' k) v. o7 p) q/ w' H#include <Dialogs.hpp>" X9 S% `+ e6 ^ c t+ a9 e; D q
#include <ExtDlgs.hpp>
5 F8 X7 h$ h- T$ Jfile://---------------------------------------------------------------------------$ a) c1 I( e( S
class TForm1 : public TForm
9 M; V% y3 T8 R& V6 P( {, U3 C{4 I, `% V" f" }- j0 w* n
__published: // IDE-managed Components
# D/ R1 k8 X+ P0 C' l( o TImage *Image1;: w) W$ {$ c+ Y8 Y% [
TPopupMenu *PopupMenu1;+ Q l! I0 q+ T4 p" q. o; [3 N
TMenuItem *Exit1;
* N4 q' z, o: g; \ TOpenPictureDialog *OpenPictureDialog1;& W4 O% m& j' D9 U
TMenuItem *Open1;1 y" q8 ]1 b" a: r
void __fastcall Exit1Click(TObject *Sender);& G. A8 y8 f# w5 ]+ F
void __fastcall FormCreate(TObject *Sender);2 K& W" R; l) a+ h8 r3 [% P8 m3 X, \
void __fastcall Image1MouseDown(TObject *Sender,
2 n( b$ y% I7 ^. C TMouseButton Button, TShiftState Shift, int X, int Y);
4 o0 t8 q; t% w8 W& Z* k void __fastcall Open1Click(TObject *Sender);
& o9 B' t+ I4 c1 h5 H, @/ {/ {. Nprivate: // User declarations) X0 B/ ?9 e, @. a
void __fastcall BmpToRgn();
& B" n: ? f- y5 C8 J' xpublic: // User declarations/ t7 ?/ l7 Z L) y
__fastcall TForm1(TComponent* Owner);
' N6 j9 ~. m3 @};
8 ^, k$ B2 l. S- ^8 Dfile://---------------------------------------------------------------------------
! O6 v( w+ _2 T1 k6 R5 Z3 rextern PACKAGE TForm1 *Form1;
3 I) B* X5 g' kfile://---------------------------------------------------------------------------
2 r8 y7 |, @7 v& z#endif</P>
" V2 ~( W' o; f% ]6 A: ?( v7 n9 Q< >
" m: T ?& ] u<a>file://unit1.cpp</A>
5 k( {+ t. ]2 g4 U' m) Yfile://---------------------------------------------------------------------------</P>
+ @- v# K C5 N) g. h6 [( j< >#include <vcl.h>
- {) J0 p& x' c, l#pragma hdrstop</P>6 n6 s5 g9 T* \ q
< >#include "Unit1.h"
0 P% ?- V W6 x1 sfile://---------------------------------------------------------------------------% r# U$ X( X$ f. L( I4 W% Y! q
#pragma package(smart_init)4 p# i7 t5 g9 b0 f1 K
#pragma resource "*.dfm". J) u+ q$ v- A# s5 {! s4 c
TForm1 *Form1;
& O8 }7 d7 c6 D( G) Mfile://---------------------------------------------------------------------------( ?& W$ M# l+ ^. W3 f
__fastcall TForm1::TForm1(TComponent* Owner)5 n* D4 H1 t8 R" h5 q
: TForm(Owner)
" k Q3 s$ i% z. r9 T- g0 K{
9 }9 O& o) U- T! H2 n: G9 p}* D4 o6 S! l, I p% q2 {
file://---------------------------------------------------------------------------
2 ~6 A" F4 f8 n% H8 Wvoid __fastcall TForm1::Exit1Click(TObject *Sender)
" V4 r% ?3 A0 L+ A7 u9 \) v{
. W5 r6 V7 D" R& \ Close();- U' F; k F/ g
} F! U5 S, y5 ?0 M
file://---------------------------------------------------------------------------</P>- ?- n5 }8 _5 O5 r. a* g" w
< >void __fastcall TForm1::FormCreate(TObject *Sender)2 }) l9 D& a( a, b( h) ?- k6 \) w8 ^5 Q
{</P>
8 q7 ?! z) ?$ \; P6 w< >BmpToRgn();# a7 F G( G/ C' T" C- T5 S, a
}2 n7 G. }1 _8 j' R0 D2 n* v
file://---------------------------------------------------------------------------</P>/ O8 [1 p8 N& J: K+ I
< >void __fastcall TForm1::Image1MouseDown(TObject *Sender,
4 s! @8 a" C# D0 K9 m' e, s TMouseButton Button, TShiftState Shift, int X, int Y)
* E8 i2 J3 J9 {{, l" o! ^5 j \0 o* n" s
if(Button == mbLeft)
6 ~! F7 S1 V3 Y" T, \ {
7 h6 ?% d3 J& \5 C6 V" Z. b ReleaseCapture();1 Y1 H u1 K% j+ [
Perform(WM_NCLBUTTONDOWN, HTCAPTION, 0);
) x# Z5 k* l3 f: K5 i* z! `1 t+ x }
( I1 A& ]& m2 v2 F}7 q7 P) ?6 o: m; G, p' N% p3 z6 [
file://---------------------------------------------------------------------------
% O3 n( D' E7 _void __fastcall TForm1::BmpToRgn()
, b. f: H4 {/ o5 o1 [{
( r J* m' t8 J( |. GImage1->AutoSize=true; B+ g9 p* H+ N; y) B L
Form1->AutoSize=true;/ D6 d& R. k# \4 I6 n# s7 G0 f0 x+ o
Form1->BorderStyle=bsNone;4 H& |/ L' z5 J* G' y5 E
TColor ColorKey=Image1->Canvas-> ixels[0][0];! V9 T5 I1 I5 A' b, e
int x,y;
8 o+ l c' G. b: M0 i- J) Q. uint l,r;/ r( p3 _; Y4 Z4 J6 _
POINT *a;
* L; b1 {& D* T) B nbool lb,rb;; _$ Y) y2 q% i* |
HRGN WndRgn,TempRgn;</P>1 l9 X: l& W3 ~3 L, O
< >if((a=(POINT *)malloc(Width*2*(sizeof(POINT))))==NULL)5 D* Z8 }; O P7 D- C q9 _
{ h D/ J; W% E5 z5 \7 X
ShowMessage("申请内存失败!");; e) o$ I7 W3 I" b! r. g
exit(0);
& \+ ^" O& [& P' o8 W& B# N}</P>
6 ^( R: A/ Z/ s$ o5 w& S- ]< >l=0;r=Image1->Height*2-1;
3 A5 f2 J- X. ~ t2 E# R) eWndRgn=CreateRectRgn(0,0,Image1->Width,Image1->Height);</P>! J4 N% w$ J/ I) x5 S, X4 ^
< >for(y=0;y<Image1->Height;y++)
( b# M! g; ^# R{. c: @1 b! O# i+ r1 |
lb=true;
, V2 C8 h9 l! S( q- Y for(x=0;x<Image1->Width+1;x++)) ?' j) F s, H2 T. |; } e
if(Image1->Canvas-> ixels[x][y]!=ColorKey)
4 n( c# Y: K9 ]( P) E/ D+ j {
: [6 T: k) ^: H; }" }5 Y' b6 Q+ y a[l].x=x;8 p* ~ D1 V% ~9 M3 d
a[l].y=y;9 a' F( E& ?6 W6 D9 N& r- F' u
lb=false;
7 `5 c- @- H' t$ @9 L1 G- [, Z0 Q break;
% P. O7 H( J, H }</P>' f) W7 M$ v! u! { n7 ~! u# n, p
< > if(lb) a[l]=a[l-1];- S0 q9 [/ M+ d+ [: X
l++;+ m# U8 z8 ]4 G* \" ]
rb=true;</P>6 J- n: q- x. D
< > for(x=Image1->Width;x>=0;x--)
% }; y4 H" ?: Z1 `+ ] if(Image1->Canvas-> ixels[x][y]!=ColorKey)
3 e4 z% Y2 h: H9 ~5 ` {
- X0 @6 z, Y* M) X2 t9 J' f a[r].x=x;
0 b; J& p i: H& S a[r].y=y;
0 A4 ~4 _# D% E( T8 P rb=false;/ l! x3 d" R' n8 u
break;8 F* X( ?* P8 f; l+ Y
}
/ ^( v8 V6 h: w C- A if(rb) a[r]=a[r+1];
* ~6 Y' N! p5 i G0 C; Y5 V1 M r--;, Y! S( K5 w; a% f' E9 ~7 |" v
}</P>" b# ]( L' p! a/ ]0 u
< >r=Image1->Height*2-1;# i8 x& [, d% X7 W5 x( `9 c6 L
for(y=0;y<Image1->Height-1;y++) h6 F* n+ N0 {1 r4 ?+ ~
{
4 ]" [' h! S/ u for(x=a[y].x;x<=a[r].x;x++)- H* ^( E( p5 l( o* _! z' V: C9 Y8 t
if(Image1->Canvas-> ixels[x][y]==ColorKey)
; q9 ]- X" \( U0 D2 R. L {0 ^3 j: q6 S& U( Q2 R
TempRgn=CreateRectRgn(x,y,x+1,y+1);! Z# y# t1 c2 O8 R0 L6 g6 g1 J
CombineRgn(WndRgn,WndRgn,TempRgn,RGN_XOR);5 ?$ p$ F! D k8 w0 R0 I5 Y
DeleteObject(TempRgn);
- \! x9 I k( P' q/ Y } P6 }6 t' i0 O; c8 W. M
r--;
3 S* S9 n% o, S$ s: R+ B}</P>
! e, K7 V3 z8 f" N" Q7 Y4 |< ><a>Height*2,ALTERNATE">file://TempRgn=CreatePolygonRgn(a,Image1->Height*2,ALTERNATE</A>);
* o' h) q- H3 y4 ?7 S8 k! i4 OTempRgn=CreatePolygonRgn(a,Image1->Height*2,WINDING);
: C6 J/ ~! R$ _7 X# K5 E5 DCombineRgn(WndRgn,WndRgn,TempRgn,RGN_AND);! d( k& y+ J: G' |- |! q- C
DeleteObject(TempRgn);
2 k/ n3 _3 L/ W3 y, @+ m s. ?delete a;
! H3 R" z/ r c7 k; \+ dSetWindowRgn(Handle,WndRgn,true);3 E& C& s" v" h$ c
}</P>- ^' m4 i+ W' U' {
< >void __fastcall TForm1::Open1Click(TObject *Sender)9 ?# x/ F) H/ x b
{; a9 _/ l" ~# i' G" S
if(OpenPictureDialog1->Execute())
o. L p+ x2 Q {- |7 a6 e( Z- X( K* e' `& {' y2 r
Image1-> icture->LoadFromFile(OpenPictureDialog1->FileName);
7 i% A( {9 @) {8 K BmpToRgn();: [6 L' G, B! ]$ a4 O4 w
}
o1 \$ H: h3 l) i}
7 z; S! h7 ~3 Gfile://---------------------------------------------------------------------------</P>
4 }! y6 b% W/ T< >对啦,图片的背景色要相同。+ I' m" d d$ U9 i; S; m
图片在IMAGE1的属性里加,不是在运行期通过LoadFromFile()加的。。</P>4 C4 G" f# d' G) v; @9 s3 k
< >file://--------------------(一)为窗体背景增加渐变色(蓝)---------------
3 u! F8 q( |' [( D8 Dvoid __fastcall TForm1::FormPaint(省略)! V( r1 W; i+ o& \5 W. f/ s) s& s
{$ P8 s& f0 ^ N. W2 s& a9 \& [
AnsiString ww;int bb;
; e2 T8 {/ h0 E; @, L' h ww=AnsiString(Form1->Width/256);3 Q7 l( r) R) i# Q4 g
TRect MyRect;3 I# y' w# a1 m4 L8 S1 E, ~ Z
MyRect.left=0;
+ ~1 A3 Y% ^ D! P- g+ ~ for(bb=0;bb<255;bb++)
; A' e8 R3 D- G; i" W { A! C! J' ?% n M* o% ~7 i
Form1->Canvas->Brush->Color=(TColor)RGB(0,0,bb);6 Q! Q3 r9 ? p+ I" Y9 [) l0 G
MyRect.top=bb*(ww.ToInt());6 Y, F( N* p @+ n# ^
MyRect.right=Form1->Width;, U% e; n+ T5 B& p+ P, K8 R3 ]5 Y
MyRect.bottom=(bb+1)*(ww.ToInt());
' b6 c! f' a- c+ }1 ~0 ? Form1->Canvas->FillRect(MyRect);
. e) E8 q4 P t; f# u$ L }* J# X9 M' ?% _$ H0 ~
} </P>: s( i; N2 e# B5 n
< >file://---------------透明窗体--------------------------
& {0 D+ H+ A/ B5 w- R$ Jvoid __fastcall TForm1::Button1Click(TObject *Sender)
& `7 ^2 n9 P8 R9 P' r{3 d7 `- |3 `! w- u
TRect *rctClient,*rctFrame;* o; U7 m5 o( I* E" g
HRGN hClient,hFrame;
" x2 _9 e0 r4 q& A2 q m4 B POINT *lpTL,*lpBR;3 y/ x( j; G; K* t
rctFrame=new TRect;
. w. u( u' W, m* W! X rctClient=new TRect;3 A. K: J2 g) H, a7 p G, y0 m6 T
lpTL=new POINT;
% @$ K- ~$ F( S lpBR=new POINT;8 _9 D# Z2 I* K; ~! R! d$ a' Y2 \' z
GetWindowRect(Form1->Handle,rctFrame);
. r D( q% i% l" s2 N% n6 _( k ::GetClientRect(Form1->Handle,rctClient);+ a) u( P3 \* s- F8 w
lpTL->x=rctFrame->Left;lpTL->y=rctFrame->Top;
( m- L m* k' h* C8 @ lpBR->x=rctFrame->Right;lpBR->y=rctFrame->Bottom;</P>
5 C. M# D& t! Z/ _# _3 |< > ::ScreenToClient(Form1->Handle,lpTL);+ z: I' l2 Y6 c( ?! B& E2 U+ V
::ScreenToClient(Form1->Handle,lpBR);
$ g$ L3 g; P- G& l4 T1 ^ rctFrame->Left=lpTL->x;rctFrame->Top=lpTL->y;7 Z* N2 J" R P2 ]+ J$ o. F
rctFrame->Right=lpBR->x;rctFrame->Bottom=lpBR->y;9 u& N$ p8 E- P
rctClient->Left=abs(rctFrame->Left);
& W: f8 V8 I6 l: e# v4 i" Z rctClient->Top=abs(rctFrame->Top);$ `3 i1 \0 Q. w
rctClient->Right=rctClient->Right+
3 ]6 |. }( a, L/ `- Y2 n abs(rctFrame->Left);
6 c [8 O' p4 ~* x7 ]9 B" T rctClient->Bottom=rctClient->Bottom+6 Z+ ~! j2 T/ m* U, d
abs(rctFrame->Top);6 j2 j/ b" F4 e7 l, t0 i
rctFrame->Right=rctFrame->Right+4 O- q2 U: I" O( j2 u1 x: E/ q
abs(rctFrame->Left);" m% u* ~0 L5 d, L
rctFrame->Bottom=rctFrame->Bottom+5 q$ k& V" i t0 w5 M* \
abs(rctFrame->top);
7 Y- L Z: Z: V' N/ f rctFrame->Top=0;rctFrame->Left=0;</P>
9 m5 f) X' b' F5 l I6 x1 u0 V< > hClient=CreateRectRgn(rctClient->Left,rctClient->Top,% x( w% f% w% L+ Q8 S* M2 f6 ?
rctClient->Right,rctClient->Bottom);
* j k' W, b, ~1 i hFrame=CreateRectRgn(rctFrame->left,rctFrame->Top,
4 k8 {. y& {- q: Q( D1 M rctFrame->Right,rctFrame->Bottom);2 T0 Q# [. U. m5 w. ~
CombineRgn(hFrame,hClient,hFrame,RGN_XOR);! |0 X( _: l( z# Q% A
SetWindowRgn(Form1->Handle,hFrame,true);</P>
5 F; M$ j/ x4 L; O# m# C8 @8 o< >: ?$ ]7 g# ^1 P" K7 @$ V1 J
delete rctFrame;) q. m% P' x( O* i" }
delete rctClient;
* U: P E5 C Z. W( G! x delete lpTL,lpBR;</P>3 Y; O' p9 X( V- r+ s6 }
< >} </P> |
zan
|