Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- SmtpNetworkElement.cs
- BamlVersionHeader.cs
- SingleBodyParameterMessageFormatter.cs
- Effect.cs
- XmlCDATASection.cs
- DesignerUtility.cs
- SafeCryptContextHandle.cs
- TextEditorDragDrop.cs
- Application.cs
- ValuePattern.cs
- DuplicateDetector.cs
- EmptyImpersonationContext.cs
- RtType.cs
- SrgsSemanticInterpretationTag.cs
- EntityDataReader.cs
- SizeKeyFrameCollection.cs
- TraceXPathNavigator.cs
- CodeDomDesignerLoader.cs
- Int64Converter.cs
- SpotLight.cs
- XmlSchemaInclude.cs
- AdditionalEntityFunctions.cs
- DesignerEditorPartChrome.cs
- XmlSiteMapProvider.cs
- TextPointer.cs
- TreeNode.cs
- WebServiceResponseDesigner.cs
- BlurBitmapEffect.cs
- TypefaceCollection.cs
- EdmMember.cs
- SmtpClient.cs
- TableSectionStyle.cs
- HandoffBehavior.cs
- CopyAttributesAction.cs
- COSERVERINFO.cs
- MissingFieldException.cs
- NavigationWindow.cs
- PlanCompilerUtil.cs
- EntityContainer.cs
- UnicodeEncoding.cs
- AppDomainShutdownMonitor.cs
- oledbconnectionstring.cs
- ServiceBuildProvider.cs
- EventLogReader.cs
- DesignOnlyAttribute.cs
- ScriptIgnoreAttribute.cs
- MeshGeometry3D.cs
- SrgsElementFactory.cs
- DocumentEventArgs.cs
- NavigationHelper.cs
- SqlDataSourceCommandEventArgs.cs
- SqlFacetAttribute.cs
- _IPv4Address.cs
- ADMembershipProvider.cs
- SmiSettersStream.cs
- PnrpPeerResolverBindingElement.cs
- _ContextAwareResult.cs
- Panel.cs
- XslException.cs
- HttpInputStream.cs
- ICspAsymmetricAlgorithm.cs
- DataGridViewCell.cs
- HtmlButton.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- RadioButtonBaseAdapter.cs
- TextFormatterImp.cs
- RuntimeComponentFilter.cs
- QueryResultOp.cs
- StylusEditingBehavior.cs
- FilterException.cs
- EventLogEntryCollection.cs
- OleDbFactory.cs
- CachedBitmap.cs
- ConstraintManager.cs
- BamlRecordReader.cs
- OperationContractGenerationContext.cs
- BinaryNode.cs
- MatchingStyle.cs
- ProcessModule.cs
- ObjectStorage.cs
- TreeNodeConverter.cs
- TabItemWrapperAutomationPeer.cs
- DesignTimeParseData.cs
- AspNetSynchronizationContext.cs
- MarkupCompilePass1.cs
- wmiprovider.cs
- RuntimeConfig.cs
- ErrorHandlerFaultInfo.cs
- DoubleKeyFrameCollection.cs
- COM2EnumConverter.cs
- CollectionChangedEventManager.cs
- FlatButtonAppearance.cs
- InputMethod.cs
- NamedPipeProcessProtocolHandler.cs
- HttpWebRequestElement.cs
- UICuesEvent.cs
- TextUtf8RawTextWriter.cs
- ProcessingInstructionAction.cs
- QuotedPairReader.cs
- LogicalCallContext.cs