delphi7融合DLL中的窗体无法获取焦点,求大神

Jeff-Jiang 2014-03-06 10:25:41
delphi7融合DLL中的窗体无法获取焦点,求大神看看我的代码是这样的
DLL里面是这样写的
function ShowDll(Parent:THandle;):HWND;stdcall; export;
begin
Application.Handle:= Parent;

if Form1 = nil then
Form1:= TForm1.Create(Application);
Form1.ParentWindow:= Parent;
Form1.Show;
Result:= Form1.Handle;
end;
宿主窗体里面是这样调用的
DllFormHandle:THandle;
DllFormHandle:= ShowDll(Panel1.Handle);
现在窗体能融合到宿主窗体里面了,但DLL肿的窗体无法获得焦点,里面的Edit根本没法输入内容这要怎么解决呢?
我在网上查资料http://www.360doc.com/content/12/0802/10/7873422_227797421.shtml
说是要在宿主程序中添加AppEvent控件,并在其OnMessage事件中增加如下代码:
  if IsDialogMessage(ExternMonitorHandle,Msg)then  
  Handled:=True;
但delphi7里面我找不到AppEvent控件,求大神有什么解决的方法么?除了控件之外还有没简单一点解决的方法呢?
...全文
992 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
李_军 2014-06-06
  • 打赏
  • 举报
回复
dll代码 library dllprj; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses SysUtils, Classes, Dockfrm in 'Dockfrm.pas' {frmdock}; {$R *.res} exports ShowFrm,CloseFrm; begin end. unit Dockfrm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; procedure ShowFrm(sHand:THandle);stdcall; Procedure CloseFrm;stdcall; type Tfrmdock = class(TForm) Button1: TButton; Label1: TLabel; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; var frmdock: Tfrmdock; implementation {$R *.dfm} procedure ShowFrm(sHand: THandle);stdcall; begin Application.Handle := sHand; if not Assigned(frmdock) then begin frmdock := Tfrmdock.Create(Application); frmdock.ParentWindow := sHand; frmdock.Show; end; end; Procedure CloseFrm;stdcall; begin if Assigned(frmdock) then FreeAndNil(frmdock); end; procedure Tfrmdock.Button1Click(Sender: TObject); begin Showmessage('fdsaf'); end; procedure Tfrmdock.FormClose(Sender: TObject; var Action: TCloseAction); begin Action :=CaFree; frmdock := Nil; end; end. 调用窗体代码 unit callfrm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Menus; Procedure ShowFrm(sHandle:THandle);stdcall;external 'dllprj.dll'; Procedure CloseFrm;stdcall;external 'dllprj.dll'; //function func(): Integer; stdcall; external '12345.dll'; type Tfrmcall = class(TForm) MainMenu1: TMainMenu; fdgs1: TMenuItem; N1231: TMenuItem; N2341: TMenuItem; Panel1: TPanel; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure N1231Click(Sender: TObject); procedure N2341Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var frmcall: Tfrmcall; implementation uses unit1; {$R *.dfm} procedure Tfrmcall.FormClose(Sender: TObject; var Action: TCloseAction); begin CloseFrm; end; procedure Tfrmcall.N1231Click(Sender: TObject); begin ShowFrm(Panel1.Handle); end; procedure Tfrmcall.N2341Click(Sender: TObject); begin //showmessage(IntToStr(func())); end; end.
snownxtbaby 2014-05-07
  • 打赏
  • 举报
回复
楼主要是解决了能否通知一声?我这也有好几个问题: 1、EXE窗体的标题栏为灰色; 2、用鼠标在任务栏上切换时,EXE窗体虽然被按下去了,但是没有提前; 3、有些按键鼠标离开不会恢复平面,如speedbutton 4、DLL窗体中hint无法显示; 一块讨论一下!
ahdogwang 2014-04-14
  • 打赏
  • 举报
回复
大家有没有搞定,发一个demo给我行吗? ahdogwang@163.com
Jeff-Jiang 2014-03-07
  • 打赏
  • 举报
回复
我加入了TApplicationEvents 控件但dll的窗体还是不能得到焦点,dll窗体里面的Edit控件还是不能输入内容这是怎么回事呢?
lght 2014-03-07
  • 打赏
  • 举报
回复
DLL的application要用exe的application

var
  DLLApp: TApplication;
  DLLScr: TScreen;

function CreateForm(App: TApplication; Scr: TScreen): HWND;
begin
  Application := App;
  Screen := Scr;
  Form1:= TForm1.Create(Application);
  ...
end;

procedure DLLRun(Reason: Integer);
begin
  if Reason = DLL_PROCESS_DETACH then
  begin
    Application := DLLApp;
    Screen := DLLScr;
  end;
end;

exports
  CreateForm;

begin
  DLLApp := Application;
  DLLScr := Screen;
  DLLProc := @DLLRun;
volte 2014-03-07
  • 打赏
  • 举报
回复
是否定义为子窗体?
sololie 2014-03-06
  • 打赏
  • 举报
回复
Additional 标签页中的那个带3个箭头的就是 TApplicationEvents 控件

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