home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / ecltray / traydemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-04-21  |  8.4 KB  |  233 lines

  1. VERSION 5.00
  2. Object = "{E39DB312-D923-11D1-B45E-0020AF33A8E7}#1.0#0"; "ECLTRAY.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Demo using ECLTray Control"
  5.    ClientHeight    =   1356
  6.    ClientLeft      =   48
  7.    ClientTop       =   336
  8.    ClientWidth     =   5100
  9.    LinkTopic       =   "Form1"
  10.    LockControls    =   -1  'True
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   1356
  13.    ScaleWidth      =   5100
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin ECLTrayIcon.Ecltray Ecltray1 
  17.       Left            =   96
  18.       Top             =   1248
  19.       _ExtentX        =   804
  20.       _ExtentY        =   529
  21.       IconToolTip     =   "ECLIPSE
  22.  System Tray Icon"
  23.    End
  24.    Begin VB.CommandButton Command4 
  25.       Caption         =   "E&xit"
  26.       Height          =   320
  27.       Left            =   3504
  28.       TabIndex        =   4
  29.       Top             =   850
  30.       Width           =   1500
  31.    End
  32.    Begin VB.CommandButton Command3 
  33.       Caption         =   "&Cycle Icon"
  34.       Height          =   320
  35.       Left            =   1800
  36.       TabIndex        =   3
  37.       Top             =   850
  38.       Width           =   1500
  39.    End
  40.    Begin VB.CommandButton Command2 
  41.       Caption         =   "Hide &Icon"
  42.       Height          =   320
  43.       Left            =   100
  44.       TabIndex        =   2
  45.       Top             =   850
  46.       Width           =   1500
  47.    End
  48.    Begin VB.CommandButton Command1 
  49.       Caption         =   "Change &Tip"
  50.       Height          =   320
  51.       Left            =   144
  52.       TabIndex        =   1
  53.       Top             =   144
  54.       Width           =   1500
  55.    End
  56.    Begin VB.TextBox Text1 
  57.       Height          =   300
  58.       Left            =   1944
  59.       MaxLength       =   64
  60.       TabIndex        =   0
  61.       Text            =   "Text1"
  62.       Top             =   170
  63.       Width           =   2940
  64.    End
  65.    Begin VB.Image Image1 
  66.       Height          =   384
  67.       Index           =   3
  68.       Left            =   2400
  69.       Picture         =   "TrayDemo.frx":0000
  70.       Stretch         =   -1  'True
  71.       ToolTipText     =   "My Computer"
  72.       Top             =   1272
  73.       Visible         =   0   'False
  74.       Width           =   384
  75.    End
  76.    Begin VB.Image Image1 
  77.       Height          =   384
  78.       Index           =   2
  79.       Left            =   1968
  80.       Picture         =   "TrayDemo.frx":08CA
  81.       Stretch         =   -1  'True
  82.       ToolTipText     =   "The Globe"
  83.       Top             =   1272
  84.       Visible         =   0   'False
  85.       Width           =   384
  86.    End
  87.    Begin VB.Image Image1 
  88.       Height          =   384
  89.       Index           =   1
  90.       Left            =   1416
  91.       Picture         =   "TrayDemo.frx":0BD4
  92.       Stretch         =   -1  'True
  93.       ToolTipText     =   "Windows Explorer"
  94.       Top             =   1272
  95.       Visible         =   0   'False
  96.       Width           =   384
  97.    End
  98.    Begin VB.Image Image1 
  99.       Height          =   384
  100.       Index           =   0
  101.       Left            =   888
  102.       Picture         =   "TrayDemo.frx":149E
  103.       Stretch         =   -1  'True
  104.       ToolTipText     =   "Internet Explorer"
  105.       Top             =   1272
  106.       Visible         =   0   'False
  107.       Width           =   384
  108.    End
  109.    Begin VB.Menu mnuMenu 
  110.       Caption         =   "Menu"
  111.       Visible         =   0   'False
  112.       Begin VB.Menu mnuRestore 
  113.          Caption         =   "&Restore"
  114.       End
  115.       Begin VB.Menu mnuMinimize 
  116.          Caption         =   "Mi&nimize"
  117.       End
  118.       Begin VB.Menu mnuExit 
  119.          Caption         =   "E&xit"
  120.       End
  121.    End
  122. Attribute VB_Name = "Form1"
  123. Attribute VB_GlobalNameSpace = False
  124. Attribute VB_Creatable = False
  125. Attribute VB_PredeclaredId = True
  126. Attribute VB_Exposed = False
  127. Option Explicit
  128. ' This declares should be in a module but I want to keep the code in a single file
  129. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  130. Private Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
  131. Dim OldIcon As StdPicture
  132. Dim OldToolTip As String
  133. Dim IconId As Integer
  134. Private Sub Command1_Click()
  135.      Ecltray1.IconToolTip = Text1.Text
  136. End Sub
  137. Private Sub Command2_Click()
  138.     With Ecltray1
  139.         If .ShowIcon Then
  140.             Command2.Caption = "Show &Icon"
  141.             .ShowIcon = False
  142.         Else
  143.             Command2.Caption = "Hide &Icon"
  144.             .ShowIcon = True
  145.         End If
  146.     End With
  147.      
  148. End Sub
  149. Private Sub Command3_Click()
  150.     If IconId > 4 Then IconId = 0                       'maximum number of Icon that we have
  151.     Select Case IconId
  152.     Case 0:
  153.             Set Ecltray1.TrayIcon = OldIcon         'Control's Stored Icon
  154.             Ecltray1.IconToolTip = OldToolTip       'control's stored ToolTip
  155.             Text1.Text = OldToolTip
  156.     Case 1 To 4:
  157.             Set Ecltray1.TrayIcon = Image1(IconId - 1).Picture ' copy the Image stored in Image1 -must be an Icon!
  158.             Ecltray1.IconToolTip = Image1(IconId - 1).ToolTipText   ' copy the ToolTipText of Image1. This can be set to anything
  159.             Text1.Text = Image1(IconId - 1).ToolTipText
  160.     End Select
  161.     IconId = IconId + 1
  162. End Sub
  163. Private Sub Command4_Click()
  164.     mnuExit_Click
  165. End Sub
  166. Private Sub Ecltray1_DblClick(Button As Integer)
  167.     If WindowState = 0 Then             'I tried to use 'If Not WindowState' but the Else part wouldn't trigger. I don't know why.
  168.         WindowState = vbMinimized       ' minimize the form
  169.     Else
  170.         WindowState = vbNormal          ' limit the viewable state to normal
  171.         SetForegroundWindow (Me.hwnd)   'Ensure the form is visible and has the  focus
  172.     End If
  173. End Sub
  174. Private Sub ecltray1_MouseUp(Button As Integer, shift As Integer, X As Single, Y As Single)
  175. ' Button can be 1(Left); 2(Right) or 4(Middle)
  176. ' Shift can be 1(Shiftkey is down), 2(ControlKey is down) and 4 (AltKey is Down)
  177. ' Note that value of shift can be one or combination of the three keys.i.e. 6=(Ctrl and Alt keys as pressed)
  178. ' The value of X and Y indicates the location of the mouse cursor
  179.      
  180.     If Button = 2 Then                              ' Execute only when the right Mouse Button is pressed and release
  181.         SetForegroundWindow (Me.hwnd)               'Activate form1
  182.         PopupMenu mnuMenu, vbPopupMenuRightAlign    'pops up the menu we created 'mnuMenu'
  183.     End If
  184.      
  185. End Sub
  186. Private Sub Form_Load()
  187.     Set OldIcon = Ecltray1.TrayIcon                 'copy the control's stored Icon & ToolTipText
  188.     OldToolTip = Ecltray1.IconToolTip
  189.     Text1.Text = OldToolTip
  190.     IconId = 1                                      'set the next icon to be displayed when the Cycle Icon button is pressed
  191.      
  192. End Sub
  193. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  194.     Set Form1 = Nothing
  195. End Sub
  196. Private Sub Form_Resize()
  197.     If WindowState Then
  198.         mnuMinimize.Enabled = False
  199.         mnuRestore.Enabled = True
  200.     Else
  201.         mnuMinimize.Enabled = True
  202.         mnuRestore.Enabled = False
  203.     End If
  204.      
  205. End Sub
  206. Private Sub mnuExit_Click()
  207. ' ***************************************************************
  208. ' NOTE: Quiting the program from the system Icon (popupmenu) by
  209. '       means of 'Unload Form1' statement will generate an 'Invalid
  210. '       Page Fault in Module <unknown>' message. This will happen
  211. '       only when you try to exit the program using the System Icon.
  212. '       I still don't know why this happen. To work around this
  213. '       problem I used an API call to quit the program properly
  214. '       'Postquitmessage (nExitCode as Long)'. There is one  problem
  215. '       with it, however. if you remove the code 'X = MsgBox...', the
  216. '       Exit code will be ignored and the program will continue running.
  217. '       So, the MsgBox is necessary to shut the program. Again, I still
  218. '       don't know why this happen. Please send me some information if
  219. '       you know how to work around these problems, because I'm still
  220. '       searching for an explanation.
  221. ' *****************************************************************
  222. Dim X As Integer
  223.     X = MsgBox("Are you sure You want to quit", vbYesNo Or vbQuestion)
  224.     If X = vbNo Then Exit Sub
  225.     PostQuitMessage vbFormCode
  226. End Sub
  227. Private Sub mnuMinimize_Click()
  228.     WindowState = 1         'minimize
  229. End Sub
  230. Private Sub mnuRestore_Click()
  231.     WindowState = 0         'Normal/Restore
  232. End Sub
  233.