TONT 37443 为什么桌面窗口的尺寸没有缩水,将任务栏排除在外?

原文链接:https://devblogs.microsoft.com/oldnewthing/20041029-00/?p=37443

The taskbar created all sorts of interesting problems, since the work area was not equal to the entire screen dimensions. (Multiple monitors created similar problems.) “Why didn’t the gui return the usable workspace as the root window (excluding the taskbar)?”

任务栏制造了各种各样有趣的问题,由于它的存在,工作区域的尺寸与整个屏幕的分辨率并不是相等的。(多显示器环境同样制造了类似的问题。)『为什么GUI不将可用的工作区域作为顶层窗口(排除任务栏)返回呢?』

That would have made things even worse.

那样会让事情变得更糟糕。

Lots of programs want to cover the entire screen. Games, for example, are very keen on covering the entire screen. Slideshow programs also want to cover the entire screen. (This includes both slideshows for digital pictures as well as business presentations.) Screen savers of course must cover the entire screen.

很多程序都有遮挡整个屏幕的需求。例如游戏,在这方面的需求就很强烈。幻灯片应用程序也需要遮挡整个画面(这类程序同时包含了展示数码图片和商业幻灯的场合)。屏幕保护程序则必须遮挡住整个画面。

If the desktop window didn’t include the taskbar, then those programs would leave a taskbar visible while they did their thing. This is particularly dangerous for screen savers, since a user could just click on the taskbar to switch to another program without going through the screen saver’s password lock!

如果桌面窗口没有包含任务栏区域,那么这些程序在运行时任务栏就会可见。这种情形对屏幕保护程序尤为危险,因为这样一来用户就可以通过点击任务栏来切换到其它程序,从而绕过屏幕保护程序的密码保护了!

And if the taskbar were docked at the top or left edge of the screen, this would have resulted in the desktop window not beginning at coordinates (0,0), which would no doubt have caused widespread havoc. (Alternatively, one could have changed the coordinate system so that (0, 0) was no longer the top left corner of the screen, but that would have broken so many programs it wouldn’t have been funny.)

此外,如果任务栏停靠在屏幕的上方或边缘(译注:应当指的是左侧),会使得桌面窗口的左上角坐标不再是(0,0),而这样毫无疑问将会制造出大笔的麻烦。(换个思路想想的话,把坐标系统进行一点『小小的改动』,让左上角的坐标不再是(0,0)也是一种做法,但这样大概会搞炸一大堆程序,所以这一点也不好玩。)

TONT 37453 在任务栏被发明出来之前,最小化的窗口都去了哪里?

原文链接:https://devblogs.microsoft.com/oldnewthing/20041028-00/?p=37453

Before Explorer was introduced in Windows 95, the Windows desktop was a very different place.

在资源管理器被引入到 Windows 95 之前,桌面是完全大相径庭的另一个物种。

The icons on your desktop did not represent files; rather, when you minimized a program, it turned into an icon on the desktop. To open a minimized program, you had to hunt for its icon, possibly minimizing other programs to get them out of the way, and then double-click it. (You could also Alt+Tab to the program.)

桌面上的图标不是用来代表文件的,与这种印象不同,当你最小化一个程序时,程序就会变成桌面上的一个图标。要打开一个最小化的程序,你得先找到它的图标,或许还得先把其他挡住视线的程序最小化,然后再双击图标(来打开这个最小化的程序)。(你也可以用Alt+Tab切换过去。)

Explorer changed the desktop model so that icons on your desktop represent objects (files, folders) rather than programs. The job of managing programs fell to the new taskbar.

资源管理器改变了桌面的模型,此后桌面上的图标就变成了代表对象(文件、文件夹)而不是程序。管理程序的任务就落到了新生的任务栏上。

But where did the windows go when you minimized them?

不过当程序最小化的时候,它的窗口去哪了呢?

Under the old model, when a window was minimized, it displayed as an icon, the icon had a particular position on the screen, and the program drew the icon in response to paint messages. (Of course, most programs deferred to DefWindowProc which just drew the icon.) In other words, the window never went away; it just changed its appearance.

在旧的模型之下,当一个窗口最小化时,其表现为一个图标,这个图标在屏幕上有特定的位置,而程序在响应描画的窗体消息时,会对这个图标进行绘制。(当然,大多数程序推迟了绘制图标的 DefWindowProc 方法。)换句话说,程序的窗口从来都没有消失,只是换了个表现形式。

But with the taskbar, the window really does go away when you minimize it. Its only presence is in the taskbar. The subject of how to handle windows when they were minimized went through several iterations, because it seemed that no matter what we did, some program somewhere didn’t like it.

但自从有了任务栏以后,最小化的程序的窗口就真的消失了,其存在就仅仅表现在任务栏中而已。对于如何管控最小化的窗口的设计经历了几次迭代,原因是不管我们做什么,总有一些应用程序不喜欢。

