Windows message.
Exemplo n.º 1
1
 private void Post(WM msg, int param = 0)
 {
     lock (_msgQueue)
     {
         _msgQueue.Enqueue(new MSG(){message = msg, param = param});
         Monitor.Pulse(_msgQueue);
     }
 }
Exemplo n.º 2
0
        static IntPtr WndProc2(IntPtr hwnd, WM msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr dc, old, pen;
            PAINTSTRUCT ps;
            RECT rect;

            switch(msg)
            {
                case WM.WM_PAINT:
                    //if (!x)
                    {
                        dc = BeginPaint(hwnd, out ps);
                        //Debug.WriteLine("RECT " + ps.rcPaint.Left);
                        GetClientRect(hwnd, out rect);

                        DrawText(dc, "Hello Win32!", 458,
                            ref rect, 0);

                        pen = CreatePen(0, 1, 0xff);
                        old = SelectObject(dc, pen);
                        Rectangle(dc, 100, 100, 200, 200);

                        SelectObject(dc, old);

                        EndPaint(hwnd, ref ps);
                        Debug.WriteLine(msg);
                        //x = true;
                    }
                    return IntPtr.Zero;
                case WM.WM_DESTROY:
                    PostQuitMessage(0);
                    return IntPtr.Zero;
                case WM.WM_COMMAND:
                    if (wParam.ToInt32() == 1001)
                        PostQuitMessage(0);
                    return IntPtr.Zero;
                default:
                    Debug.WriteLine(msg);
                    return DefWindowProc(hwnd, msg, wParam, lParam);
            }
        }
Exemplo n.º 3
0
 public static extern int SendMessage(IntPtr hWnd, WM Msg, int wParam, int lParam);
Exemplo n.º 4
0
 public static extern bool PostMessage(IntPtr hWnd, WM Msg, int wParam, int lParam);
