Beispiel #1
0
        public uint CallWndProc32from16(Win32.WNDPROC pfnProc, ushort hWnd, ushort message16, ushort wParam, uint lParam)
        {
            if (message16 == Win16.WM_WIN3MU_BYPASS16)
            {
                var bpm = RetrieveBypassMessage(lParam);
                bpm.retVal = pfnProc(HWND.Map.To32(hWnd), bpm.message, bpm.wParam, bpm.lParam);
                return(0);
            }

            uint message32;
            var  sem = TryGetMessageSemantics16(HWND.Map.To32(hWnd), message16, out message32);

            var msg32 = new Win32.MSG()
            {
                hWnd    = HWND.Map.To32(hWnd),
                message = message32,
            };

            var msg16 = new Win16.MSG()
            {
                hWnd    = hWnd,
                message = message16,
                wParam  = wParam,
                lParam  = lParam,
            };

            var postable = sem as MessageSemantics.Postable;

            if (postable != null)
            {
                // Convert it
                postable.To32(_machine, ref msg16, ref msg32);

                // Call it
                return((uint)pfnProc(msg32.hWnd, msg32.message, msg32.wParam, msg32.lParam));
            }

            // Callable?
            var callable = sem as MessageSemantics.Callable;

            if (callable != null)
            {
                return(callable.Call32from16(_machine, false, false, ref msg16, ref msg32, () =>
                {
                    return pfnProc(msg32.hWnd, msg32.message, msg32.wParam, msg32.lParam);
                }));
            }

            // Unsupported
            MessageMap.ThrowMessageError(HWND.Map.To32(hWnd), message16);
            return(0);
        }
Beispiel #2
0
 public Window()
 {
     // Create window and subclass it
     uint style = Win32.WS_CAPTION | Win32.WS_POPUP | Win32.WS_SYSMENU | Win32.WS_CLIPCHILDREN |
                     Win32.WS_SIZEBOX | Win32.WS_MAXIMIZEBOX | Win32.WS_MINIMIZEBOX | Win32.WS_VISIBLE |
                     Win32.DS_3DLOOK | Win32.DS_MODALFRAME;
     uint exStyle = Win32.WS_EX_LEFT | Win32.WS_EX_LTRREADING | Win32.WS_EX_RIGHTSCROLLBAR | Win32.WS_EX_DLGMODALFRAME |
                     Win32.WS_EX_WINDOWEDGE | Win32.WS_EX_CONTROLPARENT;
     _handle = Win32.CreateWindowEx(exStyle, "#32770", "UI Automation Test", style, 100, 100, 400, 300, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
     _oldWndProc = Win32.GetWindowLongPtr(_handle, (int)Win32.GWL_WNDPROC);
     _newWndProc = new Win32.WNDPROC(SubclassedWndProc);
     Win32.SetWindowLongPtr(_handle, (int)Win32.GWL_WNDPROC, System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(_newWndProc));
 }
Beispiel #3
0
        /*
         * public void ConnectWndProcs(IntPtr wndProc32, uint wndProc16)
         * {
         *  _wndProc16Map.Add(wndProc16, wndProc32);
         *  _wndProc32Map.Add(wndProc32, wndProc16);
         * }
         *
         * public IntPtr ConnectWndProcs(Win32.WNDPROC wndProc32, uint wndProc16)
         * {
         *  IntPtr ptr = Marshal.GetFunctionPointerForDelegate(wndProc32);
         *  _wndProc16Map.Add(wndProc16, ptr);
         *  _wndProc16MapManaged.Add(wndProc16, wndProc32);
         *  _wndProc32Map.Add(ptr, wndProc16);
         *  return ptr;
         * }
         *
         */

        // Wrap a 16-bit virtual window procedure in a managed delegate that
        // when invoked will call the virtual proc.
        public IntPtr GetWndProc32(uint lpfnWndProc, bool dlgProc)
        {
            if (lpfnWndProc == 0)
            {
                return(IntPtr.Zero);
            }

            // Check if already wrapped
            IntPtr wndProc32 = WndProcMap.To32(lpfnWndProc);

            if (wndProc32 != IntPtr.Zero)
            {
                return(wndProc32);
            }

            // Nope, create one
            Win32.WNDPROC wndProc32Managed = (hWnd, message, wParam, lParam) =>
            {
                return(CallWndProc16from32(lpfnWndProc, hWnd, message, wParam, lParam, dlgProc));
            };

            // Connect
            return(WndProcMap.Connect(wndProc32Managed, lpfnWndProc));
        }