DelPhi 2020. 4. 12. 13:56

// 컴포넌트를 Install 한다음 Samples 디렉토리에 가서

// EditButton 을 한번 시험해 보는 것도 재미 있을듯..

unit ButtonEdit;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;

type

TButtonEdit = class(TEdit)

private

//FCanvas: TCanvas; //commented out - see below!

//do you want to 'click' when the up or down arrow key pressed as well?

FClickOnArrow: boolean;

//do you want to 'click' when the Return key pressed as well?

FClickOnReturn: boolean;

//flag - is the button pressed or not

FPressed: boolean;

procedure Click; override;

procedure CreateWnd; override;

procedure WMPAINT(var Message: TMessage); message WM_PAINT;

procedure WMLBUTTONDOWN(var Message: TWMMouse); message WM_LBUTTONDOWN;

procedure WMLBUTTONUP(var Message: TWMMouse); message WM_LBUTTONUP;

procedure WMMOUSEMOVE(var Message: TWMMouse); message WM_MOUSEMOVE;

//procedure WMSETFOCUS(var Message: TMessage); message WM_SETFOCUS;

protected

procedure KeyDown(var Key: Word; Shift: TShiftState); override;

public

constructor Create(AOwner: TComponent); override;

published

property ClickOnArrow: boolean read FClickOnArrow write FClickOnArrow;

property ClickOnReturn: boolean read FClickOnReturn write FClickOnReturn;

end;

procedure Register;

implementation

const

BUTTONWIDTH = 17;

{----------------------------------------------------------------------}

{----------------------------------------------------------------------}

procedure Register;

begin

RegisterComponents('Samples', [TButtonEdit]);

end;

{----------------------------------------------------------------------}

constructor TButtonEdit.Create(AOwner: TComponent);

begin

inherited Create(AOwner);

FPressed := false;

FClickOnArrow := true;

FClickOnReturn := false;

end;

{----------------------------------------------------------------------}

procedure TButtonEdit.CreateWnd;

begin

inherited CreateWnd;

//this is crucial to stop text disappearing under the button...

perform(EM_SETMARGINS,EC_RIGHTMARGIN,(BUTTONWIDTH+2) shl 16);

end;

{----------------------------------------------------------------------}

procedure TButtonEdit.WMLBUTTONDOWN(var Message: TWMMouse);

begin

inherited;

//draw button in pressed state...

if message.xpos >= clientwidth-BUTTONWIDTH+1 then begin

FPressed := true;

Refresh;

end;

end;

{----------------------------------------------------------------------}

procedure TButtonEdit.WMLBUTTONUP(var Message: TWMMouse);

begin

inherited;

//draw button in non-pressed state...

if FPressed then begin

FPressed := false;

Refresh;

end;

end;

{----------------------------------------------------------------------}

procedure TButtonEdit.WMMOUSEMOVE(var Message: TWMMouse);

begin

inherited;

//change cursor when over the button to an arrow (not the default I-beam)...

if message.xpos >= clientwidth-BUTTONWIDTH+1 then cursor := crArrow

else cursor := crDefault;

end;

{----------------------------------------------------------------------}

procedure TButtonEdit.Click;

var

pt: TPoint;

begin

//fix a minor cosmetic problem...

if FPressed then begin

FPressed := false;

Repaint;

end;

//Only process an OnClick method if the button is clicked,

//NOT if the text is clicked!

GetCursorPos(pt);

if PtInRect(Rect(clientwidth-BUTTONWIDTH+1,0,clientwidth,clientheight),

ScreenToClient(pt)) then inherited Click;

end;

{----------------------------------------------------------------------}

procedure TButtonEdit.KeyDown(var Key: Word; Shift: TShiftState);

begin

//respond to up or down arrow keys or Return key with OnClick event if

//"ClickOnArrow" or "ClickOnReturn" property set...

inherited KeyDown(Key, Shift);

if ((Key = vk_Down) or (Key = vk_Up))

