GetWindowLongPtr() public static method

The GetWindowLong function retrieves information about the specified window. The function also retrieves the 32-bit (long) value at the specified offset into the extra window memory.If you are retrieving a pointer or a handle, this function has been superseded by the GetWindowLongPtr function. (Pointers and handles are 32 bits on 32-bit Microsoft Windows and 64 bits on 64-bit Windows.) To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetWindowLongPtr.
public static GetWindowLongPtr ( IntPtr hWnd, int nIndex ) : IntPtr
hWnd System.IntPtr Handle to the window and, indirectly, the class to which the window belongs
nIndex int Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus the size of an integer
return System.IntPtr
Exemplo n.º 1
0
        /// <summary>
        /// Window function
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="msg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <param name="handled"></param>
        /// <returns></returns>
        private IntPtr WindowProc(
            IntPtr hwnd,
            int msg,
            IntPtr wParam,
            IntPtr lParam,
            ref bool handled)
        {
            switch (msg)
            {
            case 0x0006 /*WM_ACTIVATE*/:
            {
                if (((short)wParam.ToInt32()) == 0)
                {
                    // BUG: Fix for MessageBox: without parent messagebox closes
                    if (hwndSource != null)
                    {
                        if (NativeMethods.GetWindowLongPtr(lParam, NativeMethods.GWL_HWNDPARENT) ==
                            hwndSource.Handle)
                        {
                            break;
                        }
                        if (openedPopups.Count(x => x.hwndSource.Handle == lParam) == 0)
                        {
                            ClosePopups(0);
                        }
                    }
                }
                else
                {
                    int index = openedPopups.IndexOf(this);
                    ClosePopups(index + 1);
                    Window wnd = Window.GetWindow(this);
                    if (wnd != null)
                    {
                        IntPtr parentHwnd = (new WindowInteropHelper(wnd)).Handle;
                        NativeMethods.SendMessage(parentHwnd, 0x0086, new IntPtr(1), IntPtr.Zero);
                    }
                }
                break;
            }

            case 0x0021 /*WM_MOUSEACTIVATE*/:
            {
                int index = openedPopups.IndexOf(this);
                ClosePopups(index + 1);
                Window wnd = Window.GetWindow(this);
                if (wnd != null)
                {
                    IntPtr parentHwnd = (new WindowInteropHelper(wnd)).Handle;
                    NativeMethods.SendMessage(parentHwnd, 0x0086, new IntPtr(1), IntPtr.Zero);
                }
                break;
            }

            case 0x0002 /*WM_DESTROY*/:
            {
                /*if ((hwndSource != null) && (!hwndSource.IsDisposed))
                 * {
                 *  // Remove hook
                 *  hwndSource.RemoveHook(WindowProc);
                 *  hwndSource = null;
                 * }*/
                break;
            }
            }
            return(IntPtr.Zero);
        }