View Full Version : Getting screen width/height
11-18-2004, 07:58 AM
Is there a way to get the current screen width and height without passing lots of parameters to a class ?
ive seen BOOL GetClientRect( HWND hWnd,LPRECT lpRect );
but this itself need the window handle, i know there is also wglGetCurrentDC() would there be a windows handle equivalent ?
11-18-2004, 09:24 AM
If you are using win32 you might as well use the window handle, you have it tucked away somewhere in your code anyway, but if that is not good enough, why don't you just save the width and height yourself in two variables, you have to set the glViewPort when the window changes size anyway, put the code in there.
11-18-2004, 09:24 AM
what does this have to do with OpenGL?
11-18-2004, 09:51 AM
thanks, ill have to try it out when i get back home.
Im using it to make sure the font position stays the same when the window is resized.. in an opengl window.
This will return the desktop's current resolution without resorting to DEVMODE:
style = $$WS_OVERLAPPEDWINDOW | $$WS_CLIPCHILDREN | $$WS_CLIPSIBLINGS
// use instead of DEVMODE, works much faster
hDC = GetDC (0)
width = GetDeviceCaps (hDC, HORZRES)
height = GetDeviceCaps (hDC, VERTRES)
ReleaseDC (0, hDC)
....Call create Window function ()
Also, you might want to consider having the Device Context, hDC, refrenced in the Global Scope so that it's available to which ever function that needs it in all of the APP.
It's faster because you're not changing the resolution, just using the current one....No need to change it back at App exit, either. But, make sure you give the user back the cursor, though.
Maybe, that helps.
05-03-2006, 11:21 PM
Anyone know how to do this in MacOs and Linux, but also get the depth (I believe it's GetDeviceCaps(hDC,COLORRES) in Windows)?
05-04-2006, 01:12 AM
On Mac OS X you can use Display Manager functions (if I remember correctly) to ascertain the current resolution and depth, and also to list all the possible choices...
That's not to say that that's the only way of doing it, though.
There are several APIs used to acquire a pixel format and create a context, such as CGL, AGL, GLUT, and perhaps others. AGL in particular will let you capture the screen for fullscreen use without having to touch the display manager functions, provided the resolution and refresh rates you specify are supported, and will then put everything back the way it was before you captured the display...
Tons of docs on Apple's website
05-04-2006, 02:12 AM
This kind of information is pretty easy to find in the documentation for your OS, isn't anyone reading the docs any longer ?
If you use Windows just go to msdn.microsoft.com, the entire MSDN documentation is available for reading there.
If you use X the there are loads of places with documentation.
05-04-2006, 08:58 PM
Thanks for the quick replies.
Mikael, in my post you'll see that I already know how to do it in Windows, but I was hoping some Mac or Linux gurus would be able to give me a quick few lines of code to accmplish the same.
Anyway, I'm using a programming environment called BlitzMax, which is an advanced OOP C\Basic hybrid that supports MacOS, Linux and Windows with choice of 2 or 3 main gfx drivers (depending on what your platform supports):
- Windows: Full native OpenGL command set, Max2D (OpenGL under the hood), Max2D (DirectX under the hood)
- Linux: Full native OpenGL command set (SDL is in the works), Max2D (OpenGL under the hood)
- MacOS (Gx and Intel): Full native OpenGL command set, Max2D (OpenGL under the hood)
Max2D command set is fully cross-platform compatible (same code compiles on all three platforms without changes) and OpenGL 1.5 is supported on all three platforms as well (fully, as far as I know).
Anyway, I just need this one feature which is not yet supported (screen depth of the desktop). Can someone help me out?
I'm not advertising for them, but if you're interested you can get more info here:
For $80(US) you can't beat it! GUI module is $25 more if you want/need it (Windowed Apps on all three platforms with same code). Demo is also available (with MaxGUI included). Updates are free and reasonably frequent.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.