急,我用主窗体调用dll(dll中有窗体),在任务栏上那dll的窗体也显示出来了?怎么把他去掉? ( 积分: 50 )

  • 主题发起人 主题发起人 yuting2003
  • 开始时间 开始时间
Y

yuting2003

Unregistered / Unconfirmed
GUEST, unregistred user!
急,我用主窗体调用dll(dll中有窗体),在任务栏上那dll的窗体也显示出来了?怎么把他去掉?<br>我想让程序运行时候在任务栏上显示主窗体.dll中的窗体不显示,<br>试了很多的,包括&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setwindowpos都不行,怎么回事啊?/<br>谁知道?
 
设置&nbsp;DLL&nbsp;里面&nbsp;Application.Handle&nbsp;为主窗体的&nbsp;Application.Handle&nbsp;就可以了.<br>以下是&nbsp;DLL&nbsp;里面借口函数的代码,参考以下就会明白.<br><br>procedure&nbsp;ShowDllForm(App:&nbsp;THandle);stdcall;<br>var<br>&nbsp;&nbsp;sHandle:&nbsp;THandle;<br>begin<br>&nbsp;&nbsp;sHandle&nbsp;:=&nbsp;Application.Handle;<br>&nbsp;&nbsp;Application.Handle&nbsp;:=&nbsp;App;<br>&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;frmDLL&nbsp;:=&nbsp;TfrmDLL.Create&nbsp;(Application);<br>&nbsp;&nbsp;&nbsp;&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frmDLL.ShowModal;<br>&nbsp;&nbsp;&nbsp;&nbsp;finally<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;frmDLL.Free;<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>&nbsp;&nbsp;except<br>&nbsp;&nbsp;&nbsp;&nbsp;on&nbsp;E:&nbsp;Exception&nbsp;do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageDlg&nbsp;('Error&nbsp;in&nbsp;DLLForm:&nbsp;'&nbsp;+<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E.Message,&nbsp;mtError,&nbsp;[mbOK],&nbsp;0);<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;Application.Handle&nbsp;:=&nbsp;sHandle;<br>end;
 
楼上的能否说明白点,我的代码是这样的,帮看看有什么问题,在任务栏就无法去掉图标<br>代码如下:<br>DLL中,<br>procedure&nbsp;OpenMyForm(handle:HWND);stdcall;<br>begin<br>&nbsp;&nbsp;if(formID=0)&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Application.Handle:=handle;<br>&nbsp;&nbsp;Application.CreateForm(Tfzrtj,&nbsp;fzrtj);<br>&nbsp;&nbsp;formID:=1;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;fzrtj.Left:=left;<br>&nbsp;&nbsp;&nbsp;fzrtj.Top:=top;<br>&nbsp;&nbsp;&nbsp;fzrtj.Width:=white;<br>&nbsp;&nbsp;&nbsp;fzrtj.Height:=hite;<br>&nbsp;&nbsp;&nbsp;//office_mianshi.adoquery1.ConnectionString:=db;<br><br>&nbsp;&nbsp;fzrtj.ShowModal();<br>end;<br><br><br>主程序调用dll代码:<br>procedure&nbsp;TForm1.ToolButton2Click(Sender:&nbsp;TObject);<br>type<br>&nbsp;&nbsp;TOpenMyForm=procedure(handle:THandle);stdcall;<br>&nbsp;&nbsp;tweizhi=function(n1,n2,n3,n4:Integer):Integer;stdcall;<br>&nbsp;&nbsp;&nbsp;var<br>&nbsp;&nbsp;OpenMyForm:TOpenMyForm;<br>&nbsp;&nbsp;lpFarProc:FARPROC;<br>&nbsp;&nbsp;weizhi:tweizhi;<br>&nbsp;&nbsp;top,Left,&nbsp;Width,Height:integer;<br>&nbsp;&nbsp;&nbsp;&nbsp;sHandle:&nbsp;THandle;<br>begin<br>&nbsp;if(hComm&lt;&gt;NULL)&nbsp;then<br>&nbsp;begin<br>&nbsp;&nbsp;lpFarProc&nbsp;:=&nbsp;GetProcAddress(hComm,'weizhi');<br>&nbsp;&nbsp;if(lpFarProc=nil)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application.MessageBox('系统严重错误,请修复或重新安装','提示')<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@weizhi&nbsp;:=&nbsp;lpFarProc;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Top:=panel5.Height+panel4.top+panel2.top+50;//(动态改变dll中的窗体大小)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Left:=((panel6.Width-903)div&nbsp;2)+TreeView1.Width;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Width:=903;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Height:=587;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;weizhi(Top,Left,Width,Height);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lpFarProc&nbsp;:=&nbsp;GetProcAddress(hComm,'OpenMyForm');<br>&nbsp;&nbsp;&nbsp;&nbsp;if(lpFarProc=nil)&nbsp;then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application.MessageBox('系统严重错误,请修复或重新安装','提示')<br>&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@OpenMyForm&nbsp;:=&nbsp;lpFarProc;&nbsp;//指针类型转换<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpenMyForm(Application.Handle);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br><br>&nbsp;end;<br><br>end;<br>可这样调用的时候&nbsp;dll中窗体的程序运行总在任务栏中显示出来,怎么也去不掉?<br>楼上的能说的详细点吗?谢谢了
 
