Total Commander裡Help菜單在菜單欄右對齊的效果是什麼原理,用C#怎麼做?
如圖:
謝謝 游民一族 的指點,終於找到方法了。
[StructLayout(LayoutKind.Sequential)]
public class MenuItemInfo
{
public Int32 cbSize;
public Int32 fMask;
public Int32 fType;
public Int32 fState;
public Int32 wID;
public IntPtr hSubMenu;
public IntPtr hbmpChecked;
public IntPtr hbmpUnchecked;
public IntPtr dwItemData;
public string dwTypeData;
public Int32 cch;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetMenuItemInfo(
HandleRef menuHandle,
Int32 itemIndex,
bool byPosition,
[In, Out]MenuItemInfo menuItemInfo);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetMenuItemInfo(
HandleRef menuHandle,
Int32 itemIndex,
bool byPosition,
MenuItemInfo menuItemInfo);
const Int32 MIIM_FTYPE = 0x00000100;
const Int32 MFT_RIGHTJUSTIFY = 0x00004000;
public static void RightJustifyMenuItem(MenuItem menuItem)
{
HandleRef menuHandle = new HandleRef(menuItem.Parent, menuItem.Parent.Handle);
MenuItemInfo menuItemInfo = new MenuItemInfo();
menuItemInfo.cbSize = Marshal.SizeOf(typeof(MenuItemInfo));
menuItemInfo.fMask = MIIM_FTYPE;
GetMenuItemInfo(menuHandle, menuItem.Index, true, menuItemInfo);