一个窗口封装到dll中就不显示
用api做一个窗口 ,直接使用可以弹出窗口, 把它封装到dll中调用窗口就不弹出了,下面是一个按钮弹出窗口的代码
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
WndClass:TWndClass;
WndHandle:HWND;
Msg:TMsg;
const
szAppName:PChar='Hellowin';
szAppTitle:PChar='The Hello Program!';
implementation
{$R *.dfm}
function WndProc(Handle:HWND;Msg:UINT;wPar:WPARAM;lPar:LPARAM):Cardinal;stdcall;
var
DC:HDC;
PS:PAINTSTRUCT;
RT:TRECT;
begin
Result:=0;
case Msg of
WM_PAINT:
begin
DC:=BeginPaint(WndHandle,PS);
GetClientRect(WndHandle,Rt);
DrawText(DC,'Hello,Windows!',-1,RT,DT_SINGLELINE or DT_CENTER
or DT_VCENTER);
EndPaint(WndHandle,PS);
end;
WM_DESTROY:
PostQuitMessage(0);
else
Result:=DefWindowProc(Handle,Msg,wPar,lPar);
end;
end;
procedure main();
begin
with WndClass do
begin
Style:=CS_HREDRAW or CS_VREDRAW;
lpfnWndProc:=@WndProc;
cbClsExtra:=0;
cbWndExtra:=0;
hInstance:=MainInstance;
hIcon:=LoadIcon(HInstance,'MAINICON');
hCursor:=LoadCursor(0,IDC_ARROW);
hbrBackground:=HBRUSH(GetStockObject(WHITE_BRUSH));
lpszMenuName:=nil;
lpszClassName:=szAppName;
end;
if windows.RegisterClass(WndClass)=0 then
begin
MessageBox(0,'Can''t create window!',szAppTitle,MB_OK or MB_ICONERROR);
Exit;
end;
WndHandle:=CreateWindow(szAppName,szAppTitle,WS_OVERLAPPEDWINDOW,
Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
0,0,hInstance,nil);
ShowWindow(WndHandle,1);
UpdateWindow(WndHandle);
while GetMessage(Msg,0,0,0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
main();
end;
begin
end.
我把main()用dll导出,再调用,窗口就不再弹出了,为什么?