Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / WinForms / Managed / System / WinForms / StringSource.cs / 1 / StringSource.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices; using System.Collections; using System.Diagnostics.CodeAnalysis; ////// /// internal class StringSource : IEnumString { private string[] strings; private int current; private int size; private UnsafeNativeMethods.IAutoComplete2 autoCompleteObject2; ////// Represents an internal class that is used bu ComboBox and TextBox AutoCompleteCustomSoucr property. /// This class is reponsible for initializing the SHAutoComplete COM object and setting options in it. /// The StringSource contains an array of Strings which is passed to the COM object as the custom source. /// ////// /// private static Guid autoCompleteClsid = new Guid("{00BB2763-6A77-11D0-A535-00C04FD7D062}"); ////// SHAutoComplete COM object CLSID. /// ////// /// public StringSource(string[] strings) { Array.Clear(strings,0, size); if (strings != null) { this.strings = strings; } current = 0; size = (strings == null ) ? 0 : strings.Length; Guid iid_iunknown = typeof(UnsafeNativeMethods.IAutoComplete2).GUID; object obj = UnsafeNativeMethods.CoCreateInstance(ref autoCompleteClsid, null, NativeMethods.CLSCTX_INPROC_SERVER, ref iid_iunknown); autoCompleteObject2 = (UnsafeNativeMethods.IAutoComplete2)obj; } ////// Constructor. /// ////// /// public bool Bind(HandleRef edit, int options) { bool retVal = false; if (autoCompleteObject2 != null) { try { autoCompleteObject2.SetOptions(options); autoCompleteObject2.Init(edit, (IEnumString)this, null, null); retVal = true; } catch { retVal = false; } } return retVal; } [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] public void ReleaseAutoComplete() { if (autoCompleteObject2 != null) { Marshal.ReleaseComObject(autoCompleteObject2); autoCompleteObject2 = null; } } public void RefreshList(string[] newSource) { Array.Clear(strings,0, size); if (strings != null) { this.strings = newSource; } current = 0; size = (strings == null ) ? 0 : strings.Length; } #region IEnumString Members void IEnumString.Clone(out IEnumString ppenum) { ppenum = new StringSource(strings); } int IEnumString.Next(int celt, string[] rgelt, IntPtr pceltFetched) { if (celt < 0) { return NativeMethods.E_INVALIDARG; } int fetched = 0; while (current < size && celt > 0) { rgelt[fetched] = strings[current]; current++; fetched++; celt--; } if (pceltFetched != IntPtr.Zero) { Marshal.WriteInt32(pceltFetched, fetched); } return celt == 0 ? NativeMethods.S_OK : NativeMethods.S_FALSE; } void IEnumString.Reset() { current = 0; } int IEnumString.Skip(int celt) { current += celt; if (current >= size) { return (NativeMethods.S_FALSE); } return NativeMethods.S_OK; } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ ///// This is the method that binds the custom source with the IAutoComplete interface.The "hWndEdit" is the handle /// to the edit Control and the "options' are the options that need to be set in the AUTOCOMPLETE mode. /// ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices; using System.Collections; using System.Diagnostics.CodeAnalysis; ////// /// internal class StringSource : IEnumString { private string[] strings; private int current; private int size; private UnsafeNativeMethods.IAutoComplete2 autoCompleteObject2; ////// Represents an internal class that is used bu ComboBox and TextBox AutoCompleteCustomSoucr property. /// This class is reponsible for initializing the SHAutoComplete COM object and setting options in it. /// The StringSource contains an array of Strings which is passed to the COM object as the custom source. /// ////// /// private static Guid autoCompleteClsid = new Guid("{00BB2763-6A77-11D0-A535-00C04FD7D062}"); ////// SHAutoComplete COM object CLSID. /// ////// /// public StringSource(string[] strings) { Array.Clear(strings,0, size); if (strings != null) { this.strings = strings; } current = 0; size = (strings == null ) ? 0 : strings.Length; Guid iid_iunknown = typeof(UnsafeNativeMethods.IAutoComplete2).GUID; object obj = UnsafeNativeMethods.CoCreateInstance(ref autoCompleteClsid, null, NativeMethods.CLSCTX_INPROC_SERVER, ref iid_iunknown); autoCompleteObject2 = (UnsafeNativeMethods.IAutoComplete2)obj; } ////// Constructor. /// ////// /// public bool Bind(HandleRef edit, int options) { bool retVal = false; if (autoCompleteObject2 != null) { try { autoCompleteObject2.SetOptions(options); autoCompleteObject2.Init(edit, (IEnumString)this, null, null); retVal = true; } catch { retVal = false; } } return retVal; } [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")] public void ReleaseAutoComplete() { if (autoCompleteObject2 != null) { Marshal.ReleaseComObject(autoCompleteObject2); autoCompleteObject2 = null; } } public void RefreshList(string[] newSource) { Array.Clear(strings,0, size); if (strings != null) { this.strings = newSource; } current = 0; size = (strings == null ) ? 0 : strings.Length; } #region IEnumString Members void IEnumString.Clone(out IEnumString ppenum) { ppenum = new StringSource(strings); } int IEnumString.Next(int celt, string[] rgelt, IntPtr pceltFetched) { if (celt < 0) { return NativeMethods.E_INVALIDARG; } int fetched = 0; while (current < size && celt > 0) { rgelt[fetched] = strings[current]; current++; fetched++; celt--; } if (pceltFetched != IntPtr.Zero) { Marshal.WriteInt32(pceltFetched, fetched); } return celt == 0 ? NativeMethods.S_OK : NativeMethods.S_FALSE; } void IEnumString.Reset() { current = 0; } int IEnumString.Skip(int celt) { current += celt; if (current >= size) { return (NativeMethods.S_FALSE); } return NativeMethods.S_OK; } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007./// This is the method that binds the custom source with the IAutoComplete interface.The "hWndEdit" is the handle /// to the edit Control and the "options' are the options that need to be set in the AUTOCOMPLETE mode. /// ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeConstant.cs
- AppDomainManager.cs
- Int16Storage.cs
- _HTTPDateParse.cs
- ApplicationActivator.cs
- SqlNodeAnnotation.cs
- DataStreams.cs
- ObjectSet.cs
- IdentityNotMappedException.cs
- OperationAbortedException.cs
- XPathParser.cs
- SoapObjectWriter.cs
- HatchBrush.cs
- ControlCollection.cs
- X509Logo.cs
- StrongNameKeyPair.cs
- ErasingStroke.cs
- EntityDataSourceWrapperCollection.cs
- ProfileModule.cs
- NavigationPropertyEmitter.cs
- ContextMenuService.cs
- SystemIPGlobalProperties.cs
- ExpressionPrinter.cs
- HttpRequest.cs
- SerializationEventsCache.cs
- FileSystemWatcher.cs
- BinaryNode.cs
- FilterableAttribute.cs
- SymmetricKey.cs
- OutputCacheSection.cs
- ActivityDesignerResources.cs
- XmlLoader.cs
- HtmlHistory.cs
- _CommandStream.cs
- CompareInfo.cs
- SqlCommand.cs
- HttpEncoder.cs
- HttpListenerRequestUriBuilder.cs
- ConnectionManagementSection.cs
- GridViewDeleteEventArgs.cs
- InstanceContext.cs
- XmlObjectSerializerWriteContextComplex.cs
- UidManager.cs
- MatrixValueSerializer.cs
- SafeFileMappingHandle.cs
- DateTimeFormatInfo.cs
- UnsafeNetInfoNativeMethods.cs
- LinearQuaternionKeyFrame.cs
- SafeNativeMethods.cs
- LoginCancelEventArgs.cs
- CheckBox.cs
- EventLogEntryCollection.cs
- EntityDataSource.cs
- Form.cs
- PackWebRequest.cs
- CalendarDataBindingHandler.cs
- SortExpressionBuilder.cs
- StyleCollectionEditor.cs
- ConstraintCollection.cs
- TypeLibConverter.cs
- ElementHostAutomationPeer.cs
- Imaging.cs
- DispatchWrapper.cs
- AggregateNode.cs
- Matrix3DConverter.cs
- TreeIterator.cs
- QueryComponents.cs
- BitmapEffectrendercontext.cs
- HTTPNotFoundHandler.cs
- SafeNativeMethods.cs
- SchemaLookupTable.cs
- Debugger.cs
- CapabilitiesPattern.cs
- OdbcStatementHandle.cs
- InternalConfigEventArgs.cs
- FloatSumAggregationOperator.cs
- ApplicationSecurityInfo.cs
- AssertUtility.cs
- PromptBuilder.cs
- GridViewItemAutomationPeer.cs
- FieldMetadata.cs
- BamlLocalizabilityResolver.cs
- TableLayoutRowStyleCollection.cs
- PipeStream.cs
- ColumnCollection.cs
- MenuItemCollection.cs
- TextEditor.cs
- XmlJsonReader.cs
- SmtpFailedRecipientsException.cs
- wgx_exports.cs
- securitycriticaldataformultiplegetandset.cs
- PointUtil.cs
- HorizontalAlignConverter.cs
- Int64AnimationUsingKeyFrames.cs
- HttpFileCollection.cs
- XmlWrappingReader.cs
- ChtmlImageAdapter.cs
- UnmanagedMemoryStream.cs
- MasterPageBuildProvider.cs
- AttachedPropertyBrowsableAttribute.cs