Exemplo n.º 1
0
        private void InitializeAeroGlass()
        {
            ResetDwmBlurBehind();
            m_glassMargins = new DwmApi.MARGINS(-1, -1, -1, -1);
            //m_glassMargins = new DwmApi.MARGINS(1, 1, 1, 1);

            if (DwmApi.DwmIsCompositionEnabled())
            {
                DwmApi.DwmExtendFrameIntoClientArea(this.Handle, m_glassMargins);
            }
        }
Exemplo n.º 2
0
 private void ResetDwmBlurBehind()
 {
     if (DwmApi.DwmIsCompositionEnabled())
     {
         DwmApi.DWM_BLURBEHIND bbhOff = new DwmApi.DWM_BLURBEHIND();
         bbhOff.dwFlags     = DwmApi.DWM_BLURBEHIND.DWM_BB_ENABLE | DwmApi.DWM_BLURBEHIND.DWM_BB_BLURREGION;
         bbhOff.fEnable     = false;
         bbhOff.hRegionBlur = IntPtr.Zero;
         DwmApi.DwmEnableBlurBehindWindow(this.Handle, bbhOff);
     }
 }
Exemplo n.º 3
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (DwmApi.DwmIsCompositionEnabled())
            {
                BackColor = Color.Black;
            }
            else
            {
                BackColor = SystemColors.ControlLightLight;
            }

            base.OnPaintBackground(e);
        }
Exemplo n.º 4
0
        protected override void WndProc(ref Message m)
        {
            const int WM_DWMCOMPOSITIONCHANGED = 0x031E;

            switch (m.Msg)
            {
            case 0x0084:
                IntPtr currentActiveHandle = NativeMethods.GetForegroundWindow();
                if (NativeMethods.IsWindow(currentActiveHandle) && currentActiveHandle != this.Handle)
                {
                    lastActiveHandle = currentActiveHandle;
                }
                break;

            case 0x0021:
                int hitTestResult = (int)m.LParam & 0xff;

                // hit client
                if (hitTestResult == 1)
                {
                    m.Result = new IntPtr(3);
                    return;
                }
                break;

            case WM_DWMCOMPOSITIONCHANGED:
                if (!DwmApi.DwmIsCompositionEnabled())
                {
                    m_glassMargins = null;
                }
                else
                {
                    InitializeAeroGlass();
                }
                break;
            }
            base.WndProc(ref m);
        }
