Announcement

Collapse
No announcement yet.

Mouse Position

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mouse Position

    I use this code frequently, even inside messages received by the CallBack function. It's easy to remember and works just fine.

    Code:
    GetCursorPos pt : ScreenToClient hDlg, pt
    But what I don't do very often is extract the mouse location from the message parameters, like these examples:

    Code:
    Local pt as Point
    
    Case %WM_ContextMenu
       pt.x = Lo(Integer,Cb.LParam) : pt.y = Hi(Integer, Cb.LParam)
    
    Case %WM_MouseMove 'returns client coordinates
       pt.x = Lo(Integer,CB.lParam) : pt.y = Hi(Integer,CB.lParam)
    
    Case %WM_LButtonUp
       pt.x = Lo(Integer,CB.LParam) : pt.y = Hi(Integer,Cb.LParam)
    
    Case %WM_LButtonDown
       pt.x = Lo(Integer,Cb.LParam) : pt.y = Hi(Integer,Cb.LParam)
    For all of the possible mouse notifications, can the mouse location be found in exactly the same way? Or, do the various mouse/button/cursor notifications sometimes provide the position in different ways?

    The question would be then, do anyone have something that documents all of the various ways to get the mouse position? My snippets library doesn't have a consolidation, just examples in a variety of snippets.

  • #2
    Somewhere in that discussion is that the position from the message is the position when the event took place (such as an LButtonUp) whereas GetCursorPos may not exactly match because it is the position "right now" vs the earlier position at the time of the preceding event.

    I can't say as I've had a problem in an app from such a difference - at least, not one that I paid attention to.

    Comment


    • #3
      Not sure I undestand, but while not often used, I think %WM_MOUSEWHEEL - Lo(Word, Cb.LParam) and Hi(Word, Cb.LParam) returns x/y pos relative to screen (not client, like most other mouse messages). Just like GetCursorPos.

      Added - same with %WM_NCHITTEST and all %WM_NC..(non client) messages - gives pos relative to screen too.

      Comment


      • #4
        or all of the possible mouse notifications, can the mouse location be found in exactly the same way? Or, do the various mouse/button/cursor notifications sometimes provide the position in different ways?
        PART I



        PART II
        The question would be then, do anyone have something that documents all of the various ways to get the mouse position?
        The general way is what you are doing... GetCursorPos() at any time. If you really need the mouse coordinates when processing a particular notification message, see Part I and if mouse position is not part of the notification message's parameters, use the general method by calling GetCursorPos()

        Also don't forget WindowFromPoint() and ChildWindowFromPoint() once you have used GetCursorPos().

        I trust you seriously were not expecting someone to go thru the parameters supplied by every possible notification message looking for those which include mouse coordinates. But then I would tell you.. just track WM_MOUSEMOVE yourself. Unless you were interested on the mouse position at any time regardless of the location or what window it was over.. then you install a Windows hook (SetWindowsHookEx()) of type WH_MOUSE.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Howdy, MCM!

          You disappoint me again. Your lack of philanthropy on a forum as giving as this one puts you on the fringe as usual.

          Rather than respond to what I asked, you created a false narrative. I didn't ask someone to go do anything. I asked if someone already had such a summary.

          That kind of task is what I actually do for for folks in my gbSnippets library and in my online posts. I take code I've written and summarize the information to help folks more easily find code that might solve a problem or to help them understand possible solutions. If you had read my Reference Materials in the gbSnippets library you'd have seen how sometimes folks go to significant personal effort to generate information that other folks can use.

          Unlike you, I and other folks are happy to share our experiences and code that we've already taken the time to generate. For that matter, I often respond to folks and generate code at their request simply because I enjoy creating new solutions and because I enjoy helping document information that others who come will find useful.

          I find your attitude disappointing and would hope that you consider upgrading your approach to helping folks in a more friendly, giving way. If you chose not to be helpful then it is of course up to you. But disparaging folks who aren't so tight with their help diminishes you and all of us on the forum.

          Comment


          • #6
            Rather than respond to what I asked, you created a false narrative. I didn't ask someone to go do anything. I asked if someone already had such a summary.
            Don't ever call me pedantic again.

            Besides, you should be asking for what you want to accomplish and suggestions for how to do it. .... actually in this case you should be thanking me for showing you additional ways to accomplish what appears to be that which you wish to accomplish.

            Unlike you, I and other folks are happy to share our experiences and code that we've already taken the time to generate
            Really?

            Please do a search of the "Source Code Library" forum for author "Michael Mattias" selecting " Show threads started by member." I think five pages - with commented code - qualifies as "sharing." (Yes, that is my subjective opinion).


            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              Really?

              Please do a search of the "Source Code Library" forum for author "Michael Mattias" selecting " Show threads started by member." I think five pages - with commented code - qualifies as "sharing." (Yes, that is my subjective opinion).
              A total of three posts in the last 10 years, all just modifications of 20 -odd year old code?





              Comment


              • #8
                The fact that many of my contributtions were made in PowerBASIC's formative years does not mean I have not shared (the proximate cause of my ire).

                And as you yourself often comment, I still refer some questioners to those posts.

                But as I hope you and others understand, I have a very firm opinion on "writing your code for you" and that opinion is, I don't. I consider it an essential programming skill to be to take principles and adapt to the latest versions of the compilers.

                And frankly the fact I still refer people to 20+ year old posts should tell you just how well-written, well-documented and useful those posts have been - and still are.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment

                Working...
                X