The first try was very simple: When a window was minimized, the Windows 95 window manager set it to hidden. That didn’t play well with many applications, which cared about the distinction between minimized (and visible) and hidden (and not visible).

第一次的尝试很简单:当一个窗口最小化后,Windows 95 的窗口管理器就将其设置为隐藏。这样的设计与很多程序配合都不好,因为这些程序会严格区分最小化(同时可见)与隐藏(同时不可见)的区别。

Next, the Windows 95 window manager minimized the window just like the old days, but put the minimized window at coordinates (-32000, -32000), This didn’t work because some programs freaked out if they found their coordinates were negative.

后来,Windows 95 的窗口管理器用以往的方法将窗口最小化,但将最小化的窗口移动到坐标(-32000,-32000)。这样做的效果依然不彰,因为有些程序发现自己的坐标是负值时感觉非常不安。

So the Windows 95 window manager tried putting minimized windows at coordinates (32000, 32000), This still didn’t work because some programs freaked out if they found their coordinates were positive and too large!

所以Windows 95的窗口管理器又转而尝试将最小化的窗口放到坐标(32000,32000)上。这样做的效果仍旧不好,因为有些程序发现自己的坐标是很大的正值时吓坏了。

Finally the Windows 95 window manager tried coordinates (3000, 3000), This seemed to keep everybody happy. Not negative, not too large, but large enough that it wouldn’t show up on the screen (at least not at screen resolutions that were readily available in 1995).

最终,Windows 95 窗口管理器将移动的坐标换成了(3000,3000),这样大家似乎都很满意了。不是负值,不是很大的值,但又足够大使得不会显示在屏幕上(至少以1995年较常见的屏幕分辨率来说如此)。

If you have a triple-monitor Windows 98 machine lying around, you can try this: Set the resolution of each monitor to 1024×768 and place them corner-to-corner. At the bottom right corner of the third monitor, you will see all your minimized windows parked out in the boonies.

如果你有一台三显示器配置的 Windows 98 机器在手边,你可以尝试这样操作一下:将每台显示器的分辨率设置为1024×768,然后将三台显示器底角对顶角地排列起来。在右下角的第三台显示器上,你就能看到那些最小化的窗口们在屏幕的『郊区』安居乐业的样子了。

(Windows NT stuck with the -32000 coordinates and didn’t pick up the compatibility fixes for some reason. I guess they figured that by the time Windows NT became popular, all those broken programs would have been fixed. In other words: Let Windows 95 do your dirty work!)

(出于某些原因,Windows NT 则保留了移动到坐标-32000的做法,没有采用(移动到坐标3000的)那个兼容性补丁。我猜开发人员们大概在想等 Windows NT 普及了,那些不听话的应用程序大概都已经修复这个问题了。换句话说:让 Windows 95 去做那些苦活吧!)

TONT 37503 为什么安装程序不会问你是否要保留较新版本的系统文件?

原文链接:https://devblogs.microsoft.com/oldnewthing/20041022-00/?p=37503

Windows 95 Setup would notice that a file it was installing was older than the file already on the machine and would ask you whether you wanted to keep the existing (newer) file or to overwrite it with the older version.

Windows 95 的安装程序会注意到正在安装的文件相较于机器上已有的版本比较旧,于是就会问你是否要保留现有(较新)的文件,或者用较旧的版本进行覆盖替换。(译注:用过Win95的人都知道这是一个很容易令人摸不到头脑的问题)

Asking the user this question at all turned out to have been a bad idea. It’s one of those dialogs that ask the user a question they have no idea how to answer.

事实上向用户提出这个问题本身就是一个很差劲的主意。这种对话框属于那种用户完全不知道如何作答的类型。

Say you’re installing Windows 95 and you get the file version conflict dialog box. “The file Windows is attempting to install is older than the one already on the system. Do you want to keep the newer file?” What do you do?

比如说,你正在安装Windows 95,然后碰到了一个版本冲突提示对话框,上面写着:『Windows 当前尝试安装的文件相较于您机器上的文件版本较旧,是否保留较新的文件?』你会怎么做?

Well, if you’re like most people, you say, “Um, I guess I’ll keep the newer one,” so you click Yes.

如果你跟大多数人的想法一样,会想:『唔,那就保留新版本的文件吧』,然后点击了『是』。

And then a few seconds later, you get the same prompt for some other file. And you say Yes again.

没过几秒钟,对话框又弹了出来,这次换了个文件,你又点了『是』。

And then a few seconds later, you get the same prompt for yet another file. Now you’re getting nervous. Why is the system asking you all these questions? Is it second-guessing your previous answers? Often when this happens, it’s because you’re doing something bad and the computer is giving you one more chance to change your mind before something horrible happens. Like in the movies when you have to type Yes five times before it will launch the nuclear weapons.

