Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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;
///
///
///
/// 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.
///
///
internal class StringSource : IEnumString {
private string[] strings;
private int current;
private int size;
private UnsafeNativeMethods.IAutoComplete2 autoCompleteObject2;
///
///
///
/// SHAutoComplete COM object CLSID.
///
///
private static Guid autoCompleteClsid = new Guid("{00BB2763-6A77-11D0-A535-00C04FD7D062}");
///
///
///
/// Constructor.
///
///
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;
}
///
///
///
/// 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.
///
///
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.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ElementInit.cs
- _FtpDataStream.cs
- HttpDebugHandler.cs
- QilReplaceVisitor.cs
- LogStore.cs
- MouseGestureConverter.cs
- AudioDeviceOut.cs
- ServiceOperation.cs
- DropDownHolder.cs
- Fault.cs
- ProfilePropertySettingsCollection.cs
- RemotingHelper.cs
- ITextView.cs
- RuntimeResourceSet.cs
- QilTypeChecker.cs
- DoubleAnimationUsingPath.cs
- ResetableIterator.cs
- DataSourceCacheDurationConverter.cs
- EditorZoneBase.cs
- MobileControlsSectionHelper.cs
- CodeFieldReferenceExpression.cs
- ZipIOExtraFieldZip64Element.cs
- ScriptManagerProxy.cs
- ProcessHostMapPath.cs
- errorpatternmatcher.cs
- ActivationArguments.cs
- ASCIIEncoding.cs
- DPTypeDescriptorContext.cs
- ValidationError.cs
- CollectionEditVerbManager.cs
- DesignerDataStoredProcedure.cs
- COM2PictureConverter.cs
- FileDialogCustomPlacesCollection.cs
- GridSplitterAutomationPeer.cs
- NativeMethods.cs
- CollectionViewProxy.cs
- FieldBuilder.cs
- UriExt.cs
- FillErrorEventArgs.cs
- embossbitmapeffect.cs
- EffectiveValueEntry.cs
- InputDevice.cs
- FixedLineResult.cs
- InternalSafeNativeMethods.cs
- RadioButton.cs
- MergeLocalizationDirectives.cs
- RegexCaptureCollection.cs
- ScrollItemPattern.cs
- Pkcs7Recipient.cs
- MasterPage.cs
- XpsFilter.cs
- MenuItemBindingCollection.cs
- FirstMatchCodeGroup.cs
- BindingOperations.cs
- InitiatorSessionSymmetricMessageSecurityProtocol.cs
- OutOfProcStateClientManager.cs
- WebBrowserProgressChangedEventHandler.cs
- SqlClientWrapperSmiStream.cs
- NativeMethods.cs
- StylusPointDescription.cs
- WCFBuildProvider.cs
- SwitchLevelAttribute.cs
- ModelUIElement3D.cs
- ContextMenu.cs
- FormViewDeletedEventArgs.cs
- FillErrorEventArgs.cs
- CssStyleCollection.cs
- InvalidCardException.cs
- WebEvents.cs
- EnvironmentPermission.cs
- ResourceBinder.cs
- MessagePartDescription.cs
- PointCollectionValueSerializer.cs
- Rect3D.cs
- DBSqlParserTable.cs
- ActivityPreviewDesigner.cs
- SQLMoney.cs
- LogReserveAndAppendState.cs
- CustomErrorsSection.cs
- DeviceSpecificChoiceCollection.cs
- DirectoryNotFoundException.cs
- FileDialog_Vista.cs
- XmlArrayItemAttribute.cs
- srgsitem.cs
- AppDomainManager.cs
- ExpressionBuilderContext.cs
- EncryptedHeaderXml.cs
- LocalFileSettingsProvider.cs
- EmptyCollection.cs
- SourceFileBuildProvider.cs
- AnnotationStore.cs
- XPathMultyIterator.cs
- ColorDialog.cs
- UndoManager.cs
- CompilerParameters.cs
- KeyInfo.cs
- TablePattern.cs
- TemplateColumn.cs
- OdbcParameter.cs
- HttpCapabilitiesSectionHandler.cs