Delphi's sdk program (100分)

F

fu_xiang_yu

Unregistered / Unconfirmed
GUEST, unregistred user!
什么意思,可否说明白点
 

车金明

Unregistered / Unconfirmed
GUEST, unregistred user!
这个用API函数写的小程序是否符合你的要求?
program Project1;

uses
Windows, Messages, sysutils;

{$R *.RES}
function WindowProc(hwnd:HWND;Msg,wparam,lparam:LongWord):longint;stdcall;
const
str='用API函数生成的一个小程序';
var
pt:TPaintStruct;
dc:HDC;
begin
case msg of
WM_PAINT:
begin
dc:=BeginPaint(hwnd,pt);
TextOut(dc,20,20,str,length(str));
EndPaint(hwnd,pt);
end;
wm_destroy:postQuitMessage(0);
end;
result:=DefWindowProc(hwnd,msg,wparam,lparam);
end;
function winmain:Longint;
const
appName='SDK程序';
var
msg:TMSG;
wndclass:TWndClass;
hwnd:THandle;
begin
result:=0;
FillChar(wndclass,sizeof(TWndclass),0);
wndclass.hInstance:=HInstance;
wndclass.lpfnWndProc:=@Windowproc;
wndclass.hbrBackground:=GetStockObject(WHITE_BRUSH);
wndclass.hCursor:=loadCursor(0,IDC_ARROW);
wndclass.hIcon:=LoadIcon(0,IDI_APPLICATION);
wndclass.lpszClassName:=appName;
if RegisterClass(wndclass)=0 then exit;
hwnd:=CreateWindow(appName,appName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,hinstance,Nil);
if hwnd<>0 then
begin
UpdateWindow(hwnd);
ShowWindow(hwnd,SW_Show);
while GetMessage(msg,0,0,0)do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
result:=msg.wparam;
end;
end;
begin
winMain;
end.
 

飞来石

Unregistered / Unconfirmed
GUEST, unregistred user!
program SDKProgram;

uses
Windows,
Messages;

var
WinClass: TWndClassA;
Inst, Handle, Button1, Label1, Edit1: Integer;
Msg: TMsg;
hFont: Integer;

{ Checks if typed password is 'Amigreen' and shows Message }
procedure CheckPassword;
var
Textlength: Integer;
Text: PChar;
begin
TextLength := GetWindowTextLength(Edit1);
if TextLength = 8 then
begin
GetMem(Text, TextLength + 1);
GetWindowText(Edit1, Text, TextLength + 1);
if Text = 'Amigreen' then
begin
MessageBoxA(Handle, 'Password is correct.', 'Password check', MB_OK);
FreeMem(Text, TextLength + 1);
Exit;
end;
end;
MessageBoxA(Handle, 'Password is incorrect.', 'Password check', MB_OK);
end;

{ Custom WindowProc function }
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer
stdcall;
begin
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
{ Checks for messages }
if (lParam = Button1) and (uMsg = WM_COMMAND) then
CheckPassword;
if uMsg = WM_DESTROY then
Halt;
end;

begin
{ ** Register Custom WndClass ** }
Inst := hInstance;
with WinClass do
begin
style := CS_CLASSDC or CS_PARENTDC;
lpfnWndProc := @WindowProc;
hInstance := Inst;
hbrBackground := color_btnface + 1;
lpszClassname := 'AG_TESTWINDOW';
hCursor := LoadCursor(0, IDC_ARROW);
end
{ with }
RegisterClass(WinClass);

{ ** Create Main Window ** }
Handle := CreateWindowEx(WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'Amigreen TestWindow 1.00',
WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
363, 278, 305, 65, 0, 0, Inst, nil);
{ ** Create a button ** }
Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
216, 8, 75, 25, handle, 0, Inst, nil);
{ ** Create a label (static) ** }
Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,
8, 12, 76, 13, Handle, 0, Inst, nil);

{ ** Create an edit field ** }
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
WS_BORDER or ES_PASSWORD, 88, 8, 121, 21, Handle, 0, Inst, nil);

{ ** Create Font Handle ** }
hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');

{ Change fonts }
if hFont <> 0 then
begin
SendMessage(Button1, WM_SETFONT, hFont, 0);
SendMessage(Label1, WM_SETFONT, hFont, 0);
SendMessage(Edit1, WM_SETFONT, hFont, 0);
end;
{ Change label (static) text }
SetWindowText(Label1, 'Enter password:');
{ Set the focus to the edit control }
SetFocus(Edit1);

