Re: Point me in the right direction - Mouse utility...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The only way I know of to capture mouse clicks that way is to use global
hooks and write a C++ DLL to handle the code that catches the click, and
then forward it to your form. There maybe an ActiveX out there if you can't
make a C++ DLL, but make sure that it support global hooks. While a hook
procedure can reside in an EXE, a global hook requires a DLL to work
correctly. If you use SetWindowsHookEx and point the hook procedure to your
EXE, the function will return success, but it will monitor only the threads
in your process(EXE).

API functions to check:

SetWindowsHookEx
GetCursorPos
WindowFromPoint
SetForegroundWindow

Messages:

WM_NCMBUTTONUP
WM_MBUTTONUP

To display your menu, you could use the following VB6 code. It's what others
are using to display a popup menu when someone clicks on a tray icon.

PopupMenu mnuFile, , x, y

> - Middle-clicking the list will just close it.

I don't know if this is supported by VB6. You may have to use subclassing or
the hook procedure.

> - Right-clicking the list will pop up a context menu to access settings,
> exit the app, etc.

It's better to use a try icon for this, or a menu item "More...", otherwise
you have to make more special coding.

> - will "type" that entry into the currently selected point in the current
> application.

Use Clipboard.SetText to paste the text. Note that 3rd party apps are not
uniform, you can't use WM_SETTEXT with some applications. WM_SETTEXT can be
used to set some simple controls in 3rd party apps, like Labels and
TextBoxes, but it doesn't work on grids for example, and some applications
hide the details of the controls inside them so you can't easily get the
hWnd for them, this includes EnumWindows and EnumChildWindows. IE for
instance hides the controls that it displays on web pages. For example, you
can't paste a text other than by using the clipboard or via IE Automation.

Finally, global hook DLL's don't unload immediately when you uninstall the
hook, sometimes the DLL stays in memory until you reboot. Also, any bugs in
the hook will crash any of your applications, including the IDE, so they are
not easy to develop. Keep the hook as simple as possible and use PostMessage
to send information to your form(which is subclassed). Don't use SendMessage
unless you are sure that your message will be processed quickly. SendMessage
doesn't return to the originating app until the recipient finishes
processing the message(reached End Sub/Function), including waiting for a
user to click on a MsgBox.


"Noozer" <dont.spam@xxxxxxx> wrote in message
news:AcY1f.111295$1i.18146@xxxxxxxxxxx
> I've been looking for a simple utility to take advantage of my scrolling
> third button but have not been able to find what I'm looking for. I'm
> considering writing my own using VB6...
>
> What I simply want to do is:
> - Capture any middle click events
> - When a click occurs, display a list of items that the user can scroll
> through
> - Left-clicking on an item will "type" that entry into the currently
> selected point in the current application.
> - Middle-clicking the list will just close it.
> - Right-clicking the list will pop up a context menu to access settings,
> exit the app, etc.
> - I want to do this throughout Windows, not within a single or specific
> application. It would be nice if I could detect the currently active
> application and/or the application where the mouse was clicked over so I
> could present a list of items relative to that application.
>
> ... so, where would I start with this? It should be a piece of cake to
> write, once I figure out how to capture the mouse events from anywhere in
> Windows.
>
> Alternatively, does anyone know of an existing utility that can do this?
>
> Thanks!
>


.



Relevant Pages

  • Re: Install a keyboard hook in service app
    ... First we need to call the SetWindowsHookExto install the Keyboard ... hook, U must be passing the hook callback function. ... My service was in a simple DLL containing this keyboard hook operation. ... I did in my service app, SetWindowHook seemly is ok, but the hook func ...
    (microsoft.public.windowsce.embedded)
  • Re: Using Visual Basic to Write System-Wide Hooks
    ... >I've spent about an hour looking into writing a system-wide hook using only ... a system-wide callback function must be located within a DLL. ... >system-wide hook DLL. ... The reason is that Visual Basic has some large runtime ...
    (microsoft.public.vb.winapi)
  • Re: SetWindowsHookEx and Itanium
    ... DLL server doesn't guarantee that hooks from 64-bit processes can be seen, ... normal hook methodology is to inject the DLL into the process being ... example, if I have a SendMessage hook, referenced to a 32-bit DLL, it can ... app, and injected into the target 32-Bit process when I call InstallHook. ...
    (microsoft.public.vc.mfc)
  • Re: Preventing a program from gaining the focus with a CBT hook
    ... Giving focus back to the losing window... ... Hooks being intrusive / DLL unload issues... ... Why not "memset(caption, 0, sizeof(caption))"? ... It is easy to forget how utterly intrusive a system hook is. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: SetWindowsHookEx
    ... automatically inject into all programs. ... It sets the global hook on the ... DLL injecting - in all likelyhook SetWindowsHook returns before the DLL has ... with your shared-section, then the gHook variable (which contains ...
    (microsoft.public.vc.language)