Fullscreen window and resolution

Started by
6 comments, last by reaperrar 12 years, 6 months ago
I have two different questions:

1. Using the windows API I want to create a full-screen window. At the moment I'm creating a border-less/frame-less window the size of the desktop. This works fine, got my desktop turning black :D Now I'm assuming I have to/should:
  • Hide the windows cursor
  • Show an ingame cursor
  • Move the image cursor according to windows cursor position - old windows cursor position
  • Reset the windows cursor to the center of the fullscreen
I can do the above, just wondering if I should.
I'm also thinking I should disable the mouse clicking outside the window somehow, should I do this? If so, how?

2.
How do I go about multiple resolution support/aspect ratio etc. Is there a good guide I can follow?
Advertisement
See this for fullscreen toggling implementation in Win32. Remember that you can create a windows cursor and bundle it with your application and then use it with the system cursor instead of an an-game cursor image. This has the advantage of being fast, since the system cursor updates are fast, but game cursors' update speed depends on the frame rate. But if you decide you still want an in-game cursor (for example, if you're doing crazy cursor graphics), then yes, you should hide the system cursor and draw an in-game one.

To hide the cursor, responding to WM_SETCURSOR appropriately will result in simpler and better-behaving code than calling ShowCursor(false).

However, you should only need to adjust the cursor position when the window is not fullscreened. In full screen mode, the user can't move the cursor outside the window since it's taking up all of the screen space. In windowed mode, look into using the ClipCursor() API, or capture the mouse when the window is activated (and release it when it's deactivated) so that you receive WM_MOUSEMOVE messages when the user moves the cursor outside of the window, and respond to it by setting the cursor position back inside the window. Or, like you suggested, use an in-game cursor and keep the system cursor in the center of the window.

I'm not sure what you mean exactly by handling multiple resolutions and aspect ratios. Do you how to decide the aspect ration based on resolution? For 2D stuff, I'll just quote this:




The usual method for aspect ratio independence for 2D elements is to have a border. You put everything in a 4:3 shaped box in the middle of the screen but stretch the background to full screen. As long as the background is generic that works well. If not then it's black borders or extra backgrounds designed for different shaped resolutions (16:9 and 5:4 are the common ones).

The other option is just to stretch everything to fit.

By the way it's also worth noting that the ratio of width to height in pixels is not always the same as width to height in inches. For example 1280x1024 on a CRT probably has non square pixels, but on and LCD the pixels are probably square. I wouldn't worry about it for 2D, but it isn't too hard getting it right for 3D.

You can use (float)GetDeviceCaps(hdc, HORZRES) / (float)GetDeviceCaps(hdc, VERTRES) to find out what Windows thinks the physical aspect ratio is.


I hope this helps.

Thx for your reply, I'll read through and see how I go.
KK got most of it working, though when I exit fullscreen and restore the window's old position/dimensions everything else on screen is black. If I drag the window over the screen the black is removed, though I can not do the same for the taskbar. I have to press ctrl alt del for it to refresh. How can I fix this?
Do you want to do this for learning purposes or do you want to create an actual game? If latter, I'd suggest you screw your plans and
move ahead to a graphics api right away. These APIs like directx already have these functions like fullscreen/windowed-switching and custom hardware cursors included. Would be a waste of time bothering the win32-api that case.
Well, I am making a game... using opengl atm. How do I go about toggling fullscreen using opengl?

EDIT: I feel like I'm one step away from having fullscreen toggle working just with windows api, and I would like to know how just for the sake of knowing. Could you also tell me how to refresh the background after returning to windowed mode?
Try your win32 fullscreen toggling code on a regular window in a separate application without OpenGL and see if it works. Maybe you're doing something wrong with OpenGL.
I had a hunch I'd have to "ShowWindow" after "SetWindowLong" and "MoveWindow", not do both then show window. So I went from...

SetWindowLong(m_oHandle, GWL_STYLE, FULLSCREENWINDOWSTYLE);
MoveWindow(m_oHandle, iOldPositionX, iOldPositionY, uiOldWidth, uiOldHeight, 1);
ShowWindow(m_oHandle, SW_SHOW);


..which didn't work, to this...

SetWindowLong(m_oHandle, GWL_STYLE, FULLSCREENWINDOWSTYLE);
ShowWindow(m_oHandle, SW_SHOW);
MoveWindow(m_oHandle, iOldPositionX, iOldPositionY, uiOldWidth, uiOldHeight, 1);
ShowWindow(m_oHandle, SW_SHOW);


...which did work. So now my background is not black when the window returns to windowed mode. But I thought showing the window twice shouldn't be the fix, seems weird. So I changed my method to this...

SetWindowPlacement(m_oHandle, &m_oOldWindowPlacement);
SetWindowLong(m_oHandle, GWL_STYLE, DEFAULTWINDOWSTYLE);
ShowWindow(m_oHandle, SW_SHOW);


...which also works. Can someone explain the reasoning behind this?

This topic is closed to new replies.

Advertisement