Example #1
0
 internal static extern LRESULT CallWindowProc(WNDPROC lpPrevWndFunc, HWND hWnd, WindowMessage Msg,
     WPARAM wParam, LPARAM lParam);
Example #2
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
                case WindowMessage.Create:
                    window.SetTimer(ID_TIMER, 1000);
                    stPrevious = Windows.GetLocalTime();
                    return 0;
                case WindowMessage.Size:
                    cxClient = lParam.LowWord;
                    cyClient = lParam.HighWord;
                    return 0;
                case WindowMessage.Timer:
                    SYSTEMTIME st = Windows.GetLocalTime();
                    bool fChange = st.wHour != stPrevious.wHour ||
                        st.wMinute != stPrevious.wMinute;
                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        SetIsotropic(dc, cxClient, cyClient);
                        dc.SelectObject(StockPen.White);
                        DrawHands(dc, stPrevious, fChange);
                        dc.SelectObject(StockPen.Black);
                        DrawHands(dc, st, true);
                    }
                    stPrevious = st;
                    return 0;
                case WindowMessage.Paint:
                    using (DeviceContext dc = window.BeginPaint())
                    {
                        SetIsotropic(dc, cxClient, cyClient);
                        DrawClock(dc);
                        DrawHands(dc, stPrevious, true);
                    }
                    return 0;
                case WindowMessage.Destroy:
                    window.KillTimer(ID_TIMER);
                    Windows.PostQuitMessage(0);
                    return 0;
            }

            return Windows.DefaultWindowProcedure(window, message, wParam, lParam);
        }
Example #3
0
 public HRESULT OnTestKeyUp(WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
 {
     return(((delegate * unmanaged <ITfContextKeyEventSink *, WPARAM, LPARAM, BOOL *, int>)(lpVtbl[6]))((ITfContextKeyEventSink *)Unsafe.AsPointer(ref this), wParam, lParam, pfEaten));
 }
Example #4
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Size:
                cxBlock = lParam.LowWord / DIVISIONS;
                cyBlock = lParam.HighWord / DIVISIONS;
                return(0);

            case WindowMessage.SetFocus:
                Windows.ShowCursor(true);
                return(0);

            case WindowMessage.KillFocus:
                Windows.ShowCursor(false);
                return(0);

            case WindowMessage.KeyDown:
                POINT point = Windows.GetCursorPosition();
                window.ScreenToClient(ref point);
                int x = Math.Max(0, Math.Min(DIVISIONS - 1, point.x / cxBlock));
                int y = Math.Max(0, Math.Min(DIVISIONS - 1, point.y / cyBlock));
                switch ((VirtualKey)wParam)
                {
                case VirtualKey.Up:
                    y--;
                    break;

                case VirtualKey.Down:
                    y++;
                    break;

                case VirtualKey.Left:
                    x--;
                    break;

                case VirtualKey.Right:
                    x++;
                    break;

                case VirtualKey.Home:
                    x = y = 0;
                    break;

                case VirtualKey.End:
                    x = y = DIVISIONS - 1;
                    break;

                case VirtualKey.Return:
                case VirtualKey.Space:
                    window.SendMessage(WindowMessage.LeftButtonDown, (WPARAM)MouseKey.LeftButton,
                                       new LPARAM(y * cyBlock, x * cxBlock));
                    break;
                }
                x       = (x + DIVISIONS) % DIVISIONS;
                y       = (y + DIVISIONS) % DIVISIONS;
                point.x = x * cxBlock + cxBlock / 2;
                point.y = y * cyBlock + cyBlock / 2;
                window.ClientToScreen(ref point);
                Windows.SetCursorPosition(point.x, point.y);
                return(0);

            case WindowMessage.LeftButtonDown:
                x = lParam.LowWord / cxBlock;
                y = lParam.HighWord / cyBlock;
                if (x < DIVISIONS && y < DIVISIONS)
                {
                    fState[x, y] ^= true;
                    RECT rect = new RECT
                    {
                        left   = x * cxBlock,
                        top    = y * cyBlock,
                        right  = (x + 1) * cxBlock,
                        bottom = (y + 1) * cyBlock
                    };
                    window.InvalidateRectangle(rect, false);
                }
                else
                {
                    ErrorMethods.MessageBeep(0);
                }

                return(0);

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    for (x = 0; x < DIVISIONS; x++)
                    {
                        for (y = 0; y < DIVISIONS; y++)
                        {
                            dc.Rectangle(x * cxBlock, y * cyBlock,
                                         (x + 1) * cxBlock, (y + 1) * cyBlock);
                            if (fState[x, y])
                            {
                                dc.MoveTo(x * cxBlock, y * cyBlock);
                                dc.LineTo((x + 1) * cxBlock, (y + 1) * cyBlock);
                                dc.MoveTo(x * cxBlock, (y + 1) * cyBlock);
                                dc.LineTo((x + 1) * cxBlock, y * cyBlock);
                            }
                        }
                    }
                }
                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Example #5
