- . , vcl api. , ( ), .
- ( .dpr ):
program Window;
{
This is an example of making an application
without using the Forms unit. Forms.pas is the
Delphi unit that makes your programs so damn
huge! Forms.pas has all the code for translating
the forms you create with Delphi w/components
into windows.
}
uses Windows, Messages;
{$R *.RES}
var
wClass: TWndClass;
hFont,
hInst,
Handle,
hEncrypt,
hDecrypt,
hEdit,
hLabel,
hPW: HWND;
Msg: TMSG;
dEncrypt,
dDecrypt: Pointer;
(*------------------------------------------------*)
procedure Resize;
var
RCT:TRect;
begin
GetWindowRect(Handle,RCT);
MoveWindow(hPW,230,5,RCT.Right-RCT.Left-245,24,True);
MoveWindow(hEdit,5,34,RCT.Right-RCT.Left-20,RCT.Bottom-RCT.Top-66,True);
end;
(*------------------------------------------------*)
procedure ShutDown;
begin
DeleteObject(hFont);
UnRegisterClass('Sample Class',hInst);
ExitProcess(hInst);
end;
(*------------------------------------------------*)
procedure Decrypt;
var
x,i,
sText,sPW: Integer;
Text,PW: PChar;
begin
sText:=GetWindowTextLength(hEdit)+1;
sPW:=GetWindowTextLength(hPW)+1;
GetMem(Text,sText);
GetMem(PW,sPW);
GetWindowText(hEdit,Text,sText);
GetWindowText(hPW,PW,sPW);
x:=0;
for i:=0 to sText-2 do
begin
Text[i]:=Chr(Ord(Text[i])-Ord(PW[x]));
Inc(x);
if x=(sPW-1)then x:=0;
end;
SetWindowText(hEdit,Text);
FreeMem(Text);
FreeMem(PW);
end;
(*------------------------------------------------*)
procedure Encrypt;
var
x,i,
sText,sPW: Integer;
Text,PW: PChar;
begin
sText:=GetWindowTextLength(hEdit)+1;
sPW:=GetWindowTextLength(hPW)+1;
GetMem(Text,sText);
GetMem(PW,sPW);
GetWindowText(hEdit,Text,sText);
GetWindowText(hPW,PW,sPW);
x:=0;
for i:=0 to sText-2 do
begin
Text[i]:=Chr(Ord(Text[i])+Ord(PW[x]));
Inc(x);
if x=(sPW-1)then x:=0;
end;
SetWindowText(hEdit,Text);
FreeMem(Text);
FreeMem(PW);
end;
(*------------------------------------------------*)
function EncryptProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
var
i: Integer;
begin
Result:=CallWindowProc(dEncrypt,hWnd,Msg,wParam,lParam);
case Msg of
WM_KEYDOWN: if wParam=9 then SetFocus(hDecrypt);
end;
end;
(*------------------------------------------------*)
function DecryptProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
Result:=CallWindowProc(dEncrypt,hWnd,Msg,wParam,lParam);
case Msg of
WM_KEYDOWN: if wParam=9 then SetFocus(hEncrypt);
end;
end;
(*------------------------------------------------*)
function WindowProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
case Msg of
WM_SIZE: Resize;
WM_COMMAND: if lParam=hEncrypt then Encrypt
else if lParam=hDecrypt then Decrypt;
WM_DESTROY: ShutDown;
end;
end;
(*------------------------------------------------*)
begin
hInst:=GetModuleHandle(nil);
with wClass do
begin
Style:= CS_PARENTDC;
hIcon:= LoadIcon(hInst,'MAINICON');
lpfnWndProc:= @WindowProc;
hInstance:= hInst;
hbrBackground:= COLOR_BTNFACE+1;
lpszClassName:= 'Sample Class';
hCursor:= LoadCursor(0,IDC_ARROW);
end;
RegisterClass(wClass);
Handle:=CreateWindow(
'Sample Class',
'Encrypter',
WS_OVERLAPPEDWINDOW or
WS_VISIBLE,
10,
10,
400,
300,
0,
0,
hInst,
nil);
hEncrypt:=CreateWindow(
'Button',
'Encrypt',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
5,5,65,24,Handle,0,hInst,nil);
hDecrypt:=CreateWindow(
'Button',
'Decrypt',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
75,5,65,24,Handle,0,hInst,nil);
hEdit:=CreateWindowEx(
WS_EX_CLIENTEDGE,
'Edit',
'',
WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or ES_WANTRETURN or ES_AUTOVSCROLL or WS_VSCROLL,
5,34,380,234,Handle,0,hInst,nil);
hPW:=CreateWindowEx(
WS_EX_CLIENTEDGE,
'Edit',
'',
WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL or ES_PASSWORD,
230,5,155,24,Handle,0,hInst,nil);
hLabel:=CreateWindow(
'Static',
'Password:',
WS_VISIBLE or WS_CHILD or SS_LEFT,
160,10,70,20,Handle,0,hInst,nil);
hFont:=CreateFont(
-12,
0,
0,
0,
0,
0,
0,
0,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE,
'MS Sans Serif');
SendMessage(hEncrypt,WM_SETFONT,hFont,0);
SendMessage(hDecrypt,WM_SETFONT,hFont,0);
SendMessage(hEdit,WM_SETFONT,hFont,0);
SendMessage(hPW,WM_SETFONT,hFont,0);
SendMessage(hLabel,WM_SETFONT,hFont,0);
dEncrypt:=Pointer(GetWindowLong(hEncrypt,GWL_WNDPROC));
SetWindowLong(hEncrypt,GWL_WNDPROC,Longint(@EncryptProc));
dDecrypt:=Pointer(GetWindowLong(hDecrypt,GWL_WNDPROC));
SetWindowLong(hDecrypt,GWL_WNDPROC,Longint(@DecryptProc));
SetFocus(hEncrypt);
while(GetMessage(Msg,Handle,0,0))do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.