Exemplo n.º 5
0
        protected override void WndProc(ref Message msg)
        {
            base.WndProc(ref msg);

            const int WM_DWMCOMPOSITIONCHANGED = 0x031E;
            const int WM_NCHITTEST             = 0x84;
            const int HTCLIENT    = 0x01;
            const int WM_HOTKEY   = 0x0312;
            const int WM_COPYDATA = 0x004A;

            switch (msg.Msg)
            {
            case WM_COPYDATA:
                NativeMethods.COPYDATASTRUCT cds = Marshal.PtrToStructure(msg.LParam, typeof(NativeMethods.COPYDATASTRUCT)) as NativeMethods.COPYDATASTRUCT;
                if (cds.dwData.ToInt32() == 0x8855)
                {
                    Byte[] states = new Byte[cds.cbData];
                    Marshal.Copy(cds.lpData, states, 0, cds.cbData);
                    keyEventHandler.SetKeyboardState(states);
                }
                break;

            case WM_HOTKEY:
                if (msg.WParam.ToInt32() == softKeyboardHtkyId)
                {
                    softKeyboard.Visible = !softKeyboard.Visible;
                }
                break;

            case (int)DLLMSG.KM_INPUTLANGCHANGE:
                softKeyboard.Refresh(SoftKeyboard.RefreshFor.Label);
                break;

            //case (int)DLLMSG.KM_GETKBLNAME:
            //    try
            //    {
            //        String fileName = ActiveKeyboardList[msg.LParam.ToInt32()].file;
            //        SetFileToLoad(fileName);
            //    }
            //    catch (Exception)
            //    {
            //        //Marshal.WriteByte(DllPtrFileToLoad, 0);
            //    }
            //    break;
            case (int)DLLMSG.KM_GOTFOCUS:
                if (msg.LParam == Handle || msg.LParam == NativeMethods.GetParent(msg.LParam))
                {
                }
                else
                {
                    uint pid;
                    NativeMethods.GetWindowThreadProcessId(msg.LParam, out pid);
                    if (Process.GetCurrentProcess().Id == pid)
                    {
                        break;
                    }
                }

                //StringBuilder sb = new StringBuilder(255);
                //NativeMethods.GetClassName(msg.LParam, sb, 255);
                //Debug.WriteLine(sb.ToString());

                //if (sb.ToString().Equals("TaskSwitcherWnd"))
                //{
                //    Debug.WriteLine("Ignored");
                //    break;
                //}

                LastClientHandle = msg.LParam;
                ClearCheck(cmsLeft.Items);

                uint dwProcessId;
                uint threadId = NativeMethods.GetWindowThreadProcessId(NativeMethods.GetForegroundWindow(), out dwProcessId);
                //NativeMethods.AttachThreadInput(NativeMethods.GetCurrentThreadId(), threadId, true);

                try
                {
                    int index = 0;
                    if (engines.ContainsKey(LastClientHandle))
                    {
                        LayoutInfo layoutInfo = engines[LastClientHandle];
                        keyEventHandler.Engine = layoutInfo.engine;
                        if (keyEventHandler.Engine != null)
                        {
                            keyEventHandler.Engine.Reset();
                        }
                        SoftKeyboardEngine = keyEventHandler.Engine;
                        index = layoutInfo.index;
                    }
                    else
                    {
                        engines[LastClientHandle] = new LayoutInfo(0, null);
                        keyEventHandler.Engine    = null;
                        SoftKeyboardEngine        = null;
                    }

                    if (cmsLeft.Items.Count > index)
                    {
                        String            ActiveFile = ActiveKeyboardList[index].file;
                        ToolStripMenuItem item       = cmsLeft.Items[index] as ToolStripMenuItem;
                        item.Checked = true;

                        SetKeyboardIcon(ActiveFile);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message, "Exception");
                }
                break;

            case WM_NCHITTEST:
                if (HTCLIENT == msg.Result.ToInt32())
                {
                    // it's inside the client area

                    // Parse the WM_NCHITTEST message parameters
                    // get the mouse pointer coordinates (in screen coordinates)
                    Point p = new Point();
                    p.X = (msg.LParam.ToInt32() & 0xFFFF);  // low order word
                    p.Y = (msg.LParam.ToInt32() >> 16);     // hi order word

                    // convert screen coordinates to client area coordinates
                    p = PointToClient(p);

                    // if it's on glass, then convert it from an HTCLIENT
                    // message to an HTCAPTION message and let Windows handle it from then on
                    if (PointIsOnGlass(p))
                    {
                        msg.Result = new IntPtr(2);
                    }
                }
                break;

            case WM_DWMCOMPOSITIONCHANGED:
                if (!DwmApi.DwmIsCompositionEnabled())
                {
                    m_glassMargins = null;
                }
                else
                {
                    InitializeAeroGlass();
                }
                break;
            }
        }