0
        // Misc functions
#if LATER
        BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM lParam)
        {
            *(HWND *)lParam = hwnd;
            return(!IsWindowVisible(hwnd));
        }
Example #6
0
        static BOOL EnumWindowsCallback(HWND hWnd, LPARAM lParam)
        {
            Console.WriteLine($"{(IntPtr)hWnd} - \"{GetWindowTextV2(hWnd)}\"");

            return(true);
        }
Example #7
0
 protected MSLLHOOKSTRUCT getMSLLHOOKSTRUCT(LPARAM lParam)
 {
     return((MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)));
 }
Example #8
0
 public static extern LRESULT DefWindowProcW(
     HWND hWnd,
     Win32MessageType uMsg,
     WPARAM wParam,
     LPARAM lParam
     );
Example #9
0
 private static extern LRESULT DefWindowProc(HWND hWnd, UInt32 Msg, WPARAM wParam, LPARAM lParam);
 public static extern LRESULT ImmRequestMessageW(HIMC param0, WPARAM param1, LPARAM param2);
Example #11
0
 public abstract FilterResult process(int nCode, WPARAM wParam, LPARAM lParam);
Example #12
0
        unsafe static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            const string filter = "*.*";

            switch (message)
            {
            case WindowMessage.Create:
                SIZE baseUnits = Windows.GetDialogBaseUnits();
                rect.left = 20 * baseUnits.cx;
                rect.top  = 3 * baseUnits.cy;

                // Create listbox and static text windows.
                hwndList = Windows.CreateWindow("listbox", null,
                                                WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ListBoxStyles.Standard, ExtendedWindowStyles.None,
                                                baseUnits.cx, baseUnits.cy * 3, baseUnits.cx * 13 + Windows.GetSystemMetrics(SystemMetric.CXVSCROLL), baseUnits.cy * 10,
                                                window, (IntPtr)ID_LIST, ((CREATESTRUCT *)lParam)->hInstance, IntPtr.Zero);

                hwndText = Windows.CreateWindow("static", DirectoryMethods.GetCurrentDirectory(),
                                                WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Left, ExtendedWindowStyles.None,
                                                baseUnits.cx, baseUnits.cy, baseUnits.cx * 260, baseUnits.cy,
                                                window, (IntPtr)ID_TEXT, ((CREATESTRUCT *)lParam)->hInstance, IntPtr.Zero);

                OldList = hwndList.SetWindowProcedure(s_ListBoxProcedure);

                fixed(char *f = filter)
                hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f);

                return(0);

            case WindowMessage.Size:
                rect.right  = lParam.LowWord;
                rect.bottom = lParam.HighWord;
                return(0);

            case WindowMessage.SetFocus:
                hwndList.SetFocus();
                return(0);

            case WindowMessage.Command:
                if (wParam.LowWord == ID_LIST &&
                    (wParam.HighWord == (ushort)ListBoxNotification.DoubleClick))
                {
                    uint i = hwndList.SendMessage(ListBoxMessage.GetCurrentSelection, 0, 0);
                    if (i == WindowDefines.LB_ERR)
                    {
                        break;
                    }

                    int   iLength    = hwndList.SendMessage(ListBoxMessage.GetTextLength, i, 0) + 1;
                    char *textBuffer = stackalloc char[iLength];
                    int   result     = hwndList.SendMessage(ListBoxMessage.GetText, i, textBuffer);
                    szFile = new string(textBuffer, 0, result);

                    SafeFileHandle hFile = null;
                    try
                    {
                        using (hFile = FileMethods.CreateFile(szFile, CreationDisposition.OpenExisting,
                                                              DesiredAccess.GenericRead, ShareModes.Read))
                        {
                            if (!hFile.IsInvalid)
                            {
                                bValidFile = true;
                                hwndText.SetWindowText(DirectoryMethods.GetCurrentDirectory());
                            }
                        }
                        hFile = null;
                    }
                    catch
                    {
                    }

                    if (hFile == null && szFile[0] == ('['))
                    {
                        bValidFile = false;

                        // If setting the directory doesn’t work, maybe it’s a drive change, so try that.
                        try { DirectoryMethods.SetCurrentDirectory(szFile.Substring(1, szFile.Length - 2)); }
                        catch
                        {
                            try { DirectoryMethods.SetCurrentDirectory($"{szFile[2]}:"); }
                            catch { }
                        }

                        // Get the new directory name and fill the list box.
                        hwndText.SetWindowText(DirectoryMethods.GetCurrentDirectory());
                        hwndList.SendMessage(ListBoxMessage.ResetContent, 0, 0);

                        fixed(char *f = filter)
                        hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f);
                    }

                    window.Invalidate();
                }
                return(0);

            case WindowMessage.Paint:
                if (!bValidFile)
                {
                    break;
                }

                uint bytesRead;
                using (var hFile = FileMethods.CreateFile(szFile, CreationDisposition.OpenExisting,
                                                          DesiredAccess.GenericRead, ShareModes.Read))
                {
                    if (hFile.IsInvalid)
                    {
                        bValidFile = false;
                        break;
                    }

                    bytesRead = FileMethods.ReadFile(hFile, buffer, MAXREAD);
                }

                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SelectObject(StockFont.SystemFixed);
                    dc.SetTextColor(Windows.GetSystemColor(SystemColor.ButtonText));
                    dc.SetBackgroundColor(Windows.GetSystemColor(SystemColor.ButtonFace));
                    dc.DrawText(Encoding.UTF8.GetString(buffer), rect, DTFLAGS);
                }

                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Example #13
