0

どうやってするか?C#の有用なサンプルが見つかりませんでした。SetClassLong / SetClassLongPtrを使用する必要があることはわかっていますが、ここで見つけた定義は次のとおりです:http ://www.pinvoke.net/default.aspx/user32/SetClassLongPtr.html 。

明らかに、GCL_STYLEを指定してGetClassLongPtrを呼び出し、現在のスタイルフラグを読み取り、CS_DROPSHADOWを追加または除外してから、変更されたフラグ値を指定してSetClassLongPtrを呼び出す必要があります。しかし、そのPInvokeの定義を見ると、特に32/64ビットシステムを考慮すると、それは簡単ではありません。

誰かがリンクやこれの良い例を与えることができますか?また、CreateParamsを上書きするサンプルは提供しないでください。これは、動的シナリオでは機能しません。たぶん、それを行う別の[管理された]方法がありますか?

4

1 に答える 1

0

ここに私が書くことができたものがあります:

    private void SetSizeableCore(bool value)
    {
        fSizeable = value;
        if (value)
        {
            FormBorderStyle = FormBorderStyle.SizableToolWindow;
            DockPadding.All = 0;
            System.Version ver = Environment.OSVersion.Version;
            // Always for WinXP family, but for higher systems only if the aero theme is not in effect
            bool needShadow = ((ver.Major == 5) && (ver.Minor > 0)) || ((ver.Major > 5) && !IsAeroThemeEnabled());
            SetShadowFlag(needShadow);
        }
        else
        {
            FormBorderStyle = FormBorderStyle.None;
            DockPadding.All = 1;
            SetShadowFlag(true);
        }
    }

    private void SetShadowFlag(bool hasShadow)
    {
        if (!IsDropShadowSupported())
            return;
        System.Runtime.InteropServices.HandleRef myHandleRef = new System.Runtime.InteropServices.HandleRef(this, this.Handle);
        int myStyle = iGNativeMethods.GetClassLongPtr(myHandleRef, iGNativeMethods.CS_DROPSHADOW).ToInt32();
        if (hasShadow)
            myStyle |= iGNativeMethods.CS_DROPSHADOW;
        else
            myStyle &= ~iGNativeMethods.CS_DROPSHADOW;
        iGNativeMethods.SetClassLong(myHandleRef, iGNativeMethods.GCL_STYLE, new IntPtr(myStyle));
    }

    private bool IsDropShadowSupported()
    {
        // Win2000 does not have this feature
        if (Environment.OSVersion.Version <= new Version(5, 0))
            return false;
        bool myResult = false;
        iGNativeMethods.SystemParametersInfo(iGNativeMethods.SPI_GETDROPSHADOW, 0, ref myResult, 0);
        return myResult;
    }

    private bool IsAeroThemeEnabled()
    {
        if (Environment.OSVersion.Version.Major > 5)
        {
            bool aeroEnabled;
            iGNativeMethods.DwmIsCompositionEnabled(out aeroEnabled);
            return aeroEnabled;
        }
        return false; 
    }

私が間違っている場合は修正してください。

于 2012-11-19T14:58:53.677 に答える