This sample application demonstrates general procedures for
Submitted By:
Unknown
Rating:
(Not rated) (
Rate It)
OPTION Explicit
'------------------------------------------------------------
'This sample application demonstrates general procedures for
'installing and maintaining an icon in the Win95 toolbar tray
'from a VB3 program using CALL32.DLL to thunk the
'necessary 32-bit calls. Requires that CALL32.DLL be present
'in order to work properly. Written 8/95 by Don Bradner and
'placed in the public domain. Comments welcome to the author at
'Compuserve 76130,1007 or in the CIS VBPJ Forum. The author may
'also be contacted at [[Email Removed]] - http://www.redshift.com/~arcatpet
'------------------------------------------------------------
'Modified 9/95 to include MsgHook.VBX for callbacks.
'------------------------------------------------------------
'Modified 3/96 to work with NT 4.0 (May also work with NT 3.51
'with the "New Shell" but not tested). The earlier versions of
'this demo used icons embedded into forms and controls (dragicons).
'The handle which VB returns for these icon properties is an integer
'value, which in NT is strictly a local handle that cannot be
'passed to other processes. Various attempts to convert these
'local handles to usable global handles were unsuccessful. This
'sample now uses the 32-bit ExtractIcon function to get a long hIcon
'for an icon extracted from a file. The sample uses .ICO files, but
'it will work with single or multiple icons contained in .DLLs and
'.EXEs as well, if you know what you are after. Could be used to pull
'one of the icons out of Explorer, for example. If anyone has an
'answer to the local/global conversion problem I would like to
'hear about it.
' -----------------------------------------------------------
' NOTIFYICONDATA type is needed for Shell_NotifyIcon function
'------------------------------------------------------------
TYPE NOTIFYICONDATA
lStructureSize AS LONG
hWnd AS LONG
lID AS LONG
lFlags AS LONG
lCallBackMessage AS LONG
hIcon AS LONG
sTip AS STRING * 64
END TYPE
TYPE lRect
Left AS LONG
Top AS LONG
Right AS LONG
Bottom AS LONG
END TYPE
TYPE APPBARDATA
lStructureSize AS LONG
hWnd AS LONG
lCallBackMessage AS LONG
lEdge AS LONG
rc AS lRect
lParam AS LONG
END TYPE
'----------------------------------------------------------------------
'The OsVersionInfo structure is used by the 32-bit GetVersionEx Function
'----------------------------------------------------------------------
TYPE OsVersionInfo
dwVersionInfoSize AS LONG
dwMajorVersion AS LONG
dwMinorVersion AS LONG
dwBuildNumber AS LONG
dwPlatform AS LONG
szCSDVersion AS STRING * 128
END TYPE
' --------------------------------------------------------
' Declare32 is a general function required for call32.dll use
' --------------------------------------------------------
DECLARE FUNCTION Declare32& Lib "call32.dll" (BYVAL func$, BYVAL library$, BYVAL args$)
' --------------------------------------------------------
' 32-bit registry functions in Call32 format:
' --------------------------------------------------------
DECLARE FUNCTION Shell_NotifyIcon& Lib "call32.DLL" ALIAS "call32" (BYVAL lMessage&, NID AS NOTIFYICONDATA, BYVAL id&)
DECLARE FUNCTION SHAppBarMessage& Lib "call32.DLL" ALIAS "call32" (BYVAL dwMessage&, pData AS APPBARDATA, BYVAL id&)
DECLARE FUNCTION GetVersionEx& Lib "call32.dll" ALIAS "call32" (lpStruct AS OsVersionInfo, BYVAL id&)
DECLARE FUNCTION ExtractIcon& Lib "call32.dll" ALIAS "call32" (BYVAL hInst&, BYVAL lpszExeFileName$, BYVAL IconIndex&, BYVAL id&)
DECLARE FUNCTION DestroyIcon& Lib "call32.dll" ALIAS "call32" (BYVAL hIcon&, BYVAL id&)
' --------------------------------------------------------
' Functions to determine what Windows we are running
' --------------------------------------------------------
DECLARE FUNCTION GetWinFlags& Lib "Kernel" ()
DECLARE FUNCTION GetVersion& Lib "Kernel" ()
'---------------------------------------------------------
'Function needed to get instance for use with ExtractIcon.
'The 16-bit function will work.
'---------------------------------------------------------
DECLARE FUNCTION GetClassWord% Lib "User" (BYVAL hWnd%, BYVAL nIndex%)
Global idShell_NotifyIcon&
Global idSHAppBarMessage&
DIM idGetVersionEx&
Global idExtractIcon&
Global idDestroyIcon&
DIM OsVers AS OsVersionInfo
Global CONST NIM_ADD = 0&
Global CONST NIM_DELETE = 2&
Global CONST NIM_MODIFY = 1&
Global CONST NIF_ICON = 2&
Global CONST NIF_MESSAGE = 1&
Global CONST NIF_TIP = 4&
Global CONST ABM_GETTASKBARPOS = &H5&
Global structNotify AS NOTIFYICONDATA
Global structBarData AS APPBARDATA
Global lTempLong&
Global CONST GCW_HMODULE = -16
' --------------------------------------------------------
' Used with GetVersion and GetWinFlags
' --------------------------------------------------------
Global CONST WF_WINNT = &H4000&
Global CONST WinNT = 3
Global CONST Win32 = 2
Global CONST win16 = 1
Global iWinVers%
Global hInstance%
'----------------------------------------------------------
'This sample application implements callbacks via the MsgHook
'message handling control. Windows will generate a User
'Message with an lParam that identifies a mouse event, such
'as WM_MOUSEMOVE, and the wParam will contain the icon number.
'If the application installs more than one icon, each must be
'given a unique ID number.
'-----------------------------------------------------------
CONST WM_USER = &H400
Global CONST UM_TASKBARMESSAGE = WM_USER + &H201
'-----------------------------------------------------------
'The 10 available mouse events:
'-----------------------------------------------------------
Global CONST WM_MOUSEMOVE = &H200
Global CONST WM_LBUTTONDOWN = &H201
Global CONST WM_LBUTTONUP = &H202
Global CONST WM_LBUTTONDBLCLK = &H203
Global CONST WM_RBUTTONDOWN = &H204
Global CONST WM_RBUTTONUP = &H205
Global CONST WM_RBUTTONDBLCLK = &H206
Global CONST WM_MBUTTONDOWN = &H207
Global CONST WM_MBUTTONUP = &H208
Global CONST WM_MBUTTONDBLCLK = &H209
FUNCTION GetVersion32% ()
idGetVersionEx = Declare32("GetVersionEx", "kernel32", "p")
OsVers.dwVersionInfoSize = 148&
lTempLong = GetVersionEx(OsVers, idGetVersionEx)
GetVersion32 = OsVers.dwMajorVersion * 100 + OsVers.dwMinorVersion
END FUNCTION