private static Int32 WH_CALLWNDPROCRET_PROC(Int32 iCode, IntPtr pWParam, IntPtr pLParam)
        {
            if (iCode < 0)
            {
                return(CallNextHookEx(ClosedPopupMsg._pWH_CALLWNDPROCRET, iCode, pWParam, pLParam));
            }

            CWPRETSTRUCT cwp = (CWPRETSTRUCT)Marshal.PtrToStructure(pLParam, typeof(CWPRETSTRUCT));

            if (cwp.message == WM_INITDIALOG)
            {
                Int32 iLength = GetWindowTextLength(cwp.hwnd);

                foreach (IntPtr pChildOfDialog in ClosedPopupMsg.listChildWindows(cwp.hwnd))
                {
                    iLength = GetWindowTextLength(pChildOfDialog);
                    if (iLength > 0)
                    {
                        Int32 ctrlId = GetDlgCtrlID(pChildOfDialog);
                        SendMessage(cwp.hwnd, WM_COMMAND, new IntPtr(ctrlId), pChildOfDialog);
                    }
                }
            }

            return(CallNextHookEx(ClosedPopupMsg._pWH_CALLWNDPROCRET, iCode, pWParam, pLParam));
        }
Beispiel #2
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     ClosedPopupMsg.Hook();
     Application.Run(new Form1());
     ClosedPopupMsg.Unhook();
 }
        private static List <IntPtr> listChildWindows(IntPtr p)
        {
            List <IntPtr> lstChildWindows = new List <IntPtr>();
            GCHandle      gchChildWindows = GCHandle.Alloc(lstChildWindows);

            try
            {
                ClosedPopupMsg.EnumChildWindows(p, new EnumerateWindowDelegate(ClosedPopupMsg.enumWindowsCallback), GCHandle.ToIntPtr(gchChildWindows));
            }
            finally
            {
                if (gchChildWindows.IsAllocated)
                {
                    gchChildWindows.Free();
                }
            }

            return(lstChildWindows);
        }