예제 #1
0
 public static int GetScrollPosition(this WindowHandle window, ScrollBar scrollBar)
 => WindowMethods.GetScrollPosition(window, scrollBar);
예제 #2
0
 public static int SetScrollPosition(this WindowHandle window, ScrollBar scrollBar, int position, bool redraw)
 => WindowMethods.SetScrollPosition(window, scrollBar, position, redraw);
예제 #3
0
 public static int SetScrollInfo(this WindowHandle window, ScrollBar scrollBar, ref SCROLLINFO scrollInfo, bool redraw)
 => WindowMethods.SetScrollInfo(window, scrollBar, ref scrollInfo, redraw);
예제 #4
0
 public static RECT GetWindowRectangle(this WindowHandle window) => WindowMethods.GetWindowRectangle(window);
예제 #5
0
 public static void SetScrollRange(this WindowHandle window, ScrollBar scrollBar, int min, int max, bool redraw)
 => WindowMethods.SetScrollRange(window, scrollBar, min, max, redraw);
예제 #6
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Size:
                int cxClient = lParam.LowWord;
                int cyClient = lParam.HighWord;

                apt[0].x = cxClient / 4;
                apt[0].y = cyClient / 2;
                apt[1].x = cxClient / 2;
                apt[1].y = cyClient / 4;
                apt[2].x = cxClient / 2;
                apt[2].y = 3 * cyClient / 4;
                apt[3].x = 3 * cxClient / 4;
                apt[3].y = cyClient / 2;

                return(0);

            case WindowMessage.LeftButtonDown:
            case WindowMessage.RightButtonDown:
            case WindowMessage.MouseMove:
                MouseKey mk = (MouseKey)wParam.LowWord;
                if ((mk & (MouseKey.LeftButton | MouseKey.RightButton)) != 0)
                {
                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        dc.SelectObject(StockPen.White);
                        DrawBezier(dc, apt);

                        if ((mk & MouseKey.LeftButton) != 0)
                        {
                            apt[1].x = lParam.LowWord;
                            apt[1].y = lParam.HighWord;
                        }

                        if ((mk & MouseKey.RightButton) != 0)
                        {
                            apt[2].x = lParam.LowWord;
                            apt[2].y = lParam.HighWord;
                        }

                        dc.SelectObject(StockPen.Black);
                        DrawBezier(dc, apt);
                    }
                }
                return(0);

            case WindowMessage.Paint:
                window.Invalidate(true);
                using (DeviceContext dc = window.BeginPaint())
                {
                    DrawBezier(dc, apt);
                }
                return(0);

            case WindowMessage.Destroy:
                WindowMethods.PostQuitMessage(0);
                return(0);
            }

            return(WindowMethods.DefaultWindowProcedure(window, message, wParam, lParam));
        }
예제 #7
0
 public static CommandId MessageBox(this WindowHandle owner, string text, string caption, MessageBoxType type = MessageBoxType.Ok)
 => WindowMethods.MessageBox(owner, text, caption, type);
예제 #8
0
 public static string GetClassName(this WindowHandle window) => WindowMethods.GetClassName(window);
예제 #9
0
 public static bool IsWindowVisible(this WindowHandle window) => WindowMethods.IsWindowVisible(window);
예제 #10
0
 public static WindowHandle GetTopWindow(this WindowHandle window) => WindowMethods.GetTopWindow(window);
예제 #11
0
 public static WindowHandle GetParent(this WindowHandle window) => WindowMethods.GetParent(window);
예제 #12
0
 public static WindowHandle GetWindow(this WindowHandle window, GetWindowOption option) => WindowMethods.GetWindow(window, option);
예제 #13
0
 public static bool ShowWindow(this WindowHandle window, ShowWindow command) => WindowMethods.ShowWindow(window, command);
예제 #14
0
 static LRESULT CallDefaultProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
 {
     return(WindowMethods.DefaultWindowProcedure(window, message, wParam, lParam));
 }
