home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / CODIGO_2 / SIMP_FAX / SIMPLFAX.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-04-29  |  14.3 KB  |  407 lines

  1. VERSION 2.00
  2. Begin Form FaxRes 
  3.    Caption         =   "Extremely Simple VB/Winfax
  4.  Sample Program"
  5.    Height          =   6435
  6.    Icon            =   SIMPLFAX.FRX:0000
  7.    Left            =   1095
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    ScaleHeight     =   6030
  11.    ScaleWidth      =   5985
  12.    Top             =   1155
  13.    Width           =   6105
  14.    Begin ComboBox FaxRes 
  15.       Height          =   300
  16.       Left            =   1920
  17.       Style           =   2  'Dropdown List
  18.       TabIndex        =   11
  19.       Top             =   4860
  20.       Width           =   1695
  21.    End
  22.    Begin TextBox MessageText 
  23.       Height          =   1275
  24.       Left            =   1920
  25.       MultiLine       =   -1  'True
  26.       TabIndex        =   10
  27.       Top             =   3420
  28.       Width           =   3915
  29.    End
  30.    Begin TextBox SenderCompanyName 
  31.       Height          =   285
  32.       Left            =   1920
  33.       TabIndex        =   9
  34.       Top             =   3000
  35.       Width           =   3915
  36.    End
  37.    Begin TextBox SenderName 
  38.       Height          =   285
  39.       Left            =   1920
  40.       TabIndex        =   8
  41.       Top             =   2580
  42.       Width           =   3915
  43.    End
  44.    Begin TextBox FaxSubject 
  45.       Height          =   285
  46.       Left            =   1920
  47.       TabIndex        =   7
  48.       Top             =   2160
  49.       Width           =   3915
  50.    End
  51.    Begin TextBox RecCompanyName 
  52.       Height          =   285
  53.       Left            =   1920
  54.       TabIndex        =   6
  55.       Top             =   1740
  56.       Width           =   3915
  57.    End
  58.    Begin TextBox RecName 
  59.       Height          =   285
  60.       Left            =   1920
  61.       TabIndex        =   5
  62.       Top             =   1320
  63.       Width           =   3915
  64.    End
  65.    Begin TextBox SendFaxTime 
  66.       Enabled         =   0   'False
  67.       Height          =   285
  68.       Left            =   4140
  69.       TabIndex        =   4
  70.       Top             =   900
  71.       Width           =   915
  72.    End
  73.    Begin OptionButton SendFaxLater 
  74.       Caption         =   "On"
  75.       Height          =   255
  76.       Left            =   1920
  77.       TabIndex        =   2
  78.       Top             =   900
  79.       Width           =   615
  80.    End
  81.    Begin OptionButton SendFaxNow 
  82.       Caption         =   "Now"
  83.       Height          =   255
  84.       Left            =   1920
  85.       TabIndex        =   1
  86.       Top             =   600
  87.       Value           =   -1  'True
  88.       Width           =   795
  89.    End
  90.    Begin TextBox SendFaxDate 
  91.       Enabled         =   0   'False
  92.       Height          =   285
  93.       Left            =   2580
  94.       TabIndex        =   3
  95.       Top             =   900
  96.       Width           =   1155
  97.    End
  98.    Begin TextBox FaxNumber 
  99.       Height          =   285
  100.       Left            =   1920
  101.       TabIndex        =   0
  102.       Top             =   180
  103.       Width           =   3915
  104.    End
  105.    Begin CommandButton CancelFax 
  106.       Caption         =   "Exit"
  107.       Height          =   435
  108.       Left            =   4380
  109.       TabIndex        =   14
  110.       Top             =   5520
  111.       Width           =   1455
  112.    End
  113.    Begin CommandButton SendFax 
  114.       Caption         =   "Send fax"
  115.       Enabled         =   0   'False
  116.       Height          =   435
  117.       Left            =   2820
  118.       TabIndex        =   13
  119.       Top             =   5520
  120.       Width           =   1455
  121.    End
  122.    Begin Label Label9 
  123.       Caption         =   "Fax resolution"
  124.       Height          =   195
  125.       Left            =   180
  126.       TabIndex        =   24
  127.       Top             =   4920
  128.       Width           =   1455
  129.    End
  130.    Begin Label Label8 
  131.       Caption         =   "Message text"
  132.       Height          =   195
  133.       Left            =   180
  134.       TabIndex        =   23
  135.       Top             =   3480
  136.       Width           =   1395
  137.    End
  138.    Begin Label Label7 
  139.       Caption         =   "Company name"
  140.       Height          =   195
  141.       Left            =   180
  142.       TabIndex        =   22
  143.       Top             =   3060
  144.       Width           =   1515
  145.    End
  146.    Begin Label Label6 
  147.       Caption         =   "Sender's name"
  148.       Height          =   195
  149.       Left            =   180
  150.       TabIndex        =   21
  151.       Top             =   2640
  152.       Width           =   1515
  153.    End
  154.    Begin Label Label5 
  155.       Caption         =   "Fax subject"
  156.       Height          =   195
  157.       Left            =   180
  158.       TabIndex        =   20
  159.       Top             =   2220
  160.       Width           =   1455
  161.    End
  162.    Begin Label Label4 
  163.       Caption         =   "Company name"
  164.       Height          =   195
  165.       Left            =   180
  166.       TabIndex        =   19
  167.       Top             =   1800
  168.       Width           =   1515
  169.    End
  170.    Begin Label Label3 
  171.       Caption         =   "Recipient's name"
  172.       Height          =   195
  173.       Left            =   180
  174.       TabIndex        =   18
  175.       Top             =   1380
  176.       Width           =   1515
  177.    End
  178.    Begin Label SendFaxAtLabel 
  179.       Caption         =   "at"
  180.       Height          =   195
  181.       Left            =   3840
  182.       TabIndex        =   17
  183.       Top             =   960
  184.       Width           =   255
  185.    End
  186.    Begin Label Label2 
  187.       Caption         =   "Send fax"
  188.       Height          =   195
  189.       Left            =   180
  190.       TabIndex        =   16
  191.       Top             =   660
  192.       Width           =   1215
  193.    End
  194.    Begin Label Label1 
  195.       Caption         =   "Fax number"
  196.       Height          =   255
  197.       Left            =   180
  198.       TabIndex        =   15
  199.       Top             =   240
  200.       Width           =   1095
  201.    End
  202.    Begin Label DDElabel 
  203.       Caption         =   "The invisible DDElabel ..."
  204.       Height          =   255
  205.       Left            =   120
  206.       TabIndex        =   12
  207.       Top             =   5640
  208.       Visible         =   0   'False
  209.       Width           =   2295
  210.    End
  211. Sub CancelFax_Click ()
  212. If MsgBox("Exit the fax program?", 36, "User-friendly question #17") Then
  213.     End
  214. End If
  215. End Sub
  216. Sub FaxNumber_Change ()
  217. If Len(FaxNumber.Text) > 47 Then
  218.     MsgBox "Maximum fax number length is 47." + Chr$(13) + Chr$(10) + "Additional digits will be ignored.", 48, "Sorry!"
  219.     FaxNumber.Text = Left$(FaxNumber.Text, 47)
  220. End If
  221. If Len(LTrim$(RTrim$(FaxNumber.Text))) <> 0 Then
  222.     SendFax.Enabled = True
  223.     SendFax.Enabled = False
  224. End If
  225. End Sub
  226. Sub Form_Activate ()
  227. FaxNumber.SetFocus
  228. End Sub
  229. Sub Form_Load ()
  230. ad$ = "SIMPLFAX 1.0 - VB/WinFax Sample Program" + Chr$(13) + Chr$(10) + "Copyright 
  231. 1993 michiel de bruijn"
  232. ad$ = ad$ + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10) + "You may freely use and distribute this program and its source code in accordance to the licence agreement as included in SIMPLFAX.WRI"
  233. MsgBox ad$, 64, "About SIMPLFAX"
  234. tmp$ = Date$
  235. For a% = 1 To Len(tmp$)
  236.     If Mid$(tmp$, a%, 1) = "-" Then Mid$(tmp$, a%, 1) = "/"
  237. Next a%
  238. SendFaxDate.Text = tmp$
  239. SendFaxTime.Text = Time$
  240. FaxRes.AddItem "Normal"
  241. FaxRes.AddItem "High"
  242. FaxRes.ListIndex = 1
  243. End Sub
  244. Static Sub nop ()
  245. End Sub
  246. Sub RecCompanyName_Change ()
  247. If Len(RecCompanyName.Text) > 42 Then
  248.     MsgBox "Maximum name length is 42." + Chr$(13) + Chr$(10) + "Additional characters will be ignored.", 48, "Sorry!"
  249.     RecCompanyName.Text = Left$(RecCompanyName.Text, 42)
  250. End If
  251. End Sub
  252. Sub RecName_Change ()
  253. If Len(RecName.Text) > 31 Then
  254.     MsgBox "Maximum name length is 31." + Chr$(13) + Chr$(10) + "Additional characters will be ignored.", 48, "Sorry!"
  255.     RecName.Text = Left$(RecName.Text, 31)
  256. End If
  257. End Sub
  258. Sub SendFax_Click ()
  259. '====================================================================================================
  260. ' STEP 1: Set WinFax as the default printer so we can print to it using the VB printer object
  261. '====================================================================================================
  262. ' First, retrieve the current default printer, if any
  263. buf$ = Space$(256)
  264. dummy% = GetProfileString("windows" + Chr$(0), "device" + Chr$(0), Chr$(0), buf$, Len(buf$))
  265. PrevDefaultPrinter$ = buf$
  266. ' Then find out the WinFax setup (driver name & port)
  267. buf$ = Space$(256)
  268. dummy% = GetProfileString("printerports" + Chr$(0), "winfax" + Chr$(0), Chr$(0), buf$, Len(buf$))
  269. If Left$(buf$, 1) = Chr$(0) Then
  270.     MsgBox "WinFax is not properly installed as a printer on this machine", 16, "Cannot send fax"
  271.     Exit Sub
  272. End If
  273. x% = InStr(buf$, ":")
  274. wfparms$ = Left$(buf$, x%)
  275. ' And set WinFax as the default printer
  276. res% = WriteProfileString("windows" + Chr$(0), "device" + Chr$(0), "WINFAX," + wfparms$ + Chr$(0))
  277. If res% <> 1 Then
  278.     MsgBox "Could not select WinFax as the default printer.", 16, "Cannot send fax"
  279.     Exit Sub
  280. End If
  281. '====================================================================================================
  282. ' STEP 2: Contact WinFax via DDE and send the phone number etc. in advance
  283. '====================================================================================================
  284. ' Set the application name and topic (see pg. 12-12 of the WinFax PRO 3.0 manual)
  285. DDElabel.LinkTopic = "FAXMNG|Transmit"
  286. ' Try to create the link. The error handler is used to start WinFax if it's not already running
  287. On Local Error GoTo NoWinFax
  288. DDElabel.LinkMode = 2
  289. On Local Error GoTo 0
  290. ' WinFax should be running and listening at this point. Send the required data
  291. DDElabel.LinkItem = "Sendfax"
  292. tmp$ = "recipient(" + Chr$(34) + FaxNumber.Text + Chr$(34) + ","
  293. If SendFaxNow.Value = True Then
  294.     tmp$ = tmp$ + ",,"
  295.     tmp$ = tmp$ + Chr$(34) + SendFaxDate.Text + Chr$(34) + "," + Chr$(34) + SendFaxTime.Text + Chr$(34) + ","
  296. End If
  297. tmp$ = tmp$ + Chr$(34) + RecName.Text + Chr$(34) + ","
  298. tmp$ = tmp$ + Chr$(34) + RecCompanyName.Text + Chr$(34) + ","
  299. tmp$ = tmp$ + Chr$(34) + FaxSubject.Text + Chr$(34) + ")"
  300. DDElabel.Caption = tmp$
  301. DDElabel.LinkPoke
  302. If FaxRes.ListIndex = 0 Then tmp$ = "low" Else tmp$ = "high"
  303. DDElabel.Caption = "resolution(" + Chr$(34) + tmp$ + Chr$(34) + ")"
  304. DDElabel.LinkPoke
  305. '====================================================================================================
  306. ' STEP 3: Do the actual printing
  307. '====================================================================================================
  308. printer.FontName = "Arial": printer.FontSize = 62
  309. printer.FontBold = True: printer.FontItalic = True
  310. tmp$ = "FAX MESSAGE"
  311. printer.CurrentY = 100
  312. printer.CurrentX = (printer.ScaleWidth \ 2) - (printer.TextWidth(tmp$) \ 2)
  313. printer.Print tmp$
  314. printer.FontSize = 14: printer.FontBold = False: printer.FontItalic = False
  315. printer.Print
  316. printer.CurrentX = 1000: printer.Print "Date/Time";
  317. printer.CurrentX = 3000: printer.Print Date$; " "; Time$
  318. printer.Print
  319. printer.CurrentX = 1000: printer.Print "To";
  320. printer.CurrentX = 3000: printer.Print RecName.Text
  321. printer.Print
  322. printer.CurrentX = 1000: printer.Print "Company";
  323. printer.CurrentX = 3000: printer.Print RecCompanyName.Text
  324. printer.Print
  325. printer.CurrentX = 1000: printer.Print "Subject";
  326. printer.CurrentX = 3000: printer.Print FaxSubject.Text
  327. printer.Print
  328. printer.CurrentX = 1000: printer.Print "From";
  329. printer.CurrentX = 3000: printer.Print SenderName.Text
  330. printer.Print
  331. printer.CurrentX = 1000: printer.Print "Company";
  332. printer.CurrentX = 3000: printer.Print SenderCompanyName.Text
  333. printer.Print
  334. printer.Print
  335. printer.FontName = "Times New Roman"
  336. ' PROGRAMMER'S HEALTH WARNING! Extremely slow, simplistic & braindead
  337. ' formatting code ahead. Read at your own risk!!
  338. margin% = printer.ScaleWidth - 2000
  339. printer.CurrentX = 1000
  340. For a% = 1 To Len(MessageText.Text)
  341.     char$ = Mid$(MessageText.Text, a%, 1)
  342.     If (char$ = " ") And printer.CurrentX > margin% Then
  343.         printer.Print
  344.         printer.CurrentX = 1000
  345.     ElseIf char$ = Chr$(13) Then
  346.         printer.Print
  347.         printer.CurrentX = 1000
  348.     ElseIf char$ = Chr$(10) Then
  349.         nop
  350.     Else
  351.         printer.Print char$;
  352.     End If
  353. Next a%
  354. ' (if you read it anyway: it's OK to go and scream now. I'm sorry)
  355. printer.EndDoc
  356. MsgBox "Your fax was sent OK to the WinFax program.", 64, "Printing complete"
  357. '====================================================================================================
  358. ' STEP 3: Cleanup: Terminate our DDE conversation with WinFax and restore the default printer
  359. '====================================================================================================
  360. DDElabel.LinkMode = 0
  361. DDElabel.LinkTopic = ""
  362. RecName.Text = "": RecCompanyName.Text = ""
  363. SenderName.Text = "": SenderCompanyName.Text = ""
  364. FaxSubject.Text = "": MessageText.Text = ""
  365. FaxNumber.Text = ""
  366. RestoreDefaultPrinter:
  367. res% = WriteProfileString("windows" + Chr$(0), "device" + Chr$(0), PrevDefaultPrinter$ + Chr$(0))
  368. If res% <> 1 Then
  369.     MsgBox "Could not restore your default printer." + Chr$(13) + Chr$(10) + "Please do so manually via the Control Panel", 48, "Problem detected"
  370.     Exit Sub
  371. End If
  372. Exit Sub
  373. '====================================================================================================
  374. ' Error handling (limited)
  375. '====================================================================================================
  376. NoWinFax:
  377.     If Err = 282 Then
  378.         buf$ = Space$(256)
  379.         dummy% = GetProfileString("winfax" + Chr$(0), "exepath" + Chr$(0), Chr$(0), buf$, Len(buf$))
  380.         x% = InStr(buf$, Chr$(0))
  381.         If x% <> 1 Then
  382.             exepath$ = Left$(buf$, x% - 1)
  383.             dummy% = Shell(exepath$ + "faxmng.exe")
  384.             Resume
  385.         Else
  386.             MsgBox "Winfax is not properly installed on this machine." + Chr$(13) + Chr$(10) + "Please ensure that you have version 3.x and your setup is correct.", 16, "Fatal error: "
  387.             Resume RestoreDefaultPrinter
  388.         End If
  389.     Else
  390.         MsgBox "Error talking to WinFax!" + Chr$(13) + Chr$(10) + "Please ensure that you have version 3.x and your setup is correct.", 16, "Fatal error: "
  391.         Exit Sub
  392.     End If
  393. End Sub
  394. Sub SendFaxAtLabel_Click ()
  395. SendFaxLater.Value = True
  396. SendFaxLater_Click
  397. End Sub
  398. Sub SendFaxLater_Click ()
  399. SendFaxDate.Enabled = True
  400. SendFaxTime.Enabled = True
  401. SendFaxTime.Text = Time$
  402. End Sub
  403. Sub SendFaxNow_Click ()
  404. SendFaxDate.Enabled = False
  405. SendFaxTime.Enabled = False
  406. End Sub
  407.