项目中需要取得当前用户的我的文档文件夹的路径。
因为我的文档文件夹和临时文件夹不一样,临时文件夹是系统级的,类库中有现成的方法可以获得;
我的文档是用户级的,文件夹位置也可变,只能在注册表中获得它的具体位置,写了一个小方法实现其功能,如下:
又因为使用helpprovider控件和Help.Showhelp()方法打开的帮助文件总是遮挡在窗口前面,被迫无奈只能调用系统API了。
以下内容为网友【平民百姓】提供。
HtmlHelp 有多个重载方法。
因为我的文档文件夹和临时文件夹不一样,临时文件夹是系统级的,类库中有现成的方法可以获得;
我的文档是用户级的,文件夹位置也可变,只能在注册表中获得它的具体位置,写了一个小方法实现其功能,如下:
/// <summary>
/// 取得系统当前用户的我的文档路径
/// 路径样式 C:Documents and SettingsAdministratorMy Documents
/// </summary>
/// <returns></returns>
public static string GetMyDocument()
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders");
return key.GetValue("Personal").ToString();
}
/// 取得系统当前用户的我的文档路径
/// 路径样式 C:Documents and SettingsAdministratorMy Documents
/// </summary>
/// <returns></returns>
public static string GetMyDocument()
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders");
return key.GetValue("Personal").ToString();
}
又因为使用helpprovider控件和Help.Showhelp()方法打开的帮助文件总是遮挡在窗口前面,被迫无奈只能调用系统API了。
以下内容为网友【平民百姓】提供。
HtmlHelp 有多个重载方法。
using
System;
using System.Runtime.InteropServices;
namespace help
{
/// <summary>
/// windows 调用帮助文件的API包装。
/// </summary>
public class WrapperHelp
{
/// <summary>
/// 获得代表整个屏幕的一个窗口(桌面窗口)句柄 (windows API)
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
/// <summary>
/// 打开帮助文件的方法 (windows API)
/// </summary>
/// <param name="hwndCaller"></param>
/// <param name="pszFile"></param>
/// <param name="uCommand"></param>
/// <param name="dwData"></param>
/// <returns></returns>
[DllImport("hhctrl.ocx", CharSet = CharSet.Auto)]
public static extern int HtmlHelp(IntPtr hwndCaller, [MarshalAs(UnmanagedType.LPTStr)] string pszFile, int uCommand, int dwData);
}
}
// 最好在HelpRequested事件中调用帮助
private void textBox1_HelpRequested( object sender, System.Windows.Forms.HelpEventArgs hlpevent)
{
WrapperHelp.HtmlHelp(WrapperHelp.GetDesktopWindow(), @"mmc.chm", 0, 0);
}
using System.Runtime.InteropServices;
namespace help
{
/// <summary>
/// windows 调用帮助文件的API包装。
/// </summary>
public class WrapperHelp
{
/// <summary>
/// 获得代表整个屏幕的一个窗口(桌面窗口)句柄 (windows API)
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetDesktopWindow();
/// <summary>
/// 打开帮助文件的方法 (windows API)
/// </summary>
/// <param name="hwndCaller"></param>
/// <param name="pszFile"></param>
/// <param name="uCommand"></param>
/// <param name="dwData"></param>
/// <returns></returns>
[DllImport("hhctrl.ocx", CharSet = CharSet.Auto)]
public static extern int HtmlHelp(IntPtr hwndCaller, [MarshalAs(UnmanagedType.LPTStr)] string pszFile, int uCommand, int dwData);
}
}
// 最好在HelpRequested事件中调用帮助
private void textBox1_HelpRequested( object sender, System.Windows.Forms.HelpEventArgs hlpevent)
{
WrapperHelp.HtmlHelp(WrapperHelp.GetDesktopWindow(), @"mmc.chm", 0, 0);
}