Home > Back-end >  A window in the DLL will not display
A window in the DLL will not display

Time:09-19

The use of API in a window, can directly use pop-up Windows, encapsulate it into DLL call window doesn't pop up, here is a button pop-up window code
The unit Unit3.

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
For: 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}

The function WndProc (Handle: HWND; Msg: UINT; Running: WPARAM; Them: LPARAM) : the Cardinal; Stdcall;
Var
DC: HDC.
PS: the PAINTSTRUCT;
RT: TRECT;
The begin
Result:=0;
Case Msg of
The WM_PAINT:
The begin
DC:=BeginPaint (WndHandle, PS);
GetClientRect (WndHandle, Rt);
DrawText (DC, 'Hello, Windows! ', 1, RT, DT_SINGLELINE or DT_CENTER
The or DT_VCENTER);
EndPaint (WndHandle, PS);
end;
WM_DESTROY:
The PostQuitMessage (0);
The else
Result:=DefWindowProc (Handle, Msg, starved, wouldn't);
end;
end;

Procedure the main ();
The begin
With WndClass do
The 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
The begin
MessageBox (0, 'Can' 't create the window! 'szAppTitle, MB_OK or MB_ICONERROR);
The 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) do
The begin
The TranslateMessage (Msg);
DispatchMessage (Msg);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
The begin
The main ();
end;
The begin
End.
I put the main () using DLL export, and then call, there would be no pop-up window, why?
  • Related