Hacker News new | ask | show | jobs
by muststopmyths 56 days ago
ctrl-f4 is used in MDI applications to close one document window of a multi-document application. alt-f4 to close the whole application.

Well, I say "is used", but nothing in Windows is consistent anymore. Especially since web browsers started disrespecting the OS shortcuts. Now it seems like every application follows the web browser UI conventions instead of OS ones.

1 comments

Alt+F4 in Windows has always been "close window", not close app. It is even shown on the traditional "application icon" menu on each window, that many new apps are unfortunately doing away with.
> Alt+F4 in Windows has always been "close window", not close app.

Well, if we're talking about traditional Windows behavior, there's no such thing as an app in the first place.

Some programs allowed multiple windows to be open at the same time (e.g. Notepad), and some didn't (e.g. Paint), but for those that did, they spawned each window as its own process. Closing the window closed the process. That two processes shared the same executable had no deeper meaning until Windows XP added taskbar grouping.

Windows has had support for multiple windows in a single "app" (that is, a single C program that had one WinMain() function), from all points of view, since Windows 1.0. One sense is irrelevant here - all UI elements that we consider Controls today (such as a button) are "windows" in the standard Windows API. But even in what we normally call windows, these were present from the start of Windows 1.0: your application starts with one main window, and it can later create dialog windows, tiled windows, or popup windows - each of which can be closed without killing the main window.

Now, Alt+F4 didn't exist as a standard keyboard shortcut in Windows 1.0 - it was added later, but certainly by Windows 95 at the latest. And already in Windows 95, Alt+F4 was the "Close Active Window" shortcut, which would close the window or dialog that was currently active - not the entire application whose window this was. So pressing Alt+F4 on your keyboard while a "Save As" dialog was present in Word 95 would close that "Save As" dialog, it wouldn't close your Word document.

You can check the Windows Programming Guide to see how to create dialog windows or popup windows in the same app that already had a main window in Windows 1.03: https://archive.org/details/win103-sdk-manuals/5%20-%20Windo...

In Win16 all instances of executable shared memory (that's why there's hInstance in WinMain). But that should be transparent to user if implemented correctly.

Except Excel, which wants to act like single application with multiple windows.

Console applications, which do not have win32 windows with message pumps can be closed with alt-f4.

For GUI apps it sends a WM_CLOSE, because that's they way to "close" a GUI application.

For console applications it sends a message through the "Console control handler". Which the console subsystem no longer lets the application properly handle and kills the process summarily anyway.

Note that I keep saying "application" because that has been the terminology in windows forever. "GUI apps" and "console apps" were a thing before mobile.

This is good detail, but I wasn't comparing to mobile, I was comparing to Macintosh. A native app on Windows has always been more of a loose collection of related files, whereas it is a single file on Macs and is presented as a cohesive unit throughout the operating system. Thus, Cmd+Q was more feasible than a similar shortcut could have been on Windows, and Alt+F4 really was its closest equivalent because Windows didn't organize things the way Mac did.
An "app" in Windows has always meant a process that starts with a WinMain() function. And as I said in other comments, a single app could always create multiple windows using the CreateWindow() function, that could each be independently closed (though not by Alt+F4). Nothing stops Windows in principle from having a way to close the entire application/process on pressing some keyboard shortcut regardless of which of its windows is currently in focus - they just didn't ever implement one. They could have defined a special message that the application's main message loop can handle to gracefully clean up everything, and then made a keyboard shortcut that would post this message, they just never did it.
I'm responding to both your comments to me in one place. My memory here is fuzzy, especially of 16-bit Windows (which I did use, but I was a child at the time). But, from what I can gather, there is an important difference between 16-bit and 32-bit Windows programs.

In 16-bit land, WinMain is an application entrypoint, and launching an already-open application again causes its WinMain to be invoked with hPrevInstance set to a non-NULL value. Here, the distinction between "process" and "application" was nonexistent/irrelevant.

In 32-bit land, WinMain is a process entrypoint, hPrevInstance is always NULL, and launching an already-open application again causes a new process to be spawned by the O/S. If the application wasn't coded for explicit coordination (using O/S-level mutexes or IPC mechanisms), then two or more running copies of the same application are not aware of each other, do not share any resources, and for a long time were not treated as a single "application" by the operating system.