//DLL代码:<br>library&nbsp;DLL;<br><br>uses<br>&nbsp;&nbsp;SysUtils,<br>&nbsp;&nbsp;Classes,&nbsp;Forms,<br>&nbsp;&nbsp;DLLForm&nbsp;in&nbsp;'DLLForm.pas'&nbsp;{FrmDLLChild};<br><br>{$R&nbsp;*.res}<br><br>var<br>&nbsp;&nbsp;DllApp:&nbsp;TApplication;<br><br>{&nbsp;用于初始化:保存DLL本身的Application,然后设置DLL的Application指向Host的Application&nbsp;}<br>procedure&nbsp;InitDLL(App:&nbsp;TApplication);&nbsp;stdcall;<br>begin<br>&nbsp;&nbsp;DllApp:=&nbsp;Application;<br>&nbsp;&nbsp;Application:=&nbsp;App;<br>end;<br><br>{&nbsp;善后工作:恢复DLL原来的Application&nbsp;}<br>procedure&nbsp;FreeDLL;&nbsp;stdcall;<br>begin<br>&nbsp;&nbsp;Application:=&nbsp;DllApp;<br>end;<br><br>{&nbsp;返回一个窗体对象,这是DLL的主要功能&nbsp;}<br>function&nbsp;GetDllChildForm(Parent:&nbsp;TComponent):&nbsp;TFrmDLLChild;&nbsp;stdcall;<br>begin<br>&nbsp;&nbsp;Result:=&nbsp;TFrmDLLChild.Create(Parent);<br>end;<br><br>exports&nbsp;<br>&nbsp;&nbsp;InitDLL,&nbsp;FreeDLL,&nbsp;GetDllChildForm;<br><br>begin<br><br>end.<br><br>在使用DLL的时候,需要注意:首先必须调用InitDLL,并且传递主程序的Application作为参数<br><br><br>//主程序代码:<br>unit&nbsp;MDIMain;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,&nbsp;DLLForm,&nbsp;StdCtrls,&nbsp;Menus;<br><br>type<br>&nbsp;&nbsp;TFrmMDIMain&nbsp;=&nbsp;class(TForm)<br>&nbsp;&nbsp;&nbsp;&nbsp;Button1:&nbsp;TButton;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormCreate(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;FormDestroy(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;Button1Click(Sender:&nbsp;TObject);<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Private&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;Public&nbsp;declarations&nbsp;}<br>&nbsp;&nbsp;end;<br><br>function&nbsp;GetDllChildForm(Parent:&nbsp;TComponent):&nbsp;TFrmDllChild;&nbsp;stdcall;&nbsp;external&nbsp;'dll.dll';<br>procedure&nbsp;InitDLL(App:&nbsp;TApplication);&nbsp;stdcall;&nbsp;external&nbsp;'dll.dll';<br>procedure&nbsp;FreeDLL;&nbsp;stdcall;&nbsp;external&nbsp;'dll.dll';<br><br>var<br>&nbsp;&nbsp;FrmMDIMain:&nbsp;TFrmMDIMain;<br><br>implementation<br><br>{$R&nbsp;*.dfm}<br><br>procedure&nbsp;TFrmMDIMain.FormCreate(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;InitDLL(Application);&nbsp;//这里传入参数Application<br>end;<br><br>procedure&nbsp;TFrmMDIMain.FormDestroy(Sender:&nbsp;TObject);<br>begin<br>&nbsp;&nbsp;FreeDLL;<br>end;<br><br>procedure&nbsp;TFrmMDIMain.Button1Click(Sender:&nbsp;TObject);<br>var<br>&nbsp;&nbsp;DForm:&nbsp;TFrmDllChild;<br>begin<br>&nbsp;&nbsp;DForm:=&nbsp;GetDllChildForm(Self);<br>&nbsp;&nbsp;DForm.Show;<br>end;
 
djry看下我的代码,我在OpenMyForm中不是已经传入Application.Handle了吗,可在程序运行后在任务栏中出现2个,一个是主程序,一个是dll中的窗体,请问怎么回事啊?<br>谢谢了
 
我检查了你的代码,屏蔽了&nbsp;weizhi&nbsp;运行,没有发现任何问题.<br>weizhi&nbsp;的代码贴出来吧.
 
