Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Cursor positions

Cursor positions

Scheduled Pinned Locked Moved Managed C++/CLI
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    richiemac
    wrote on last edited by
    #1

    Hi all, I have a form where I want to set some regions. When the mouse moves over these regions I want the cursor image to change. My idea is to set up some rectangles and use the mousemove event (somehow) to check against the current position of the cursor. I just want to know what properties do I need to use for this and is there a better way. I suppose I'm basically asking how I can check if the mouse is over a certain area of a form. Thanks in advance Rich

    S 1 Reply Last reply
    0
    • R richiemac

      Hi all, I have a form where I want to set some regions. When the mouse moves over these regions I want the cursor image to change. My idea is to set up some rectangles and use the mousemove event (somehow) to check against the current position of the cursor. I just want to know what properties do I need to use for this and is there a better way. I suppose I'm basically asking how I can check if the mouse is over a certain area of a form. Thanks in advance Rich

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      Try override event MouseMove to get mouse position. Or use MouseEnter, MouseHover or MouseLeave event to evulate if mouse is in or on certian controls.

      R 1 Reply Last reply
      0
      • S Saksida Bojan

        Try override event MouseMove to get mouse position. Or use MouseEnter, MouseHover or MouseLeave event to evulate if mouse is in or on certian controls.

        R Offline
        R Offline
        richiemac
        wrote on last edited by
        #3

        So I've got a rectangle that defines an area. How do I then check whether the mouse position is in that area. I've tried using, myRec.Contains ( this->MousePosition ); but it doesn't seem to use the whole area. It only seems to work at a certain spot. I'm obviously misunderstanding something.

        S 1 Reply Last reply
        0
        • R richiemac

          So I've got a rectangle that defines an area. How do I then check whether the mouse position is in that area. I've tried using, myRec.Contains ( this->MousePosition ); but it doesn't seem to use the whole area. It only seems to work at a certain spot. I'm obviously misunderstanding something.

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          I have found the problem. MousePosition gets you position, point 0,0 top left of the creen, not the form. There is work around this problem.

          #include //Win32 header

          RECT *rect = new RECT(); //Create Rectangle Win32 Syntax
          HWND hWnd = GetActiveWindow(); //Gets Handle of current Form
          GetWindowRect(hWnd, rect); //Gets Position of the form

          // Get Mouse position and calculate to form cordinate
          int x = this->MousePosition.X - rect->left - 4;
          int y = this->MousePosition.Y - rect->top - 30;

          //Check if the mouse is insade the rectangle
          if (myRec->Contains(x, y) == true)
          label1->Text = S"True";
          else
          label1->Text = S"False";

          ps: Overridng Those event like MouseEnter, and other i have posted will work only if it is a control. I have reread and now i anderstand what you have ment.

          R 1 Reply Last reply
          0
          • S Saksida Bojan

            I have found the problem. MousePosition gets you position, point 0,0 top left of the creen, not the form. There is work around this problem.

            #include //Win32 header

            RECT *rect = new RECT(); //Create Rectangle Win32 Syntax
            HWND hWnd = GetActiveWindow(); //Gets Handle of current Form
            GetWindowRect(hWnd, rect); //Gets Position of the form

            // Get Mouse position and calculate to form cordinate
            int x = this->MousePosition.X - rect->left - 4;
            int y = this->MousePosition.Y - rect->top - 30;

            //Check if the mouse is insade the rectangle
            if (myRec->Contains(x, y) == true)
            label1->Text = S"True";
            else
            label1->Text = S"False";

            ps: Overridng Those event like MouseEnter, and other i have posted will work only if it is a control. I have reread and now i anderstand what you have ment.

            R Offline
            R Offline
            richiemac
            wrote on last edited by
            #5

            Thanks for the help. I'm having trouble firstly with the drawing or placement of the rectangle. It's not in the correct place - for instance, if I draw a picturebox with the same coordinates they are in different positions on the screen. Very confused as to why this is - so I assume from your previous post they are being drawn with different relative positions. So I've tried to use the work around you posted but if I include the windows header I have a lot of problems with my message boxes and some other components that I need. Is there no way of doing the same thing without the need for the win32 api.

            S 1 Reply Last reply
            0
            • R richiemac

              Thanks for the help. I'm having trouble firstly with the drawing or placement of the rectangle. It's not in the correct place - for instance, if I draw a picturebox with the same coordinates they are in different positions on the screen. Very confused as to why this is - so I assume from your previous post they are being drawn with different relative positions. So I've tried to use the work around you posted but if I include the windows header I have a lot of problems with my message boxes and some other components that I need. Is there no way of doing the same thing without the need for the win32 api.

              S Offline
              S Offline
              Saksida Bojan
              wrote on last edited by
              #6

              Sorry, I can't get that error. Try to make another unmanaget class with old syntax:

              #ifndef _MPOINT_H_
              #define _MPOINT_H_
              #include

              struct pointMData
              {
              int x;
              int y;
              };

              class MPoint
              {
              public:
              MPoint(void){}
              ~MPoint(void){}

              void GetPoint(pointMData \*pData)
              {
              	RECT \*rect = new RECT();
              	HWND hWnd = GetActiveWindow();
              	GetWindowRect(hWnd, rect);
              	pData->x = rect->left;
              	pData->y = rect->top;
              
              	return;
              }
              

              };
              #endif

              This is unmanaged class, so i have created pointMData for retreaving, because i have a problem using Rectangle in umanaged class. If this doesn't work, then try Creating Win32 DLL. quote: Is there no way of doing the same thing without the need for the win32 api. I couldn't find in framework for this workaround, so i used Win32 api. I don't know if exist. ps: i hope this works

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups