Exemplo n.º 1
0
        internal Screen(IntPtr monitor, IntPtr hdc)
        {
            IntPtr screenDC = hdc;

            if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR)
            {
                // Single monitor system
                //
                bounds      = SystemInformation.VirtualScreen;
                workingArea = SystemInformation.WorkingArea;
                primary     = true;
                deviceName  = "DISPLAY";
            }
            else
            {
                // MultiMonitor System
                // We call the 'A' version of GetMonitorInfoA() because
                // the 'W' version just never fills out the struct properly on Win2K.
                //
                NativeMethods.MONITORINFOEX info = new NativeMethods.MONITORINFOEX();
                SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info);
                bounds      = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom);
                workingArea = Rectangle.FromLTRB(info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom);
                primary     = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0);
                int count = info.szDevice.Length;
                while (count > 0 && info.szDevice[count - 1] == (char)0)
                {
                    count--;
                }

                deviceName = new string(info.szDevice);
                deviceName = deviceName.TrimEnd((char)0);

                if (hdc == IntPtr.Zero)
                {
                    screenDC = UnsafeNativeMethods.CreateDC(deviceName);
                }
            }
            hmonitor = monitor;

            this.bitDepth  = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.BITSPIXEL);
            this.bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.PLANES);

            if (hdc != screenDC)
            {
                UnsafeNativeMethods.DeleteDC(new HandleRef(null, screenDC));
            }
        }
Exemplo n.º 2
0
        internal Screen(IntPtr monitor, IntPtr hdc)
        {
            IntPtr screenDC = hdc;

            if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR)
            {
                // Single monitor system
                //
                bounds     = SystemInformation.VirtualScreen;
                primary    = true;
                deviceName = "DISPLAY";
            }
            else
            {
                // Multiple monitor system
                var info = new NativeMethods.MONITORINFOEX();
                SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info);
                bounds  = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom);
                primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0);

                deviceName = new string(info.szDevice);
                deviceName = deviceName.TrimEnd((char)0);

                if (hdc == IntPtr.Zero)
                {
                    screenDC = UnsafeNativeMethods.CreateDC(deviceName);
                }
            }
            hmonitor = monitor;

            this.bitDepth  = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.BITSPIXEL);
            this.bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.PLANES);

            if (hdc != screenDC)
            {
                UnsafeNativeMethods.DeleteDC(new HandleRef(null, screenDC));
            }
        }
Exemplo n.º 3
0
            protected override void Dispose(bool disposing)
            {
                Debug.Assert(disposing, "Never let a graphics buffer finalize!");

                Debug.WriteLineIf(DoubleBuffering.TraceInfo, "Dispose(" + disposing + ") {");
                Debug.Indent();

                if (disposing && compatGraphics != null)
                {
                    Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "Disposing compatGraphics");
                    compatGraphics.Dispose();
                    compatGraphics = null;
                }
                if (oldBitmap != IntPtr.Zero && compatDC != IntPtr.Zero)
                {
                    Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "restoring bitmap to DC");
                    SafeNativeMethods.SelectObject(new HandleRef(this, compatDC), new HandleRef(this, oldBitmap));
                    oldBitmap = IntPtr.Zero;
                }
                if (compatDC != IntPtr.Zero)
                {
                    Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "delete compat DC");
                    UnsafeNativeMethods.DeleteDC(new HandleRef(this, compatDC));
                    compatDC = IntPtr.Zero;
                }
                if (dib != IntPtr.Zero)
                {
                    Debug.WriteLineIf(DoubleBuffering.TraceVerbose, "delete dib");
                    SafeNativeMethods.DeleteObject(new HandleRef(this, dib));
                    dib = IntPtr.Zero;
                }
                bufferWidth   = -1;
                bufferHeight  = -1;
                virtualWidth  = -1;
                virtualHeight = -1;
                Debug.Unindent();
                Debug.WriteLineIf(DoubleBuffering.TraceInfo, "}");
            }