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. CursorClip Drawing Region

CursorClip Drawing Region

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestion
4 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.
  • J Offline
    J Offline
    jw81
    wrote on last edited by
    #1

    Hi all I tried to use CursorClip to limit my drawing region on SDI. Any easier way to do that? I need to limit my drawing region to a rectangle (400x400 pixels). Thanks;)

    B 1 Reply Last reply
    0
    • J jw81

      Hi all I tried to use CursorClip to limit my drawing region on SDI. Any easier way to do that? I need to limit my drawing region to a rectangle (400x400 pixels). Thanks;)

      B Offline
      B Offline
      Branislav
      wrote on last edited by
      #2

      RECT rcClip; // new area for ClipCursor RECT rcOldClip; // previous area for ClipCursor // Record the area in which the cursor can move. GetClipCursor(&rcOldClip); // Get the dimensions of the application's window. rcClip = your_rectangle(400x400); // Confine the cursor to the application's window. ClipCursor(&rcClip); // // Process input from the confined cursor. // // Restore the cursor to its previous area. ClipCursor(&rcOldClip);

      J 1 Reply Last reply
      0
      • B Branislav

        RECT rcClip; // new area for ClipCursor RECT rcOldClip; // previous area for ClipCursor // Record the area in which the cursor can move. GetClipCursor(&rcOldClip); // Get the dimensions of the application's window. rcClip = your_rectangle(400x400); // Confine the cursor to the application's window. ClipCursor(&rcClip); // // Process input from the confined cursor. // // Restore the cursor to its previous area. ClipCursor(&rcOldClip);

        J Offline
        J Offline
        jw81
        wrote on last edited by
        #3

        THanks for the code. But I am still quite confused. // Get the dimensions of the application's window. rcClip = your_rectangle(400x400); When I use GetClientRect(), it retrieved the coordinates of the top left of the client. However, when I am using SDI, there is menu and toolbar. Can you write more detailed? I am new to visual C++ but I have programming experience. Thanks;)

        B 1 Reply Last reply
        0
        • J jw81

          THanks for the code. But I am still quite confused. // Get the dimensions of the application's window. rcClip = your_rectangle(400x400); When I use GetClientRect(), it retrieved the coordinates of the top left of the client. However, when I am using SDI, there is menu and toolbar. Can you write more detailed? I am new to visual C++ but I have programming experience. Thanks;)

          B Offline
          B Offline
          Branislav
          wrote on last edited by
          #4

          POINT p; GetClientRect(hwnd, &rcClip); p.x = rcClip.left; p.y = rcClip.top; ClientToScreen(hwnd, &p); OffsetRect(&rcClip, p.x, p.y); ClipCursor(&rcClip); ShowCursor(TRUE); ////////////////////////////// // The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner will be (0,0). // The ClientToScreen function replaces the client coordinates in the POINT structure with the screen coordinates. The screen coordinates are relative to the upper-left corner of the screen. // The OffsetRect function moves the specified rectangle by the specified offsets. // The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area.

          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