0
        unsafe static LRESULT ListBoxProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            if (message == WindowMessage.KeyDown && (VirtualKey)wParam == VirtualKey.Return)
            {
                window.GetParent().SendMessage(WindowMessage.Command,
                                               new WPARAM(1, (ushort)ListBoxNotification.DoubleClick), (LPARAM)window);
            }

            return(WindowMethods.CallWindowProcedure(OldList, window, message, wParam, lParam));
        }
Example #14
0
 /// <summary>
 /// Allocates new memory block and returns its address.
 /// </summary>
 /// <param name="size">Byte count.</param>
 /// <param name="zeroInit">Set all bytes = 0.</param>
 /// <exception cref="OutOfMemoryException">Failed. Probably size is too big.</exception>
 /// <remarks>
 /// Calls API <msdn>HeapAlloc</msdn>.
 /// The memory is unmanaged and will not be freed automatically. Always call <see cref="Free"/> when done or <see cref="ReAlloc"/> if need to resize it without losing data.
 /// </remarks>
 public static void *Alloc(LPARAM size, bool zeroInit = false) => ReAlloc(null, size, zeroInit);
Example #15
0
 internal static extern BOOL PostMessage(
     HWND hWnd,
     WindowMessage Msg,
     WPARAM wParam,
     LPARAM lParam
 );
Example #16
0
 public static extern LRESULT CallWindowProc(HWND lpPrevWndFunc, HWND hWnd, UInt32 msg, WPARAM wParam, LPARAM lParam);
 public static ushort GET_KEYSTATE_LPARAM(LPARAM lParam) => GET_FLAGS_LPARAM(lParam);
 static LRESULT CallDefaultProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
 {
     return(WindowMethods.DefaultWindowProcedure(window, message, wParam, lParam));
 }
Example #19
0
 /// <param name="nCode">A code that uses to determine how to process the message.</param>
 /// <param name="wParam">The identifier of the mouse message.</param>
 /// <param name="lParam">A pointer to an MSLLHOOKSTRUCT structure.</param>
 /// <returns></returns>
 public abstract FilterResult msg(int nCode, WPARAM wParam, LPARAM lParam);
Example #20
0
 /// <summary>
 /// Gets bits 1-16 as ushort.
 /// Like C macro LOWORD.
 /// </summary>
 /// <remarks>
 /// The parameter is interpreted as uint. Its declared type is LPARAM because it allows to avoid explicit casting from other integer types and IntPtr (casting from IntPtr to uint could throw OverflowException).
 /// </remarks>
 public static ushort LoUshort(LPARAM x) => (ushort)((uint)x & 0xFFFF);