and (Shift = []) and FClickOnArrow then begin

Key := 0;

inherited Click;

end

else if (Key = vk_return) and FClickOnReturn then begin

Key := 0;

inherited Click;

end;

end;

{----------------------------------------------------------------------}

//This no longer seems to be necessary ... I've left it here just in case!

{procedure TButtonEdit.WMSETFOCUS(var Message: TMessage);

begin

inherited;

repaint;

end;}

{----------------------------------------------------------------------}

procedure TButtonEdit.WMPAINT(var Message: TMessage);

var

dc: HDC;

CntrPt: TPoint;

pic: array [0..3] of TPoint; //arrow 'picture' points

begin

// let windows draw the text!

// I don't really want to struggle with all the scrolling issues etc!

inherited;

//NOW DRAW THE BUTTON ... (not as bad as it looks if you take out the comments!)

//find the centre of the button...

CntrPt := point(clientwidth - BUTTONWIDTH div 2, clientheight div 2);

//offset CntrPt by 1 if pressed...

if FPressed then CntrPt := point(CntrPt.x+1,CntrPt.y+1);

//get button arrow drawing coordinates from CntrPt...

pic[0] := point( CntrPt.x-5,CntrPt.y);

pic[1] := point( CntrPt.x,CntrPt.y-5);

pic[2] := point( CntrPt.x+5, CntrPt.y);

pic[3] := point( CntrPt.x, CntrPt.y+5);

//Notes:

//1. As I'm calling the inherited WMPAINT method before drawing the button -

// I have to use getDC(handle) instead of beginpaint(handle,paintstruct)

// otherwise I don't see the button! (I think due to clipping.)

//2. If I wanted to draw the text as well as the button (without calling

// the inherited method) then I would have to use beginpaint(handle,paintstruct).

dc := getDC(handle);

//To make this method a little more efficient you could add a private Canvas field

// to the component and create it once only in TButtonEdit.create and free it in

//TButtonEdit.destroy. I've kept it all here for simplicity.

//(Don't use TControlCanvas instead of TCanvas in TButtonEdit.create -

//It doesn't work! - Someone might explain TControlCanvas to me.)

with TCanvas.create do begin

Handle := dc;

Brush.Color := clBtnFace;

//Brush.style := bsSolid;

//paint the button surface...

FillRect(rect(clientwidth-BUTTONWIDTH+1,0,clientwidth,clientheight));

//draw the button edges...

if FPressed then Pen.color := clBtnShadow else Pen.color := clBtnHighlight;

Moveto(clientwidth-BUTTONWIDTH+2,clientheight-1);

Lineto(clientwidth-BUTTONWIDTH+2,1);

Lineto(clientwidth-1,1);

if FPressed then Pen.color := clBtnHighlight else Pen.color := clBtnShadow;

Lineto(clientwidth-1,clientheight-1);

Lineto(clientwidth-BUTTONWIDTH+2,clientheight-1);

//draw the arrows...

Brush.Color := clGreen;

Pen.color := clBlack;

polygon(pic);

Pen.color := clBtnFace;

Moveto(CntrPt.x-5,CntrPt.y);

Lineto(CntrPt.x+6,CntrPt.y);

Handle := 0;

free; //the canvas.

end;

ReleaseDC(handle,dc);

end;

{----------------------------------------------------------------------}

