Ok, first of all, I'm not sure if this belongs to C section. Since WinAPI is written in C, I'll post here. I'm using OpenGL with Win32 windows (not sure how to call that). I can't switch to fullscreen mode after creating the window. I'm using Windows 7 (64-bits) and VS 2008. Here's the part of the code where I switch to fullscreen mode:

DEVMODE dmScreenSettings;

// ...

if(ContextPtr->Fullscreen)
{
  memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
  dmScreenSettings.dmSize = sizeof(dmScreenSettings);
  dmScreenSettings.dmPelsWidth = ContextPtr->ScreenWidth;
  dmScreenSettings.dmPelsHeight = ContextPtr->ScreenHeight;
  dmScreenSettings.dmBitsPerPel = ContextPtr->ScreenDepth;
  dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

  if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
  {
    ContextPtr->Fullscreen = false;
  }
}

I've tried copying some code from SDL (SDL_dibvideo.c), but it didn't work either. There's a similar example in some book on games development:
(the link was a bit long)

Need help :)
Thanks

Dani AI

Generated

Short practical summary and a few follow-ups to the existing posts: ’s problem was the common one — the card/driver didn’t expose the 24‑bit desktop mode, so the mode change failed while a 32‑bit mode succeeded. ’s suggestion to inspect the ChangeDisplaySettings return value was exactly the right first step. Below are concrete, safe steps and tips to make your fullscreen mode switching robust across hardware.

First, enumerate what the driver actually supports before trying to change it. Use EnumDisplaySettings to list available resolutions and bits‑per‑pixel and choose a supported mode or fall back to 32 bpp:

DEVMODE dm;
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
int i = 0;
while (EnumDisplaySettings(NULL, i++, &dm)) {
    printf("%ld x %ld @ %ld bpp\n", dm.dmPelsWidth, dm.dmPelsHeight, dm.dmBitsPerPel);
}

Always save the current mode (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &orig)) so you can restore it on exit. If you try a mode and ChangeDisplaySettings returns a failure (e.g., BADMODE), try a fallback (most drivers offer 32 bpp) or skip the desktop mode change and use a borderless fullscreen window instead.

OpenGL note: you do not always need to change the desktop bpp to get a 24‑bit framebuffer — request the pixel format you want (PIXELFORMATDESCRIPTOR or wglChoosePixelFormatARB) and the driver will often give you a 24‑bit color buffer on a 32‑bit desktop. For multi‑monitor setups, use ChangeDisplaySettingsEx with the device name to avoid changing the wrong adapter. Finally, log the numeric return from ChangeDisplaySettings and test on the target GPUs — hardware differences are the usual cause of this class of problems.

Recommended Answers

All 2 Replies

ChangeDisplaySettings returns DISP_CHANGE_BADMODE, which means that the display mode is not supported. It works with 32-bit depth, I was trying to use 24-bit depth. I guess this thread is solved now. Thank you for your help Salem.

commented: Good detective work :) +17
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.