一个窗口封装到dll中就不显示

yning112 yning112 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用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导出,再调用,窗口就不再弹出了,为什么?
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
yning112
Windows SDK/API 1,184 成员 22,326 内容