home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 2.00 Begin Form Form1 Caption = "NetPrint" ClientHeight = 3900 ClientLeft = 2625 ClientTop = 1635 ClientWidth = 3840 Height = 4305 Icon = NETPRINT.FRX:0000 Left = 2565 LinkMode = 1 'Source LinkTopic = "Form1" ScaleHeight = 3900 ScaleWidth = 3840 Top = 1290 Width = 3960 Begin Frame Frame1 Caption = "Linked Printers" Height = 1872 Left = 120 TabIndex = 0 Top = 1920 Width = 3612 Begin CommandButton Disconnect Caption = "&Disconnect" Height = 372 Left = 2400 TabIndex = 5 Top = 720 Width = 1092 End Begin ListBox LinkedPrinters Height = 1395 Left = 120 Sorted = -1 'True TabIndex = 4 Top = 300 Width = 2175 End End Begin Frame Frame2 Caption = "Available Printers and Ports" Height = 1752 Left = 120 TabIndex = 6 Top = 60 Width = 3612 Begin CommandButton Connect Caption = "&Connect" Height = 372 Left = 2400 TabIndex = 3 Top = 1260 Width = 1092 End Begin ListBox PrintPorts Height = 1005 Left = 2400 Sorted = -1 'True TabIndex = 2 Top = 240 Width = 1095 End Begin ListBox NetPrinters Height = 1395 Left = 120 Sorted = -1 'True TabIndex = 1 Top = 240 Width = 2175 End End 'NetPrint has been placed in the public domain by Art Krumsee 'CompuServe ID 76702,1526. Internet address art.krumsee@osu.edu Declare Function WNetGetConnection Lib "User" (ByVal LocalDev$, ByVal rmtname$, buffsize%) As Integer Declare Function WNetAddConnection Lib "User" (ByVal NetPath As String, ByVal Password As String, ByVal LocalDev As String) As Integer Declare Function WNetCancelConnection Lib "User" (ByVal LocalDev As String, ByVal Force As Integer) As Integer Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, KeyName As Any, Default As Any, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer Declare Function SendMessage% Lib "User" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam&) Declare Function GetFocus% Lib "User" () Declare Function PutFocus% Lib "User" Alias "SetFocus" (ByVal hWnd%) Const WM_USER = &H400 Const LB_RESETCONTENT = WM_USER + 5 Sub ClearListBox (Ctrl As Control) hWndOld% = GetFocus() Ctrl.SetFocus X = SendMessage(GetFocus(), LB_RESETCONTENT, 0, 0) Suc% = PutFocus(hWndOld%) End Sub Sub Connect_Click () 'x% = MsgBox(printports.text) If netprinters.listindex = -1 Or printports.listindex = -1 Then X% = MsgBox("You must select a printer and a port and then press Connect.") Else Link_Printer$ = netprinters.text Link_Port$ = printports.text X% = WNetAddConnection(Link_Printer$, "", Link_Port$) Select Case X% Case 0 ClearListBox linkedPrinters ClearListBox printports findlinks Case 6 n% = MsgBox("Password required. Could not connect printer.") Case 52 n% = MsgBox("Network Connection to that port already exists.") Case Else n% = MsgBox("Network Link Failed") End Select End If End Sub Sub Disconnect_Click () 'x% = MsgBox(printports.text) If linkedPrinters.listindex = -1 Then X% = MsgBox("You must select a linked printer and then press Disconnect.") Else Linked_Port$ = Left$(linkedPrinters.text, 5) X% = WNetCancelConnection(Linked_Port$, 0) Select Case X% Case 0 ClearListBox linkedPrinters ClearListBox printports findlinks Case 48 n% = MsgBox("This printer port was not connected to a network device.") Case 49 n% = MsgBox("Open files prevented the completion of this operation") Case Else n% = MsgBox("Network Disconnect Failed") End Select End If End Sub Sub findlinks () 'Find out which printer ports are already linked For X = 1 To 4 n% = 0 rmtname$ = String$(255, 0) LocalDev$ = "LPT" + LTrim$(Str$(X)) + ":" n% = WNetGetConnection(LocalDev$, rmtname$, 255) If n% = 0 Then rmtname$ = Left$(rmtname$, InStr(rmtname$, Chr$(0)) - 1) linkedPrinters.AddItem LocalDev$ + " " + rmtname$ Else printports.AddItem LocalDev$ End If Next X printports.Refresh End Sub Sub Form_Load () 'NetPrint has been placed in the public domain by Art Krumsee 'CompuServe ID 76702,1526. Internet address art.krumsee@osu.edu findlinks 'Get list of available printers from NETPRINT.ini ret$ = String$(255, 0) App_Name$ = "Netprint" Key_Val = 0& Def_Val$ = "No Printers Defined" Ini_Name$ = "netprint.ini" n% = GetPrivateProfileString(App_Name$, ByVal Key_Val, Def_Val$, ret$, 255, Ini_Name$) While Left$(ret$, 1) <> Chr$(0) rmtname$ = Left$(ret$, InStr(ret$, Chr$(0)) - 1) netprinters.AddItem ret$ ret$ = Right$(ret$, Len(ret$) - InStr(ret$, Chr$(0))) Wend End Sub