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控制元件,求大神有什么解決的方法么?除了控制元件之外還有沒簡單一點解決的方法呢?
uj5u.com熱心網友回復:
Additional 標簽頁中的那個帶3個箭頭的就是 TApplicationEvents 控制元件uj5u.com熱心網友回復:
我加入了TApplicationEvents 控制元件但dll的表單還是不能得到焦點,dll表單里面的Edit控制元件還是不能輸入內容這是怎么回事呢?
uj5u.com熱心網友回復:
是否定義為子表單?uj5u.com熱心網友回復:
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;
uj5u.com熱心網友回復:
大家有沒有搞定,發一個demo給我行嗎?[email protected]
uj5u.com熱心網友回復:
樓主要是解決了能否通知一聲?我這也有好幾個問題:1、EXE表單的標題欄為灰色;
2、用滑鼠在任務欄上切換時,EXE表單雖然被按下去了,但是沒有提前;
3、有些按鍵滑鼠離開不會恢復平面,如speedbutton
4、DLL表單中hint無法顯示;
一塊討論一下!
uj5u.com熱心網友回復:
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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/107212.html