这是dll中的全部代码:<br>我在运行时候在任务栏中显示2个,一个是主程序的,一个是dll里窗体的,<br>我不是让你们找代码错误,我是说怎么解决,让dll里窗体在任务栏中不显示<br>一个程序在任务栏中显示2个不太好吧,<br><br><br>library&nbsp;guanlidll;<br><br>{&nbsp;Important&nbsp;note&nbsp;about&nbsp;DLL&nbsp;memory&nbsp;management:&nbsp;ShareMem&nbsp;must&nbsp;be&nbsp;the<br>&nbsp;&nbsp;first&nbsp;unit&nbsp;in&nbsp;your&nbsp;library's&nbsp;USES&nbsp;clause&nbsp;AND&nbsp;your&nbsp;project's&nbsp;(select<br>&nbsp;&nbsp;Project-View&nbsp;Source)&nbsp;USES&nbsp;clause&nbsp;if&nbsp;your&nbsp;DLL&nbsp;exports&nbsp;any&nbsp;procedures&nbsp;or<br>&nbsp;&nbsp;functions&nbsp;that&nbsp;pass&nbsp;strings&nbsp;as&nbsp;parameters&nbsp;or&nbsp;function&nbsp;results.&nbsp;This<br>&nbsp;&nbsp;applies&nbsp;to&nbsp;all&nbsp;strings&nbsp;passed&nbsp;to&nbsp;and&nbsp;from&nbsp;your&nbsp;DLL--even&nbsp;those&nbsp;that<br>&nbsp;&nbsp;are&nbsp;nested&nbsp;in&nbsp;records&nbsp;and&nbsp;classes.&nbsp;ShareMem&nbsp;is&nbsp;the&nbsp;interface&nbsp;unit&nbsp;to<br>&nbsp;&nbsp;the&nbsp;BORLNDMM.DLL&nbsp;shared&nbsp;memory&nbsp;manager,&nbsp;which&nbsp;must&nbsp;be&nbsp;deployed&nbsp;along<br>&nbsp;&nbsp;with&nbsp;your&nbsp;DLL.&nbsp;To&nbsp;avoid&nbsp;using&nbsp;BORLNDMM.DLL,&nbsp;pass&nbsp;string&nbsp;information<br>&nbsp;&nbsp;using&nbsp;PChar&nbsp;or&nbsp;ShortString&nbsp;parameters.&nbsp;}<br><br>uses<br>&nbsp;&nbsp;windows,<br>&nbsp;&nbsp;dialogs,<br>&nbsp;&nbsp;forms,<br>&nbsp;&nbsp;SysUtils,<br>&nbsp;&nbsp;Classes,<br>&nbsp;&nbsp;fzru&nbsp;in&nbsp;'fzru.pas'&nbsp;{fzrtj};<br><br>{$R&nbsp;*.res}<br><br>var<br>formid,left,top,white,hite:integer;<br><br>function&nbsp;weizhi(n1,n2,n3,n4:Integer):Integer;stdcall;<br>begin<br>left:=n2;<br>top:=n1;<br>white:=n3;<br>hite:=n4;<br>end;<br><br>procedure&nbsp;OpenMyForm(handle:HWND);stdcall;<br>begin<br>&nbsp;&nbsp;if(formID=0)&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;Application.Handle:=handle;<br>&nbsp;&nbsp;Application.CreateForm(Tfzrtj,&nbsp;fzrtj);<br>&nbsp;&nbsp;formID:=1;<br>&nbsp;&nbsp;end;<br>&nbsp;&nbsp;fzrtj.Left:=left;<br>&nbsp;&nbsp;&nbsp;fzrtj.Top:=top;<br>&nbsp;&nbsp;&nbsp;fzrtj.Width:=white;<br>&nbsp;&nbsp;&nbsp;fzrtj.Height:=hite;<br>&nbsp;&nbsp;&nbsp;//office_mianshi.adoquery1.ConnectionString:=db;<br><br>&nbsp;&nbsp;fzrtj.ShowModal();<br>end;<br><br>procedure&nbsp;CloseMyForm();stdcall;<br>begin<br>&nbsp;&nbsp;if(formID=1)&nbsp;then<br>&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;fzrtj.Close();<br>&nbsp;&nbsp;&nbsp;&nbsp;formID:=0;<br>&nbsp;&nbsp;end;<br>end;<br>exports<br>weizhi,<br>OpenMyForm,<br>CloseMyForm;<br>end.
 
我拷贝了楼主的代码,只增加了以下代码:<br>&nbsp;&nbsp;hComm:&nbsp;THandle;<br><br>&nbsp;&nbsp;hComm&nbsp;:=&nbsp;SafeLoadLibrary(guanlidll.dll');<br><br>&nbsp;&nbsp;FreeLibrary(hComm);<br><br>任务栏上只有主窗体的,没有&nbsp;DLL&nbsp;窗体的。<br>建议楼主检查一下其它地方的代码。<br>可以的话可以发个&nbsp;DEMO&nbsp;我看看&nbsp;liyinwei@gmail.com
 
终于发现是delphi&nbsp;2007本身的问题,我以前写的dll拿来用都没事的,我用delphi&nbsp;2007编译了下再用,就在任务栏上出现了,郁闷哦,不知道你们谁有在用delphi&nbsp;2007的
 
dll窗体BorderStyle设为bsToolWindow
 
谁能确认下,delphi2007下的dll(里面有窗体的)在调用的时候在任务中也显示出来?<br>也就是说主窗体一个,dll中的窗体也一个?
 
谢谢大家
 
后退
顶部