UpdateWindow(Handle);

{ ** Message Loop ** }
while(GetMessage(Msg, Handle, 0, 0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end
{ with }
end.

别忘记给我加分呀!
 
Y

yxyyyy

Unregistered / Unconfirmed
GUEST, unregistred user!
难道你要一个DELPHI的纯API程序??
请看!!!!!!!!!!
program Project1;
{$R *.RES}
uses
Windows,
messages;

const
id_Button = 100;

function PlainWinProc(hWnd : THandle
nMsg : UINT;
wParam, IParam: Cardinal ): Cardinal
export
stdcall;
var
hdc: THandle ;
ps : TPaintStruct ;
Rect : TRect ;
begin
Result := 0;
case nMsg of
wm_Command:
//if it comes from the button
if LoWord(wParam ) = id_Button then
//if it is a click
if HiWord(wParam) = bn_Clicked then
MessageBox (hWnd,'Button Clicked',
'Plain API 2',MB_OK);
wm_Create:
//create button
CreateWindowEx (0,//wxtended styles
'BUTTON',
'&amp;Click here',
WS_CHILD or WS_VISIBLE or WS_BORDER or BS_PUSHBUTTON ,// styles
0, 0 ,//position : see wm_size
200, 80, //size
hwnd, //parent
id_Button, //identifier(not a menu handle)
hInstance, //application id
nil)
//init info pointer
wm_Size:
begin
// get the size of the client region of the main window
GetClientRect (hWnd, Rect);
//move the button window
SetWindowPos(
GetDlgItem(hWnd,id_Button),//button handle
0, //zOrder
Rect.Right div 2 -100,
Rect.Bottom div 2 - 40,
0,0,//new size
swp_NoZOrder or swp_NoSize);
end;
wm_lButtonDown:
MessageBox(hWnd, 'Mouse Clicked',
'Plain API',MB_OK) ;
wm_Paint:
begin
hdc := beginPaint(hWnd,ps);
Ellipse(hdc,100,100,300,300);
EndPaint(hwnd,ps);
end ;
wm_Destroy:
postQuitMessage (0);
else
Result := DefWindowProc(hWnd,nMsg,wParam,IParam) ;
end;
end;

procedure WinMain;
var
hWnd : THandle;
Msg : TMsg;
WndClassEx : TWndClassEx;
begin
// initialize the window class structure
WndClassEx.cbSize := sizeOf(TWndClassEx);
WndClassEx.lpszClassName := 'PlainWindow';
WndClassEx.style := CS_VREDRAW or CS_HREDRAW;
WndClassEx.hInstance := HINSTANCE;
WndClassEx.lpfnWndProc := @PlainWinProc;
WndClassEx.cbClsExtra := 0 ;
WndClassEx.cbWndExtra := 0 ;
WndClassEx.hIcon := LoadIcon(HINSTANCE, makeintResource('MAINICON'));
WndClassEx.hIconSm := LoadIcon(HINSTANCE, makeintResource('MAINICON'));
WndClassEx.hCursor := LoadCursor(0, IDC_ARROW);
WndClassEx.hbrBackground := GetStockObject (WHITE_BRUSH);
WndClassEx.lpszMenuName := nil ;
// register the class
if RegisterClassEx(WndClassEx) = 0 then
begin
MessageBox (0,'Invalid class registration','Plain API',MB_OK);
exit;
end;
hWnd := CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW , // wxtended styles
WndClassEx.lpszClassName , //class name
'Plain API Demo', //title
WS_OVERLAPPEDWINDOW , // old styles
CW_USEDEFAULT , 0 , // window position
CW_USEDEFAULT , 0 , //window size
0, // parent window(if any)
0, //menu resource handle
HInstance, //application-instance handle
nil)
// pointer to initial paramters
if hWnd = 0 then
MessageBox(0,'Window not created','Plain API',MB_OK)
else
begin
ShowWindow (hWnd, SW_SHOWNORMAL );
while GetMessage (Msg, 0, 0, 0) do
begin
TranslateMessage (Msg);
DispatchMessage (Msg );
end;
end;
end;

begin
WinMain;
end.
 
W

wjiachun

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 
顶部