Exemplo n.º 6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Width < 1 && Height < 1)
            {
                return;
            }

            Graphics g = e.Graphics;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            if (DwmApi.DwmIsCompositionEnabled())
            {
                g.Clear(Color.Transparent);
            }
            else
            {
                g.Clear(SystemColors.ControlLightLight);
            }

            Rectangle border = Rectangle.FromLTRB(0, 0, Width - 1, Height - 1);

            using (GraphicsPath roundBorderPath = RoundedRectangle.Create(border))
            {
                if (isDown || (isChecked && checkAble))
                {
                    using (LinearGradientBrush gradientBrush = new LinearGradientBrush(border, downColor[0], downColor[1], LinearGradientMode.Vertical))
                    {
                        g.FillPath(gradientBrush, roundBorderPath);
                    }
                }
                else
                {
                    using (LinearGradientBrush gradientBrush = new LinearGradientBrush(border, normalColor[0], normalColor[1], LinearGradientMode.Vertical))
                    {
                        g.FillPath(gradientBrush, roundBorderPath);
                    }
                }

                if (isHovering)
                {
                    using (Pen p = new Pen(Color.FromArgb(80, SystemColors.Highlight), 3))
                    {
                        g.DrawPath(p, roundBorderPath);
                    }

                    using (Pen p = new Pen(Color.FromArgb(150, SystemColors.Highlight), 1))
                    {
                        g.DrawPath(p, roundBorderPath);
                    }
                }
                else
                {
                    using (Pen p = new Pen(Color.FromArgb(80, BorderColor), 2))
                    {
                        g.DrawPath(p, roundBorderPath);
                    }

                    using (Pen p = new Pen(Color.FromArgb(150, BorderColor), 1))
                    {
                        g.DrawPath(p, roundBorderPath);
                    }
                }
            }

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            TextFormatFlags tff = TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.SingleLine | TextFormatFlags.NoPrefix;

            if (DwmApi.DwmIsCompositionEnabled())
            {
                DrawTextOnGlass(g, Text, Font, ClientRectangle, ForeColor, tff);
            }
            else
            {
                TextRenderer.DrawText(g, Text, Font, ClientRectangle, ForeColor, tff);
            }
        }
Exemplo n.º 7
0
        internal void DrawControl(Graphics g)
        {
            if (DwmApi.DwmIsCompositionEnabled())
            {
                g.Clear(Color.Transparent);
            }
            else
            {
                g.Clear(SystemColors.ControlLightLight);
            }
            if (TabCount > 0)
            {
                g.FillRectangle(Brushes.White, GetTabRect(0).X, GetTabRect(0).Bottom, ClientRectangle.Width, ClientRectangle.Height);
                Rectangle contentRect = Rectangle.FromLTRB(ClientRectangle.X, GetTabRect(0).Bottom, ClientRectangle.Right - 1, ClientRectangle.Bottom - 1);
                g.DrawRectangle(Pens.Gray, contentRect);
            }

            for (int i = 0; i < TabCount; i++)
            {
                TabPage   tab     = TabPages[i];
                Rectangle tabRect = GetTabRect(i);
                tabRect.Inflate(-2, 0);

                //draw shadow
                Rectangle shadowRect = tabRect;
                shadowRect.Offset(2, 2);

                using (GraphicsPath path = CreateCompleteTabPath(shadowRect))
                {
                    Rectangle tabBar = Rectangle.FromLTRB(ClientRectangle.Left, ClientRectangle.Top,
                                                          ClientRectangle.Right, tabRect.Bottom);

                    Region region = g.Clip;
                    g.SetClip(tabBar);
                    SolidBrush shadow = new SolidBrush(Color.FromArgb(100, Color.Gray));
                    g.FillPath(shadow, path);
                    g.Clip = region;
                }

                if (tab == SelectedTab)
                {
                    using (GraphicsPath path = CreateTabPath(tabRect))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.FillPath(Brushes.White, path);
                        g.DrawPath(Pens.Gray, path);
                    }

                    Rectangle fillRect = tabRect;
                    fillRect.Offset(0, 2);
                    using (GraphicsPath path = CreateCompleteTabPath(fillRect))
                    {
                        g.FillPath(Brushes.White, path);
                    }
                }
                else
                {
                    using (GraphicsPath path = CreateCompleteTabPath(tabRect))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.FillPath(Brushes.White, path);
                        g.DrawPath(Pens.Gray, path);
                    }
                }

                if (i == mouseIsOn)
                {
                    using (GraphicsPath path = CreateTabPath(tabRect))
                    {
                        using (Pen p = new Pen(Color.FromArgb(80, SystemColors.Highlight)))
                        {
                            p.Width = 4;
                            g.DrawPath(p, path);
                        }

                        using (Pen p = new Pen(Color.FromArgb(150, SystemColors.Highlight)))
                        {
                            p.Width = 2;
                            g.DrawPath(p, path);
                        }
                    }
                }


                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;

                g.DrawString(tab.Text, tab.Font, new SolidBrush(tab.ForeColor), tabRect, stringFormat);
            }
        }