一个窗口封装到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导出,再调用,窗口就不再弹出了,为什么?
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导出,再调用,窗口就不再弹出了,为什么?
...全文
相关推荐
DLL_Windows.rar_delphi dll窗口_多层_窗口_窗口 DLL
多层窗口封装在DLL中,各自调用的特殊处理,有模式显示,有非模式显示,关键是在任务栏的现实处理
修复PADS窗口显示不全的解决方法(适合PADS所有版本和系统)
因此小编到网上找到了使用Resource Hacker这个工具修改选项窗口的属性来修复PADS LOGIC选项菜单显示不全的BUG和修复PADS Layout封装向导窗口显示不全的Bug。最近升级了新版的Windows系统,发现PADS 9.5/VX.等版本会出现窗口显示不全的问题(如下图所示),常规办法是网上找到DLL补丁去替换原有的DLL文件,有些效果但没完全修复。当然比如修改其它的一些对话框 8809、9940、10010等等,根据自己的需要去修改一些显示不全的对话框。(修改前一定要先备份。
dll产生独立进程的运行状态窗口
dll产生独立进程的运行状态窗口
多文档框架视图封装在dll中
多文档框架视图封装在dll中,有利于系统的模块化开发,非“dll封装多文档框架视图的例子”,无BUG
VC使用DLL多风格切换窗口
摘要:VC/C++源码,界面编程,风格切换 运行环境:Windows/Visual C/C++


Windows SDK/API