又过了几秒钟,对话框换了个文件又一次弹了出来,这下你开始变得焦虑起来了。为什么系统会问我这些问题?是想让我对前面的问题再作三思吗?类似这样的情况发生时,通常是因为你做错了什么事,而计算机正在事情变得无法挽留之前再给你一次改变主意的机会,就像在电影里,在发射核武器之前需要输入五次『Yes』一样。

Maybe this is one of those times.

而眼下大概就是那种场景。

Now you start saying No. Besides, it’s always safer to say No, isn’t it?

于是你开始点『否』了。说实话,说『否』更安全些,不是吗?

After a few more dialogs (answering No this time), Setup finally completes. The system reboots, and… it bluescreens.

又看过几个对话框之后(而你在面对这些对话框时都点了『否』),安装程序终于收工,计算机重启,然后……等着你的是一片蓝屏。

Why?

怎么会这样?

Because those five files were part of a matched set of files that together form your video driver. By saying Yes to some of them and No to others, you ended up with a mishmash of files that don’t work together.

因为你点了『否』的那五个文件是你的显卡驱动的一部分。对其中一部分文件选择了『是』,又对另一部分选择了『否』,结果新旧文件掺杂在一起,无法正常工作。

We learned our lesson. Setup doesn’t ask this question any more. It always overwrites the files with the ones that come with the operating system. Sure, you may lose functionality, but at least you will be able to boot. Afterwards, you can go to Windows Update and update that driver to the latest version.

我们接受了这个教训,安装程序再也不会问这类问题了,现在它总是会用随操作系统出厂的文件对其进行覆盖。的确,这样会损失一些新功能,但至少可以正常启动。在那之后,你总可以去Windows Update里将驱动更新到新版本。

Note, however, that this rule does not apply to hotfixes and Service Packs.

不过需要注意的是,这样的规则并不适用于系统补丁(Hotfix)和服务包(Service Packs)。

TONT 37523 资源管理器是如何检测你的程序是否支持长文件名的?

原文链接:https://devblogs.microsoft.com/oldnewthing/20041020-00/?p=37523

When you register your program with a file association, the shell needs to decide whether your program supports long file names so it can decide whether to pass you the long name (which may contains spaces! so make sure you put quotation marks around the “%1” in your registration) or the short name.

当你为自己的应用程序建立文件关联时,系统需要知道你的应用程序是否支持长文件名,这样才能决定是否向你的程序传递长文件名(可能会包含空格!所以请保证在注册文件关联时在%1前后包上西文引号)还是短文件名。

The rule is simple: The shell looks at your program’s EXE header to see what kind of program it is.

规则很简单:系统会依据程序exe文件的文件头来进行判断。

  • If it is a 16-bit program, then the shell assumes that it supports long file names if it is marked as Windows 95-compatible. Otherwise, the shell assumes that it does not support long file anmes.
    如果是16位应用程序,并且标记为Windows 95兼容,系统会认为其支持长文件名,否则认为不支持。(译注:anmes疑为names误植,此处原样保留)
  • If it is a 32-bit program (or 64-bit program for 64-bit systems), then the shell assumes that it supports long file names.
    如果是32位应用程序(或面向64位系统的64位应用程序),系统会认为其支持长文件名。
  • If it can’t find your program, then the shell plays it safe and assumes that the program doesn’t support long file names.
    如果找不到你的程序,系统会保守起见认为其不支持长文件名。

Note that third case. If you mess up your program registration, then the shell will be unable to determine whether your program supports long file names and assumes not. Then when your program displays the file name in, say, the title bar, you end up displaying some icky short file name alias instead of the proper long file name that the user expects to see.

注意第三种情况。如果你注册文件关联的时候玩脱了,那么系统就无法判定你的程序是否支持长文件名,并假定其不支持。这样如果你的程序在某些地方显示文件名(比如标题栏)的话,就会显示成那种看上去很讨厌的短文件名别名,而不是用户期望看到的长文件名。

The most common way people mess up their program registration is by forgetting to quote spaces in the path to the program itself! For example, an erroneous registration might go something like this:

最常见玩脱注册文件关联的方式,是忘记将程序路径包含在引号的里面!例如,某程序错误地注册文件关联的情况如下所示:

HKEY_CLASSES_ROOT\litfile\shell\open\command

(default) = C:\Program Files\LitWare Deluxe\litware.exe “%1”

Observe that the spaces in the path “C:\Program Files\Litware Deluxe\litware.exe” are not quoted in the program registration. Consequently, the shell mistakenly believes that the program name is “C:\Program”, which it cannot find. The shell therefore plays it safe and assumes no LFN support.

