Showing tag results for Code

Mar 13, 2014
Post comments count0
Post likes count1

Why does the Directory.GetFiles method sometimes ignore *.html files when I ask for *.htm?

Raymond Chen
Raymond Chen

The documentation for the method says When using the asterisk wildcard character in a search­Pattern, such as "*.txt", the matching behavior when the extension is exactly three characters long is different than when the extension is more or less than three characters long. A search­Pattern with a file extension of exactly three character...

Code
Mar 10, 2014
Post comments count0
Post likes count1

Programmatically uploading a file to an FTP site

Raymond Chen
Raymond Chen

Today's Little Program uploads a file to an FTP site in binary mode with the assistance of the Wininet library. This program has sat in my bag of tools for years. The program accepts five command line arguments: site (no "ftp://" in front) userid password path for the file to upload location to place the uploaded file For example, I might s...

Code
Mar 7, 2014
Post comments count0
Post likes count1

Converting from a UTC-based SYSTEMTIME directly to a local-time-based SYSTEMTIME

Raymond Chen
Raymond Chen

Last year, I presented this commutative diagram A 2-by-2 grid of boxes. The top row is labeled FILE­TIME; the bottom row is labeled SYSTEM­TIME. The first column is labeled UTC; the second column is labeled Local. The upper left box is labeled Get­System­Time­As­File­Time. There is an outgoing arrow to th...

CodeTime
Mar 5, 2014
Post comments count0
Post likes count1

Why do I have to add 1 to the color index when I set it as the hbrBackground of a window class?

Raymond Chen
Raymond Chen

Our scratch program sets the background color to by setting the class background brush as follows: What's with the ? Okay, first of all, let's backtrack a bit. The real first question is, "What's the deal with taking an integer () and casting it to a and expecting anything sane to happen?" The window manager wants to provide multiple w...

Code
Mar 3, 2014
Post comments count0
Post likes count1

Adventures in automation: Dismissing all message boxes from a particular application but only if they say that the operation succeeded

Raymond Chen
Raymond Chen

Suppose you have a program that is part of your workflow, and it has the annoying habit of showing a message box when it is finished. You want to automate this workflow, and part of that automation is dismissing the message box. Let's start by writing the annoying program: This annoying program pretends to do work for a little while, and then...

Code
Feb 28, 2014
Post comments count0
Post likes count1

How can I detect that my program was run from Task Scheduler, or my custom shortcut, or a service, or whatever

Raymond Chen
Raymond Chen

Suppose you want your program to behave differently depending on whether it is launched from the Start menu, or by clicking the pinned icon on the taskbar, or by Scheduled Task, or from a service, or whatever. How can a program detect and distinguish these scenarios? The answer is you don't. And you shouldn't try. Instead of trying to guess how y...

Code
Feb 27, 2014
Post comments count0
Post likes count1

What does the SEE_MASK_UNICODE flag in ShellExecuteEx actually do?

Raymond Chen
Raymond Chen

Somebody with a rude name wonders what the flag does. It does nothing. The flag was introduced when porting the Windows 95 shell to Windows NT. It happened further back in history than I have permission to access the Windows source code history database, but I can guess how it got introduced. One of the things that the porting team ...

Code
Feb 26, 2014
Post comments count0
Post likes count1

Why are leading digits converted to language-specific digit shapes, but not trailing digits, and how do I suppress the conversion entirely?

Raymond Chen
Raymond Chen

If you have a string like , and you render it on an Arabic system, you might get ٠١٢٣٤ABCDE67890. The leading digits are rendered as Arabic-Indic digits, but the trailing digits are rendered as European digits. What's going on here? This is a feature known as contextual digit substitution. You can specify whether Euro...

Code
Feb 24, 2014
Post comments count0
Post likes count1

Logging the contents of every message box dialog via automation

Raymond Chen
Raymond Chen

Today's Little Program logs the contents of every message box dialog, or anything that vaguely resembles a message box dialog. (Since there's no way for sure to know whether a dialog box is a message box or not.) This is the same pattern as the program we wrote last week, but with different guts when the window opens. This time, we see if the...

Code