Exemplo n.º 1
0
            /// <summary>
            /// Validate the header and CRC-32 of this structure.
            /// </summary>
            /// <returns>True if the structure is valid.</returns>
            /// <remarks></remarks>
            public bool Validate()
            {
                bool ValidateRet = default;
                var  mm          = new MemPtr();

                mm.FromStruct(this);
                mm.UIntAt(4L) = 0U;

                // validate the crc and the signature moniker
                ValidateRet = HeaderCRC32 == mm.CalculateCrc32() && Signature == 0x5452415020494645;
                mm.Free();
                return(ValidateRet);
            }
Exemplo n.º 2
0
        public static IntPtr DoRegisterDeviceClassNotification(IntPtr hWnd, Guid devclass)
        {
            var mm = new MemPtr();

            var bh = new DEV_BROADCAST_HDR();
            var di = new DEV_BROADCAST_DEVICEINTERFACE();

            bh.dbch_size = Marshal.SizeOf <DEV_BROADCAST_HDR>();
            di.dbcc_size = Marshal.SizeOf <DEV_BROADCAST_DEVICEINTERFACE>();

            bh.dbch_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
            di.dbcc_classguid  = devclass;

            mm.Alloc(bh.dbch_size + di.dbcc_size);

            mm.FromStruct(bh);
            mm.FromStructAt(bh.dbch_size, di);

            var ret = RegisterDeviceNotification(hWnd, mm, DEVICE_NOTIFY_WINDOW_HANDLE);

            mm.Free();

            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a collection of fonts based on the specified criteria.
        /// </summary>
        /// <param name="families">Bit Field representing which font families to retrieve.</param>
        /// <param name="pitch">Specify the desired pitch.</param>
        /// <param name="charset">Specify the desired character set.</param>
        /// <param name="weight">Specify the desired weight.</param>
        /// <param name="Script">Specify the desired script(s) (this can be a String or an array of Strings).</param>
        /// <param name="Style">Specify the desired style(s) (this can be a String or an array of Strings).</param>
        /// <returns></returns>
        public static FontCollection GetFonts(FontFamilies families = FontFamilies.DontCare, FontPitch pitch = FontPitch.Default, FontCharSet charset = FontCharSet.Default, FontWeight weight = FontWeight.DontCare, object Script = null, object Style = null)
        {
            IntPtr hdc;

            var fonts = new List <ENUMLOGFONTEX>();

            var lf = new LOGFONT();

            string s;

            MemPtr mm = new MemPtr();

            string[] wscript;
            string[] wstyle;

            if (Script is null)
            {
                wscript = new[] { "Western" };
            }
            else if (Script is string)
            {
                wscript = new[] { (string)(Script) };
            }
            else if (Script is string[])
            {
                wscript = (string[])Script;
            }
            else
            {
                throw new ArgumentException("Invalid parameter type for Script");
            }

            if (Style is null)
            {
                wstyle = new[] { "", "Normal", "Regular" };
            }
            else if (Style is string)
            {
                wstyle = new[] { (string)(Style) };
            }
            else if (Style is string[])
            {
                wstyle = (string[])Style;
            }
            else
            {
                throw new ArgumentException("Invalid parameter type for Style");
            }

            lf.lfCharSet  = (byte)charset;
            lf.lfFaceName = "";
            mm.Alloc(Marshal.SizeOf(lf));
            mm.FromStruct(lf);
            hdc = User32.CreateDC("DISPLAY", null, IntPtr.Zero, IntPtr.Zero);

            int  e;
            bool bo = false;

            e = EnumFontFamiliesEx(hdc, mm, (ref ENUMLOGFONTEX lpelfe, IntPtr lpntme, uint FontType, IntPtr lParam) =>
            {
                int z;
                if (fonts is null)
                {
                    z = 0;
                }
                else
                {
                    z = fonts.Count;
                }


                // make sure it's the normal, regular version

                bo = false;
                foreach (var y in wstyle)
                {
                    if ((y.ToLower() ?? "") == (lpelfe.elfStyle.ToLower() ?? ""))
                    {
                        bo = true;
                        break;
                    }
                }

                if (bo == false)
                {
                    return(1);
                }
                bo = false;
                foreach (var y in wscript)
                {
                    if ((y.ToLower() ?? "") == (lpelfe.elfScript.ToLower() ?? ""))
                    {
                        bo = true;
                        break;
                    }
                }

                if (bo == false)
                {
                    return(1);
                }
                bo = false;
                if (weight != FontWeight.DontCare && lpelfe.elfLogFont.lfWeight != (int)weight)
                {
                    return(1);
                }

                // we don't really need two of the same font.
                if (z > 0)
                {
                    if ((lpelfe.elfFullName ?? "") == (fonts[z - 1].elfFullName ?? ""))
                    {
                        return(1);
                    }
                }

                // the @ indicates a vertical writing font which we definitely do not want.
                if (lpelfe.elfFullName.Substring(0, 1) == "@")
                {
                    return(1);
                }
                if (!CheckFamily(lpelfe.elfLogFont, families))
                {
                    return(1);
                }

                // lpelfe.elfLogFont.lfCharSet = charset
                // If (lpelfe.elfLogFont.lfCharSet <> charset) Then Return 1

                if (pitch != FontPitch.Default && (lpelfe.elfLogFont.lfPitchAndFamily & 3) != (int)pitch)
                {
                    return(1);
                }
                fonts.Add(lpelfe);
                return(1);
            }, IntPtr.Zero, 0U);
            User32.DeleteDC(hdc);
            mm.Free();
            if (e == 0)
            {
                e = User32.GetLastError();
                s = NativeError.Message;
            }

            FontInfo nf;
            var      ccol = new FontCollection();

            foreach (var f in fonts)
            {
                nf = new FontInfo(f);
                ccol.Add(nf);
            }

            ccol.Sort();
            return(ccol);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Copy the ENUMLOGFONTEX structure for this object into a memory buffer.
        /// </summary>
        /// <param name="lpElf">Pointer to a buffer to receive the ENUMLOGFONTEX structure.  The memory must already be allocated and freed by the caller.</param>
        public void GetElfEx(IntPtr lpElf)
        {
            var mm = new MemPtr(lpElf);

            mm.FromStruct(elf);
        }