注意观察程序路径『C:\Program Files\Litware Deluxe\litware.exe』并没有用引号括起来。由此,系统便错误地认为程序的名称是『C:\Program』,并且也找不到对应的文件,所以系统决定保守起见,认为这个程序不支持长文件名。

Compatibility note: As part of other security work, the code in the shell that parses these command lines was augmented to chase down the “intended” path of the program. This presented the opportunity to fix that third case, so that the shell could find the program after all and see that it supported long file names, thereby saving the user the ignominy of seeing their wonderful file name turn into a mush of tildes.

这里有一个兼容性相关的小故事:作为安全方面考量的一环,系统中有关处理这些命令行的代码曾被要求可以主动找出对应程序『原本』的路径。这样的设计提供了一种对前述第三种情况补救的机会,系统可能因此找到对应的程序文件,并实际判断其是否支持长文件名,如此一来用户就不会对其美妙的文件名变成一堆小浪花(译注:~符号,长文件名压缩到短文件名时用以区别多个压缩后同名文件的机制之一,形如FILENA~1.DOC、FILENA~2.DOC等)而干瞪眼了。

And after we made the change, we had to take it out.

我们在做出这样的改进后,又不得不将其撤了下来。

Because there were programs that not only registered themselves incorrectly, but were relying on the shell not being smart enough to find their real location, resulting in the program receiving the short name on the command line. Turns out these programs wanted the short name, and doing this fake-out was their way of accomplishing it.

因为(这样改进之后)某些应用程序不光不用正确的方式去注册文件关联,甚至还依赖这种原先系统无法找到其程序文件的缺陷,由此使系统传短文件名进去。我们发现这个程序就是想要短文件名,而它则是用这种欺骗的手段来达成目的的。

(And to those of you who are already shouting, “Go ahead and break them,” that’s all fine and good as long as the thing that’s incompatible isn’t something you use. But if it’s your program, or a program your company relies on, I expect you’re going to change your tune.)

(此外,对那些此时已经在大喊『那就别管他们啊』的人们,只要这不是你非用不可的软件,怎么样都是好的。但如果这样做的就是你的软件,或者你们公司依赖的软件,我很乐意看到你收回你的说法。)

TONT 37533 即使是内部数据也会有兼容性约束的需求

原文链接:https://devblogs.microsoft.com/oldnewthing/20041019-00/?p=37533

The Listview control when placed in report mode has a child header control which it uses to display column header titles. This header control is the property of the listview, but the listview is kind enough to let you retrieve the handle to that header control.

当Listview控件置于报表模式下时,其内有一个表头控件,用来展示列标题。这个表头控件是属于Listview的“私有财产”,不过Listview很大方,允许你去获取这个表头空间的句柄。

And some programs abuse that kindness.

而有些应用程序就滥用了这种大方。

It so happens that the original listview control did not use the lParam of the header control item for anything. So some programs said, “Well, if you’re not using it, then I will!” and stashed their own private data into it.

凑巧,原始版本的Listview没有使用这个表头控件的lParam,这时个别程序就决定,『你不用的话,我就用一下好了!』然后将其内部数据塞了进去。

Then a later version of the listview decided, “Gosh, there’s some data I need to keep track of for each header item. Fortunately, since this is my header control, I can stash my data in the lParam of the header item.”

后续版本的Listview做了个决定:『哎呀,这些个表头有些数据我得跟踪监视,不过还好,这个表头控件是属于我的,只要把数据藏进lParam里去修好了。』

And then the application compatibility team takes those two ingredients (the program that stuffs data into the header control and the listview that does the same) to their laboratory, mixes them, and an explosion occurs.

后来,应用程序兼容性团队把这两种成分(把私有数据塞进表头控件里的应用、和同样这样做的Listview)带进了实验室,将二者混合,然后就炸了。

After some forensic analysis, the listview development team figures out what happened and curses that they have to work around yet another program that grovels into internal data structures. The auxiliary data is now stored in some other less convenient place so those programs can continue to run without crashing.

经过一番正经八百的论证,Listview控件的开发团队找到了问题的原因,并选择在这又一个随便挖进内部数据结构的应用程序面前退让一步。前面提到的辅助数据现在被放进了不太容易被乱来的地方,这样那个乱改(Listview)内部数据的程序就能继续运行而不崩溃了。

The moral of the story: Even if you change something that nobody should be relying on, there’s a decent chance that somebody is relying on it.

故事的寓意是:即便你修改了别人不该依赖的位置,还是有相当的可能有人是依赖它的。

(I’m sure there will be the usual chorus of people who will say, “You should’ve just broken them.” What if I told you that one of the programs that does this is a widly-used system administration tool? Eh, that probably wouldn’t change your mind.)

(我敢肯定肯定又有很多人要说,『别管那家伙不就好了』,要是我告诉你这样做的程序之一是某个被广泛使用的系统管理工具呢?不过,这大概也不会让你收回前言吧。)