Why are documents printed out of order when you multiselect and choose “Print”?

Date:December 3, 2004 / year-entry #409
Tags:other
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20041203-00/?p=37143
Comments:    26
Summary:If you select say five files and then right-click them and choose "Print", they tend to print in a random order. Why is that? The shell invokes the Print verb on each file in turn, and depending on how the program responsible for printing the document is registered, one of several things can happen. Most...

If you select say five files and then right-click them and choose "Print", they tend to print in a random order. Why is that?

The shell invokes the Print verb on each file in turn, and depending on how the program responsible for printing the document is registered, one of several things can happen.

  • Most commonly, the program that prints the document registered a simple command line under the shell\print\command registry key. In this case, the program is launched five times, each with a different file. All these print commands are now racing to the printer and it's a question of which copy of the program submits its print job first that determines the order in which they come out of the printer. (You're probably going to see the shortest and simplest documents come out first since they take less time to render.)
  • Occasionally, the program that prints the document registered a DDE verb under the shell\print\ddeexec registry key. In this case, one copy of the program is launched and it is given each filename one at a time. What it does with those filenames is now up to the program. If the program supports background printing, it will probably shunt the printing of the document onto a background thread, and now you're roughly in the same fix as the previous scenario: Five background threads each racing to see who can submit their print job first.
  • Extremely rarely, the program that prints the document registered a drop handler under the shell\print\DropTarget key. In this case, the drop target is instantiated and is given the list of files. It is then up to the drop target to decide what to do with the documents.

These three ways of registering print actions are described in the MSDN documentation on verbs and file associations.

[Update: 7:30am, fixed title.]