Exemplo n.º 5
0
        internal IntPtr ProcessMessages(IntPtr handle, WM message, IntPtr wParam, IntPtr lParam)
        {
            switch (message)
            {
                #region Size / Move / Style events

                case WM.ACTIVATE:
                    // See http://msdn.microsoft.com/en-us/library/ms646274(VS.85).aspx (WM_ACTIVATE notification):
                    // wParam: The low-order word specifies whether the window is being activated or deactivated.
                    //bool newFocusedState = focused;
                    if (IntPtr.Size == 4)
                        focused = (wParam.ToInt32() & 0xFFFF) != 0;
                    else
                        focused = (wParam.ToInt64() & 0xFFFF) != 0;

                    //if (newFocusedState != focused && FocusedChanged != null)
                    //    FocusedChanged(this, EventArgs.Empty);

                    if (focused)
                    {
                        input.OnGotFocus();
                    }
                    else
                    {
                        input.OnLostFocus();
                    }

                    break;

                case WM.ENTERMENULOOP:
                    //StartTimer(handle);
                    break;
                case WM.ENTERSIZEMOVE:
                    // Entering the modal size/move loop: we don't want rendering to
                    // stop during this time, so we register a timer callback to continue
                    // processing from time to time.
                    //StartTimer(handle);
                    resizingOrMoving = true;
                    break;

                case WM.EXITMENULOOP:
                    //StopTimer(handle);
                    break;
                case WM.EXITSIZEMOVE:
                    // ExitingmModal size/move loop: the timer callback is no longer
                    // necessary.
                    //StopTimer(handle);
                    resizingOrMoving = false;
                    break;
                    /*
                case WM.TIMER:
                    if (wParam == timerHandle)
                    {
                        onTimer();
                    }
                    break;*/

                case WM.ERASEBKGND:
                    {
                        return new IntPtr(1);
                    }
                case WM.SYSCOMMAND:
                    {
                        if (wParam.ToInt32() == 61696)
                        {
                            return NULL;
                        }
                    }
                    break;
                    /*
                case WindowMessage.WINDOWPOSCHANGED:
                    unsafe
                    {
                        WindowPosition* pos = (WindowPosition*)lParam;
                        if (window != null && pos->hwnd == window.WindowHandle)
                        {
                            Point new_location = new Point(pos->x, pos->y);
                            if (Location != new_location)
                            {
                                bounds.Location = new_location;
                                if (Move != null)
                                    Move(this, EventArgs.Empty);
                            }

                            Size new_size = new Size(pos->cx, pos->cy);
                            if (Size != new_size)
                            {
                                bounds.SwapChainWidth = pos->cx;
                                bounds.SwapChainHeight = pos->cy;

                                Win32Rectangle rect;
                                Functions.GetClientRect(handle, out rect);
                                client_rectangle = rect.ToRectangle();

                                Functions.SetWindowPos(child_window.WindowHandle, IntPtr.Zero, 0, 0, ClientRectangle.SwapChainWidth, ClientRectangle.SwapChainHeight,
                                    SetWindowPosFlags.NOZORDER | SetWindowPosFlags.NOOWNERZORDER |
                                    SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSENDCHANGING);

                                if (suppress_resize <= 0 && Resize != null)
                                    Resize(this, EventArgs.Empty);
                            }
                        }
                    }
                    break;*/
                case WM.WINDOWPOSCHANGED:
                    {
                        Functions.GetClientRect(hwnd, out clientRectangle);
                    }
                    break;

                    /*
                case WindowMessage.STYLECHANGED:
                    unsafe
                    {
                        if (wParam.ToInt64() == (long)GWL.STYLE)
                        {
                            WindowStyle style = ((StyleStruct*)lParam)->New;
                            if ((style & WindowStyle.Popup) != 0)
                                windowBorder = WindowBorder.Hidden;
                            else if ((style & WindowStyle.ThickFrame) != 0)
                                windowBorder = WindowBorder.Resizable;
                            else if ((style & ~(WindowStyle.ThickFrame | WindowStyle.MaximizeBox)) != 0)
                                windowBorder = WindowBorder.Fixed;
                        }
                    }

                    break;*/

                    /*
                case WindowMessage.SIZE:
                    SizeMessage state = (SizeMessage)wParam.ToInt64();
                    WindowState new_state = windowState;
                    switch (state)
                    {
                        case SizeMessage.RESTORED: new_state = borderless_maximized_window_state ?
                            WindowState.Maximized : WindowState.Normal; break;
                        case SizeMessage.MINIMIZED: new_state = WindowState.Minimized; break;
                        case SizeMessage.MAXIMIZED: new_state = WindowBorder == WindowBorder.Hidden ?
                            WindowState.Fullscreen : WindowState.Maximized;
                            break;
                    }

                    if (new_state != windowState)
                    {
                        windowState = new_state;
                        if (WindowStateChanged != null)
                            WindowStateChanged(this, EventArgs.Empty);
                    }

                    break;*/

                case WM.SIZE:
                    {
                        SIZE state = (SIZE)wParam.ToInt64();
                        minimized = state == SIZE.MINIMIZED;
                        Functions.GetClientRect(hwnd, out clientRectangle);
                    }
                    break;
                #endregion

                #region Input
                    /*
                case WM.CHAR:
                    */
                case WM.MOUSEMOVE:
                    OnMouseEvent(MouseEventType.Move, wParam, lParam);
                    break;
                case WM.LBUTTONDOWN:
                case WM.RBUTTONDOWN:
                case WM.MBUTTONDOWN:
                case WM.XBUTTONDOWN:
                    OnMouseEvent(MouseEventType.Down, wParam, lParam);
                    break;
                case WM.LBUTTONUP:
                case WM.RBUTTONUP:
                case WM.MBUTTONUP:
                case WM.XBUTTONUP:
                    OnMouseEvent(MouseEventType.Up, wParam, lParam);
                    break;
                case WM.LBUTTONDBLCLK:
                case WM.RBUTTONDBLCLK:
                case WM.MBUTTONDBLCLK:
                case WM.XBUTTONDBLCLK:
                    OnMouseEvent(MouseEventType.DoubleClick, wParam, lParam);
                    break;
                case WM.MOUSEWHEEL:
                    OnMouseEvent(MouseEventType.Wheel, wParam, lParam);
                    break;
                #endregion

                case WM.DESTROY:
                    Functions.UnregisterClass(className, instance);
                    Functions.PostQuitMessage(0);
                    break;
            }

            return Functions.DefWindowProc(handle, message, wParam, lParam);
        }
Exemplo n.º 6
0
 public static extern IntPtr SendMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam);
Exemplo n.º 7
0
 public static extern bool PostThreadMessage(uint threadId, WM msg, IntPtr wParam, IntPtr lParam);
Exemplo n.º 8
0
 public static extern int PostMessage(IntPtr hWnd, WM Msg, IntPtr wParam, IntPtr lParam);
Exemplo n.º 9
0
 public static extern IntPtr DefWindowProcW(
     IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam
     );
Exemplo n.º 10
0
 private static IntPtr CustomWndProc(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam)
 {
     return Import.DefWindowProcW(hWnd, msg, wParam, lParam);
 }
 internal static extern int SendMessage(IntPtr hWnd, WM msg, int wParam, int lParam);
Exemplo n.º 12
-1
        static IntPtr WndProc2(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr hdc;
            PAINTSTRUCT ps;
            RECT rect;

            switch (msg)
            {
                case WM.WM_PAINT:
                    hdc = BeginPaint(hWnd, out ps);
                    GetClientRect(hWnd, out rect);

                    DrawText(hdc, "Hello, Windows 98!", -1, ref rect,
                    DT_SINGLELINE | DT_CENTER | DT_VCENTER);

                    EndPaint(hWnd, ref ps);
                    return IntPtr.Zero;
                case WM.WM_DESTROY:
                    PostQuitMessage(0);
                    return IntPtr.Zero;
                default:
                    Debug.WriteLine(msg);
                    return DefWindowProc(hWnd, msg, wParam, lParam);
            }
        }