count mouse clicks
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: count mouse clicks

  1. #1
    Join Date
    Feb 2013
    Posts
    29

    count mouse clicks

    Hi everyboby,

    i'm a begginer in C++ so plz forgive my lack of knowledge. I've been trying for 3days now to understand how to manage mouse events in C++ but in vain. i've tried searching the web but almost everything was out of date with headers no longer in use and mainly dealing with the possition of the mouse rather than the clicks. i even tried the msdn tutorials with no luck there either...i want to make a program that counts the 3 mouse buttons clicks but i don't even know how to count the left button clicks so... can someone provide me with the needed knowledge. eventually the final program would be a form that counts clicks and return some results based on them. for any further info plz let me know. thanks in advance for your time!!!

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,742

    Re: count mouse clicks

    Are you programming for Windows? In the WIN32 API there are three mouse events that indicate when a mouse button has been pressed - WM_LBUTTONDOWN, WM_MBUTTONDOWN and WM_RBUTTONDOWN. These are received through the main windowproc function.

  3. #3
    Join Date
    Feb 2013
    Posts
    29

    Re: count mouse clicks

    Yes, i'm aware of these commands i've seen them in msdn, but i dont know how to use them right, what headers to include etc. can you please be a little bit more enlightening...

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,204

    Re: count mouse clicks

    Quote Originally Posted by The_Sire View Post
    Yes, i'm aware of these commands i've seen them in msdn, but i dont know how to use them right, what headers to include etc. can you please be a little bit more enlightening...
    You're asking how to write Windows programs in a forum. The reply is usually found in books containing 1,000 pages or more. I'd suggest you start with one of them,

  5. #5
    Join Date
    Feb 2013
    Posts
    29

    Re: count mouse clicks

    oh, come on don't be so mean... this should take less than 3 min to someone who is familiar with this kind of things. I just want the right direction and help since i'm new in this and i don't understand msdn tutorials on mouse events. if you think that you can't help me it's ok.thanks for you time mate!!! if some one has a similar program with comments that would help me just enought!

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,204

    Re: count mouse clicks

    Quote Originally Posted by The_Sire View Post
    oh, come on don't be so mean... this should take less than 3 min to someone who is familiar with this kind of things. I just want the right direction and help since i'm new in this and i don't understand msdn tutorials on mouse events. if you think that you can't help me it's ok.thanks for you time mate!!! if some one has a similar program with comments that would help me just enought!
    I am familiar with "this kind of things", and I'm serious. The reason you don't understand the tutorials is because you don't understand Windows programming in general and it takes more than three minutes to explain and learn Windows programming. I'm not being mean, I'm being honest.

  7. #7
    Join Date
    Jul 2002
    Posts
    2,521

    Re: count mouse clicks

    Create Windows Application using Visual Studio Application Wizard. Find WindowProc or WndProc function in the code generated by the Wizard. This is the function that handles Windows messages. It contains several "case WM_..." lines. Add your own lines for WM_LBUTTONDOWN, WM_MBUTTONDOWN and WM_RBUTTONDOWN messages and increment click counters there. If something goes wrong, ask another, more specific question, post the code you have and describe what is the problem exactly.

  8. #8
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,742

    Re: count mouse clicks

    GCDEF is not being mean. The most simple Win32 program to just display a window and nothing else takes about 40 lines of code by the time you have registered a class, created the window, have the mesage pump and the callback function for the windows messages. How to do this must be learnt - not from a forum like this. If you have problems with some code that you post here we will most certainly try to help - but we can't write the programs for you from scratch.

    Within the windows callback function you need something like this

    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
          	switch (message) {
               case WM_LBUTTONDOWN:
                        ....
                        break;
    
               case WM_RBUTTONDOWN:
                        ....
                        break;
    
         .......
    }
    If this is not familiar then you really, really need to learn windows programming from the beginning. I would suggest

    Programming Windows 5th Edition Book/CD Package: The definitive guide to the Win32 API (Microsoft Programming Series) Charles Petzold
    http://www.amazon.co.uk/Programming-...0245454&sr=1-5

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,204

    Re: count mouse clicks

    Quote Originally Posted by 2kaud View Post

    If this is not familiar then you really, really need to learn windows programming from the beginning. I would suggest

    Programming Windows 5th Edition Book/CD Package: The definitive guide to the Win32 API (Microsoft Programming Series) Charles Petzold
    http://www.amazon.co.uk/Programming-...0245454&sr=1-5
    Unless you're a real masochist, I wouldn't recommend learning old-school Windows style programming. MFC at least hides some of the really ugly stuff from you. .Net hides even more. I've never written an app using nothing but the API, and I don't think I've missed much.

  10. #10
    Join Date
    Feb 2013
    Posts
    29

    Re: count mouse clicks

    thanks guys! I'll do that and i'll came back this some code...
    Last edited by The_Sire; February 7th, 2013 at 09:33 AM.

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,050

    Re: count mouse clicks

    Quote Originally Posted by The_Sire View Post
    oh, come on don't be so mean... this should take less than 3 min to someone who is familiar with this kind of things.
    Now try to think about the situation from my standpoint. Yes, I'm familiar with this kind of things. But I know nothing about you. I can compose a demo at least three different ways (and BTW none of those would take less than 30 minutes, trust me as I know the subject and I'm not a magician). As I said, I know nothing about how much you're prepared to perceive any, so you definitely make me guess, which I hate to do without serious reasons for that. Finally, I'm facing with the choice between posting something that is going to be most probably useless to the ultimate purpose, or just suggest you to learn basics of asking questions unambiguous way (what knowledge comes along with gaining experience, learning subject, technical vocabulary, etc.) Guess what my choice would be.
    Best regards,
    Igor

  12. #12
    Join Date
    Feb 2013
    Posts
    29

    Re: count mouse clicks

    Quote Originally Posted by Igor Vartanov View Post
    Now try to think about the situation from my standpoint. Yes, I'm familiar with this kind of things. But I know nothing about you. I can compose a demo at least three different ways (and BTW none of those would take less than 30 minutes, trust me as I know the subject and I'm not a magician). As I said, I know nothing about how much you're prepared to perceive any, so you definitely make me guess, which I hate to do without serious reasons for that. Finally, I'm facing with the choice between posting something that is going to be most probably useless to the ultimate purpose, or just suggest you to learn basics of asking questions unambiguous way (what knowledge comes along with gaining experience, learning subject, technical vocabulary, etc.) Guess what my choice would be.
    ok, i understand that what i said about the 3 mins was excessive. i take it back, even thought i didn't ask anyone to write the code for me (that would be at least crazy) but to point me to the right directions. if you do that and realize that i'm not trying to understand and just waiting for the answer to come with no efford you can stop helping. but i believe that some code (even not the exact solution) is better than no code.

  13. #13
    Join Date
    Apr 1999
    Posts
    27,444

    Re: count mouse clicks

    Quote Originally Posted by The_Sire View Post
    ok, i understand that what i said about the 3 mins was excessive. i take it back, even thought i didn't ask anyone to write the code for me (that would be at least crazy) but to point me to the right directions. if you do that and realize that i'm not trying to understand and just waiting for the answer to come with no efford you can stop helping. but i believe that some code (even not the exact solution) is better than no code.
    There are two hurdles, not just one.

    First, you must be competent in C or C++ programming, regardless of whether you want to process keystrokes. In other words, if you're coming back to CodeGuru asking basic C/C++ questions, then you're really not competent enough to tackle Windows programming. Sorry to be blunt about it, but that's the way it is. Reading and understanding the Windows API assumes you know how to use the C++ language already. In this forum, we come across too many people who do not know C++ properly, and screw up the most basic Windows program due to lack of knowledge of C++ itself.

    Second, even if you are competent in C/C++ programming, heck, you could be a professional programmer in these languages for decades, that does not make you a Windows programmer. This is the point that is being made by the others here. Learning Windows programming, even for a professional, non-Windows programmer, takes time to learn. That's why the Windows programming books are hundreds, if not thousands of pages, and are not 3 or 4 page pamphlets or cheat sheets you would find for, say, HTML commands.

    If Bjarne Stroustrup (the inventor of C++) never coded a Windows application, even he would need to read books on how to get started in writing one.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; February 7th, 2013 at 11:24 AM.

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,050

    Re: count mouse clicks

    Quote Originally Posted by The_Sire View Post
    but i believe that some code (even not the exact solution) is better than no code.
    Here you go.
    Attached Files Attached Files
    Best regards,
    Igor

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center