예제 #1
0
        private void RefreshValues()
        {
            if (!this.Visible || this.Disposing)
            {
                return;
            }

            IntPtr hWndHost         = Process.GetCurrentProcess().MainWindowHandle;
            IntPtr hWndTaskpane     = this.Handle;
            IntPtr hWndContainer    = DPIHelper.FindParentWithClassName(hWndTaskpane, "MsoCommandBar");
            IntPtr hWndTaskpaneHost = DPIHelper.FindParentWithClassName(hWndTaskpane, "CMMOcxHostChildWindowMixedMode");

            this.txtThreadAwareness.Text  = DPIHelper.GetThreadDpiAwareness().ToString();
            this.txtProcessAwareness.Text = DPIHelper.GetProcessDpi().ToString();

            if (this.Handle != null)
            {
                this.txtTaskpaneWindowAwareness.Text =
                    DPIHelper.GetWindowDpiAwarenessContext(this.Handle).ToString();
            }

            this.txtHostWindowAwareness.Text =
                DPIHelper.GetWindowDpiAwarenessContext(hWndHost).ToString();

            this.txtChildWindowMixedMode.Text =
                DPIHelper.GetThreadDpiHostingBehavior(hWndTaskpaneHost).ToString();

            this.txtTaskpaneRect.Text  = HwndInfoString(hWndTaskpane);
            this.txtContainerRect.Text = HwndInfoString(hWndContainer);

            if (m_customTaskPane != null)
            {
                this.txtGetWidthHeight.Text = string.Format("{0}, {1}", m_customTaskPane.Width, m_customTaskPane.Height);
            }
        }
 public DpiAwareWindowsForm()
 {
     this.HandleCreated += new EventHandler((sender, args) =>
     {
         m_oldDpi = m_newDpi = DPIHelper.GetDpiForWindowSizeF(this.Handle);
     });
 }
예제 #3
0
        public Top_Level_Forms()
        {
            InitializeComponent();

            // Hook up DPIChanged event
            // this.Parent.dpi += new System.Windows.Forms.DpiChangedEventHandler();

            cboDpiContext.DataSource      = DpiAwarenessContexts;
            cboHostingBehavior.DataSource = DpiHostingBehaviors;

            // Fill template combo
            Type formType = typeof(UserControl);

            foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (formType.IsAssignableFrom(type))
                {
                    cboTemplate.Items.Add(type.Name);
                }
            }

            // Set cbo defaults
            cboTemplate.Text = this.Name;

            //if (this.Handle != null)
            //{
            //    cboDpiContext.Text =
            //        DPIHelper.GetWindowDpiAwarenessContext(this.Handle).ToString();
            //}

            cboHostingBehavior.Text =
                DPIHelper.GetThreadDpiHostingBehavior().ToString();
        }
예제 #4
0
        private void SetThreadDPI(DPI_AWARENESS_CONTEXT newvalue, bool showMessage)
        {
            DPI_AWARENESS_CONTEXT previous =
                DPIHelper.SetThreadDpiAwarenessContext(newvalue);
            int processId = Process.GetCurrentProcess().Id;
            int threadId  = Thread.CurrentThread.ManagedThreadId;

            if (showMessage)
            {
                MessageBox.Show(String.Format("DPI Awareness set to {0}, was {1}\nProcessId {2}, ThreadId {3}", newvalue, previous, processId, threadId));
            }
        }
예제 #5
0
        public static DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form    form         = new Form();
            Label   label        = new Label();
            TextBox textBox      = new TextBox();
            Button  buttonOk     = new Button();
            Button  buttonCancel = new Button();

            form.Text    = title;
            label.Text   = promptText;
            textBox.Text = value;

            buttonOk.Text             = "OK";
            buttonCancel.Text         = "Cancel";
            buttonOk.DialogResult     = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 11, 372, 13);
            textBox.SetBounds(10, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize      = true;
            textBox.Anchor      = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor     = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize      = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition   = FormStartPosition.CenterParent;
            form.MinimizeBox     = false;
            form.MaximizeBox     = false;
            form.AcceptButton    = buttonOk;
            form.CancelButton    = buttonCancel;

            DialogResult dialogResult = DialogResult.None;
            IntPtr       hwndApp      = DPIHelper.GetAncestor(form.Handle, DPIHelper.GA_ROOT);

            if (hwndApp != IntPtr.Zero)
            {
                dialogResult = form.ShowDialog(new WindowWrapper(hwndApp));
            }
            else
            {
                dialogResult = form.ShowDialog();
            }
            value = textBox.Text;
            return(dialogResult);
        }
예제 #6
0
        private string HwndInfoString(IntPtr hWnd)
        {
            RECT rSA;
            RECT rPMA;

            {
                DPIContextBlock saBlock = new DPIContextBlock(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
                rSA = DPIHelper.GetWindowRectangle(hWnd);
            }
            {
                DPIContextBlock saBlock = new DPIContextBlock(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
                rPMA = DPIHelper.GetWindowRectangle(hWnd);
            }

            return(String.Format("SA: {0}, {1} PMA: {2}, {3}",
                                 (rSA.right - rSA.left).ToString(),
                                 (rSA.bottom - rSA.top).ToString(),
                                 (rPMA.right - rPMA.left).ToString(),
                                 (rPMA.bottom - rPMA.top).ToString()));
        }
예제 #7
0
 public DPIContextBlock(DPI_AWARENESS_CONTEXT contextSwitchTo)
 {
     resetContext = DPIHelper.SetThreadDpiAwarenessContext(contextSwitchTo);
 }
예제 #8
0
 private void setCWMMNormal_Click(object sender, EventArgs e)
 {
     DPIHelper.SetThreadDpiHostingBehavior(DPIHelper.DPI_HOSTING_BEHAVIOR.DPI_HOSTING_BEHAVIOR_DEFAULT);
     // MessageBox.Show(String.Format("DPI Hosting Behavior is {0}", DPIHelper.GetChildWindowMixedMode(this.Handle).ToString()));
 }
예제 #9
0
        private void CustomTaskPaneDockChangeHandler(object sender, EventArgs e)
        {
            CustomTaskPane ctp = (CustomTaskPane)sender;

            MessageBox.Show(string.Format("CustomTaskPane DockChange {0} with DpiThreadAwarenessContext {1}", ctp.DockPosition, DPIHelper.GetThreadDpiAwarenessContext().ToString()));
        }