Showing tag results for Code

May 20, 2013
Post comments count0
Post likes count2

Copying a file to the clipboard so you can paste it into Explorer or an email message or whatever

Raymond Chen

Today's Little Program takes a fully-qualified file name from the command line and puts that file onto the clipboard. Once there, you can paste it into an Explorer window, or into an email message, or a word processing document, or anybody else who understands shell data objects. #include <windows.h> #include <shlobj.h> #include <...

Code
May 17, 2013
Post comments count0
Post likes count1

Who sends the initial WM_UPDATEUISTATE message?

Raymond Chen

Last time, we looked at the confusingly-named WM_UPDATE­UI­STATE and WM_CHANGE­UI­STATE messages. But how does the whole indicator thingie get off the ground? The default state for a window is to show all indicators. But as a special trick, the dialog manager will send a WM_UPDATE­UI­STATE message with UIS_INITIALIZE aft...

Code
May 16, 2013
Post comments count0
Post likes count1

Untangling the confusingly-named WM_UPDATEUISTATE and WM_CHANGEUISTATE messages

Raymond Chen

I always get confused by the and messages, and I have to go figure them out each time I need to mess with them. So this time, I'm going to write it down so I don't forget. Because the act of writing it down helps me to remember. It's like in school, where the teacher says, "This is a closed-book, closed-notes exam, but you are allowed to bring ...

Code
May 15, 2013
Post comments count0
Post likes count1

What does GDI use biXPelsPerMeter and SetBitmapDimensionEx for?

Raymond Chen

What does GDI use and for? Nothing. The and are completely ignored by GDI when loading a bitmap. The values are there for the benefit of image-editing programs who want to record additional information about the bitmap, but GDI ignores them. Similarly, the and functions update a structure associated with each bitmap, but GDI does not...

Code
May 13, 2013
Post comments count0
Post likes count1

How can I display a live screenshot of a piece of another application?

Raymond Chen

Today's Little Program takes a rectangular portion of another application and continuously replicates it in its own client area. You might want to do this if you want to monitor a portion of an application like a custom progress bar, and the application doesn't use the Windows 7 taskbar progress indicator feature. (Maybe it's an old applicati...

Code
May 10, 2013
Post comments count0
Post likes count1

If you want to use a name for your file mapping, don’t just use the name of the file itself

Raymond Chen

The original question from the customer was why they couldn't get named file mappings to work at all, but it turns out that the reason is that they were using the full path to the file as the name, even though backslashes have special meaning in file mapping names. Okay, that problem can be solved by changing the backslash to some character lega...

Code
May 9, 2013
Post comments count0
Post likes count1

Why am I getting LNK2019 unresolved external for my inline function?

Raymond Chen

More than once, I've seen somebody confused by how inline functions work. I have implemented a few inline functions in one of my cpp files, and I want to use it from other cpp files, so I declare them as extern. But sometimes I will get linker error 2019 (unresolved external) for the inline functions. // a.cpp inline bool foo() { return false...

Code
May 8, 2013
Post comments count0
Post likes count1

Mathematical formulas are designed to be pretty, not to be suitable for computation

Raymond Chen

When you ask a mathematician to come up with a formula to solve a problem, you will get something that looks pretty, but that doesn't mean that it lends itself well to computation. For example, consider the binomial coefficient, traditionally written nCk or C(n, k), and in more modern notation as ( nk ). If you ask a mathematician f...

Code
May 6, 2013
Post comments count0
Post likes count1

Reading mouse input from a console program, and programmatically turning off Quick Edit mode

Raymond Chen

Today's Little program shows how to read mouse input from a console program. You might use this if you are writing a console-mode text editor with mouse support, or maybe you want to want to add mouse support to your roguelike game. But I'm not going to implement the game itself. Instead, I'm just going to print mouse coordinates to the screen....

Code
May 3, 2013
Post comments count0
Post likes count1

Creating a simple pidl: For the times you care enough to send the very fake

Raymond Chen

I'll assume that we all know what pidls are and how the shell namespace uses them. That's the prerequisite for today. A simple pidl is an item ID list that refers to a file or directory that may not actually exist. It's a way of playing "what if": "If there were a file or directory at this location, here is what I would have created to represent...

Code