Hello,
When I customized the following string resource in order to change context menu captions of window, it seems to be applied to window button's tooltip(Close,Minimize,Maximize).
- UICommandMinimizeWindowText
- UICommandMaximizeWindowText
- UICommandRestoreWindowText
- UICommandMoveWindowText
- UICommandSizeWindowText
I'd like to set separated caption to context menu and window button's tooltip.
It is because our customer want to use access key to operate context menu. (But it is not good that window button's tooltip has `_` text...)
Is there any solution?
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private static class NativeMethods
{
[DllImport("user32.dll")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
internal static extern IntPtr GetMenuStringA(IntPtr hMenu, uint uIdEnableItem, [MarshalAs(UnmanagedType.LPStr)] StringBuilder parm3, uint chmax, uint flag);
}
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
SetContextMenuText();
}
private void SetContextMenuText()
{
var windowHandle = new WindowInteropHelper(this).Handle;
var hMenu = NativeMethods.GetSystemMenu(windowHandle, false);
var srNameList = new Dictionary<int, string>
{
{0, ActiproSoftware.Products.Shared.SRName.UICommandRestoreWindowText.ToString() },
{1, ActiproSoftware.Products.Shared.SRName.UICommandMoveWindowText.ToString() },
{2, ActiproSoftware.Products.Shared.SRName.UICommandSizeWindowText.ToString() },
{3, ActiproSoftware.Products.Shared.SRName.UICommandMinimizeWindowText.ToString()},
{4, ActiproSoftware.Products.Shared.SRName.UICommandMaximizeWindowText.ToString()},
{6, ActiproSoftware.Products.Shared.SRName.UICommandCloseWindowText.ToString() },
};
foreach (var item in srNameList)
{
var menuString = new StringBuilder(250);
_ = NativeMethods.GetMenuStringA(hMenu, (uint)item.Key, menuString, 250, 0x00000400);
ActiproSoftware.Products.Shared.SR.SetCustomString(
item.Value,
menuString.ToString().Replace("&", "_").Replace("Alt+F4", string.Empty));
}
}
}