(*

//Old WMPAINT Method (not using TCanvas)...

procedure TButtonEdit.WMPAINT(var Message: TMessage);

var

dc: HDC;

SilverBrush, ArrowBrush, Oldbrush: HBrush;

WhitePen, GrayPen, SilverPen, OldPen: HPen;

CntrPt: TPoint;

pic: array [0..3] of TPoint; // for arrow 'picture'.

begin

inherited;

//NOW DRAW BUTTON ...

//find the centre of the button...

CntrPt := point(clientwidth - BUTTONWIDTH div 2, clientheight div 2);

//offset by 1 if pressed...

if FPressed then CntrPt := point(CntrPt.x+1,CntrPt.y+1);

//get button arrow coordinates...

pic[0] := point( CntrPt.x-5,CntrPt.y);

pic[1] := point( CntrPt.x,CntrPt.y-5);

pic[2] := point( CntrPt.x+5, CntrPt.y);

pic[3] := point( CntrPt.x, CntrPt.y+5);

//create handles ...

dc := getDC(handle);

SilverBrush := CreateSolidBrush(GetSysColor(COLOR_BTNFACE));

ArrowBrush := CreateSolidBrush(clGreen);

WhitePen := CreatePen(PS_SOLID,1,clWhite);

GrayPen := CreatePen(PS_SOLID,1,clGray);

SilverPen := CreatePen(PS_SOLID,1,GetSysColor(COLOR_BTNFACE));

//draw button surface and outline...

OldBrush := SelectObject(dc, ArrowBrush);

FillRect(dc,rect(clientwidth-BUTTONWIDTH+1,0,clientwidth,clientheight),SilverBrush);

if FPressed then OldPen := SelectObject(dc,GrayPen)

else OldPen := SelectObject(dc,WhitePen);

MovetoEx(dc,clientwidth-BUTTONWIDTH+2,clientheight-1,nil);

Lineto(dc,clientwidth-BUTTONWIDTH+2,1);

Lineto(dc,clientwidth-1,1);

if FPressed then SelectObject(dc,WhitePen)

else SelectObject(dc,GrayPen);

Lineto(dc,clientwidth-1,clientheight-1);

Lineto(dc,clientwidth-BUTTONWIDTH+2,clientheight-1);

//draw up&down arrows...

SelectObject(dc,OldPen);

polygon(dc,pic,4);

SelectObject(dc,SilverPen);

MovetoEx(dc,CntrPt.x-5,CntrPt.y,nil);

Lineto(dc,CntrPt.x+6,CntrPt.y);

//clean up ...

SelectObject(dc,OldPen);

SelectObject(dc, OldBrush);

DeleteObject(WhitePen);

DeleteObject(SilverPen);

DeleteObject(GrayPen);

DeleteObject(SilverBrush);

DeleteObject(ArrowBrush);

ReleaseDC(handle,dc);

end;

*)

{----------------------------------------------------------------------}

end.

posted by 핵커 커뮤니티
:
DelPhi 2020. 4. 12. 13:50

<?
function random_string() {
$random= "";
for( $i=0; $i<rand(7,8); $i++) {
     if(rand(0,1)) {
$random .= rand(0, 9);
} else {
$random .= chr(rand(98, 122));
}
}
return $random;
}
print_r(random_string());
?>

posted by 핵커 커뮤니티
:
DelPhi 2020. 4. 12. 13:40

▶ 폼(Form)의 정의

폼은 델파이 프로그래밍에서 가장 중심적인 요소이며 실행시 사용자의 눈에 직접적으로 나타나는 하나의 윈도우가 된다.

폼은 도화지에 비유할 수 있으며 버튼이나 레이블, 리스트 박스, 콤보 박스 등의 컴포넌트를 바로 이 폼에 배치해 놓음으로써

완성되어 간다.



▶ 폼의 중요 속성

폼도 일종의 컴포넌트이므로 다양한 속성을 가지고 있다. 완성된 어플리케이션의 윈도우로 나타나게될 폼은 그 속성을 어떻게

지정하느냐에 따라 각기 다른 여러 가지의 외형을 갖게 되는 것이다.

★ Align

☞ 폼의 사이즈 및 위치를 정해준다. 디폴트 값은 alNone 이다.

alNone : 폼의 크기 및 위치가 사용자가 디자인한 사이즈,위치로서 나타난다.

alClient : 크기가 모니터 화면 전체 크기로 조정되어 나타난다.

alTop : 폼이 모니터 화면 상단에 나타난다.

alBottom : 폼이 모니터 화면 하단에 나타난다.

