DLL封装的子窗体不能接受键盘消息 |
尚未結案
|
bolidehi
一般會員 發表:11 回覆:11 積分:4 註冊:2004-03-10 發送簡訊給我 |
我在写Mis系统时,将子窗体封状在DLL中,但子窗体不能接收键盘消息。如在子窗体上放三个EDIT,当打开该子窗体时,按TAB键会跳到MDI的空间上,而不是在子窗体中的Edit中切换。
1.在M DI中放一按钮调用DLL,源代码如下:
unit UFrmMain;
interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DB, DBClient, MConnect, SConnect, Grids,
DBGrids, WinSkinData, ComCtrls, dxtree; const
wm_FreeDll=wm_User $10;
type
TDllFun = function(App : TApplication; SConn : TSocketConnection) : TForm;//定义了一个函数类型
TForm1 = class(TForm)
Button1: TButton;
SocketConnection1: TSocketConnection;
SkinData1: TSkinData;
Edit1: TEdit;
dxTreeView1: TdxTreeView;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
private
DllHandle : THandle;
DllFrm : TForm;
Procedure FreeDll(var Msg : TMessage);Message wm_FreeDll; { Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
//按钮调用DLL
procedure TForm1.Button1Click(Sender: TObject);
Var
DllFun : TDllFun;
FarProc : TFarProc;
begin
DllHandle := LoadLibrary(PAnsiChar(ExtractFilePath(Application.ExeName) ’QGC.DLL’));
if DllHandle>0 then
begin
Try
FarProc := GetProcAddress(DllHandle,'ShowForm');
if Assigned(FarProc) then
begin
DllFun := TDllFun(FarProc);
DllFrm := DllFun(Application,SocketConnection1);
//DLlFrm.ParentWindow := self.Panel1.Handle;
//DLlFrm.Align := alClient;
Try
DllFrm.Show;
Finally
{DllFrm.Free;
DllFrm:=Nil;}
end;
end
else
Raise Exception.Create('接口函数不正确!');
Finally
{FreeLibrary(DllHandle);
DllHandle:=0;}
end;
end
else
Raise Exception.Create('没找到文件');
end; {子窗体退出处理}
procedure TForm1.FreeDll(var Msg: TMessage);
begin
ShowMessage('1');
if DllFrm<>nil then
begin
Try
DllFrm.Free;
DllFrm:=Nil;
Finally
FreeLibrary(DllHandle);
DllHandle:=0;
end;
end; end; end. //QGC.DLL源码
ibrary Qgc; { 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
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBClient, MConnect, SConnect,WinSkinData,
UDllChildFrm in 'UDllChildFrm.pas' {DllChildFrm}; {$R *.res}
Var
OldApp : TApplication;
{接口函数}
Function ShowForm(App : TApplication; SConn : TSocketConnection): TForm;
begin
Application := App;
Result := TDllChildFrm.Create(Application);
TDllChildFrm(Result).SocketConn := SConn;
end; procedure ExitDll(Reason : integer);
begin
if Reason = DLL_PROCESS_DETACH then
Application := OldApp;
end;
DLL封装的窗体代码
unit UDllChildFrm; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBClient, MConnect, SConnect, Grids, DBGrids,
ExtCtrls, DBCtrls, dxsbar, WinSkinData;
const
wm_FreeDLl=wm_user $10;
type
TDllChildFrm = class(TForm)
DataSource1: TDataSource;
ClientDataSet: TClientDataSet;
ClientDataSetBDCODE: TStringField;
ClientDataSetBDNAME: TStringField;
ClientDataSetBDLB: TStringField;
ClientDataSetPARENTID: TStringField;
ClientDataSetZGXLBD: TStringField;
ClientDataSetZGCK: TStringField;
ClientDataSetNO: TIntegerField;
Splitter1: TSplitter;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure ClientDataSetCalcFields(DataSet: TDataSet);
private
{ Private declarations }
public
SocketConn : TSocketConnection;
{ Public declarations }
end; var
DllChildFrm: TDllChildFrm; implementation {$R *.dfm} procedure TDllChildFrm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//Action := caHide;
PostMessage(Application.MainForm.Handle,wm_FreeDll,0,0);
end; procedure TDllChildFrm.FormShow(Sender: TObject);
begin
ClientDataSet.RemoteServer := SocketConn;
ClientDataSet.ProviderName := 'p_select';
ClientDataSet.CommandText := 'Select * From GuideItem';
ClientDataSet.Open;
ClientDataSet.First;
end; procedure TDllChildFrm.Button1Click(Sender: TObject);
begin
Close;
end; procedure TDllChildFrm.Button3Click(Sender: TObject);
begin
ClientDataSet.Insert;
end; procedure TDllChildFrm.Button4Click(Sender: TObject);
begin
ClientDataSet.Delete;
end; procedure TDllChildFrm.ClientDataSetCalcFields(DataSet: TDataSet);
begin
DataSet.FieldByName('NO').AsInteger := DataSet.RecNo;
end; end.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |