Windows Shell 的应用

 不明白为什么 PrintDialog 没有集成 FindPrinter 按钮,那么如何寻找网络中的打印机呢?这个FindPrinter的Dialog 位于 Microsoft Shell Controls And Automation COM 组件中。 我们需要定制这个PrintDialog , 然后给他添加FindPrinter的功能,真是麻烦啊。

(在PrintDialogEx 中是有FindPrinter按钮的,但是我就想在标准框中使用这个FindPrinter)

 

1. 添加这个COM组件至引用。

2.  Code (C#) Shell32;

using

Shell32.Shell shell; private IShellDispatch2 shell2;

 

 

 

 

 

private

 

 

shell = new Shell();

 

 

 

 

 

 

shell2 = shell as IShellDispatch2;

 

 

 

shell2.FindPrinter(null,null,null);

就可以弹出这个FindPrinter的对话框了。

 

其实Shell这个组件可以调出很多其他的系统对话框,而不是Common Dialog.  下文转自Windows Shell 为编程带来了什么?

 

其实,在Windows中,它已经为我们提供了一个可复用的COM类库,Microsoft Shell Controls And Automation。调用它,我们可以轻易地实现以下功能:

1)调用目录浏览对话框。

2)启动停止服务。

3)排序Windows窗口。

4)调用控制面板项目。

5)打开资源管理器。

6)打开URL

7)调用系统运行对话框。

8)打开查找计算机对话框

9)打开查找文件对话框

10)打开查找打印机对话框

 

当然,还有更多的功能,

 

注意:Shell32.dll中的COM引用在Windows XP和Windows Vista上是不通用的,所以你必须为你的程序做不同系统上的打包。

 

希望这些功能对你有用,~好运~~~~@!!

 

 

以下以Visual Basic .NET来作为例子给出相关的代码。

'测试平台:Windows Server 2008 SP1

'开发平台:Visual Studio Team System 2008 SP1 90days Try

'引用:Microsoft Shell Controls And Automation

 

 

Public Class Form1

    Public shl As New Shell32.Shell

    '目录浏览功能
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fl As Shell32.Folder
        fl = shl.BrowseForFolder(Me.Handle, "请选择一个要浏览的目录", Shell32.ShellFolderViewOptions.SFVVO_SHOWEXTENSIONS, Shell32.ShellSpecialFolderConstants.ssfDRIVES)
    End Sub

    '资源管理器
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        shl.Explore("D:/")
    End Sub

    '运行
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        shl.FileRun()
    End Sub

    '查找文件
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        shl.FindFiles()
    End Sub

    '查找计算机
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        shl.FindComputer()
    End Sub

    '查找打印机
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        shl.FindPrinter()
    End Sub

    '获取Hash值
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        MsgBox(shl.GetHashCode)
    End Sub

    '层叠窗口
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        shl.CascadeWindows()
    End Sub

    '水平平铺
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        shl.TileHorizontally()
    End Sub

    '垂直平铺
    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        shl.TileVertically()
    End Sub

    '全部最小化
    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        shl.MinimizeAll()
    End Sub

    '打开控制面板项
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        shl.ControlPanelItem("main.cpl")
    End Sub

    '设置时间
    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        shl.SetTime()
    End Sub

    '关闭计算机
    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        shl.ShutdownWindows()
    End Sub

    '显示桌面
    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        shl.ToggleDesktop()
    End Sub

    'WIndows Vista中的Win+Tab组合键效果
    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        shl.WindowSwitcher()
    End Sub

End Class

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值