예제 #15
0
 public static void GetScrollInfo(this WindowHandle window, ScrollBar scrollBar, ref SCROLLINFO scrollInfo)
 => WindowMethods.GetScrollInfo(window, scrollBar, ref scrollInfo);
예제 #16
0
 public static bool IsWindowUnicode(this WindowHandle window) => WindowMethods.IsWindowUnicode(window);
예제 #17
0
 public static int ScrollWindow(this WindowHandle window, int dx, int dy) => WindowMethods.ScrollWindow(window, dx, dy);
예제 #18
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            SCROLLINFO si;

            switch (message)
            {
            case WindowMessage.Create:
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    dc.GetTextMetrics(out TEXTMETRIC tm);
                    cxChar = tm.tmAveCharWidth;
                    cxCaps = ((tm.tmPitchAndFamily.PitchTypes & FontPitchTypes.VariablePitch) != 0 ? 3 : 2) * cxChar / 2;
                    cyChar = tm.tmHeight + tm.tmExternalLeading;
                }

                // Save the width of the three columns
                iMaxWidth = 40 * cxChar + 22 * cxCaps;

                return(0);

            case WindowMessage.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;

                // Set vertical scroll bar range and page size
                si = new SCROLLINFO
                {
                    fMask = ScrollInfoMask.Range | ScrollInfoMask.Page,
                    nMin  = 0,
                    nMax  = SysMets.sysmetrics.Count - 1,
                    nPage = (uint)(cyClient / cyChar),
                };
                window.SetScrollInfo(ScrollBar.Vertical, ref si, true);

                // Set horizontal scroll bar range and page size
                si.nMax  = 2 + iMaxWidth / cxChar;
                si.nPage = (uint)(cxClient / cxChar);
                window.SetScrollInfo(ScrollBar.Horizontal, ref si, true);

                return(0);

            case WindowMessage.VerticalScroll:
                // Get all the vertical scroll bar information
                si = new SCROLLINFO
                {
                    fMask = ScrollInfoMask.All
                };
                window.GetScrollInfo(ScrollBar.Vertical, ref si);

                // Save the position for comparison later on
                int iVertPos = si.nPos;

                switch ((ScrollCommand)wParam.LowWord)
                {
                case ScrollCommand.Top:
                    si.nPos = si.nMin;
                    break;

                case ScrollCommand.Bottom:
                    si.nPos = si.nMax;
                    break;

                case ScrollCommand.LineUp:
                    si.nPos -= 1;
                    break;

                case ScrollCommand.LineDown:
                    si.nPos += 1;
                    break;

                case ScrollCommand.PageUp:
                    si.nPos -= (int)si.nPage;
                    break;

                case ScrollCommand.PageDown:
                    si.nPos += (int)si.nPage;
                    break;

                case ScrollCommand.ThumbTrack:
                    si.nPos = si.nTrackPos;
                    break;
                }

                // Set the position and then retrieve it. Due to adjustments
                // by Windows it may not be the same as the value set.
                si.fMask = ScrollInfoMask.Position;
                window.SetScrollInfo(ScrollBar.Vertical, ref si, true);
                window.GetScrollInfo(ScrollBar.Vertical, ref si);

                // If the position has changed, scroll the window and update it
                if (si.nPos != iVertPos)
                {
                    window.ScrollWindow(0, cyChar * (iVertPos - si.nPos));
                    window.UpdateWindow();
                }
                return(0);

            case WindowMessage.HorizontalScroll:
                // Get all the horizontal scroll bar information
                si = new SCROLLINFO
                {
                    fMask = ScrollInfoMask.All
                };
                window.GetScrollInfo(ScrollBar.Horizontal, ref si);

                // Save the position for comparison later on
                int iHorzPos = si.nPos;
                switch ((ScrollCommand)wParam.LowWord)
                {
                case ScrollCommand.LineLeft:
                    si.nPos -= 1;
                    break;

                case ScrollCommand.LineRight:
                    si.nPos += 1;
                    break;

                case ScrollCommand.PageLeft:
                    si.nPos -= (int)si.nPage;
                    break;

                case ScrollCommand.PageRight:
                    si.nPos += (int)si.nPage;
                    break;

                case ScrollCommand.ThumbPosition:
                    si.nPos = si.nTrackPos;
                    break;
                }

                // Set the position and then retrieve it. Due to adjustments
                // by Windows it may not be the same as the value set.
                si.fMask = ScrollInfoMask.Position;
                window.SetScrollInfo(ScrollBar.Horizontal, ref si, true);
                window.GetScrollInfo(ScrollBar.Horizontal, ref si);

                // If the position has changed, scroll the window
                if (si.nPos != iHorzPos)
                {
                    window.ScrollWindow(cxChar * (iHorzPos - si.nPos), 0);
                }
                return(0);

            case WindowMessage.KeyDown:
                switch ((VirtualKey)wParam)
                {
                case VirtualKey.Home:
                    window.SendMessage(WindowMessage.VerticalScroll, (uint)ScrollCommand.Top, 0);
                    break;

                case VirtualKey.End:
                    window.SendMessage(WindowMessage.VerticalScroll, (uint)ScrollCommand.Bottom, 0);
                    break;

                case VirtualKey.Prior:
                    window.SendMessage(WindowMessage.VerticalScroll, (uint)ScrollCommand.PageUp, 0);
                    break;

                case VirtualKey.Next:
                    window.SendMessage(WindowMessage.VerticalScroll, (uint)ScrollCommand.PageDown, 0);
                    break;

                case VirtualKey.Up:
                    window.SendMessage(WindowMessage.VerticalScroll, (uint)ScrollCommand.LineUp, 0);
                    break;

                case VirtualKey.Down:
                    window.SendMessage(WindowMessage.VerticalScroll, (uint)ScrollCommand.LineDown, 0);
                    break;

                case VirtualKey.Left:
                    window.SendMessage(WindowMessage.HorizontalScroll, (uint)ScrollCommand.PageUp, 0);
                    break;

                case VirtualKey.Right:
                    window.SendMessage(WindowMessage.HorizontalScroll, (uint)ScrollCommand.PageDown, 0);
                    break;
                }
                return(0);

            case WindowMessage.Paint:
                PAINTSTRUCT ps;
                using (DeviceContext dc = window.BeginPaint(out ps))
                {
                    // Get vertical scroll bar position
                    si = new SCROLLINFO
                    {
                        fMask = ScrollInfoMask.Position
                    };
                    window.GetScrollInfo(ScrollBar.Vertical, ref si);
                    iVertPos = si.nPos;

                    // Get horizontal scroll bar position
                    window.GetScrollInfo(ScrollBar.Horizontal, ref si);
                    iHorzPos = si.nPos;

                    // Find painting limits
                    int iPaintBeg = Math.Max(0, iVertPos + ps.rcPaint.top / cyChar);
                    int iPaintEnd = Math.Min(SysMets.sysmetrics.Count - 1, iVertPos + ps.rcPaint.bottom / cyChar);

                    var keys = SysMets.sysmetrics.Keys.ToArray();
                    for (int i = iPaintBeg; i <= iPaintEnd; i++)
                    {
                        var metric = keys[i];
                        int x      = cxChar * (1 - iHorzPos);
                        int y      = cyChar * (i - iVertPos);

                        dc.TextOut(x, y, metric.ToString());
                        dc.TextOut(x + 22 * cxCaps, y, SysMets.sysmetrics[metric]);
                        dc.SetTextAlignment(new TextAlignment(TextAlignment.Horizontal.Right, TextAlignment.Vertical.Top));
                        dc.TextOut(x + 22 * cxCaps + 40 * cxChar, y, WindowMethods.GetSystemMetrics(metric).ToString());
                        dc.SetTextAlignment(new TextAlignment(TextAlignment.Horizontal.Left, TextAlignment.Vertical.Top));
                    }
                }
                return(0);

            case WindowMessage.Destroy:
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }