我的代码如下,请大家看看,我认为是MdiChild在消息处理上和其他类型的窗口有区别,但<br>不知道区别在哪里,着急啊!!!<br><br>mdichild子窗口dll<br>/////////////////////////////////////////////////////////////////////<br>library mdi;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> SysUtils,<br> Classes,<br> Windows,<br> Forms,<br> Unit1 in 'Unit1.pas' {Form1};<br><br>procedure Load(ParentApplication : TApplication; ParentForm : TForm); export; stdcall;<br>var<br> DllProc : Pointer;<br>begin<br> Application:=ParentApplication;<br> Form1:=TForm1.Create(ParentForm);<br> Form1.MyParentForm:=ParentForm;<br> Form1.MyParentApplication:=ParentApplication;<br> Form1.Show;<br>end;<br><br>procedure DLLUnloadProc(Reason : Integer); register;<br>begin<br> if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;<br>end;<br><br>{$R *.RES}<br><br>exports<br> Load;<br><br>begin<br> DllApplication:=Application;<br> DllProc:=@DLLUnloadProc;<br>end.<br>/////////////////////////////////////////////////////////////////////<br><br>/////////////////////////////////////////////////////////////////////<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>const<br> M_A_S = 'A';<br> M_B_S = 'B';<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Button3: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> private<br> { Private declarations }<br> M_A : WPARAM;<br> M_B : WPARAM;<br> procedure Do_M_A(var msg:TMessage); message 12345;<br> protected<br> procedure WndProc(var Message : TMessage); override;<br> public<br> { Public declarations }<br> MyParentForm : TForm;<br> MyParentApplication : TApplication; <br> end;<br><br>var<br> Form1: TForm1;<br> DllApplication : TApplication;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> M_A:=RegisterWindowMessage(M_A_S);<br> M_B:=RegisterWindowMessage(M_B_S);<br>end;<br><br>procedure TForm1.WndProc(var Message : TMessage);<br>begin<br> if Message.Msg = M_A then<br> ShowMessage('received : M_A from Mdi');<br> if Message.Msg = M_B then<br> ShowMessage('received : M_B from Mdi');<br><br> inherited WndProc(Message);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> //SendMessage(HWND_BROADCAST,M_A,0,0);<br> PostMessage(HWND_BROADCAST,M_A,0,0);<br> ShowMessage('sended : M_A');<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> SendMessage(HWND_BROADCAST,M_B,0,0);<br> ShowMessage('sended : M_B');<br>end;<br><br>procedure TForm1.Do_M_A(var msg:TMessage);<br>begin<br> ShowMessage('received : 12345 from Mdi');<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>begin<br> SendMessage(HWND_BROADCAST,12345,0,0);<br>end;<br><br>end.<br>/////////////////////////////////////////////////////////////////////<br><br>SDI框架<br>/////////////////////////////////////////////////////////////////////<br>unit Sdimain;<br><br>interface<br><br>uses Windows, Classes, Graphics, Forms, Controls, Menus,<br> Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, ImgList, StdActns,<br> ActnList, ToolWin, Messages;<br><br>const<br> M_A_S = 'A';<br> M_B_S = 'B';<br><br>type<br> TSDIAppForm = class(TForm)<br> OpenDialog: TOpenDialog;<br> SaveDialog: TSaveDialog;<br> ToolBar1: TToolBar;<br> ToolButton9: TToolButton;<br> ToolButton1: TToolButton;<br> ToolButton2: TToolButton;<br> ToolButton3: TToolButton;<br> ToolButton4: TToolButton;<br> ToolButton5: TToolButton;<br> ToolButton6: TToolButton;<br> ActionList1: TActionList;<br> FileNew1: TAction;<br> FileOpen1: TAction;<br> FileSave1: TAction;<br> FileSaveAs1: TAction;<br> FileExit1: TAction;<br> EditCut1: TEditCut;<br> EditCopy1: TEditCopy;<br> EditPaste1: TEditPaste;<br> HelpAbout1: TAction;<br> StatusBar: TStatusBar;<br> ImageList1: TImageList;<br> MainMenu1: TMainMenu;<br> File1: TMenuItem;<br> FileNewItem: TMenuItem;<br> FileOpenItem: TMenuItem;<br> FileSaveItem: TMenuItem;<br> FileSaveAsItem: TMenuItem;<br> N1: TMenuItem;<br> FileExitItem: TMenuItem;<br> Edit1: TMenuItem;<br> CutItem: TMenuItem;<br> CopyItem: TMenuItem;<br> PasteItem: TMenuItem;<br> Help1: TMenuItem;<br> HelpAboutItem: TMenuItem;<br> Message1: TMenuItem;<br> A1: TMenuItem;<br> B1: TMenuItem;<br> Dll1: TMenuItem;<br> LoadMdi1: TMenuItem;<br> procedure FileNew1Execute(Sender: TObject);<br> procedure FileOpen1Execute(Sender: TObject);<br> procedure FileSave1Execute(Sender: TObject);<br> procedure FileExit1Execute(Sender: TObject);<br> procedure HelpAbout1Execute(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure A1Click(Sender: TObject);<br> procedure B1Click(Sender: TObject);<br> procedure LoadMdi1Click(Sender: TObject);<br> private<br> { Private declarations }<br> M_A : WPARAM;<br> M_B : WPARAM;<br> protected<br> procedure WndProc(var Message : TMessage); override; <br> public<br> { Public declarations }<br> end;<br><br> T_ProvaChild = procedure (ParentApplication : TApplication; ParentForm : TForm); stdcall;<br><br>var<br> SDIAppForm: TSDIAppForm;<br><br>implementation<br><br>uses About;<br><br>{$R *.DFM}<br><br>procedure TSDIAppForm.FileNew1Execute(Sender: TObject);<br>begin<br> { Do nothing }<br>end;<br><br>procedure TSDIAppForm.FileOpen1Execute(Sender: TObject);<br>begin<br> OpenDialog.Execute;<br>end;<br><br>procedure TSDIAppForm.FileSave1Execute(Sender: TObject);<br>begin<br> SaveDialog.Execute;<br>end;<br><br>procedure TSDIAppForm.FileExit1Execute(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>procedure TSDIAppForm.HelpAbout1Execute(Sender: TObject);<br>begin<br> AboutBox.ShowModal;<br>end;<br><br>procedure TSDIAppForm.FormCreate(Sender: TObject);<br>begin<br> M_A:=RegisterWindowMessage(M_A_S);<br> M_B:=RegisterWindowMessage(M_B_S);<br>end;<br><br>procedure TSDIAppForm.A1Click(Sender: TObject);<br>begin<br> SendMessage(HWND_BROADCAST,M_A,0,0);<br> ShowMessage('sended : M_A');<br>end;<br><br>procedure TSDIAppForm.B1Click(Sender: TObject);<br>begin<br> SendMessage(HWND_BROADCAST,M_B,0,0);<br> ShowMessage('sended : M_B'); <br>end;<br><br>procedure TSDIAppForm.WndProc(var Message : TMessage);<br>begin<br> if Message.Msg = M_A then<br> ShowMessage('received : M_A');<br> if Message.Msg = M_B then<br> ShowMessage('received : M_B');<br><br> inherited WndProc(Message);<br>end;<br><br>procedure TSDIAppForm.LoadMdi1Click(Sender: TObject);<br>var<br> DllHandle : THandle;<br> ProcAddr : FarProc;<br> ProvaChild : T_ProvaChild;<br>begin<br> DllHandle:=LoadLibrary('mdi.dll');<br> ProcAddr:=GetProcAddress(DllHandle,'Load');<br> if ProcAddr <> nil then<br> begin<br> ProvaChild:=ProcAddr;<br> ProvaChild(Application,SDIAppForm);<br> end<br> else<br> ShowMessage('调用模块失败!');<br>end;<br><br>end.<br>/////////////////////////////////////////////////////////////////////<br><br>