Example #21
0
        bool _OnSetCursor(Control c, LPARAM lParam)
        {
            bool R = false, hilite = false, isTooltip = false;

            if ((((uint)lParam) & 0xFFFF) == Api.HTCLIENT && !c.Capture)
            {
                var p = c.MouseClientXY();
                switch (_HitTest(c, p.x, p.y, out var ht))
                {
                case _HitTestResult.Splitter:
                    //info: works better than Cursor=x in OnMouseMove.
                    var cursor = ht.gs.IsVerticalSplit ? Cursors.VSplit : Cursors.HSplit;
                    Api.SetCursor(cursor.Handle);
                    R = true;
                    break;

                case _HitTestResult.Caption:
                    var gt = ht.ParentTab;
                    if (gt != null && ht.gp != gt.ActiveItem)
                    {
                        hilite = true;                                                          //highlight inactive tab button
                    }
                    else if (ht.gp != null && ht.gp.HasToolbar)
                    {
                        hilite = true;                                                            //change toolbar caption color from form background color to panel caption color
                    }
                    if (hilite)
                    {
                        if (_hilitedTabButton != ht.gp)
                        {
                            _UnhiliteTabButton();
                            _hilitedTabButton = ht.gp;
                            _hilitedTabButton.InvalidateCaption();
                        }
                    }
                    //tooltip
                    var tt = ht.gp?.ToolTipText;
                    if (!tt.NE())
                    {
                        isTooltip = true;
                        if (_toolTipTabButton != ht.gp)
                        {
                            int delay = _toolTipTabButton == null ? _toolTip.InitialDelay : _toolTip.ReshowDelay;
                            _HideTooltip();
                            _toolTipTabButton = ht.gp;
                            ATimer.After(delay, _ => {
                                var gp = _toolTipTabButton; if (gp == null)
                                {
                                    return;
                                }
                                var p2 = gp.ParentControl.MouseClientXY();
                                _toolTip.Show(gp.ToolTipText, gp.ParentControl, p2.x, p2.y + 20, _toolTip.AutoPopDelay);
                            });
                        }
                    }
                    break;
                }
            }
            if (!hilite)
            {
                _UnhiliteTabButton();
            }
            if (!isTooltip)
            {
                _HideTooltip();
            }
            return(R);
        }
Example #22
0
 /// <summary>
 /// Gets bits 17-32 as ushort.
 /// Like C macro HIWORD.
 /// </summary>
 /// <remarks>
 /// The parameter is interpreted as uint. Its declared type is LPARAM because it allows to avoid explicit casting from other integer types and IntPtr (casting from IntPtr to uint could throw OverflowException).
 /// </remarks>
 public static ushort HiUshort(LPARAM x) => (ushort)((uint)x >> 16);
Example #23
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                window.SetTimer(ID_TIMER, 1000, TimerProcedure);
                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Example #24
0
 /// <summary>
 /// Gets bits 1-16 as short.
 /// Like C macro GET_X_LPARAM.
 /// </summary>
 /// <remarks>
 /// The parameter is interpreted as uint. Its declared type is LPARAM because it allows to avoid explicit casting from other integer types and IntPtr (casting from IntPtr to uint could throw OverflowException).
 /// </remarks>
 public static short LoShort(LPARAM x) => (short)((uint)x & 0xFFFF);
 public HRESULT CallBack(IShellFolder *psf, HWND hwndOwner, IDataObject *pdtobj, uint uMsg, WPARAM wParam, LPARAM lParam)
 {
     return(((delegate * unmanaged <IContextMenuCB *, IShellFolder *, HWND, IDataObject *, uint, WPARAM, LPARAM, int>)(lpVtbl[3]))((IContextMenuCB *)Unsafe.AsPointer(ref this), psf, hwndOwner, pdtobj, uMsg, wParam, lParam));
 }
Example #26
0
 /// <summary>
 /// Gets bits 17-32 as short.
 /// Like C macro GET_Y_LPARAM.
 /// </summary>
 /// <remarks>
 /// The parameter is interpreted as uint. Its declared type is LPARAM because it allows to avoid explicit casting from other integer types and IntPtr (casting from IntPtr to uint could throw OverflowException).
 /// </remarks>
 public static short HiShort(LPARAM x) => (short)((uint)x >> 16);
Example #27
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                window.SetTimer(ID_TIMER, 1000);
                return(0);

            case WindowMessage.Timer:
                Windows.MessageBeep();
                fFlipFlop = !fFlipFlop;
                window.Invalidate();
                return(0);

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    RECT rect = window.GetClientRectangle();
                    using (BrushHandle brush = fFlipFlop ? Windows.CreateSolidBrush(255, 0, 0) : Windows.CreateSolidBrush(0, 0, 255))
                    {
                        dc.FillRectangle(rect, brush);
                    }
                }
                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Example #28
0
 public static LRESULT SendMessage(this WindowHandle window, ListBoxMessage message, WPARAM wParam, LPARAM lParam)
 => WindowMethods.SendMessage(window, (WindowMessage)message, wParam, lParam);
Example #29
0
 private static void LPARAM_From_NInt()
 {
     LPARAM p = 1;
 }
Example #30
0
 public static extern LRESULT SendNotifyMessageA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
Example #31
0
 internal static extern LRESULT SendMessage(HWND hWnd, WindowMessage Msg, WPARAM wParam, LPARAM lParam);
Example #32
0
 public static extern BOOL PostMessageA(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
Example #33
0
        // Misc functions
#if LATER
BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM lParam) 
{
	*(HWND*)lParam = hwnd;
	return !IsWindowVisible(hwnd);
}
 public static ushort GET_FLAGS_LPARAM(LPARAM lParam) => LOWORD(unchecked ((uint)lParam));