嘻嘻,只有十几K的程序啊。 :-) ( 积分: 0 )

  • 主题发起人 主题发起人 陷队之士
  • 开始时间 开始时间

陷队之士

Unregistered / Unconfirmed
GUEST, unregistred user!
program HelloWin;
{ Standard Windows API application written in Object Pascal. }
uses
Windows,
messages,
MMSystem;
const
AppName : pChar = 'HelloWin';

function WindowProc(Window: HWnd
AMessage, WParam, LParam: LongInt):
LongInt
stdcall
export;
{ The message handler for the new window }
var
h : hdc;
ps : tPaintStruct;
r : tRect;
begin
Result := 0;
case AMessage of
WM_Create:
begin
PlaySound('C:/WINDOWS/MEDIA/Musica Windows Start.wav', 0,
Snd_FileName or Snd_Async);
Exit;
end;
WM_Paint:
begin
h := BeginPaint(Window, Ps);
GetClientRect(Window, r);
DrawText(h, 'Hello Winblows!', -1, r,
DT_SingleLine or DT_Center or DT_VCenter);
EndPaint(Window, ps);
Exit;
end;
WM_Destroy:
begin
PostQuitMessage(0);
Exit;
end;
end;
Result := DefWindowProc(Window, AMessage, WParam, LParam);
end;
{ Register the window class }

function WinRegister: Boolean;
var
WindowClass : TWndClass;
begin
WindowClass.Style := cs_HRedraw or cs_VRedraw;
WindowClass.lpfnWndProc := @WindowProc;
WindowClass.cbClsExtra := 0;
WindowClass.cbWndExtra := 0;
WindowClass.hInstance := HInstance;
WindowClass.hIcon := LoadIcon(0, idi_Application);
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
WindowClass.hbrBackground := HBrush(GetStockObject(White_Brush));
WindowClass.lpszMenuName := nil;
WindowClass.lpszClassName := AppName;
Result := RegisterClass(WindowClass) <&gt
0;
end;

function WinCreate: HWnd;
var
HWindow : HWnd;
begin
hWindow := CreateWindow(AppName,
'The Hello Program',
WS_OverlappedWindow,
CW_UseDefault, CW_UseDefault,
CW_UseDefault, CW_UseDefault,
0, 0, HInstance, nil);
if hWindow <&gt
0 then
begin
ShowWindow(hWindow, CmdShow);
UpdateWindow(hWindow);
end;
Result := hWindow;
end;
{ Main: Set up window, then give it messages until done.}
var
AMessage : TMsg;
hWindow : HWnd;
begin
if not WinRegister then
begin
MessageBox(0, 'Register Failed', nil, mb_Ok);
Exit;
end;
hWindow := WinCreate;
if hWindow = 0 then
begin
MessageBox(0, 'Register Failed', nil, mb_Ok);
Exit;
end;
while GetMessage(AMessage, 0, 0, 0) do
begin
TranslateMessage(AMessage);
DispatchMessage(AMessage);
end;
Halt(AMessage.WParam);
end.
 
program HelloWin;
{ Standard Windows API application written in Object Pascal. }
uses
Windows,
messages,
MMSystem;
const
AppName : pChar = 'HelloWin';

function WindowProc(Window: HWnd
AMessage, WParam, LParam: LongInt):
LongInt
stdcall
export;
{ The message handler for the new window }
var
h : hdc;
ps : tPaintStruct;
r : tRect;
begin
Result := 0;
case AMessage of
WM_Create:
begin
PlaySound('C:/WINDOWS/MEDIA/Musica Windows Start.wav', 0,
Snd_FileName or Snd_Async);
Exit;
end;
WM_Paint:
begin
h := BeginPaint(Window, Ps);
GetClientRect(Window, r);
DrawText(h, 'Hello Winblows!', -1, r,
DT_SingleLine or DT_Center or DT_VCenter);
EndPaint(Window, ps);
Exit;
end;
WM_Destroy:
begin
PostQuitMessage(0);
Exit;
end;
end;
Result := DefWindowProc(Window, AMessage, WParam, LParam);
end;
{ Register the window class }

function WinRegister: Boolean;
var
WindowClass : TWndClass;
begin
WindowClass.Style := cs_HRedraw or cs_VRedraw;
WindowClass.lpfnWndProc := @WindowProc;
WindowClass.cbClsExtra := 0;
WindowClass.cbWndExtra := 0;
WindowClass.hInstance := HInstance;
WindowClass.hIcon := LoadIcon(0, idi_Application);
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
WindowClass.hbrBackground := HBrush(GetStockObject(White_Brush));
WindowClass.lpszMenuName := nil;
WindowClass.lpszClassName := AppName;
Result := RegisterClass(WindowClass) <&gt
0;
end;

function WinCreate: HWnd;
var
HWindow : HWnd;
begin
hWindow := CreateWindow(AppName,
'The Hello Program',
WS_OverlappedWindow,
CW_UseDefault, CW_UseDefault,
CW_UseDefault, CW_UseDefault,
0, 0, HInstance, nil);
if hWindow <&gt
0 then
begin
ShowWindow(hWindow, CmdShow);
UpdateWindow(hWindow);
end;
Result := hWindow;
end;
{ Main: Set up window, then give it messages until done.}
var
AMessage : TMsg;
hWindow : HWnd;
begin
if not WinRegister then
begin
MessageBox(0, 'Register Failed', nil, mb_Ok);
Exit;
end;
hWindow := WinCreate;
if hWindow = 0 then
begin
MessageBox(0, 'Register Failed', nil, mb_Ok);
Exit;
end;
while GetMessage(AMessage, 0, 0, 0) do
begin
TranslateMessage(AMessage);
DispatchMessage(AMessage);
end;
Halt(AMessage.WParam);
end.
 
大家将上面的代码保存为HelloWin.dpr,再用Delphi打开,编译之,编译出来的可执行文件
只有十几K啊,呵呵 [:D]
这是一个最基本的Windows应用程序啊[:D]
 
老的不能再老的贴
 
以前就已经有高手发过这类的贴啦
 
为何,总喜欢贴老的呢?
 
太早之前就已经不是什么新鲜东西了,
 
哦,我不知道啊,别怪我[:(]
 

Similar threads

I
回复
0
查看
546
import
I
I
回复
0
查看
756
import
I
I
回复
0
查看
576
import
I
I
回复
0
查看
585
import
I
后退
顶部