home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / tskvb4 / taskbar.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-07-22  |  15.2 KB  |  407 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Form1"
  6.    ClientHeight    =   2532
  7.    ClientLeft      =   2472
  8.    ClientTop       =   2772
  9.    ClientWidth     =   4716
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   0
  13.       weight          =   700
  14.       size            =   7.8
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   2856
  21.    Icon            =   "taskbar.frx":0000
  22.    Left            =   2424
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   2532
  25.    ScaleWidth      =   4716
  26.    Top             =   2496
  27.    Width           =   4812
  28.    Begin VB.CommandButton Command5 
  29.       Appearance      =   0  'Flat
  30.       BackColor       =   &H80000005&
  31.       Caption         =   "Exit"
  32.       Height          =   372
  33.       Left            =   3300
  34.       TabIndex        =   4
  35.       Top             =   1680
  36.       Width           =   732
  37.    End
  38.    Begin VB.CommandButton Command1 
  39.       Appearance      =   0  'Flat
  40.       BackColor       =   &H80000005&
  41.       Caption         =   "Command1"
  42.       Height          =   432
  43.       Left            =   360
  44.       TabIndex        =   0
  45.       Top             =   120
  46.       Width           =   1452
  47.    End
  48.    Begin VB.Timer Timer1 
  49.       Enabled         =   0   'False
  50.       Interval        =   2000
  51.       Left            =   2280
  52.       Top             =   1440
  53.    End
  54.    Begin VB.CommandButton Command4 
  55.       Appearance      =   0  'Flat
  56.       BackColor       =   &H80000005&
  57.       Caption         =   "Command4"
  58.       Height          =   432
  59.       Left            =   360
  60.       TabIndex        =   3
  61.       Top             =   1920
  62.       Width           =   1452
  63.    End
  64.    Begin VB.CommandButton Command3 
  65.       Appearance      =   0  'Flat
  66.       BackColor       =   &H80000005&
  67.       Caption         =   "Command3"
  68.       Height          =   432
  69.       Left            =   360
  70.       TabIndex        =   2
  71.       Top             =   1320
  72.       Width           =   1452
  73.    End
  74.    Begin VB.CommandButton Command2 
  75.       Appearance      =   0  'Flat
  76.       BackColor       =   &H80000005&
  77.       Caption         =   "Command2"
  78.       Height          =   432
  79.       Left            =   360
  80.       TabIndex        =   1
  81.       Top             =   720
  82.       Width           =   1452
  83.    End
  84.    Begin MsghookLib.Msghook Msghook1 
  85.       Left            =   2532
  86.       Top             =   1980
  87.       _Version        =   65536
  88.       _ExtentX        =   677
  89.       _ExtentY        =   677
  90.       _StockProps     =   0
  91.    End
  92.    Begin ComctlLib.ImageList ImageList1 
  93.       Left            =   4140
  94.       Top             =   1920
  95.       _Version        =   65536
  96.       _ExtentX        =   804
  97.       _ExtentY        =   804
  98.       _StockProps     =   1
  99.       BackColor       =   -2147483643
  100.       ImageWidth      =   16
  101.       ImageHeight     =   16
  102.       NumImages       =   4
  103.       i1              =   "taskbar.frx":030A
  104.       i2              =   "taskbar.frx":0509
  105.       i3              =   "taskbar.frx":0708
  106.       i4              =   "taskbar.frx":0907
  107.    End
  108.    Begin VB.Label Label4 
  109.       Alignment       =   2  'Center
  110.       Appearance      =   0  'Flat
  111.       BackColor       =   &H80000005&
  112.       ForeColor       =   &H80000008&
  113.       Height          =   252
  114.       Left            =   3120
  115.       TabIndex        =   8
  116.       Top             =   900
  117.       Width           =   852
  118.    End
  119.    Begin VB.Label Label3 
  120.       Appearance      =   0  'Flat
  121.       BackColor       =   &H00C0C0C0&
  122.       Caption         =   "Icon:"
  123.       ForeColor       =   &H80000008&
  124.       Height          =   252
  125.       Left            =   2460
  126.       TabIndex        =   7
  127.       Top             =   900
  128.       Width           =   492
  129.    End
  130.    Begin VB.Label Label2 
  131.       Alignment       =   2  'Center
  132.       Appearance      =   0  'Flat
  133.       BackColor       =   &H80000005&
  134.       ForeColor       =   &H80000008&
  135.       Height          =   252
  136.       Left            =   2460
  137.       TabIndex        =   6
  138.       Top             =   540
  139.       Width           =   2052
  140.    End
  141.    Begin VB.Label Label1 
  142.       Appearance      =   0  'Flat
  143.       BackColor       =   &H00C0C0C0&
  144.       Caption         =   "Mouse Event:"
  145.       ForeColor       =   &H80000008&
  146.       Height          =   252
  147.       Left            =   2460
  148.       TabIndex        =   5
  149.       Top             =   180
  150.       Width           =   1512
  151.    End
  152. Attribute VB_Name = "Form1"
  153. Attribute VB_Creatable = False
  154. Attribute VB_Exposed = False
  155. Option Explicit
  156. '------------------------------------------------------------
  157. 'This sample application demonstrates general procedures for
  158. 'installing and maintaining an icon in the Win95 toolbar Notification
  159. 'Area (also known as the Tray) from a VB4/32 program.  Requires
  160. 'COMCTL32.OCX and MsgHoo32.OCX.
  161. '-------------------------------------------------------------------
  162. 'Copyright 1995/1996 by Don Bradner.  May be freely distributed
  163. 'Author contact: CIS 76130,1007; internet dbirdman@redshift.com
  164. 'http://www.redshift.com/~arcatpet.  Support available as time
  165. 'allows, including the VBPJ and MSBASIC forums on Compuserve.
  166. '----------------------------------------------------------------------
  167. 'The OsVersionInfo structure is used by the 32-bit GetVersionEx Function
  168. '----------------------------------------------------------------------
  169. Private Type OsVersionInfo
  170.     dwVersionInfoSize As Long
  171.     dwMajorVersion As Long
  172.     dwMinorVersion As Long
  173.     dwBuildNumber As Long
  174.     dwPlatform As Long
  175.     szCSDVersion As String * 128
  176. End Type
  177. Private Declare Function GetVersionEx& Lib "kernel32.dll" Alias "GetVersionExA" (lpStruct As OsVersionInfo)
  178. Private OsVers As OsVersionInfo
  179. Private lTempLong&
  180. ' --------------------------------------------------------
  181. ' Used with GetVersion and GetWinFlags
  182. ' --------------------------------------------------------
  183. Const VER_PLATFORM_WIN32_WINDOWS = 1
  184. Const VER_PLATFORM_WIN32_NT = 2
  185. '----------------------------------------------------------
  186. 'This sample application implements callbacks via the MsgHook
  187. 'message handling control.  Windows will generate a User
  188. 'Message with an lParam that identifies a mouse event, such
  189. 'as WM_MOUSEMOVE, and the wParam will contain the icon number.
  190. 'If the application installs more than one icon, each must be
  191. 'given a unique ID number.
  192. '-----------------------------------------------------------
  193. '-----------------------------------------------------------
  194. 'The 10 available mouse events:
  195. '-----------------------------------------------------------
  196. Const WM_MOUSEMOVE = &H200
  197. Const WM_LBUTTONDOWN = &H201
  198. Const WM_LBUTTONUP = &H202
  199. Const WM_LBUTTONDBLCLK = &H203
  200. Const WM_RBUTTONDOWN = &H204
  201. Const WM_RBUTTONUP = &H205
  202. Const WM_RBUTTONDBLCLK = &H206
  203. Const WM_MBUTTONDOWN = &H207
  204. Const WM_MBUTTONUP = &H208
  205. Const WM_MBUTTONDBLCLK = &H209
  206. Dim TaskBr As New CTaskBar
  207. Private iIconUsed&
  208. Private lIconAdded&
  209. Private Sub Command1_Click()
  210. '-----------------------------------------------------
  211. 'This button adds a new icon to the tray.
  212. '-----------------------------------------------------
  213. Dim hIcon&
  214. Dim sTip$
  215.     '---------------------------------------------------
  216.     'Select one of the icons from the ImageList.  The
  217.     'ImageList may have 16x16, 32x32, or 48x48 icons, but
  218.     'if it is a bitmap source rather than an icon source
  219.     'this program will fail.  32x32 and larger are scaled
  220.     'down to 16x16, so 16x16 will look the best.
  221.     '---------------------------------------------------
  222.     '---------------------------------------------------
  223.     'In a "real-world" application the icon would
  224.     'not be randomly generated, and we would keep track
  225.     'of which icon had which ID number.
  226.     '---------------------------------------------------
  227.     iIconUsed = iIconUsed + 1
  228.     If iIconUsed = 5 Then
  229.         iIconUsed = 1
  230.     End If
  231.     hIcon = ImageList1.ListImages(iIconUsed).Picture
  232.     '------------------------------------------------------------
  233.     'Select an ID number for use during callbacks.
  234.     '------------------------------------------------------------
  235.     lIconAdded = lIconAdded + 1
  236.     sTip = "This is icon number " & CStr(lIconAdded)
  237.     TaskBr.AddIcon lIconAdded, sTip, hIcon
  238. End Sub
  239. Private Sub Command2_Click()
  240.     '--------------------------------------------------------
  241.     'This routine changes the text a user will see when placing
  242.     'the mouse over a tray icon.
  243.     '--------------------------------------------------------
  244.     Dim sTip$
  245.     Dim lID&
  246.     lID = Val(InputBox("Icon ID Number", , ""))
  247.     If lID = 0 Then
  248.         Exit Sub
  249.     End If
  250.     sTip = InputBox("New text", , "This is a test")
  251.     If Len(sTip) > 63 Then sTip = Left$(sTip, 63)
  252.     TaskBr.ChangeMessage lID, sTip
  253. End Sub
  254. Private Sub Command3_Click()
  255.     '--------------------------------------------------
  256.     'This routine demonstrates changing the icon under
  257.     'program control.
  258.     'Icon modification would routinely be used as a status
  259.     'indicator.  For example, the Win95 Dial-Up utility
  260.     'places a modem with read and send indicators that cycle
  261.     'between red and green.
  262.     '--------------------------------------------------
  263.     Dim lID&
  264.     Dim hIcon&
  265.     lID = Val(InputBox("Icon ID Number", , ""))
  266.     If lID = 0 Then
  267.         Exit Sub
  268.     End If
  269.     iIconUsed = iIconUsed + 1
  270.     If iIconUsed = 5 Then
  271.         iIconUsed = 1
  272.     End If
  273.     hIcon = ImageList1.ListImages(iIconUsed).Picture
  274.     TaskBr.ChangeIcon lID, hIcon
  275. End Sub
  276. Private Sub Command4_Click()
  277.     '-------------------------------------------
  278.     'Deletes an Icon
  279.     '-------------------------------------------
  280.     Dim lID&
  281.     lID = Val(InputBox("Icon ID Number", , ""))
  282.     If lID = 0 Then
  283.         Exit Sub
  284.     End If
  285.     TaskBr.DeleteIcon lID
  286. End Sub
  287. Private Sub Command5_Click()
  288.     Unload Me
  289. End Sub
  290. Private Sub Form_Load()
  291.     Dim lVerNum&
  292.     Dim iVerWord%
  293.     Dim iVersNum%
  294.     Dim iTrueVers%
  295.     '-----------------------------------------------------
  296.     'First we find out what Windows is running.  This will
  297.     'not work with NT 3.5 and earlier.
  298.     '-----------------------------------------------------
  299.     OsVers.dwVersionInfoSize = 148&
  300.     lTempLong = GetVersionEx(OsVers)
  301.     Select Case OsVers.dwPlatform
  302.         Case VER_PLATFORM_WIN32_NT
  303.             iTrueVers = OsVers.dwMajorVersion * 100 + OsVers.dwMinorVersion
  304.             Select Case iTrueVers
  305.                 Case Is < 351
  306.                     MsgBox "This program will not work on NT versions earlier then 3.51"
  307.                     Unload Form1
  308.                     Exit Sub
  309.                 Case 351
  310.                     'Program has not been tested thoroughly with NT 3.51.  Should
  311.                     'not crash, but definitely requires NewShell to work.
  312.             End Select
  313.         Case VER_PLATFORM_WIN32_WINDOWS
  314.             'Windows 95 - we're OK
  315.         Case Else 'Shouldn't happen
  316.             MsgBox "This program is intended only for use with 32-bit Windows versions."
  317.             Unload Form1
  318.     End Select
  319.      
  320.     '---------------------------------------------------------
  321.     'Check for presence of Taskbar.  The user may have a different
  322.     'Shell that doesn't support one.
  323.     '---------------------------------------------------------
  324.     If TaskBr.AppBarExists <> 1 Then
  325.         MsgBox "There is no tray currently available"
  326.         Unload Form1
  327.         Exit Sub
  328.     End If
  329.     '----------------------------------------------------------
  330.     'Enable the MsgHook control to receive callbacks from the taskbar
  331.     '----------------------------------------------------------
  332.     Msghook1.HwndHook = Me.hWnd
  333.     Msghook1.Message(TaskBr.Message) = True
  334.     '-------------------------------------------------------------
  335.     'The MsgHook control used with this sample is MSGHOO32.OCX.
  336.     'Originally supplied with the Waite Group's "Visual Basic 4 HOW-TO"
  337.     'book, but now freeware.  Many thanks to the author of MSGHOO32,
  338.     'Zane Thomas, Mabry Software, and Waite Group Press.  You will need
  339.     'to obtain this control prior to running the sample.  It can be found
  340.     'on Compuserve in the VBPJFO forum; from Zane's web page at
  341.     'http://activexpert.com/msghook.htm: from the author's web page at
  342.     'http://www.redshift.com/~arcatpet/vb.html.
  343.     '--------------------------------------------------------------
  344.     command1.Caption = "Add Icon"
  345.     command2.Caption = "Tooltip Text"
  346.     command3.Caption = "Change Icon"
  347.     command4.Caption = "Delete Icon"
  348.     TaskBr.hWnd = Me
  349. End Sub
  350. Private Sub Form_Unload(Cancel As Integer)
  351.     TaskBr.RemoveAllIcons (lIconAdded)
  352. End Sub
  353. Private Sub MsgHook1_Message(ByVal msg&, ByVal wparam&, ByVal lparam&, result&)
  354.     '--------------------------------------------------------------------------
  355.     'Using the TaskBar Tray for any purpose other than signaling requires that
  356.     'we be able to receive messages generated by the system when there are mouse
  357.     'events associated with the Notification Area icons.  The only way to receive these
  358.     'messages in VB4/32 is with a message handling OCX.  There is not one
  359.     'supplies with this example at this time.  All of the code is present to
  360.     'use MSGHOO32.OCX, which is included with the Waite Group's Visual Basic 4
  361.     'How To book.  To use that control, place an instance of it on this form and
  362.     'remove the commenting in the Form_Load event.  To use another control
  363.     'such as MsgBlaster.OCX you will need to alther the code to meet the parameters
  364.     'of that code.
  365.     '---------------------------------------------------------------------------
  366.     '--------------------------------------------------------------------------
  367.     'These are all of the possible messages sent to our program from the
  368.     'TaskBar Notification Area icons.
  369.     '--------------------------------------------------------------------------
  370.     Select Case msg
  371.       Case TaskBr.Message
  372.         label4 = wparam
  373.         Select Case lparam
  374.             Case WM_MOUSEMOVE
  375.                 label2 = "MOUSEMOVE"
  376.             Case WM_RBUTTONDBLCLK
  377.                 label2 = "RBUTTONDBLCLK"
  378.             Case WM_RBUTTONDOWN
  379.                 label2 = "RBUTTONDOWN"
  380.             Case WM_RBUTTONUP
  381.                 label2 = "RBUTTONUP"
  382.             Case WM_MBUTTONDBLCLK
  383.                 label2 = "MBUTTONDBLCLK"
  384.             Case WM_MBUTTONDOWN
  385.                 label2 = "MBUTTONDOWN"
  386.             Case WM_MBUTTONUP
  387.                 label2 = "MBUTTONUP"
  388.             Case WM_LBUTTONDBLCLK
  389.                 label2 = "LBUTTONDBLCLK"
  390.             Case WM_LBUTTONDOWN
  391.                 label2 = "LBUTTONDOWN"
  392.             Case WM_LBUTTONUP
  393.                 label2 = "LBUTTONUP"
  394.         End Select
  395.         Timer1.Enabled = True
  396.   End Select
  397. End Sub
  398. Private Sub Timer1_Timer()
  399.     '-------------------------------------
  400.     'Used to blank the message labels after
  401.     'a short period.
  402.     '-------------------------------------
  403.     label2 = ""
  404.     label4 = ""
  405.     Timer1.Enabled = False
  406. End Sub
  407.