Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dialog window association and _InputBox$ support on Windows #245

Merged
merged 4 commits into from Nov 13, 2022

Conversation

mkilgore
Copy link
Contributor

The commit messages have more detailed information, but a summary of the changes:

  1. The previous handling of determining what Window handle to associate with dialogs and notifications was mostly just GetForegroundWindow(), which is pretty bad since it just gives the focused Window which might not even be ours. We now use three approaches (in this order) to get a window to associate with dialogs and notifications:
    a. Use EnumWindows() and find a top-level window associated with our Process ID.
    b. Try using GetConsoleWindow() and see if it gives us back a valid handle.
    c. Create a hidden window.
  2. The _InputBox$ dialog was improved, it's now always on the top and tabbing through the controls works correctly.
  3. I swapped the test images from the previous Fix PAINT when border color is not supplied (QB64Official/qb64#38) #241 PR to be png instead of bmp. For the tests it doesn't matter which we use, but pngs are smaller and also show up natively on GitHub.
  4. I fixed up our headers to include stdint.h on Windows (which we were already using but not including directly).

Functionally it doesn't matter what kind of images we store for the
tests, as _LOADIMAGE() will open them exactly the same. png however has
the advantages of being substantially smaller, and also viewable
directly on GitHub in PRs, making them easier to review.
Currently we have two different ways of determining what Window handle
to tie our dialogs too - we either use GetForegroundWindow(), or create
a completely new and hidden handle. The associated window determines
what process names shows up on notifications, and also which window
can't be interacted with while a dialog is open.

Both of those approaches aren't really good. In the case of
GetForegroundWindow(), it just returns whatever window the user has in
focus, which might be a completely different process. With the hidden
window, it means the dialog and notification aren't really tied to the
QB64-PE program, so you can still interact with the window even when a
dialog is open, and the notification doesn't show an exectuable name.

To solve this we're now using EnumWindows() to enumerate over all the
Windows on the system and find one associated with our ProcessId. We
then check if it's the top-level window and return it if it is.

If that process fails to find a window (such as if this is a
console-only program, or $SCREENHIDE is used) then we check if
GetConsoleWindow() gives us a handle and use that.

If neither approach works, then we fall back to creating a hidden window
so that the dialogs can still work.
This applies various dialog settings so that the dialog is always on
top, and also so that Tab works as expected to move between the
controls. The Edit control is moved first so that it's focused when the
window appears.
It seems we weren't including stdint.h on Windows by mistake. Likely we
were getting it anywy from some other header, but it sounds like that
got changed in newer versions of MinGW and either way we shouldn't rely
on that.

Being that we include stdint.h on all platforms, I also changed os.h to
always use these types when defining the `int32` and friends sized
types. Ideally we get rid of those defines in the future but we can at
least use the stdint.h types going forward (as we already have).
@mkilgore mkilgore added the bug Something isn't working label Nov 13, 2022
@a740g
Copy link
Contributor

a740g commented Nov 13, 2022

4. I fixed up our headers to include stdint.h on Windows (which we were already using but not including directly).

Thank you for doing this! Honestly, I think that all new stuff we are writing should use the stdint.h typedefs.

@mkilgore
Copy link
Contributor Author

  1. I fixed up our headers to include stdint.h on Windows (which we were already using but not including directly).

Thank you for doing this! Honestly, I think that all new stuff we are writing should use the stdint.h typedefs.

I agree, I've pretty much been doing that already.

@mkilgore mkilgore merged commit 855eaac into QB64-Phoenix-Edition:main Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants