Well, in that case, Windows can't do any better. In order to defrag a filesystem, that requires free space to copy and move files around. If that space isn't there (because the HDD is nearly full), there isn't much you can do.
It's worth noting that while the Windows defrag utility is completely useless without a lot of free space available, many of the third party defrag tools can still work (albeit much more slowly) in that situation.
Of course with SSDs becoming more and more prevalent, this is becoming a non-issue anyway.