请问在不更改BorderStyle属性的情况下如何去掉或隐藏窗体的标题栏?

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
       SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle,GWL_STYLE)  and not WS_CAPTION);
    end;
      

  2.   

    我自己用的函数procedure HideTitleBar(IsHide: Boolean; frm: TForm);
    var
      lStyle: Integer;
      r: TRect;
    begin
      GetWindowRect(frm.Handle, r);
      lStyle := GetWindowLong(frm.Handle, GWL_STYLE);
      if IsHide then
      begin
        lStyle := lStyle and not WS_SYSMENU;
        lStyle := lStyle and not WS_CAPTION;
      end
      else begin
        lStyle := lStyle or WS_SYSMENU;
        lStyle := lStyle or WS_CAPTION;
      end;
      SetWindowLong(frm.Handle, GWL_STYLE, lStyle);
      SetWindowPos(
        frm.Handle,
        0,
        r.Left,
        r.Top,
        r.Right - r.Left,
        r.Bottom - r.Top,
        SWP_NOREPOSITION or SWP_NOZORDER or SWP_FRAMECHANGED
      );
    end;