Need help on integrating a program with the desktop
Hello
I teach basic computer skills and found that some students (people who never used computers before) are having trouble "mastering" basic mouse functions such as drag and drop. For that reason I wrote a very simple program that whould show them on the screen when the mouse mouse buttons are used.
I managed to do that from reading certain tutorials on the internet (I am not a programer) but I couldn't find anything about making it work with the desktop which means showing the mouse on the background (top right of the screen) while using the desktop.
here is the code:
(clppicture is a picture of the 3 mouse states - no button pressed, left button pressed and right button pressed)
VB Code:
Private Sub Form_DblClick()
pctBox.Picture = clppicture.GraphicCell(1)
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
pctBox.Picture = clppicture.GraphicCell(Button)
ElseIf Button = vbRightButton Then
pctBox.Picture = clppicture.GraphicCell(Button)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Button = 0
pctBox.Picture = clppicture.GraphicCell(Button)
End Sub
Any help whould be appreciated
thanks
Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
Re: Need help on integrating a program with the desktop
Welcome to the forums!
What is the problem?
I usually like to let users play with MSPAINT to get acquainted with the mouse. Most people (especially kids) like to draw, and they tend to pick it up quicker, clicking on the control, then using the buttons to draw lines and squares.
My 6 year old niece is getting pretty good at it.
Re: Need help on integrating a program with the desktop
Well actually its the elderly, they never used computers before. Ill give MSpaint a try but I still think it whould be a good idea to demonstrate the button functions using this program.
The program is only working at the moment within a form ,I want it to display the buttons work while Im pressing Icons on the desktop and dragging and droping Icons outside the form, it should run on the background. I just hope its not to complicated
Re: Need help on integrating a program with the desktop
Of course it can be done in VB
Can you clarify the effect you want to achieve? As I understand it you want an on-screen display of the mouse buttons, that reacts to the buttons being pressed, am I correct?
Re: Need help on integrating a program with the desktop
Originally Posted by penagate
Of course it can be done in VB
Can you clarify the effect you want to achieve? As I understand it you want an on-screen display of the mouse buttons, that reacts to the buttons being pressed, am I correct?
Yep, thats correct.. I managed to write a small program that reacts to the buttons within the form, but I have no idea how to make it work on the screen.
(the program should keep running while the user is working with the mouse buttons on the desktop).
Last edited by nirwaiz; Sep 17th, 2005 at 11:48 AM.
Re: Need help on integrating a program with the desktop
Ok I was probably not clear so I'll try to explain it again.
picture1:a picture of a mouse
picture2:a picture of a mouse with the left button pressed
picture3 a picture of a mouse with the right button pressed
at the moment I have a window (or a form) with a picture of a mouse in it (picture1). when I press the left or the right buttons *in the window* picture1 changes to picture2 or picture3 and When I release it goes back to picture 1.
I want it to work when I press buttons outside the window as well
so when I press the mouse buttons anywhere on the desktop (including the taskbar, icons and so on..) my program is still displayed and changing pictures.
Re: Need help on integrating a program with the desktop
Sorry about the delay. I couldn't get the scroll wheel working properly (it can't distinguish between up and down for some reason). But the rest works.
The hooking code itself is in MHookProc.bas, there is a class IMouseHook which is just an interface for classes/forms using the hooking code to implement, and a form demonstrating use of those two modules.
Edit: It can't distinguish between up and down because wParam is used for the WM_MOUSEWHEEL message itself, not the movement as it would be in a WndProc.
Edit: Attachment removed, see corrected version below.
Last edited by penagate; Sep 22nd, 2005 at 11:14 PM.
Re: Need help on integrating a program with the desktop
Originally Posted by penagate
Sorry about the delay. I couldn't get the scroll wheel working properly (it can't distinguish between up and down for some reason). But the rest works.
The hooking code itself is in MHookProc.bas, there is a class IMouseHook which is just an interface for classes/forms using the hooking code to implement, and a form demonstrating use of those two modules.
Edit: It can't distinguish between up and down because wParam is used for the WM_MOUSEWHEEL message itself, not the movement as it would be in a WndProc.
Thanks for the effort, I appreciate it a lot.I compiled it and tested it but unfortunately it still does not interact with the desktop. The program works within the form (window) in the "unhook" mode but it doesn't work outside the form (on the desktop) in the "hooked" mode (or the "unhooked" mode). My goal was to make it work outside the form.
Re: Need help on integrating a program with the desktop
Sorry, I guess I should have tested it a bit more thoroughly It seems a WH_MOUSE hook is thread-local when installed from an application (as opposed to DLL). The easiest way to achieve a global hook in a VB app is to replace it with a journal recording hook which receives all messages before they are directed to specific threads. I've implemented that in the example and it works fine now
Re: Need help on integrating a program with the desktop
Alright!! thats exactly what I needed and it works great.. I gave it a final touch and added some "graphics" so now you can see a picture of a mouse on the screen.. thanks for all the help, this small program will be very useful.