473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to force the cursor to the center of a window.

Atli
5,058 Expert 4TB
Hi guys.

I'm writing a game in C++ and DirectX and I'm looking for a way to force the mouse to stay in the center of the window.

I tried this, but it doesn't seem to work. It doesn't give any errors, it simply does nothing.
Expand|Select|Wrap|Line Numbers
  1. RECT wRect;
  2. GetWindowRect(hWnd, &wRect);
  3. COORD wCoord = {wRect.left + (CLIENT_WIDTH / 2), wRect.top + (CLIENT_HEIGHT / 2)};
  4. SetConsoleCursorPosition(
  5.     GetStdHandle ( STD_OUTPUT_HANDLE ),
  6.     wCoord
  7. );
  8.  
I also tried to use the IDirect3DDevice9::SetCursorPosition method but that also did nothing.
Expand|Select|Wrap|Line Numbers
  1. RECT wRect;
  2. GetWindowRect(hWnd, &wRect);
  3. d3dDevice->SetCursorPosition(
  4.     wRect.left + (CLIENT_WIDTH / 2), 
  5.     wRect.top + (CLIENT_HEIGHT / 2), 
  6.     D3DCURSOR_IMMEDIATE_UPDATE
  7. );
  8.  
Anybody know how I can do this?

I should add that I'm using DirectInput to capture the mouse. Don't think it matters, but then again, what do I know :P
Jun 16 '07 #1
3 8437
ilikepython
844 Expert 512MB
Hi guys.

I'm writing a game in C++ and DirectX and I'm looking for a way to force the mouse to stay in the center of the window.

I tried this, but it doesn't seem to work. It doesn't give any errors, it simply does nothing.
Expand|Select|Wrap|Line Numbers
  1. RECT wRect;
  2. GetWindowRect(hWnd, &wRect);
  3. COORD wCoord = {wRect.left + (CLIENT_WIDTH / 2), wRect.top + (CLIENT_HEIGHT / 2)};
  4. SetConsoleCursorPosition(
  5.     GetStdHandle ( STD_OUTPUT_HANDLE ),
  6.     wCoord
  7. );
  8.  
I also tried to use the IDirect3DDevice9::SetCursorPosition method but that also did nothing.
Expand|Select|Wrap|Line Numbers
  1. RECT wRect;
  2. GetWindowRect(hWnd, &wRect);
  3. d3dDevice->SetCursorPosition(
  4.     wRect.left + (CLIENT_WIDTH / 2), 
  5.     wRect.top + (CLIENT_HEIGHT / 2), 
  6.     D3DCURSOR_IMMEDIATE_UPDATE
  7. );
  8.  
Anybody know how I can do this?

I should add that I'm using DirectInput to capture the mouse. Don't think it matters, but then again, what do I know :P
I'm not sure if this might work but try the SetCusorPos function:
Expand|Select|Wrap|Line Numbers
  1. SetCursorPos(CLIENT_WIDTH / 2, CLIENT_HEIGHT / 2);
  2.  
Jun 16 '07 #2
Atli
5,058 Expert 4TB
I'm not sure if this might work but try the SetCusorPos function:
Expand|Select|Wrap|Line Numbers
  1. SetCursorPos(CLIENT_WIDTH / 2, CLIENT_HEIGHT / 2);
  2.  
That works perfectly!

Thanks very much.
Jun 16 '07 #3
ilikepython
844 Expert 512MB
That works perfectly!

Thanks very much.
Glad to help .
Jun 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: brian | last post by:
Hi, I am beginner using Python 1.52, GTK 1.2.10, and Glade .0.6.2 to develop a gui which will kick off various scripts. After checking some configurations I would like to pop up a window...
3
by: Csaba2000 | last post by:
I have set onmousedown to change the cursor, but this setting is ignored (IE 5.5; NN 6.1 on Win 2K Pro) until the mouse is either moved or the mouse button is released. On Opera 7.01, the setting...
1
by: Yaron Cohen | last post by:
Hi, I would like to ask for your help (I am using only IE5.5). I have a very big table that I would like to sort. During the sort I would like the cursor changed to 'wait' state and back to...
3
by: Phil | last post by:
how do I force a window, pened alone, to be displayed in its frame set? tried this: if (parent.location.href == self.location.href) { window.location.href = '../'; } the problem is that...
18
by: Andrew Poulos | last post by:
If I manage to call the following bit of javascript in IE and MZ w = window.open("", "s", 'status=no,resizable=no,width=450,height=450'); I get a window that is not resizable and without a...
3
by: Bob | last post by:
I am trying to create a popup page (to act as a menu) from a parent page. When the parent page (index.jsp) calls my popup function (see below) it will properly open the correct size browser window...
17
by: Geoff Cox | last post by:
Hello, Can I use JavaScript to force a maximised window ? Thanks
1
by: Daniel Friend | last post by:
Hi have a window (FormBorderStyle=NONE) and the form is a MDI child. For some reason the form is not getting focus. I have tried the following code and nothing seems to work. sForm.Show()...
5
by: annagel | last post by:
I am looking for a way to force a Tkinter window into focus on a system level. I know the force focus method should bring one window of my application into focus, but it seems I need to have some...
6
by: Jen | last post by:
I've implemented single-instance functionality in my .exe by using the mutex method. Works great. But when the .exe detects that it is not the first instance I want to bring the main window of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.