当前位置: 首页>>代码示例>>C#>>正文


C# IntPtr.Where方法代码示例

本文整理汇总了C#中System.IntPtr.Where方法的典型用法代码示例。如果您正苦于以下问题:C# IntPtr.Where方法的具体用法?C# IntPtr.Where怎么用?C# IntPtr.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IntPtr的用法示例。


在下文中一共展示了IntPtr.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleDialogBoxes

        /// <summary>
        ///     This is the thread method.
        /// </summary>
        private void HandleDialogBoxes()
        {
            // No synchronization numberOfDialogsToWaitFor since it is readonly
            var hwnds = new IntPtr[_numberOfDialogsToWaitFor];
            var dialogBoxCloseResults = new bool[_numberOfDialogsToWaitFor];

            try
            {
                // Signal that we started
                lock (Mutex)
                {
                    _threadStarted.Set();
                }

                // The loop will be exited either if a message is send by the caller thread or if we found the dialog. If a message box text is specified the loop will not exit until the dialog is found.
                bool stayInLoop = true;
                int dialogBoxesToWaitFor = 1;

                while (stayInLoop)
                {
                    int hwndIndex = dialogBoxesToWaitFor - 1;

                    // We need to lock since the caller might set context to null.
                    lock (Mutex)
                    {
                        if (_exitThread)
                        {
                            break;
                        }

                        // We protect the shell too from reentrency.
                        _uiShell.GetDialogOwnerHwnd(out hwnds[hwndIndex]);
                    }

                    if (hwnds[hwndIndex] != IntPtr.Zero)
                    {
                        var windowClassName = new StringBuilder(256);
                        NativeMethods.GetClassName(hwnds[hwndIndex], windowClassName, windowClassName.Capacity);

                        // The #32770 is the class name of a messagebox dialog.
                        if (!windowClassName.ToString().Contains("#32770")) continue;
                        var unmanagedMemoryLocation = IntPtr.Zero;
                        string dialogBoxText;
                        try
                        {
                            unmanagedMemoryLocation = Marshal.AllocHGlobal(10*1024);
                            NativeMethods.EnumChildWindows(hwnds[hwndIndex], FindMessageBoxString,
                                unmanagedMemoryLocation);
                            dialogBoxText = Marshal.PtrToStringUni(unmanagedMemoryLocation);
                        }
                        finally
                        {
                            if (unmanagedMemoryLocation != IntPtr.Zero)
                            {
                                Marshal.FreeHGlobal(unmanagedMemoryLocation);
                            }
                        }

                        lock (Mutex)
                        {
                            // Since this is running on the main thread be sure that we close the dialog.
                            bool dialogCloseResult = false;
                            if (_buttonAction != 0)
                            {
                                dialogCloseResult = NativeMethods.EndDialog(hwnds[hwndIndex], _buttonAction);
                            }

                            // Check if we have found the right dialog box.
                            if (String.IsNullOrEmpty(_expectedDialogBoxText) ||
                                (!String.IsNullOrEmpty(dialogBoxText) &&
                                 String.Compare(_expectedDialogBoxText, dialogBoxText.Trim(),
                                     StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                dialogBoxCloseResults[hwndIndex] = dialogCloseResult;
                                if (dialogBoxesToWaitFor++ >= _numberOfDialogsToWaitFor)
                                {
                                    stayInLoop = false;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                //Let the main thread run a possible close command.
                Thread.Sleep(2000);

                foreach (var hwnd in hwnds.Where(hwnd => hwnd != IntPtr.Zero))
                {
                    NativeMethods.SendMessage(hwnd, NativeMethods.WM_CLOSE, 0, new IntPtr(0));
                }

                lock (Mutex)
                {
                    // Be optimistic.
                    _dialogBoxCloseResult = dialogBoxCloseResults.All(t => t);
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:tfsautoshelve,代码行数:101,代码来源:DialogboxPurger.cs


注:本文中的System.IntPtr.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。