Example #1
0
        protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
        {
            if (msg == 0x4e)
            {
                this.dialogHWnd = System.Windows.Forms.UnsafeNativeMethods.GetParent(new HandleRef(null, hWnd));
                try
                {
                    System.Windows.Forms.UnsafeNativeMethods.OFNOTIFY structure = (System.Windows.Forms.UnsafeNativeMethods.OFNOTIFY)System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(lparam, typeof(System.Windows.Forms.UnsafeNativeMethods.OFNOTIFY));
                    switch (structure.hdr_code)
                    {
                    case -606:
                        if (this.ignoreSecondFileOkNotification)
                        {
                            if (this.okNotificationCount != 0)
                            {
                                break;
                            }
                            this.okNotificationCount = 1;
                        }
                        goto Label_0171;

                    case -604:
                        this.ignoreSecondFileOkNotification = true;
                        this.okNotificationCount            = 0;
                        goto Label_01CF;

                    case -602:
                    {
                        System.Windows.Forms.NativeMethods.OPENFILENAME_I openfilename_i = (System.Windows.Forms.NativeMethods.OPENFILENAME_I)System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(structure.lpOFN, typeof(System.Windows.Forms.NativeMethods.OPENFILENAME_I));
                        int num = (int)System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.dialogHWnd), 0x464, IntPtr.Zero, IntPtr.Zero);
                        if (num > openfilename_i.nMaxFile)
                        {
                            try
                            {
                                int size = num + 0x800;
                                System.Windows.Forms.UnsafeNativeMethods.CharBuffer buffer = System.Windows.Forms.UnsafeNativeMethods.CharBuffer.CreateBuffer(size);
                                IntPtr ptr = buffer.AllocCoTaskMem();
                                Marshal.FreeCoTaskMem(openfilename_i.lpstrFile);
                                openfilename_i.lpstrFile = ptr;
                                openfilename_i.nMaxFile  = size;
                                this.charBuffer          = buffer;
                                Marshal.StructureToPtr(openfilename_i, structure.lpOFN, true);
                                Marshal.StructureToPtr(structure, lparam, true);
                            }
                            catch
                            {
                            }
                        }
                        this.ignoreSecondFileOkNotification = false;
                        goto Label_01CF;
                    }

                    case -601:
                        CommonDialog.MoveToScreenCenter(this.dialogHWnd);
                        goto Label_01CF;

                    default:
                        goto Label_01CF;
                    }
                    this.ignoreSecondFileOkNotification = false;
                    System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(new HandleRef(null, hWnd), 0, new HandleRef(null, System.Windows.Forms.NativeMethods.InvalidIntPtr));
                    return(System.Windows.Forms.NativeMethods.InvalidIntPtr);

Label_0171:
                    if (!this.DoFileOk(structure.lpOFN))
                    {
                        System.Windows.Forms.UnsafeNativeMethods.SetWindowLong(new HandleRef(null, hWnd), 0, new HandleRef(null, System.Windows.Forms.NativeMethods.InvalidIntPtr));
                        return(System.Windows.Forms.NativeMethods.InvalidIntPtr);
                    }
                }
                catch
                {
                    if (this.dialogHWnd != IntPtr.Zero)
                    {
                        System.Windows.Forms.UnsafeNativeMethods.EndDialog(new HandleRef(this, this.dialogHWnd), IntPtr.Zero);
                    }
                    throw;
                }
            }
Label_01CF:
            return(IntPtr.Zero);
        }