無caption的form動態產生及最大化不蓋住工作列

有關Delphi 的語法, 程式, 等
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

無caption的form動態產生及最大化不蓋住工作列

文章 tim »

使用了 SetWindowLong 來進行, 並配合 SetBounds 修改原 form 的有效區域:

代碼: 選擇全部

     
    //模擬最大化的無 caption form 
    procedure Tform1.Button1Click(Sender: TObject); 
    begin 
      SetWindowLong(Handle,GWL_style,GetWindowLong(Handle,GWL_style)and(not WS_CAPTION)); 
      SetBounds( Left - ClientOrigin.X, Top - ClientOrigin.Y, GetDeviceCaps( Canvas.handle, HORZRES ) 
        + (Width - ClientWidth), GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight )); 
    end; 
     
     
    //無 caption form 
    procedure Tform1.Button2Click(Sender: TObject); 
    begin 
      SetWindowLong(Handle,GWL_style,GetWindowLong(Handle,GWL_style)and(not WS_CAPTION)); 
      SetBounds( Left , Top , ClientWidth, ClientHeight); 
    end; 

轉貼兩篇參考文章:

http://www.lmc-mediaagentur.de/dpool/tips/0548.htm

How to create a full screen form without auto-hiding the Windows Taskbar
--------------------------------------------------------------------------------


How do I set my form to display in full screen? No title bar, no borders, and it goes over the task bar (not by setting the task bar to "Auto Hide").


Emulating full screen mode:

代碼: 選擇全部

private  {in form declaration}
 procedure WMGetMinMaxInfo(var msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO;


procedure Tform1.WMGetMinMaxInfo(var msg: TWMGetMinMaxInfo);
begin
 inherited;
 with msg.MinMaxInfo^.ptMaxTrackSize do begin
   X := GetDeviceCaps( Canvas.handle, HORZRES ) + (Width - ClientWidth);
   Y := GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight );
 end;
end;


procedure Tform1.Button2Click(Sender: TObject);
const
 Rect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
 FullScreen: Boolean = False;
begin
 FullScreen := not FullScreen;  
 if FullScreen then
 begin
   Rect := BoundsRect;
   SetBounds( Left - ClientOrigin.X, Top - ClientOrigin.Y, GetDeviceCaps( Canvas.handle, HORZRES )
   + (Width - ClientWidth), GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight ));
   {Label2.caption := IntToStr(GetDeviceCaps( Canvas.handle, VERTRES ));}
 end
 else
   BoundsRect := Rect;
end;
Tip by Peter Below


http://www.lmc-mediaagentur.de/dpool/tips/0215.htm

How to hide and show the title bar of a Tform
--------------------------------------------------------------------------------

Here is how to hide the titlebar:

代碼: 選擇全部

procedure TYourformName.HideTitlebar;
var
 Save: LongInt;
begin
 if Borderstyle = bsNone then
   Exit;
 Save := GetWindowLong(Handle, GWL_style);
 if (Save and WS_CAPTION) = WS_CAPTION then
 begin
   case Borderstyle of
     bsSingle, bsSizeable:
       SetWindowLong(Handle, GWL_style, Save and (not (WS_CAPTION)) or WS_BORDER);
     bsDialog:
       SetWindowLong(Handle, GWL_style, Save and (not (WS_CAPTION)) or DS_MODALFRAME
                                       or WS_DLGFRAME);
   end;
   Height := Height - GetSystemMetrics(SM_CYCAPTION);
   Refresh;
 end;
end;
And here is how we show it again:

代碼: 選擇全部

procedure TYourformName.ShowTitlebar;
var
 Save: LongInt;
begin
 if Borderstyle = bsNone then
   Exit;
 Save := GetWindowLong(Handle, GWL_style);
 if (Save and WS_CAPTION) <> WS_CAPTION then
 begin
   case Borderstyle of
     bsSingle, bsSizeable:
       SetWindowLong(Handle, GWL_style, Save or WS_CAPTION or WS_BORDER);
     bsDialog :
       SetWindowLong(Handle, GWL_style, Save or WS_CAPTION or DS_MODALFRAME or WS_DLGFRAME);
   end;
   Height := Height + GetSystemMetrics(SM_CYCAPTION);
   Refresh;
 end;
end;
Tip by Claus Ziegler
多多留言, 整理文章, 把經驗累積下來.....
回覆文章