1

Im making a game with a custom game engine and when you have selected the window that it creates it doesn't allow you to use media keys e.g. changing volume or playing/pausing music or anything that has to do with windows like getting the windows start menu and alt+tab behaves weird

It feels like my window is "blocking" all system specific keys and commands

The code is written in c++

Heres the code i'm using for creating the window:

bool FrameWork::CreateDXWnd(int x, int y, int width, int height)
{
    HWND hwnd;
    WNDCLASSEX wc;

    m_hInstance = GetModuleHandle(nullptr);

    //setup window class with default setings:
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = m_hInstance;
    //wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO);
    wc.hIcon = (HICON)LoadImage(m_hInstance, ".\\Assets\\Icons\\NgineIcon512.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
    wc.hIconSm = wc.hIcon;
    wc.hCursor = LoadCursor(nullptr, IDC_HAND);
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = nullptr;
    wc.lpszClassName = applicationName.c_str();
    wc.cbSize = sizeof(WNDCLASSEX);

    if (!RegisterClassEx(&wc))
    {
        Error(1);
        return false;
    }

    //Style of window
    //int nStyle = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX;
    int nStyle = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX;

    SettingsManager::GetInstance()->SetNativeResolution(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));

    if (SettingsManager::GetInstance()->GetDisplayMode() == FULLSCREEN)
    {
        DEVMODE dmScreenSettings;
        memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
        dmScreenSettings.dmSize = sizeof(dmScreenSettings);
        dmScreenSettings.dmPelsWidth = (unsigned long)SettingsManager::GetInstance()->GetScreenWidth();
        dmScreenSettings.dmPelsHeight = (unsigned long)SettingsManager::GetInstance()->GetScreenHeight();
        dmScreenSettings.dmBitsPerPel = 32;
        dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

        ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
    }
    else
    {

    }
    if ((SettingsManager::GetInstance()->GetDisplayMode() == BORDERLESS))
    {
        hwnd = CreateWindowEx(WS_EX_APPWINDOW, applicationName.c_str(), applicationName.c_str(), WS_POPUP, x, y, SettingsManager::GetInstance()->GetScreenWidth(), SettingsManager::GetInstance()->GetScreenHeight(), nullptr, nullptr, m_hInstance, nullptr);
    }
    else
    {
        hwnd = CreateWindowEx(WS_EX_APPWINDOW, applicationName.c_str(), applicationName.c_str(), nStyle, x, y, SettingsManager::GetInstance()->GetScreenWidth(), SettingsManager::GetInstance()->GetScreenHeight(), nullptr, nullptr, m_hInstance, nullptr);

    }


    if (hwnd == nullptr)
    {
        Error(2);
        Ngine::GetInstance()->Release();
        PostQuitMessage(0);
        return false;
    }

    if (!Ngine::GetInstance()->InitGraphics(hwnd))
    {
        Error(hwnd, 30);
        Ngine::GetInstance()->Release();
        PostQuitMessage(0);
        UnregisterClass(applicationName.c_str(), m_hInstance);
        m_hInstance = nullptr;
        DestroyWindow(hwnd);

        return false;
    }

    Ngine::GetInstance()->GetGraphics()->SetHwnd(hwnd);

    ShowWindow(hwnd, SW_SHOW);
    SetForegroundWindow(hwnd);
    SetFocus(hwnd);

    return true;
}
  • 1
    The code posted here does not seem to have anything to do with input handling. Just like directx. – user7860670 Nov 12 '18 at 19:34
  • Which part of code do you suggest ill post i don't think it's a not a problem with input handling as i'm not using the media buttons in game. Do i perhaps need to forward them in some way to the system? – Tim Roberts Nov 12 '18 at 19:41
  • You should probably look into the parts of that "custom game engine" and figure out how does it handle input. – user7860670 Nov 12 '18 at 19:42
  • ALT+TAB is likely to behave weird because you are using an outdated function (``ChangeDisplaySettings``) to implement fullscreen mode. You should be using DXGI, using 'fake full screen', or better yet just a 'maximized borderless window'. See [directx-vs-templates](https://github.com/walbourn/directx-vs-templates/wiki) for some bare-bones Win32 DirectX window/message loops. – Chuck Walbourn Nov 13 '18 at 19:25

1 Answers1

0

Tim. The code you are showing deals with creating a window, not with how to handle the input to the window. To handle input, you need to set up a Message handling loop in your code.

Typically, in a game engine, you will have a main loop or "Game Loop", with each pass through the loop typically resulting in a single frame drawn. The first thing the Game Loop does is handle window messages. This allows you to handle the typical windows functions. Then, once you have no more messages to deal with, you will move on to handling your game's logic and rendering.

I recommend you take a look at Braynzarsoft's tutorials. The tutorial I linked deals with setting up your window and how to make a bare-bones Windows Message system.

Once you understand the basics of that, you can refine your post if needed to get more information.

GaleRazorwind
  • 229
  • 2
  • 7