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. snapping windows

snapping windows

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
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
    Roman Nurik
    wrote on last edited by
    #1

    hey, I override WM_MOVING to change the drag rectangle of a moving window to "snap" to the borders of the desktop... the problem is "unsnapping" -- i can't unsnap because the original drag rectangle isn't stored and whenever i want to move the drag rectangle it keeps moving back to the snapped position:

    case WM_MOVING:
    {
    RECT rcWorkArea;
    if (SystemParametersInfo(SPI_GETWORKAREA,0,&rcWorkArea,0))
    {
    RECT* pRC = (RECT*)lParam;
    if (pRC->bottom >= rcWorkArea.bottom - 10) // distance before snapping = 10
    OffsetRect(pRC,0,rcWorkArea.bottom - pRC->bottom);
    else if (pRC->top <= rcWorkArea.top + 10)
    OffsetRect(pRC,0,rcWorkArea.top - pRC->top);
    }
    return TRUE;
    }

    also, how the hell do i get the position of the mouse! i thought there was a function GetMousePos which took in a pointer to a POINT structure but it doesn't exist... so how do i do it?

    r -€

    K A 2 Replies Last reply
    0
    • R Roman Nurik

      hey, I override WM_MOVING to change the drag rectangle of a moving window to "snap" to the borders of the desktop... the problem is "unsnapping" -- i can't unsnap because the original drag rectangle isn't stored and whenever i want to move the drag rectangle it keeps moving back to the snapped position:

      case WM_MOVING:
      {
      RECT rcWorkArea;
      if (SystemParametersInfo(SPI_GETWORKAREA,0,&rcWorkArea,0))
      {
      RECT* pRC = (RECT*)lParam;
      if (pRC->bottom >= rcWorkArea.bottom - 10) // distance before snapping = 10
      OffsetRect(pRC,0,rcWorkArea.bottom - pRC->bottom);
      else if (pRC->top <= rcWorkArea.top + 10)
      OffsetRect(pRC,0,rcWorkArea.top - pRC->top);
      }
      return TRUE;
      }

      also, how the hell do i get the position of the mouse! i thought there was a function GetMousePos which took in a pointer to a POINT structure but it doesn't exist... so how do i do it?

      r -€

      K Offline
      K Offline
      KalliMan
      wrote on last edited by
      #2

      for mouse pos, try with GetCursorPos(LPPOINT); or DWORD pos = GetMessagePos(); CPoint pt(LOWORD(pos), HIWORD(pos)); ScreenToClient(&pt); KalliMan

      1 Reply Last reply
      0
      • R Roman Nurik

        hey, I override WM_MOVING to change the drag rectangle of a moving window to "snap" to the borders of the desktop... the problem is "unsnapping" -- i can't unsnap because the original drag rectangle isn't stored and whenever i want to move the drag rectangle it keeps moving back to the snapped position:

        case WM_MOVING:
        {
        RECT rcWorkArea;
        if (SystemParametersInfo(SPI_GETWORKAREA,0,&rcWorkArea,0))
        {
        RECT* pRC = (RECT*)lParam;
        if (pRC->bottom >= rcWorkArea.bottom - 10) // distance before snapping = 10
        OffsetRect(pRC,0,rcWorkArea.bottom - pRC->bottom);
        else if (pRC->top <= rcWorkArea.top + 10)
        OffsetRect(pRC,0,rcWorkArea.top - pRC->top);
        }
        return TRUE;
        }

        also, how the hell do i get the position of the mouse! i thought there was a function GetMousePos which took in a pointer to a POINT structure but it doesn't exist... so how do i do it?

        r -€

        A Offline
        A Offline
        Antony M Kancidrowski
        wrote on last edited by
        #3

        If you want to unsnap you will need to track the direction of the mouse movement. i.e. if it is moving away from the edge then do not apply the snap criteria. For this you will need to store the last position of the mouse then compare with current position. You can then decide whether to snap or not. Ant.

        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