View Full Version : سوال: کد در مورد شکل خاص دادن به فرم
kamran_14
دوشنبه 11 بهمن 1389, 18:03 عصر
procedure TForm1.FormClick(Sender: TObject);
Var
Rgn1,Rgn2,Rgn3,Rgn4,FormRgn:HRgn;
begin
Width:=Form1.Width;
Height:=Form1.Height;
Rgn1:=CreateRectRgn(20,0,772,18);
Rgn2:=CreateRectRgn(0,17,792,583);
Rgn3:=CreateEllipticRgn(0,0,46,38);
Rgn4:=CreateEllipticRgn(747,0,793,38);
FormRgn:=CreateEllipticRgn(0,0,0,0);
CombineRgn(FormRgn,FormRgn,Rgn1,RGN_OR);
CombineRgn(FormRgn,FormRgn,Rgn2,RGN_OR);
CombineRgn(FormRgn,FormRgn,Rgn3,RGN_OR);
CombineRgn(FormRgn,FormRgn,Rgn4,RGN_OR);
SelectClipRgn(Canvas.Handle,FormRgn);
SetWindowRgn(form1.Handle,FormRgn,true);
DeleteObject(Rgn1);
DeleteObject(Rgn2);
DeleteObject(Rgn3);
DeleteObject(Rgn4);
DeleteObject(FormRgn);
end;
می شه این دستورات رو توضیح بدید دستتون درد نکنه؟
ahmadi3d_ali
دوشنبه 11 بهمن 1389, 18:08 عصر
با این کدها میشه فرم را هر شکلی خواست داد مثلا یه تیکه را برید! شکل مربع دایره و ... داد چی چی را توضیح بدم؟!>
ahmadi3d_ali
دوشنبه 11 بهمن 1389, 18:16 عصر
اگر منظورتون توضیح هر پارامتر هست بفرمایید :
CreateRectRgn این 4 تا مقدار میگیره که هر کدوم توضیحش این هست : HRGN CreateRectRgn(
__in int nLeftRect,
__in int nTopRect,
__in int nRightRect,
__in int nBottomRect
);
Parameters
nLeftRect [in]
Specifies the x-coordinate of the upper-left corner of the region in logical units.
nTopRect [in]
Specifies the y-coordinate of the upper-left corner of the region in logical units.
nRightRect [in]
Specifies the x-coordinate of the lower-right corner of the region in logical units.
nBottomRect [in]
Specifies the y-coordinate of the lower-right corner of the region in logical units.
Return Value
If the function succeeds, the return value is the handle to the region.
If the function fails, the return value is NULL.
بعدی CombineRgn هست که 4 تا مقدار میگیره باز که هر کدوم در زیر توضیح داده شده :
HRGN hrgnSrc1,
HRGN hrgnSrc2,
int fnCombineMode
);
Parameters
hrgnDest
[in] Handle to a new region with dimensions defined by combining two other regions. (This region must exist before CombineRgn is called.)
hrgnSrc1
[in] Handle to the first of two regions to be combined.
hrgnSrc2
[in] Handle to the second of two regions to be combined.
fnCombineMode
[in] Specifies a mode indicating how the two regions will be combined.
This parameter can be one of the following values. Value Description
RGN_AND Creates the intersection of the two combined regions.
RGN_COPY Creates a copy of the region identified by hrgnSrc1.
RGN_DIFF Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
RGN_OR Creates the union of two combined regions.
RGN_XOR Creates the union of two combined regions except for any overlapping areas.
Return Values
The return value specifies the type of the resulting region. NULLREGION indicates that the region is empty.
SIMPLEREGION indicates that the region is a single rectangle.
COMPLEXREGION indicates that the region is more than a single rectangle.
ERROR indicates that no region is created.
بعدی SelectClipRgn هست که 2 تا مقدار میگیره که در زیر توضیحش هست :
int SelectClipRgn(
HDC hdc,
HRGN hrgn
);
Parameters
hdc
[in] Handle to the device context.
hrgn
[in] Handle to the region to be selected.
Return Values
The return value specifies the region's complexity. NULLREGION indicates that the region is empty. SIMPLEREGION indicates that the region is a single rectangle. COMPLEXREGION indicates that the region is more than a single rectangle. ERROR indicates that an error occurred; the current clipping region is unaffected.
To get extended error Information, call GetLastError.
بعدی SetWindowRgn هست که توضیحش اینه :
int SetWindowRgn(
HWND hWnd,
HRGN hRgn,
BOOL bRedraw
);
Parameters
hWnd
Handle to the window whose window region is to be set.
hRgn
Handle to a region.
The function sets the window region of the window to this region.
If hRgn is NULL, the function sets the window region to NULL.
bRedraw
Specifies whether the system redraws the window after setting the window region.
If bRedraw is TRUE, the system does so; otherwise, it does not.
Typically, you set bRedraw to TRUE if the window is visible.
و در آخر DeleteObject هست که باید بگم وقتی متغیری از نوع HRgn تعریف می کنی آخرش که کارت باهاش تموم شد باید delete بشه که با این Delete میشه !
موفق باشی
mbshareat
سه شنبه 12 بهمن 1389, 00:32 صبح
با سلام
من فکر کنم تو همون تاپیک که کد رو گذاشتم گفتم که یه چهار گوش با دو تا لبه گرد برای شکل لبه فرم در نظر می گیره.
CreateRectRgn ناحیه مستطیل شکل و CreateEllipticRgn ناحیه بیضی شکل تعریف می کنه و CombineRgn هم دو ناحیه رو ترکیب می کنه.
البته ناگفته نماند که می شد این کار رو با ترکیب یه ناحیه مستطیلی معمولی و یه ناحیه مستطیل با لبه گرد (CreateRoundRectRGN ) هم به آسونی انجام داد.:خجالت:
SetWindowRgn هم به ویندوز میگه این ناحیه ها رو که تعیین کردم برای شکل فرم به کار ببر.:لبخند:
DeleteObject رو هم نمی دونم ضرورت داره یا نه . من چون تو کد نمونه دیدم از مثال تقلید کردم.:گیج:
kamran_14
پنج شنبه 14 بهمن 1389, 09:49 صبح
لبته ناگفته نماند که می شد این کار رو با ترکیب یه ناحیه مستطیلی معمولی و یه ناحیه مستطیل با لبه گرد (CreateRoundRectRGN ) هم به آسونی انجام داد
می شه در مورد پارامترهای CreateRoundRectRGN توضیح بدین
ممنون
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.