Comments (26)
  1. Mat Hall says:

    There’s also a slight oddity in the order that multiple selections are returned from file dialogs; clicking on a file in an Open dialog, then holding Shift and clicking a second file usually results in the file you selected first moving to the END of the list…

  2. I would bet that 95 out of 100 users don’t know you right-click, print.

  3. Andrew Quinn says:

    I actually just had to explain a semi-sort-of-similar thing to a friend who was getting very annoyed with WMP. He was selecting an album’s worth of tracks in Explorer, all nicely numbered and ordered, and dragging them over to WMP, which would start playing at some random point halfway down the list.

    But hey, this is almost a feature, in a way, once you figure it out. The list of files in the drag starts with whichever one the mouse is over when you start the drag.

    I can’t imagine trying to justify this to somebody non-technical… but at least it’s consistent.

  4. Fat Agnus and Denise says:

    What about Amiga? Does it print sequentially when you drop files on printer icon?

  5. Merle says:

    Mat: yes, that always disturbed me that the first file selected becomes the last, either when opening or when copying (copying you only notice on huge files).

    I heard a description once about why this happened, but it did not make sense, and eludes me currently. Raymond?

  6. Ben Hutchings says:

    Fat Agnus and Denise: No, it doesn’t even have printer icons. Printing support really, really sucked.

  7. Vorn says:

    On the other hand not many OSes do printing right anyway; Windows was very fortunate in this respect, because it made drawing to the printer exactly like drawing to the screen. (isn’t that nice of them?) Using CUPS (Common Unix Printing System) is a pain because often you have to manually turn your document into a PostScript file before sending it to the printer queue.

    Vorn

  8. Almost Anonymous says:

    I’m constantly encountering that last-file-first issue with selecting files. Usually it’s in file selection dialogs like when trying to view slideshow images.

    I’ve started the practice of selecting from the bottom to the top to ensure I get things in order.

    The reason for the weird selection is that the currently selected item is always first. This is one of those cases where Windows doesn’t "do what I mean" even if it’s somewhat logical.

  9. Merle: That’s a good question. I tried looking for an answer in the ‘The Windows User Experience’ book, but couldn’t find much information about activating multiple objects.

    Selection of multiple objects is explained in good details :)

  10. Yes, the shell’s notion of the "active object" in a multiple selection leads to some surprising behavior. Much of what the shell does with multiple selections doesn’t make much sense, and I quickly lost interest in trying to emulate it exactly when writing runmenu, for which I had to go to some lengths to conjure up a context menu for a list of files residing in different directories. Here are some things I noticed about the "active object" and decided not to emulate in my MultiContextMenu class:

    1. The shell’s context menu for a multiple selection typically includes "Open with", but it applies only to the item within the selection that was right-clicked. So the shell adds items to the context menu for a multiple selection that don’t apply to the entire selection.

    2. The items which appear on the menu for a multiple selection depend on which file was right-clicked. Select a .url and .lnk file as a multiple selection and alternate the one you right-click on to see what I mean.

    3. If two .lnk files are selected, the shell may resolve the name of the one right-clicked on and send it alone to the item you choose from the context menu. I observe this with WinRAR, Panda AntiVirus, and my own Eluent Tools stuff. (However, the "Send To Any Folder" powertoy gets both the .lnk files. Anyone know how to get the "Send To" behavior?)

    It seems like whoever wrote the shell code felt that shortcuttedness should override multiple selectioness, and the file right-clicked upon in a multiple selection should cause some menu items to act as if it were the only file selected. The result is a whole lot of inconsistency and surprising behavior. I think the context menu for a multiple selection should not resolve shortcuts, nor should it give special status to the item which had the focus when the context menu was invoked. That’s the approach I ended up taking in MultiContextMenu.

  11. Jon Potter says:

    So what exactly is MultiContextMenu? Google knows nothing…

  12. MultiContextMenu is a C++ class I wrote several years ago, originally for Eluent Dir (a file finder), which I later used in runmenu. It supports creating a context menu for a list of files which reside in different directories. While IShellFolder::GetUIObjectOf can create a context menu for a list of objects all in the same folder, the shell provides no way to create a context menu for a list of objects residing in different folders. Note that Explorer does implement such functionality in its search results pane, but I guess it’s an Explorer-only thing; Windows doesn’t expose it to shell programmers.

  13. Doug, was CDefFolderMenu_Create2 what were you looking for? because it was only documented recently, as part of an out-of-court settlement for the antitrust case (it’s one of the infamous "ordinal-only" shell32.dll exports). Have a look at it

  14. Jonathan says:

    When you drag files into an Outlook Express maiol mesaage, Shell puts the file you dragged from first, and then the rest of the files – in the order they appear. So if you selected files 1 2 3 4 5, and dragged the selection grabbing file 3, in the email you’d get 3 1 2 4 5.

    Except that OE actually reverses the order shell sends it, so you’d actually get 5 4 2 1 3.

    I enevtually figured it out, and I now sort backwards (5 4 3 2 1), and drag by grabbing the last one (5) – that gives me the 1 2 3 4 5 that I want. Took me a while to figure out.

  15. I can’t tell from the docs if CDefFolderMenu_Create2 can handle objects in multiple directories.

    Provided it can cope with objects in multiple directories, messages I found on Usenet say the function will add Cut/Copy/Delete/Properties/etc items to the context menu, which is indeed useful. My MultiContextMenu has to provide those menu items itself, because they aren’t implemented as IContextMenu extensions, that one can discover through the registry. In addition, determining when to enable Cut/Copy/Delete is a pain, and perhaps CDefFolderMenu_Create2 would do that for you.

    I think using CDefFolderMenu_Create2 would require a lot of experimentation to fill out the sparse documentation, but if someone feels like trying it out on a selection such as C:temp1a.txt C:temp2b.exe, I’d be happy to hear their results. :)

  16. I always had the impression (though I didn’t look very carefully) when dragging files into the Winamp playlist, that I’d get, with 1 2 3 4 5 selected, 5 2 3 4 1 as a result.

  17. Norman Diamond says:

    Even doing a multiselection and Ctrl-C, then Ctrl-V into another folder, copies the files out of order. Some of the replies have stated what seems to be the reason for this. Regardless of the reason, this makes it fun (not) when trying to use Windows Explorer to copy a bunch of files, then trying to narrow down a problem by doing a larger number of copy operations on smaller bunches of the files. When a copy operation aborted, the list of files copied so far was not the list of files up to that point in Windows Explorer’s display of them.

    (By the way, the Windows Explorer copy operation is one of those that offers a "yes to all" but doesn’t offer a "no to all". Sometimes really convenient would be a "yes to copy new ones on top of old ones but no to old ones on top of new ones", which is obviously beyond the capabilities of Windows Explorer, but why is there no "no to all"?)

  18. Tom says:

    Norman, shift+No == "no to all".

  19. Mat Hall says:

    ‘shift+No == "no to all"’

    That’s quite possibly the most useful thing I’ve ever heard!

  20. Ben Hutchings says:

    Vorn: Yes, printing is one of the few things I felt Windows was doing very well even in version 3. However I think the remote printing architecture is a bit of a botch and a security nightmare: the client must trust the binaries provided by the server and the server must trust the client not to send a print job that will break the printer. I wonder why Windows doesn’t support generic remote printing using print jobs based on metafiles?

  21. Tom says:

    Ben,

    I think the whole driver per printer thing is a pain. There should be some kind of generic printer driver that takes an image file jpeg’d or losslessly compressed (or even a tiling of the two) and prints it. I can see this being good for things like USB On the Go where your camera uses the printer as a device, and it’s not really feasible to have more than one driver.

    For mono text, zlib/bzip2 lossless compression is probably OK, and JPEG does fine for images. The printer driver could either know which one to use (e.g. in a Camera, where everything is JPEG’d), or it could devise an optimum combination of both (on a PC, where you have lots of info about how the image was constructed not to mention memory+CPU power to burn). This would be in addition to whatever proprietary page description language the printer supports, because these are much more flexible. The USB printer would have a special descriptor to tell the host that it supports this generic mode.

    Then you’d have a generic printer driver on Windows a bit like the generic video driver, but you could replace it with a device specific one if you had one. Cheap printers could only implement the generic protocol, perhaps in an ASIC. For black and white, you could even skip the JPEG support completely.

    Oh, and there were "GDI printers", based on what looks like generating a bitmap on the PC, run length compressing it and sending it down to the printer where hardware (or very simple software) could decompress it, but it never really caught on.

  22. Raymond Chen says:

    What is the DPI of the generic printer? If the actual printer has a different DPI, then all documents will come out looking blocky.

  23. Tom says:

    I guess the printer would need to tell the host, especially for text or lineart. You could put this information (and much else, like colour and compression support) into a USB Descriptor, and the generic driver could use it from there.

  24. Norman Diamond says:

    12/6/2004 6:28 AM Tom

    > Norman, shift+No == "no to all".

    Thank you! Out of curiosity, how did you discover that?

  25. David Candy says:

    Raymond had a big fight with nearly everyone in the world (not me though) who wanted dialogs that duplicated XCopy’s switches during XP’s beta. Then this No To All poped up in the gold version. If you go through the tips in Tweakui you’ll find it.

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index