用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匯出,再呼叫,視窗就不再彈出了,為什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/53704.html
