Hey:)
I'm not actually sure what it's called..so just calling it "mouse window locking" - What i mean by this is how do you lock the mouse to a window ie: The mouse can not leave the window unless you alt tab. So when the user drags the mouse to the edge of the window it will not leave the window it will just stop at the window's max cords. If that makes sense?:P I'm following the OpenGL tutorials on Nehe Help would be much appreciated:)

I assume you mean in MS-Windows operating system. You would not want to do that even if you could because it would not allow the user to easily select a different desktop icon, the start menu, or any of the icons in the desktop trey. And that would piss off your customers so bad that they would just delete your program, or maybe even sue you.

The only reason to write such a program is for malicious purposes.

I'm not thinking like that at all!:P "malicious purposes"
I'm thinking gaming....I don't know if you have ever played baldur's gate1 or 2...when you move the mouse to the side of the screen it will scroll through the map. but that's only for full screen...im assuming it's not possible for windowed mode then?

RECT r;
GetWindowRect( hwnd, &r);
ClipCursor( &r );

Replace hwnd with whatever the window is called, and you're done.

commented: Thanks. It works.. +0

works awesomely. tyvm:)

Also for anyone reading this post. You will need to set the ClipCursor inside a loop to constantly update that cursor is infact still inside the window

Also for anyone reading this post. You will need to set the ClipCursor inside a loop to constantly update that cursor is infact still inside the window

No, you just have to freeze the thread after you've called it, you don't have to keep calling it. Example:

#include <iostream>
#include <windows.h>

int main() {
  RECT r = {100, 100, 200, 200};
  ClipCursor( &r );
  std::cin.ignore();
}

Ah there we go, is working now^^ thx dude

Just something i found out....If the user resizes the window and the rect is not updated to the correct size the clipcursor will no longer function properly. So yes I think you do need to keep updating the clipcursor...I could be totally wrong though...but this seems to work for me:P

You will have to get the window resize message process, and update the cursor clip there instead. If you aren't using the Win32 API, then it's probably easier to do just do this every frame:

static RECT oldRect;
RECT newRect;
GetWindowRect( hwnd, &newRect );

if ( memcmp(&oldRect, &newRect, sizeof(RECT)) == 0 ) {
  ClipCursor( &newRect );
}

oldRect = newRect;

That should work, try it.

Works like a charm. Thanks for your time:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.