2012-03-19 50 views
3

目前,我試圖在Windows窗體中使用自定義框架(使用DevExpress'SkinManager.EnableFormSkins function)並且在Windows 7 Aero上運行時在窗口附近有一個陰影。可能使用WM_NCPAINT,並仍然獲得Aero窗口背後的影子?

窗口目前看起來是這樣的:

enter image description here

,我希望它看起來像這樣:

enter image description here

(即周圍有窗口軟陰影)。

我做了很多的研究,並嘗試和錯誤,包括使用CS_DROPSHADOWasking the DevExpress supportreading on SOother blogsMSDN documentation

但是,沒有什麼能給我的窗戶帶來陰影。

儘管我認爲我的要求根本無法實現,但我仍想抓住機會在SO上提出問題。

(我甚至想通過讓我實際的窗口後面的本地航空窗口僞裝的,但未能實現......)

我的問題是:

是否有可能有一個窗口有一個自定義繪製的非客戶端(NC)區域,當Aero處於活動狀態時,仍然會在此窗口周圍留下陰影。

回答

0

總結,並關閉我自己的問題,經過多方的努力,我不認爲這是根本不可能的。

我的成就是通過使用Locus Effects article中使用的技術來模擬陰影。

基本上使用透明窗口,動態使用alpha混合PNG作爲模擬陰影,並在窗口的邊(角)周圍繪製;移動透明窗口,當真實窗口移動時等等。

這個效果很好,但對於用戶來說仍然顯得有點不專業,因爲當其他窗口被激活時不會像預期那樣行爲時,影子消失等小事情。

所以我的結論是:不合理的努力。

+1

我認爲這是可能的,覆蓋wndproc並放入'if(m.Msg == WM_ACTIVATE)DwmExtendFrameIntoClientArea(this.Handle,ref MARGIN);'MARGIN應該填入1(0不起作用)例如'MARGIN = {1,1,1,1};'FrameBorderStyle也必須是FrameBorderStyle.Sizeable才能工作。所以你必須這樣做:'if(m.Msg == WM_NCCALCSIZE && m.WParam!= IntPtr.Zero){m.Result = IntPtr.Zero;返回; }'去除框架邊框。 – 2014-12-12 14:53:17

0

你可以嘗試定製贏形式的陰影像這樣:

/// <summary> 
/// Base class for drop shadows forms. 
/// </summary> 
public partial class DropShadowForm : Form 
{ 
    private const int CS_DROPSHADOW = 0x00020000; 

    /// <summary> 
    /// Creates new instance of DropShadowForm. 
    /// </summary> 
    public DropShadowForm() 
    { 
     InitializeComponent(); 
    } 

    /// <summary> 
    /// Overrides from base class. 
    /// </summary> 
    protected override CreateParams CreateParams 
    { 
     [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] 
     get 
     { 
      CreateParams parameters = base.CreateParams; 

      if (DropShadowSupported) 
      { 
       parameters.ClassStyle = (parameters.ClassStyle | CS_DROPSHADOW); 
      } 

      return parameters; 
     } 
    } 

    /// <summary> 
    /// Gets indicator if drop shadow is supported 
    /// </summary> 
    public static bool DropShadowSupported 
    { 
     get 
     { 
      OperatingSystem system = Environment.OSVersion; 
      bool runningNT = system.Platform == PlatformID.Win32NT; 

      return runningNT && system.Version.CompareTo(new Version(5, 1, 0, 0)) >= 0; 
     } 
    }  
} 
+0

Thanks @Marcin - 我忘了提及我已經嘗試了一段時間。不幸的是,該投影與Aero影子無關。 – 2012-03-19 18:45:28

相關問題