home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / bitmas1g / module1.bas < prev   
Encoding:
BASIC Source File  |  1999-09-03  |  2.9 KB  |  96 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. Public fMainForm As frmMain
  5. ' this is used to determine which button or menu item the user picked
  6. Public index As String
  7. Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  8.  
  9.  
  10. Sub Main()
  11.     Set fMainForm = New frmMain
  12.     fMainForm.Show
  13.     
  14. End Sub
  15.  
  16. Public Sub ActivateAlarm(index As String)
  17.     Select Case index
  18.         Case Is = "Program"
  19.                 ' when the user chooses the file name from the
  20.                 ' dialog box the filename is placed in this label
  21.                 ' on the main form
  22.                 Call RunProgram(fMainForm.lblMsg.Caption)
  23.         Case Is = "Sound"
  24.                 Call PlaySound(fMainForm.lblMsg.Caption)
  25.                 
  26.         Case Is = "Message"
  27.                 Call ShowMessage(fMainForm.lblMsg.Caption)
  28.                 
  29.         End Select
  30.                 
  31. End Sub
  32. Public Sub PlaySound(soundfile As String)
  33.     Dim S As Long
  34.     Const SYNC = 1
  35.     ' disable the timer
  36.     fMainForm.Timer1.Enabled = False
  37.     S = sndPlaySound(ByVal soundfile, SYNC)
  38.  
  39. End Sub
  40.  
  41. Public Sub RunProgram(name As String)
  42.     Dim x As Double
  43.     fMainForm.Timer1.Enabled = False
  44.     x = Shell(name, vbNormalFocus)
  45.        
  46. End Sub
  47.  
  48. Public Sub ShowMessage(msg As String)
  49.     frmMain.Timer1.Enabled = False
  50.     ' fmainform is defined in the module
  51.     fMainForm.WindowState = 1
  52.     Load frmMessage
  53.     Call SetUpForm(frmMessage)
  54.     frmMessage.Show
  55.  
  56. End Sub
  57.  
  58. Public Sub SetUpForm(frm As Form)
  59.     Dim msg As String
  60.     Dim WidthFactor As Integer
  61.     Dim HeightFactor As Integer
  62.     Dim LeftCoord As Integer
  63.     Dim TopCoord As Integer
  64.     
  65.     ' get the users message
  66.     msg = fMainForm.txtMessage.Text
  67.     
  68.     ' set up the form with all the correct options
  69.     With frm
  70.         .BackColor = fMainForm.txtMessage.BackColor
  71.         .ForeColor = fMainForm.txtMessage.ForeColor
  72.         .Font = fMainForm.txtMessage.Font
  73.         .Font.Size = fMainForm.txtMessage.Font.Size
  74.         .Font.Italic = fMainForm.txtMessage.Font.Italic
  75.         .Font.Strikethrough = fMainForm.txtMessage.Font.Strikethrough
  76.         .Font.Underline = fMainForm.txtMessage.Font.Underline
  77.         .Font.Bold = fMainForm.txtMessage.Font.Bold
  78.         .Width = .TextWidth(msg) + 500
  79.         ' add twice the height so the form is not too small
  80.         .Height = .TextHeight(msg) + .TextHeight(msg)
  81.     End With
  82.     
  83.     ' here i am centering the users message on the form
  84.     frm.Cls
  85.     LeftCoord = frm.ScaleWidth / 2
  86.     TopCoord = frm.ScaleHeight / 2
  87.     LeftCoord = frm.ScaleLeft + LeftCoord
  88.     TopCoord = frm.ScaleTop + TopCoord
  89.     WidthFactor = frm.TextWidth(msg) / 2
  90.     HeightFactor = frm.TextHeight(msg) / 2
  91.     frm.CurrentX = LeftCoord - WidthFactor
  92.     frm.CurrentY = TopCoord - HeightFactor
  93.     frm.Print msg
  94. End Sub
  95.  
  96.