Пример #1
0
        /// <summary>Returns a DialogResult indicating the user action.</summary>
        /// <param name="owner">The System.Windows.Forms.IWin32Window the dialog will display in front of.</param>
        /// <remarks>Sets the name, password and SaveChecked accessors to the state of the dialog as it was dismissed by the user.</remarks>
        private DialogResult ShowDialog(IWin32Window owner)
        {
            // set the api call parameters
            StringBuilder name = new StringBuilder(CREDUI.MAX_USERNAME_LENGTH);

            name.Append(Name);

            StringBuilder password = new StringBuilder(CREDUI.MAX_PASSWORD_LENGTH);

            password.Append(Password);

            int saveChecked = Convert.ToInt32(SaveChecked);

            CREDUI.INFO  info  = GetInfo(owner);
            CREDUI.FLAGS flags = GetFlags();

            // make the api call
            CREDUI.ReturnCodes code = CREDUI.PromptForCredentials(ref info, Target, IntPtr.Zero, 0, name, CREDUI.MAX_USERNAME_LENGTH, password, CREDUI.MAX_PASSWORD_LENGTH, ref saveChecked, flags);

            // clean up resources
            if (Banner != null)
            {
                Win32.DeleteObject(info.hbmBanner);
            }

            // set the accessors from the api call parameters
            Name        = name.ToString();
            Password    = password.ToString();
            SaveChecked = Convert.ToBoolean(saveChecked);
            return(GetDialogResult(code));
        }
Пример #2
0
 /// <summary>Returns the info structure for dialog display settings.</summary>
 /// <param name="owner">The System.Windows.Forms.IWin32Window the dialog will display in front of.</param>
 private CREDUI.INFO GetInfo(IWin32Window owner)
 {
     CREDUI.INFO info = new CREDUI.INFO();
     if (owner != null)
     {
         info.hwndParent = owner.Handle;
     }
     info.pszCaptionText = Caption;
     info.pszMessageText = Message;
     if (Banner != null)
     {
         info.hbmBanner = new Bitmap(Banner, ValidBannerWidth, ValidBannerHeight).GetHbitmap();
     }
     info.cbSize = Marshal.SizeOf(info);
     return(info);
 }