private unsafe void CreateDitherBrush() { Debug.Assert(_hbrushDither.IsNull, "Brush should not be recreated."); short *patternBits = stackalloc short[] { unchecked ((short)0xAAAA), unchecked ((short)0x5555), unchecked ((short)0xAAAA), unchecked ((short)0x5555), unchecked ((short)0xAAAA), unchecked ((short)0x5555), unchecked ((short)0xAAAA), unchecked ((short)0x5555) }; Gdi32.HBITMAP hbitmapTemp = Gdi32.CreateBitmap(8, 8, 1, 1, patternBits); Debug.Assert( !hbitmapTemp.IsNull, "could not create dither bitmap. Page selector UI will not be correct"); if (!hbitmapTemp.IsNull) { _hbrushDither = Gdi32.CreatePatternBrush(hbitmapTemp); Debug.Assert( !_hbrushDither.IsNull, "Unable to created dithered brush. Page selector UI will not be correct"); Gdi32.DeleteObject(hbitmapTemp); } }
private void UpdateMainMenuBrush() { // screen states where there is no menu yet if (Menu == null) return; if (WindowState == FormWindowState.Minimized) return; // alias colorized resources ColorizedResources cres = ColorizedResources.Instance; // dispose any existing brush and/or bitmaps if (_hMainMenuBrush != IntPtr.Zero) DisposeGDIObject(ref _hMainMenuBrush); if (_hMainMenuBitmap != IntPtr.Zero) DisposeGDIObject(ref _hMainMenuBitmap); if (_hMainMenuBrushBitmap != IntPtr.Zero) DisposeGDIObject(ref _hMainMenuBrushBitmap); if (_mainMenuBitmap != null) { Bitmap tmp = _mainMenuBitmap; _mainMenuBitmap = null; tmp.Dispose(); } // create a brush which contains the menu background _mainMenuBitmap = new Bitmap(Width, -RelativeWindowBounds.Y); _hMainMenuBitmap = _mainMenuBitmap.GetHbitmap(); using (Graphics g = Graphics.FromImage(_mainMenuBitmap)) { Rectangle bounds = MenuBounds; Debug.WriteLine("MenuBounds: " + bounds); if (cres.CustomMainMenuPainting) { // paint custom menu background CustomPaintMenuBackground(g, bounds); } else { using (Brush brush = new SolidBrush(SystemMainMenuColor)) g.FillRectangle(brush, bounds); } } _hMainMenuBrushBitmap = _mainMenuBitmap.GetHbitmap(); _hMainMenuBrush = Gdi32.CreatePatternBrush(_hMainMenuBrushBitmap); // set the brush MENUINFO mi = new MENUINFO(); mi.cbSize = Marshal.SizeOf(typeof(MENUINFO)); mi.fMask = MIM.BACKGROUND; mi.hbrBack = _hMainMenuBrush; User32.SetMenuInfo(Menu.Handle, ref mi); User32.DrawMenuBar(Handle); }