我在DLL中创建了一个窗体,并且只用在DLL内部调用,但显示的时候却会在任务栏上显示标题。
网上搜索了一下,大多是以下两个解决方案:
1、将主程序的Handler做为参数传递到DLL中
2、在窗体的OnCreate事件中使用API函数隐藏。我现在想使用第2种方法实现,但是没有找到如何在DLL给创建的窗体绑定FormCreate事件过程的方法。
还有一天就要交工了,希望兄弟姐妹们帮帮忙,谢谢!附部分代码:
var
     Showfrm:TForm;($R *.res)procedure CreateShowInfoFrm();Stdcall; //初始化窗体
begin
        //窗体部分
        Showfrm:=TForm.Create(application);        With Showfrm do
        begin
                BorderStyle:=bsNone;
                Caption:='';
                Ctl3D:=false;
                Color:=clInactiveCaptionText;
                ClientHeight:=177;
                ClientWidth:=274;
                FormStyle:=fsStayOnTop;
                OldCreateOrder:=false;
        end;        Label_Info:=TLabel.Create(Showfrm);
        With Label_Info do
        begin
                AutoSize:=false;
                Parent:=Showfrm;
                Caption:='';
                Visible:=true;
                WordWrap:= true;
                Layout:=tlCenter;
                AlignMent:=taLeftJustify;
        end;
end;function ShowInfo():integer;Stdcall;    //显示窗口
begin        Showfrm.Repaint;
        Showfrm.Top:=Screen.WorkAreaHeight-180;
        Showfrm.Left:=Screen.WorkAreaWidth-Showfrm.Width-1;
        Showfrm.show;
        {这里如果窗口句柄是Application.Handle,标题栏不会隐藏,没有任何效果,如果是Showfrm.Handle则隐藏标题栏的同时窗口也被隐藏看不到了。
        showwindow(Showfrm.Handle,sw_hide); //隐藏图标
        setwindowlong(Showfrm.Handle,gwl_exstyle,
        getwindowlong(Showfrm.Handle,gwl_exstyle) or ws_ex_toolwindow and not ws_ex_appwindow);
        Showfrm.Show;
        } 
        With Showfrm.Canvas do
        begin
                MoveTo(0, Showfrm.Height - 1);
                LineTo(0, 0); //绘制左边线
                LineTo(Showfrm.Width - 1, 0); //绘制上边线
                LineTo(Showfrm.Width - 1, Showfrm.Height); //绘制右边线
        end;
        With Label_Info do
        begin
                Width:=showfrm.Width-16;
                Height:=showfrm.Height-16;
                Top:=8;
                Left:=8;
        end;
        Showfrm.Refresh;
        Result:=0;
end;procedure WaitInfo(Const cStr:String);
begin
        Label_Info.Caption:=cStr;
        Label_Info.Refresh;
        If not Showfrm.Visible then
                ShowInfo();
end;procedure test;stdcall;
begin
        WaitInfo('测试显示');
end;
procedure ExitDLL(Reason:Integer);
begin
        if Reason = DLL_PROCESS_DETACH then
        begin
                CoUninitialize;
        end;
end;
exports test;begin
        ActiveX.CoInitialize(nil);
        MyComm:=TMSComm.Create(MyComm);
        CreateShowInfoFrm;      //初始化窗口
        DllProc := @ExitDLL;
end.

解决方案 »

  1.   

    bsnone 看看或者返回类再CreateWindow
      

  2.   

    BorderStyle属性已经是bsNone了怎么个返回类?我这是刚开始学delphi
      

  3.   


    直接
    SetWindowLong(application.handle,gwl_exstyle,ws_ex_toolwindow);
      

  4.   


    这个方法在 Delphi2007 已经无效!
      

  5.   

    function WindowShow(OwnerHandle: Thandle; WinCaption: string): Longint;
    var
     myform: TForm1;
    begin
      try
        Application.Handle:=OwnerHandle;
        myform:=TForm1.Create(application);
        result:=Longint(myform);
        myform.Caption:=WinCaption;
        myform.ShowModal;
      finally
        FreeAndNil(myForm);
      end;
    end;导出此函数:
    exports
      WindowShow;
      

  6.   

    3楼的方法我试过的,没有用,另外,我用的是Delphi7.05楼的方法我试一下
      

  7.   

    要隐藏dll窗体的标题栏,建议用第一种方法
    将主程序的Application的Handle传递到dll中并且替换掉dll中的application变量的Handle,让dll的窗体编程主程序的一部分,这样就dll窗体就不会在任务量上显示标题了