Пример #1
0
        /// <summary>
        /// Dialog template representation in a standard text format.
        /// </summary>
        /// <returns>Multiline string.</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Format("{0}, {1}, {2}, {3}", x, y, x + cx, y + cy));

            string style = DialogTemplateUtil.StyleToString <User32.WindowStyles, User32.DialogStyles>(Style);

            if (!string.IsNullOrEmpty(style))
            {
                sb.AppendLine("STYLE " + style);
            }

            string exstyle = DialogTemplateUtil.StyleToString <User32.WindowStyles, User32.ExtendedDialogStyles>(ExtendedStyle);

            if (!string.IsNullOrEmpty(exstyle))
            {
                sb.AppendLine("EXSTYLE " + exstyle);
            }

            sb.AppendLine(string.Format("CAPTION \"{0}\"", _caption));
            sb.AppendLine(string.Format("FONT {0}, \"{1}\"", _pointSize, _typeface));

            if (_controls.Count > 0)
            {
                sb.AppendLine("{");
                foreach (DialogTemplateControlBase control in _controls)
                {
                    sb.AppendLine(" " + control.ToString());
                }
                sb.AppendLine("}");
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Return a string representation of the dialog control.
        /// </summary>
        /// <returns>A single line in the "CLASS name id, dimensions and styles' format.</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0} \"{1}\" {2}, {3}, {4}, {5}, {6}, {7}, {8}",
                            ControlClassId, CaptionId, Id, ControlClassId, x, y, cx, cy,
                            DialogTemplateUtil.StyleToString <User32.WindowStyles, User32.StaticControlStyles>(Style, ExtendedStyle));

            if (ControlClassId.IsIntResource())
            {
                switch (ControlClass)
                {
                case User32.DialogItemClass.Button:
                    sb.AppendFormat("| {0}", (User32.ButtonControlStyles)(Style & 0xFFFF));
                    break;

                case User32.DialogItemClass.Edit:
                    sb.AppendFormat("| {0}",
                                    DialogTemplateUtil.StyleToString <User32.EditControlStyles>(Style & 0xFFFF));
                    break;
                }
            }

            return(sb.ToString());
        }
Пример #3
0
 /// <summary>
 /// Write the resource to a binary stream.
 /// </summary>
 /// <param name="w">Binary stream.</param>
 public virtual void Write(BinaryWriter w)
 {
     // menu
     DialogTemplateUtil.WriteResourceId(w, _menuId);
     // window class
     DialogTemplateUtil.WriteResourceId(w, _windowClassId);
     // caption
     w.Write(Encoding.Unicode.GetBytes(Caption));
     w.Write((UInt16)0);
     // point size
     if ((Style & (uint)User32.DialogStyles.DS_SETFONT) > 0 ||
         (Style & (uint)User32.DialogStyles.DS_SHELLFONT) > 0)
     {
         w.Write((UInt16)PointSize);
     }
 }
        /// <summary>
        /// Write the dialog control to a binary stream.
        /// </summary>
        /// <param name="w">Binary stream.</param>
        public virtual void Write(BinaryWriter w)
        {
            // control class
            DialogTemplateUtil.WriteResourceId(w, _controlClassId);
            // caption
            DialogTemplateUtil.WriteResourceId(w, _captionId);

            if (_creationData == null)
            {
                w.Write((UInt16)0);
            }
            else
            {
                ResourceUtil.PadToWORD(w);
                w.Write((UInt16)_creationData.Length);
                w.Write(_creationData);
            }
        }
Пример #5
0
        internal virtual IntPtr Read(IntPtr lpRes)
        {
            // menu
            lpRes = DialogTemplateUtil.ReadResourceId(lpRes, out _menuId);
            // window class
            lpRes = DialogTemplateUtil.ReadResourceId(lpRes, out _windowClassId);
            // caption
            Caption = Marshal.PtrToStringUni(lpRes);
            lpRes   = new IntPtr(lpRes.ToInt32() + (Caption.Length + 1) * Marshal.SystemDefaultCharSize);

            if ((Style & (uint)User32.DialogStyles.DS_SETFONT) > 0 ||
                (Style & (uint)User32.DialogStyles.DS_SHELLFONT) > 0)
            {
                // point size
                PointSize = (UInt16)Marshal.ReadInt16(lpRes);
                lpRes     = new IntPtr(lpRes.ToInt32() + 2);
            }

            return(lpRes);
        }
        internal virtual IntPtr Read(IntPtr lpRes)
        {
            // control class
            lpRes = DialogTemplateUtil.ReadResourceId(lpRes, out _controlClassId);
            // caption
            lpRes = DialogTemplateUtil.ReadResourceId(lpRes, out _captionId);

            // optional/additional creation data
            switch ((UInt16)Marshal.ReadInt16(lpRes))
            {
            case 0x0000:     // no data
                lpRes = new IntPtr(lpRes.ToInt32() + 2);
                break;

            default:
                UInt16 size = (UInt16)Marshal.ReadInt16(lpRes);
                _creationData = new byte[size];
                Marshal.Copy(lpRes, _creationData, 0, _creationData.Length);
                lpRes = new IntPtr(lpRes.ToInt32() + size);
                break;
            }

            return(lpRes);
        }