walbourn / directx-vs-templates

Direct3D Visual Studio Templates
https://walbourn.github.io/direct3d-game-visual-studio-templates-redux/
MIT License
412 stars 56 forks source link

WS_POPUP recommended but not used #47

Closed jpark37 closed 3 years ago

jpark37 commented 3 years ago

The comment next to the CreateWindowExW call says to use WS_POPUP for fullscreen, but the WM_SYSKEYDOWN handler seems to set GWL_STYLE to 0 instead. Is this a mistake?

walbourn commented 3 years ago

When you initially create the window, if you don't provide WS_POPUP and just use '0', you end up with a title bar which we don't want in the full-screen case. Same thing happens with WS_OVERLAPPED because that is defined to 0.

jpark37 commented 3 years ago

You're right that passing 0 causes the style to actually be set to WS_CLIPSIBLINGS | WS_CAPTION.

I'm a little weirded out with WS_POPUP though because GetWindowLongPtr returns WS_POPUP | WS_CLIPSIBLINGS after CreateWindowEx. SetWindowLongPtr(hWnd, GWL_STYLE, 0) adjusts that to just WS_CLIPSIBLINGS. Maybe WS_POPUP is harmless? I don't know much about window styles, but having an extra flag on initial fullscreen vs. on-the-fly fullscreen triggers my OCD.

walbourn commented 3 years ago

Windows styles are a definitely a bit 'magic', but I didn't find any other windows style that did what I wanted...

jpark37 commented 3 years ago

Maybe the guidance should be to leave the CreateWindowEx call alone, but to set the styles immediately afterward. Something like:

HWND hwnd = CreateWindowExW(0, L"Direct11WindowClass", g_szAppName, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, hInstance,
    nullptr);
// TODO: Apply these styles to default to fullscreen. Must apply style afterward because creating with a style of 0 will add a title bar.
// SetWindowLongPtr(hwnd, GWL_STYLE, 0);
// SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_TOPMOST);
walbourn commented 3 years ago

I was trying for the simplest instructions :)

jpark37 commented 3 years ago

That's fine if having the extra WS_POPUP bit is a NOP, but I wonder if that alters window behavior in some way.

jpark37 commented 3 years ago

Consistency can also be achieved by setting WS_POPUP instead of 0 in the WndProc I think?

Sorry for all the messages over this relatively minor issue.

walbourn commented 3 years ago

That's fine. Happy to take feedback.

Fixed in this commit