Esempio n. 1
0
        public bool ConvertPostableMessageTo16(ref Win32.MSG msg32, out Win16.MSG msg16)
        {
            // Setup basic message
            msg16 = new Win16.MSG()
            {
                message = (ushort)msg32.message,
                hWnd    = HWND.Map.To16(msg32.hWnd),
                time    = msg32.time,
                pt      = msg32.p.Convert(),
            };

            // Get message semantics
            var sem = TryGetMessageSemantics32(msg32.hWnd, msg32.message, out msg16.message);

            // If it should be bypassed, just return false
            if (sem != null && sem.ShouldBypass(_machine, ref msg32))
            {
                return(false);
            }

            // Postable message?
            var postable = sem as MessageSemantics.Postable;

            if (postable != null)
            {
                postable.To16(_machine, ref msg32, ref msg16);
                return(true);
            }

            MessageMap.ThrowMessageError(msg32.hWnd, msg32.message);
            return(false);
        }
Esempio n. 2
0
        // Postable messages are any message that don't contain pointers and can be fully
        // represented by wParam and lParam

        public bool ConvertPostableMessageTo32(ref Win16.MSG msg16, out Win32.MSG msg32)
        {
            // Setup basic message
            msg32 = new Win32.MSG()
            {
                hWnd    = HWND.Map.To32(msg16.hWnd),
                message = (ushort)msg16.message,
                time    = msg16.time,
                p       = msg16.pt.Convert(),
            };

            // Get message semantics
            var sem = TryGetMessageSemantics16(msg32.hWnd, msg16.message, out msg32.message);

            // Postable message?
            var postable = sem as MessageSemantics.Postable;

            if (postable != null)
            {
                postable.To32(_machine, ref msg16, ref msg32);
                return(true);
            }

            MessageMap.ThrowMessageError(msg32.hWnd, msg32.message);
            return(false);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public void Convert32to16(ref Win32.MSG msg32, Action <Win16.MSG> callback)
        {
            if (_machine.IsStoppedInDebugger)
            {
                return;
            }

            ushort message16;
            var    sem = TryGetMessageSemantics32(msg32.hWnd, msg32.message, out message16);

            var msg16 = new Win16.MSG()
            {
                hWnd    = HWND.Map.To16(msg32.hWnd),
                message = message16,
            };


            if (sem != null && sem.ShouldBypass(_machine, ref msg32))
            {
                return;
            }

            var postable = sem as MessageSemantics.Postable;

            if (postable != null)
            {
                // Convert it
                postable.To16(_machine, ref msg32, ref msg16);
                callback(msg16);
                return;
            }

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

            if (callable != null)
            {
                callable.Call16from32(_machine, true, false, ref msg32, ref msg16, () =>
                {
                    callback(msg16);
                    return(0);
                });
                return;
            }

            MessageMap.ThrowMessageError(msg32.hWnd, msg32.message);
            throw new NotImplementedException();
        }
Esempio n. 5
0
        public void Convert16to32(ref Win16.MSG msg16, Action <Win32.MSG> callback)
        {
            if (msg16.message == Win16.WM_WIN3MU_BYPASS16)
            {
                return;
            }

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

            var sem = TryGetMessageSemantics16(msg32.hWnd, msg16.message, out msg32.message);

            var postable = sem as MessageSemantics.Postable;

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

                // Call it
                callback(msg32);
                return;
            }

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

            if (callable != null)
            {
                callable.Call32from16(_machine, false, false, ref msg16, ref msg32, () =>
                {
                    callback(msg32);
                    return(IntPtr.Zero);
                });
                return;
            }

            // Unsupported
            MessageMap.ThrowMessageError(msg32.hWnd, msg16.message);
        }
Esempio n. 6
0
        public IntPtr CallWndProc16from32(uint pfnProc, IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam, bool dlgProc)
        {
            // Package it
            var msg32 = new Win32.MSG()
            {
                hWnd    = hWnd,
                message = message,
                wParam  = wParam,
                lParam  = lParam,
            };

            if (_machine.IsStoppedInDebugger)
            {
                if (dlgProc)
                {
                    return(IntPtr.Zero);
                }
                return(User.DefWindowProc(hWnd, message, wParam, lParam));
            }

            // Call filters
            for (int i = 0; i < _wndProcFilters.Count; i++)
            {
                var f    = _wndProcFilters[i];
                var retv = f.PreWndProc(pfnProc, ref msg32, dlgProc);
                if (retv.HasValue)
                {
                    return(retv.Value);
                }
            }

            // Log messages?
            if (_machine.logMessages)
            {
                Log.WriteLine("Message: [{4}] hWnd: {0} message:{1} wParam:{2} lParam:{3}", (HWND)hWnd, MessageNames.NameOfMessage(message), wParam, lParam, User.GetTickCount());
            }

            ushort message16;
            var    sem = TryGetMessageSemantics32(hWnd, message, out message16);

            var msg16 = new Win16.MSG()
            {
                hWnd    = HWND.Map.To16(hWnd),
                message = message16,
            };


            if (sem != null && sem.ShouldBypass(_machine, ref msg32))
            {
                if (dlgProc)
                {
                    return(IntPtr.Zero);
                }

                // Unsupported message - sneak it through
                var bpm = AllocBypassMessage(message, wParam, lParam);
                var ret = _machine.CallWndProc16(pfnProc, HWND.Map.To16(hWnd), Win16.WM_WIN3MU_BYPASS16, 0, bpm.id);
                return(FreeBypassMessage(bpm));
            }

            var postable = sem as MessageSemantics.Postable;

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

                // Call it
                var x = _machine.CallWndProc16(pfnProc, msg16.hWnd, msg16.message, msg16.wParam, msg16.lParam);

                if (dlgProc)
                {
                    x = x.Loword();
                }

                return(BitUtils.DWordToIntPtr(x));
            }

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

            if (callable != null)
            {
                var x = callable.Call16from32(_machine, false, dlgProc, ref msg32, ref msg16, () =>
                {
                    return(_machine.CallWndProc16(pfnProc, msg16.hWnd, msg16.message, msg16.wParam, msg16.lParam));
                });
                if (dlgProc)
                {
                    x = (IntPtr)(x.ToInt32().Loword());

                    // If not handled by dialog proc and ctlcolor message, switch to white
                    if (x == IntPtr.Zero)
                    {
                        bool recolor = false;
                        switch (message)
                        {
                        case Win32.WM_CTLCOLORDLG:
                        case Win32.WM_CTLCOLORSTATIC:
                        case Win32.WM_CTLCOLORBTN:
                            recolor = true;
                            break;
                        }

                        if (recolor)
                        {
                            Gdi.SetTextColor(wParam, User._GetSysColor(Win32.COLOR_WINDOWTEXT));
                            x = User.GetSysColorBrush(Win32.COLOR_WINDOW);
                        }
                    }
                }
                return(x);
            }

            MessageMap.ThrowMessageError(hWnd, message);
            throw new NotImplementedException();
        }