MWATCH.DLL DLL to monitor the position of the mouse and provide dynamic feedback to the VB programmer, primarily in the context of providing a status bar for the user. By Jonathan Zuck Copyright 1992 User Friendly, Inc. and Jonathan Zuck Liscence: You are hearby liscensed to use MWATCH.DLL freely within your own programs, paying no royalties to UFI or Jonathan Zuck. There is only one caveat: IF YOU DISTRIBUTE YOUR SOURCE, you MUST also distribute this text file, explaining the usage of the DLL. The Problem: A number of people have asked for a way to provide a status bar for the user, depending on the position of the mouse. There are two aspects to this. First, it is necessary to know when a menu item has been highlighted by the user (althought not yet selected). Both MS EXCEL and MS WORD for WINDOWS provide a short help prompt depending on which menu item is highlighted. The second part of this task is to provide some help prompt when the mouse is hovering over a particular control. While the Mouse_Enter event is available under HyperCard and Toolbook, it is missing from VB (and from Windows, in general). The Solution: As you might guess, MWATCH.DLL is the solution!...or at least a partial one. Once you register your Form with MWATCH, a Form_KeyDown event will be triggered every time the cursor is someplace different, either over a new control or in a menu. If the cursor has been moved over a control, the hWnd of that control is passed to the _KeyDown event in the KeyCode parameter. If a menu item has been selected than the Menu ID of that menu item is passed as a negative number in the KeyCode parameter. The Cursor Enters a Control: Once the cursor moves over a control, the Form_KeyDown event is triggered with the hWnd of the control in the KeyCode parameter, as noted above. You can determine the hWnd of various controls at start-up, using various methods, including my CTLHWND.DLL and then use a Select Case loop to determine the help text to display. Alternatively, MWATCH also exports a couple of useful utility functions to assist you: HWndCtlName and HWndTag. HWndCtlName$ will return the name of a control, given its hWnd and HWndTag will return the text in the .Tag property of the passed hWnd. Using this technique, you can either used a Select Case loop through the CtlName's to determine the help text or, if you don't need the .Tag property for something else, the easiest thing is to put your help text in the .Tag property and simply use HWndTag to retrieve this text at run-time. Please see the sample app MENTER.MAK for demonstrates of these functions in context. The Cursor Enters a Menu: Once the cursor highlights a menu item (or it is triggered with the keyboard), the Form_KeyDown event is triggered with the MenuId in in the KeyCode parameter. Once again, you can check these once when you are finished designing your menu because they will be the same (except for the top-level menu heading) every time the app is run. You could then set up a Select Case statement to check KeyCode against various MenuIds. Alternatively, MWATCH exports a function called: MenuCaption. The MenuCaption$ function takes a MenuId as a parameter and returns the caption of the menu item. See MENTER.MAK for an example of this function in use. PLEASE NOTE: the MenuCaption function was written specifically for this DLL to save you calling a bunch of Windows API functions and it WILL NOT work outside of your Form_KeyDown handler! The HWndCtlName and HWndTag functions can be used in other contexts but this is NOT THE CASE with the MenuCaption function. Also, at this point, MWATCH doesn't generate an event when the user is in the system (or control) menu. I was just lazy. If a lot of people request it, I can add it. People Using HOTKEY.DLL Many of you are using HOTKEY.DLL (which makes me happy, of course!) and you are using your Form as the "hotkey handler." Since HOTKEY gives you a choice of hWnd's and MWATCH does not, you will need to copy your current Form_KeyDown code to a hidden Picture Box or something, if you want to use both DLLs. Hope you find this useful! Enjoy! -=- Jonathan Zuck User Friendly, Inc. 1718 M Street, N.W. Suite 291 Washington, DC 20036 (202) 387-1949 (202) 785-3607 FAX 76702,1605 CIS