Showing tag results for 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
May 1, 2013
Post comments count0
Post likes count1

How do I get the current value of the RSP register from a C/C++ function? (No answer, but a solution.)

Raymond Chen

A customer using Visual Studio wanted to know how to obtain the current value of the x64 RSP register from a C/C++ function. They noted that on the x86, you can drop to inline assembly, and on the ia64, you can use the intrinsic to retrieve the value of any register. There is no corresponding intrinsic on x64. There's no really good way of doin...

Code
Apr 29, 2013
Post comments count0
Post likes count1

Getting the display name for a shell property

Raymond Chen

Today's Little Program takes the symbolic name for a shell property and returns a string suitable for display to the end-user, translated into the user's specified display language. #include <windows.h> #include <ole2.h> #include <propsys.h> #include <propkey.h> #include <atlbase.h> #include <atlalloc.h> int ...

Code
Apr 26, 2013
Post comments count0
Post likes count1

Another way to create a process with attributes, maybe worse maybe better

Raymond Chen

Adam Rosenfield noted that "those sure are a lot of hoops you have to jump through to solve this unusual problem" of specifying which handles are inherited by a new process. Well, first of all, what's so wrong with that? You have to jump through a lot of hoops when you are in an unusual situation. But by definition, most people are not in an unus...

Code