alLeft : 폼이 모니터 화면 좌측에 나타난다.

alRight : 폼이 모니터 화면 우측에 나타난다.



★ BorderStyle

☞ 폼의 성질을 정해준다. 디폴트 값은 bsSizeable 이다.

bsSingle : 크기 조절이 불가능하며 하나의 선을 가진 경계선을 갖는다.

bsToolWindow : bsSingle과 같으나 종료버튼만을 가지며 컨트롤 메뉴도 가지지 않는다.

bsSizeable : 크기 조절, 위치 이동, 최소화-최대화 버튼, 컨트롤 메뉴 기능과 경계선을 모두 갖는다.

bsSizeToolWin : bsSizeable과 같으나 종료버튼만을 가지며 컨트롤 메뉴도 가지지 않는다.

bsDialog : 크기 조절이 불가능한 일종의 대화상자의 형태를 갖는다.

bsNone : 크기 조절, 최소화-최대화 버튼, 컨트롤 메뉴, 위치 변경 기능이 모두 불가능하며 경계선도

없는 가장 단순한 폼이다.



★ Caption

☞ 폼의 경계선의 제목을 설정한다.


★ Color

☞ 폼 표면의 색을 설정한다.


★ Height, width, left, top

☞ Height : 폼의 크기 조절

☞ width : 폼의 높이 조절

☞ left : 폼의 맨 왼쪽 모서리의 위치 조절

☞ top : 폼의 맨 위쪽 모서리의 위치 조절


★ VerScrollBar 와 HorzScrollBar

☞ 폼에 생성될 수직, 또는 수평 스크롤 바의 유무와 세부 속성들을 지정한다.



▶ 폼의 중요 이벤트

☞ OnActive : 폼이 포커스를 받을 때 발생

☞ OnClose : 폼이 종료할때 발생

☞ OnCloseQuery : 폼의 종료 조건을 지정할 수 있다.

☞ OnClick : 폼 위에서 마우스가 클릭될 때 발생

☞ OnCreate : 프로그램이 실행됨에 따라 폼이 생성되면서 발생하는 디폴트 이벤트이다.

☞ OnDeactivate : 폼이 포커스를 잃을 때 발생

☞ OnHide : 폼이 보이지 않을 때 발생

☞ OnPaint : 폼이 새로 그려질 때 발생

☞ OnResize : 폼의 크기가 변경될 때 발생

☞ OnShow : 폼이 보이게 될 때 발생



▶ 폼의 중요 메소드

★ Close

☞ 폼 안에 배치된 모든 컴포넌트 및 모듈을 메모리에서 완전히 제거하고 폼을 닫는다.

예제1) Form14.close;

☞ name이 Form14인 폼을 닫는다.

예제2) close;

☞ 현재 코딩을 하고 있는 자기 자신의 폼을 닫는다.

다시 말해서, Form1의 유닛에서 이 메소드가 쓰여지고 있을때, Form1을 close시키는 것과 같다.


★ Hide

☞ 폼을 보이지 않도록 하나 메모리에서 완전히 제거하는 것은 아니다.


★ Show

☞ 폼을 보여준다.


★ ShowModal

☞ 폼을 보여주되 Modal 형태로 보여준다. 해당 폼을 종료하지 않고서는 다른 폼이나 어플리케이션으로 전환 할

수 없는 폼을 모달 폼(Modal Form)이라 한다

posted by 핵커 커뮤니티
:
DelPhi 2020. 4. 11. 13:50

Delphi.7.Second.Edition.v7.2.vol1.egg
10.00MB
Delphi.7.Second.Edition.v7.2.vol2.egg
10.00MB
Delphi.7.Second.Edition.v7.2.vol3.egg
10.00MB
Delphi.7.Second.Edition.v7.2.vol4.egg
10.00MB
Delphi.7.Second.Edition.v7.2.vol5.egg
2.05MB

posted by 핵커 커뮤니티
: