Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions src/System.Windows.Forms.Primitives/src/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ SetViewportOrgEx
SetWindowExtEx
SetWindowOrgEx
SetWindowsHookEx
SHAutoComplete
SHCreateItemFromParsingName
SHBrowseForFolder
SHCreateShellItem
Expand All @@ -234,6 +235,7 @@ SHGetPathFromIDList
SHGetSpecialFolderLocation
ShowCursor
SHGetSpecialFolderLocation
SHLoadIndirectString
SHParseDisplayName
SIATTRIBFLAGS
SIGDN
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Windows.Win32
{
internal static partial class PInvoke
{
public static HRESULT SHAutoComplete<T>(in T hwndEdit, SHELL_AUTOCOMPLETE_FLAGS flags) where T : IHandle<HWND>
{
HRESULT result = SHAutoComplete(hwndEdit.Handle, flags);
GC.KeepAlive(hwndEdit.Wrapper);
return result;
}
}
}
20 changes: 10 additions & 10 deletions src/System.Windows.Forms/src/System/Windows/Forms/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,7 @@ private void SetAutoComplete(bool reset, bool recreate)
{
if (AutoCompleteCustomSource.Count == 0)
{
Shlwapi.SHAutoComplete(new HandleRef(this, _childEdit.Handle), Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF);
PInvoke.SHAutoComplete(new HandleRef<HWND>(this, _childEdit.HWND), SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF);
}
else
{
Expand All @@ -3342,7 +3342,7 @@ private void SetAutoComplete(bool reset, bool recreate)
{
if (_itemsCollection.Count == 0)
{
Shlwapi.SHAutoComplete(new HandleRef(this, _childEdit.Handle), Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF);
PInvoke.SHAutoComplete(new HandleRef<HWND>(this, _childEdit.HWND), SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF);
}
else
{
Expand All @@ -3365,34 +3365,34 @@ private void SetAutoComplete(bool reset, bool recreate)
{
// Drop Down List special handling
Debug.Assert(DropDownStyle == ComboBoxStyle.DropDownList);
Shlwapi.SHAutoComplete(new HandleRef(this, _childEdit.Handle), Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF);
PInvoke.SHAutoComplete(new HandleRef<HWND>(this, _childEdit.HWND), SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF);
}
}
else
{
Shlwapi.SHACF mode = Shlwapi.SHACF.DEFAULT;
SHELL_AUTOCOMPLETE_FLAGS mode = SHELL_AUTOCOMPLETE_FLAGS.SHACF_DEFAULT;
if (AutoCompleteMode == AutoCompleteMode.Suggest)
{
mode |= Shlwapi.SHACF.AUTOSUGGEST_FORCE_ON | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_ON | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF;
}

if (AutoCompleteMode == AutoCompleteMode.Append)
{
mode |= Shlwapi.SHACF.AUTOAPPEND_FORCE_ON | Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_ON | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF;
}

if (AutoCompleteMode == AutoCompleteMode.SuggestAppend)
{
mode |= Shlwapi.SHACF.AUTOSUGGEST_FORCE_ON;
mode |= Shlwapi.SHACF.AUTOAPPEND_FORCE_ON;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_ON;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_ON;
}

Shlwapi.SHAutoComplete(new HandleRef(this, _childEdit.Handle), (Shlwapi.SHACF)AutoCompleteSource | mode);
PInvoke.SHAutoComplete(new HandleRef<HWND>(this, _childEdit.HWND), (SHELL_AUTOCOMPLETE_FLAGS)AutoCompleteSource | mode);
}
}
else if (reset)
{
Shlwapi.SHAutoComplete(new HandleRef(this, _childEdit.Handle), Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF);
PInvoke.SHAutoComplete(new HandleRef<HWND>(this, _childEdit.HWND), SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using Microsoft.Win32;
using Windows.Win32.UI.TextServices;
using static Interop;
Expand Down Expand Up @@ -283,11 +282,18 @@ Look in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\000
{
if (layoutDisplayName is not null)
{
var sb = new StringBuilder(512);
HRESULT res = Shlwapi.SHLoadIndirectString(layoutDisplayName, sb, (uint)sb.Capacity, IntPtr.Zero);
if (res == HRESULT.S_OK)
unsafe
{
return sb.ToString();
var ppvReserved = (void*)IntPtr.Zero;
Span<char> buffer = stackalloc char[512];
fixed (char* pBuffer = buffer)
{
HRESULT res = PInvoke.SHLoadIndirectString(layoutDisplayName, pBuffer, (uint)buffer.Length, ref ppvReserved);
if (res == HRESULT.S_OK)
{
return buffer.SliceAtFirstNull().ToString();
}
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/System.Windows.Forms/src/System/Windows/Forms/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,24 +796,24 @@ private void SetAutoComplete(bool reset)
{
if (IsHandleCreated)
{
Shlwapi.SHACF mode = Shlwapi.SHACF.DEFAULT;
SHELL_AUTOCOMPLETE_FLAGS mode = SHELL_AUTOCOMPLETE_FLAGS.SHACF_DEFAULT;
if (AutoCompleteMode == AutoCompleteMode.Suggest)
{
mode |= Shlwapi.SHACF.AUTOSUGGEST_FORCE_ON | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_ON | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF;
}

if (AutoCompleteMode == AutoCompleteMode.Append)
{
mode |= Shlwapi.SHACF.AUTOAPPEND_FORCE_ON | Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_ON | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF;
}

if (AutoCompleteMode == AutoCompleteMode.SuggestAppend)
{
mode |= Shlwapi.SHACF.AUTOSUGGEST_FORCE_ON;
mode |= Shlwapi.SHACF.AUTOAPPEND_FORCE_ON;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_ON;
mode |= SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_ON;
}

Shlwapi.SHAutoComplete(this, (Shlwapi.SHACF)AutoCompleteSource | mode);
PInvoke.SHAutoComplete(this, (SHELL_AUTOCOMPLETE_FLAGS)AutoCompleteSource | mode);
}
}
}
Expand All @@ -830,7 +830,7 @@ private void ResetAutoComplete(bool force)
{
if ((AutoCompleteMode != AutoCompleteMode.None || force) && IsHandleCreated)
{
Shlwapi.SHAutoComplete(this, (Shlwapi.SHACF)AutoCompleteSource.AllSystemSources | Shlwapi.SHACF.AUTOSUGGEST_FORCE_OFF | Shlwapi.SHACF.AUTOAPPEND_FORCE_OFF);
PInvoke.SHAutoComplete(this, (SHELL_AUTOCOMPLETE_FLAGS)AutoCompleteSource.AllSystemSources | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOSUGGEST_FORCE_OFF | SHELL_AUTOCOMPLETE_FLAGS.SHACF_AUTOAPPEND_FORCE_OFF);
}
}

Expand Down