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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to give mouse event on rectangle and resize

How to give mouse event on rectangle and resize

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorial
3 Posts 3 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
    raju_shiva
    wrote on last edited by
    #1

    Hi all, I am drawing one rectangle with some given values and degree. Now i want to give the mouse event if i click the mouse on that rectangle,it should be activated so that i can drag it and resize. The code i am using to draw rectangle is:

    LPTSTR lpsz;

    ColliAngle = "45";
    int ang;

    ang = _ttoi(ColliAngle);
    float Angle = ( 3.142 * ang ) / 180;
    int x[4];
    int y[4];
    x[0] = -x1 * cos(Angle) - y2 * sin(Angle);
    y[0] = x1 * sin(Angle) - y2 * cos(Angle);
    x[1] = -x1 * cos(Angle) + y1 * sin(Angle);
    y[1] = x1 * sin(Angle) + y1 * cos(Angle);
    x[2] = x2 * cos(Angle) + y1 * sin(Angle);
    y[2] = -x2 * sin(Angle) + y1 * cos(Angle);
    x[3] = x2 * cos(Angle) - y2 * sin(Angle);
    y[3] = -x2 * sin(Angle) - y2 * cos(Angle);
    for (int i=0; i<4; i++)
    {
    x[i] += center.x;
    y[i] += center.y;
    }
    MoveToEx(pCellInfo->hDC,x[3],y[3],NULL);
    for (int i=0; i<4; i++)
    {

    LineTo(pCellInfo->hDC, x\[i\],y\[i\]);
    

    }

    Please help me i dont know how to start and totally hanged. Thanks Raj

    _ M 2 Replies Last reply
    0
    • R raju_shiva

      Hi all, I am drawing one rectangle with some given values and degree. Now i want to give the mouse event if i click the mouse on that rectangle,it should be activated so that i can drag it and resize. The code i am using to draw rectangle is:

      LPTSTR lpsz;

      ColliAngle = "45";
      int ang;

      ang = _ttoi(ColliAngle);
      float Angle = ( 3.142 * ang ) / 180;
      int x[4];
      int y[4];
      x[0] = -x1 * cos(Angle) - y2 * sin(Angle);
      y[0] = x1 * sin(Angle) - y2 * cos(Angle);
      x[1] = -x1 * cos(Angle) + y1 * sin(Angle);
      y[1] = x1 * sin(Angle) + y1 * cos(Angle);
      x[2] = x2 * cos(Angle) + y1 * sin(Angle);
      y[2] = -x2 * sin(Angle) + y1 * cos(Angle);
      x[3] = x2 * cos(Angle) - y2 * sin(Angle);
      y[3] = -x2 * sin(Angle) - y2 * cos(Angle);
      for (int i=0; i<4; i++)
      {
      x[i] += center.x;
      y[i] += center.y;
      }
      MoveToEx(pCellInfo->hDC,x[3],y[3],NULL);
      for (int i=0; i<4; i++)
      {

      LineTo(pCellInfo->hDC, x\[i\],y\[i\]);
      

      }

      Please help me i dont know how to start and totally hanged. Thanks Raj

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      To identify if the mouse is clicked on the line use the LineDDA function. This function calls a callback function with each point on the line. Compare this will the point where the mouse was clicked.

      «_Superman_»
      I love work. It gives me something to do between weekends.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • R raju_shiva

        Hi all, I am drawing one rectangle with some given values and degree. Now i want to give the mouse event if i click the mouse on that rectangle,it should be activated so that i can drag it and resize. The code i am using to draw rectangle is:

        LPTSTR lpsz;

        ColliAngle = "45";
        int ang;

        ang = _ttoi(ColliAngle);
        float Angle = ( 3.142 * ang ) / 180;
        int x[4];
        int y[4];
        x[0] = -x1 * cos(Angle) - y2 * sin(Angle);
        y[0] = x1 * sin(Angle) - y2 * cos(Angle);
        x[1] = -x1 * cos(Angle) + y1 * sin(Angle);
        y[1] = x1 * sin(Angle) + y1 * cos(Angle);
        x[2] = x2 * cos(Angle) + y1 * sin(Angle);
        y[2] = -x2 * sin(Angle) + y1 * cos(Angle);
        x[3] = x2 * cos(Angle) - y2 * sin(Angle);
        y[3] = -x2 * sin(Angle) - y2 * cos(Angle);
        for (int i=0; i<4; i++)
        {
        x[i] += center.x;
        y[i] += center.y;
        }
        MoveToEx(pCellInfo->hDC,x[3],y[3],NULL);
        for (int i=0; i<4; i++)
        {

        LineTo(pCellInfo->hDC, x\[i\],y\[i\]);
        

        }

        Please help me i dont know how to start and totally hanged. Thanks Raj

        M Offline
        M Offline
        mesajflaviu
        wrote on last edited by
        #3

        You can also insipre from here^

        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