光大项目的三期已经启动了,我已经没有多少时间写DeviceAnywhere了,昨天晚上努力了一把Desktop端基本上写的差不多了。在写帮助菜单的时候还是按着惯例想加入一个“联系作者”菜单,其中就两个功能点,其一就是点击“博客”按钮打开http://blog.youkuaiyun.com/wellwelcome,其二则是点击“E-mail”按钮调用系统默认的邮件程序发送邮件给wuzhongxin@263.net。在写delphi的时候这两个功能非常简单,只要用ShellExecute这个Api函数就可以了,delphi对shell32.dll进行了封装就是ShellApi单元,而.net大家都知道的用api函数必须自己invoke,还好有delphi的功底,下面把我的方法写出来,姑且作为备忘吧,哈哈!
以下为函数的声明和函数参数的声明:
[DllImport("shell32.dll")]
public extern static IntPtr ShellExecute(IntPtr hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
int nShowCmd
);
public enum ShowWindowCommands : int
{
SW_HIDE = 0,
SW_SHOWNORMAL = 1,
SW_NORMAL = 1,
SW_SHOWMINIMIZED = 2,
SW_SHOWMAXIMIZED = 3,
SW_MAXIMIZE = 3,
SW_SHOWNOACTIVATE = 4,
SW_SHOW = 5,
SW_MINIMIZE = 6,
SW_SHOWMINNOACTIVE = 7,
SW_SHOWNA = 8,
SW_RESTORE = 9,
SW_SHOWDEFAULT = 10,
SW_MAX = 10
}
一下则是为实现我上述两个功能的函数调用:
1、访问http://blog.youkuaiyun.com/wellwelcome
ShellExecute(this.Handle, "open", "http://blog.youkuaiyun.com/wellwelcome", null, null, (int)ShowWindowCommands.SW_SHOW);
2、email wuzhongxin@263.net
ShellExecute(this.Handle, "open", "mailto:wuzhongxin@263.net", null, null, (int)ShowWindowCommands.SW_SHOW);