晨风资讯网
新闻资讯网络冲浪网页设计网络编程图形图像数据库网络媒体服务器网络安全网站运营软件教程黑客认证Wap技术
教程搜索
教程搜索:
  首页 > 程序开发 > VB/VB.NET > 正文  

VB.Net传真机编程实例[2]
日期:2008-6-20 12:10:26 来源: 作者: 浏览:

VB.Net传真机编程实例[2]

SendToFaxRecipient.vb  VB.Net传真机编程实例

测试环境 vs2005  系统环境 : windows2003   Xp Vista

代码:

'==========================================================================
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
'--------------------------------------------------------------------------

Imports System
Imports System.Globalization
Imports System.Security.Permissions
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.ApplicationServices

<Assembly: System.Reflection.AssemblyKeyFile("key.snk")>
<Assembly: CLSCompliant(True)>
Namespace Microsoft.Samples.Fax.SendToFax.VB

    Module SendToFax

        'Function exported by fxsutility.dll
        Public Enum SendToMode
            SendToFaxRecipientAttachment
        End Enum
        Public Class SendToFax
            Private Sub New()
            End Sub
            Declare Unicode Function CanSendToFaxRecipient Lib "fxsutility.dll" () As Boolean
            Declare Unicode Function SendToFaxRecipient Lib "fxsutility.dll" (ByVal enumType As SendToMode, ByVal strDoc As Char()) As UInt32
        End Class

        '+---------------------------------------------------------------------------更多实例来自乐博网
        '
        '  function:   GiveUsage
        '
        '  Synopsis:   prints the usage of the application
        '
        '  Arguments:  void
        '
        '  Returns:    void
        '
        '----------------------------------------------------------------------------
        Sub GiveUsage()
            System.Console.WriteLine("Usage : " + System.Diagnostics.Process.GetCurrentProcess().ProcessName)
            System.Console.WriteLine(" /o <cansendtofax> or <sendtofax> ")
            System.Console.WriteLine(" /d Document that is to be sent as Fax ")
            System.Console.WriteLine("Usage : " + System.Diagnostics.Process.GetCurrentProcess().ProcessName + " /? -- help message")
        End Sub

        '+---------------------------------------------------------------------------
        '
        '  function:   IsOSVersionCompatible
        '
        '  Synopsis:   finds whether the target OS supports this functionality.
        '
        '  Arguments:  [iVersion] - Minimum Version of the OS required for the Sample to run.
        '
        '  Returns:    bool - true if the Sample can run on this OS
        '
        '----------------------------------------------------------------------------
        Function IsOSVersionCompatible(ByVal iVersion As Integer) As Boolean
            Dim os As OperatingSystem
            Dim osVersion As Version

            os = Environment.OSVersion
            osVersion = os.Version
            If (osVersion.Major >= iVersion) Then
                Return True
            Else
                Return False
            End If
        End Function


        Sub Main()
            Dim strDoc As String
            Dim strOption As String
            Dim bRetVal As Boolean
            Dim iVista As Integer
            Dim iRet As UInt32
            Dim bVersion As Boolean
            Dim count As Integer
            Dim args As String

            iVista = 6
            bVersion = IsOSVersionCompatible(iVista)

            If (bVersion = False) Then
                System.Console.WriteLine("This sample is compatible with Windows Vista")       
                bRetVal = False
                Return
            End If

            strDoc = Nothing
            strOption = Nothing
            bRetVal = True
            iRet = 0
            count = 0
            args = Nothing

            Try
                If ((My.Application.CommandLineArgs.Count = 0)) Then
                    System.Console.WriteLine("Missing args.")
                    GiveUsage()
                    bRetVal = False
                    GoTo ExitFun
                End If

                ' check for commandline switches
                Do Until count = My.Application.CommandLineArgs.Count -1
                    If count >= My.Application.CommandLineArgs.Count - 1 Then
                        Exit Do
                    End If
                    args = My.Application.CommandLineArgs.Item(count)
                    If ((String.Compare(args.Substring(0, 1), "/", True, CultureInfo.CurrentCulture) = 0) Or (String.Compare(args.Substring(0, 1), "-", True, CultureInfo.CurrentCulture) = 0)) Then
                        Select Case (((args.ToLower(CultureInfo.CurrentCulture).Substring(1, 1))))
                            Case "o"
                                If (String.IsNullOrEmpty(strOption) = False) Then
                                    GiveUsage()
                                    bRetVal = False
                                    GoTo ExitFun
                                End If
                                strOption = My.Application.CommandLineArgs.Item(count + 1)
                            Case "d"
                                If (String.IsNullOrEmpty(strDoc) = False) Then
                                    GiveUsage()
                                    bRetVal = False
                                    GoTo ExitFun
                                End If
                                strDoc = My.Application.CommandLineArgs.Item(count + 1)
                            Case "?"
                                GiveUsage()
                                bRetVal = False
                                GoTo ExitFun
                            Case Else
                        End Select
                    End If
                    count = count + 1
                Loop

                If ((String.IsNullOrEmpty(strOption) = True)) Then
                    System.Console.WriteLine("Missing args.")
                    GiveUsage()
                    bRetVal = False
                    GoTo ExitFun
                End If

                If ((String.Compare("sendtofax", strOption.ToLower(CultureInfo.CurrentCulture), True, CultureInfo.CurrentCulture) =0) and (String.IsNullOrEmpty(strDoc) = True)) Then
                    System.Console.WriteLine("Missing args.")
                    GiveUsage()
                    bRetVal = False
                    GoTo ExitFun
                End If

                'if sendtofax option is selected
                If (String.Compare("sendtofax", strOption.ToLower(CultureInfo.CurrentCulture), True, CultureInfo.CurrentCulture) = 0) Then
                    strDoc = strDoc.Replace(";", " ")
                    iRet = SendToFax.SendToFaxRecipient(SendToMode.SendToFaxRecipientAttachment, strDoc.ToCharArray())
                    If (iRet <> 0) Then
                        System.Console.Write("SendToFaxRecipient: failed. Error ")
                        System.Console.Write(iRet)
                        System.Console.WriteLine()
                        bRetVal = False
                        GoTo ExitFun
                    End If
                    System.Console.WriteLine("SendToFaxRecipient was successful")
                End If

                'if cansendtofax option is selected
                If (String.Compare("cansendtofax", strOption.ToLower(CultureInfo.CurrentCulture), True, CultureInfo.CurrentCulture) = 0) Then

                    If (SendToFax.CanSendToFaxRecipient() = False) Then
                        System.Console.WriteLine("CanSendToFaxRecipient: failed. ")
                        bRetVal = False
                    End If
                    System.Console.WriteLine("CanSendToFaxRecipient was successful")
                End If

            Catch excep As Exception
                System.Console.WriteLine("Exception:" + excep.Message)
            End Try
ExitFun:
            If (bRetVal = False) Then
                System.Console.WriteLine("Function Failed")
            End If
        End Sub
    End Module
End Namespace


上一篇: VB.Net传真机编程实例[1] 下一篇:

VB.Net串口通讯的实例

返回列表 打印此页 加入收藏 资讯论坛 关闭窗口 点击复制本页地址,发送给QQ/MSN好友
关于我们 - 联系我们 - 版权声明 - 帮助(?) - 广告服务 - 友情链接 - 服务项目 - 人才招聘
2003-2008 版权所有 © 晨风资讯网 未经授权禁止复制或建立镜像
CopyRight 2003-2008 www.Net118.com,All Rights Reserved.Design By ChenFeng Network Studio