Results 1 to 16 of 16

Thread: Need help on integrating a program with the desktop

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    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:
    1. Private Sub Form_DblClick()
    2. pctBox.Picture = clppicture.GraphicCell(1)
    3. End Sub
    4.  
    5. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6.  
    7. If Button = vbLeftButton Then
    8. pctBox.Picture = clppicture.GraphicCell(Button)
    9. ElseIf Button = vbRightButton Then
    10. pctBox.Picture = clppicture.GraphicCell(Button)
    11. End If
    12. End Sub
    13.  
    14. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    15. Button = 0
    16. pctBox.Picture = clppicture.GraphicCell(Button)
    17. End Sub

    Any help whould be appreciated

    thanks



    Edit: Added [vbcode][/vbcode] tags for clairty. - Hack
    Last edited by Hack; Sep 14th, 2005 at 12:13 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

    What do you want your program to do?

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    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

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Need help on integrating a program with the desktop

    You might put a few icons in pictureboxes in your form. I'm not sure that you could have your code respond to Windows events.

    Well, if they don't like to draw, then show them the Solitaire game. Most everyone likes a game!

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    Re: Need help: making the code respond to windows events

    Well, if it can't be done with VB any idea what (simple) programming language I can use to do that?

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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?

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    Re: Need help on integrating a program with the desktop

    Quote 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.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Need help on integrating a program with the desktop

    What do you want them to be able to do to the icons?

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    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.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Need help on integrating a program with the desktop

    You would need a mouse hook to capture all mouse events. I'll whip up a demo for ya

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    Re: Need help on integrating a program with the desktop

    Quote Originally Posted by penagate
    You would need a mouse hook to capture all mouse events. I'll whip up a demo for ya
    That whould be great. Thanks

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  13. #13

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    Re: Need help on integrating a program with the desktop

    Quote 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.

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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

    Attached Files Attached Files

  15. #15

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    8

    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.
    Attached Files Attached Files

  16. #16
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Need help on integrating a program with the desktop

    No worries

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width