全部博文(788)
分类:
2009-04-08 09:22:44
还是用c吧。
虽然写法差不多,
找到一个给你参考,个人认为不错
Advanced Delphi Windows / Shell / API / Graphics / OLE Programming
可以的~
自己找例子啦,很多的呢~
诸位能否费心看看我的代码,编译是没有问题的,为什么窗体没有显示出来呢
为什么呢
算了,我找到答案了
program OnlyAPI;
uses
Windows,
Messages,
SysUtils;
const
AppName = 'ObjectPascalHello';
function WindowProc(Window: HWnd; AMessage: UINT; WParam : WPARAM;
LParam: LPARAM): LRESULT; stdcall; export;
var
dc : hdc;
ps : TPaintStruct;
r : TRect;
begin
WindowProc := 0;
case AMessage of
WM_PAINT :
begin
dc := BeginPaint(Window,ps);
GetClientRect(Window,r);
DrawText(dc,'使用Object Pascal撰写的Native Windows程序',-1,r,DT_SINGLELINE or DT_CENTER or DT_VCENTER);
EndPaint(Window,ps);
Exit;
end;
WM_MOUSEMOVE :
begin
dc := BeginPaint(Window,ps);
GetClientRect(Window,r);
DrawText(dc,'移动了Mouse',-1,r,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
EndPaint(Window,ps);
Exit;
end;
WM_LBUTTONDOWN :
begin
dc := BeginPaint(Window,ps);
GetClientRect(Window,r);
DrawText(dc,'点击了Mouse',-1,r,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
EndPaint(Window,ps);
Exit;
end;
wm_Destroy:
begin
PostQuitMessage(0);
Exit;
end;
end;
WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
end;
{ Register the Window Class }
function WinRegister: Boolean;
var
WindowClass: WndClass;
begin
WindowClass.Style := cs_hRedraw or cs_vRedraw;
WindowClass.lpfnWndProc := TFNWndProc(@WindowProc);
WindowClass.cbClsExtra := 0;
WindowClass.cbWndExtra := 0;
WindowClass.hInstance := system.MainInstance;
WindowClass.hIcon := LoadIcon(0, idi_Application);
WindowClass.hCursor := LoadCursor(0, idc_Arrow);
WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
WindowClass.lpszMenuName := nil;
WindowClass.lpszClassName := AppName;
Result := RegisterClass(WindowClass) <> 0;
end;
{ Create the Window Class }
function WinCreate: HWnd;
var
hWindow: HWnd;
begin
hWindow := CreateWindow(AppName, 'Hello world Object Pascal program',ws_OverlappedWindow, cw_UseDefault, cw_UseDefault, cw_UseDefault, cw_UseDefault, 0, 0, system.MainInstance, nil);
if hWindow <> 0 then begin
ShowWindow(hWindow, CmdShow);
ShowWindow(hWindow, SW_SHOW);
UpdateWindow(hWindow);
end;
Result := hWindow;
end;
var
AMessage: TMsg;
hWindow: HWnd;
begin
if not WinRegister then begin
MessageBox(0, 'Register failed', nil, mb_Ok);
Exit;
end;
hWindow := WinCreate;
if longint(hWindow) = 0 then begin
MessageBox(0, 'WinCreate failed', nil, mb_Ok);
Exit;
end;
while GetMessage(AMessage, 0, 0, 0) do begin
TranslateMessage(AMessage);
DispatchMessage(AMessage);
end;
Halt(AMessage.wParam);
end.
李维的代码,学习下先
uses windows
或者自己 直接 声明引用的 dll
呵呵 我是直接在在工程文件中用DLL 所引用的DLL 里面的具体功能也用DLL来实现 全部动态加载 这样占用的内存就是很少的 然后在加上定时内存整理 基本上能满足需要
吼吼,回到VB的年代了...