Showing tag results for Code

Jul 29, 2010
Post comments count0
Post likes count1

Why is my icon being drawn at the wrong size when I call DrawIcon?

Raymond Chen
Raymond Chen

Some time ago I had a problem with icon drawing. When I tried to draw an icon with it ended up being drawn at the wrong size. A call to confirmed that the icon was 48×48, but it drew at 32×32. The answer is documented in a backwards sort of way in the function, which says at the bottom, To duplicate DrawIcon (hDC, X, Y, hIcon),...

Code
Jul 23, 2010
Post comments count0
Post likes count2

If I'm not supposed to call IsBadXxxPtr, how can I check if a pointer is bad?

Raymond Chen
Raymond Chen

Some time ago, I opined that should really be called and you really should just let the program crash if somebody passes you a bad pointer. It is common to put pointer validation code at the start of functions for debugging purposes (as long as you don't make logic decisions based on whether the pointer is valid). But if you can't use , how can...

Code
Jul 19, 2010
Post comments count0
Post likes count1

To enable and disable a window, use the EnableWindow function

Raymond Chen
Raymond Chen

Commenter Chris 'Xenon' Hanson points out that fiddling with the style directly via leads to strange behavior. However it isn't the case that "most widget classes work fine." Reaching in and fiddling the style bit directly is like reaching into a program's internal variables and just changing the values: All the other work that is associated wi...

Code
Jul 16, 2010
Post comments count0
Post likes count1

How do I launch the Explorer Search window with specific search criteria?

Raymond Chen
Raymond Chen

A customer wanted to know how to launch Explorer's Search window with specific fixed search criteria. It turns out that there are two ways of doing this, the poor man's way and the overachiever's way. The overachiever's way is actually easier to discover. You can use the search-ms protocol to generate a command string that describes the query you...

Code
Jul 9, 2010
Post comments count0
Post likes count1

What's the difference between LastWriteTime and ChangeTime in FILE_BASIC_INFO?

Raymond Chen
Raymond Chen

The structure contains a number of fields which record the last time a particular action occurred. Two of the fields seem to describe the same thing. Last­Write­Time The time the file was last written to. Change­Time The time the file was changed. What's the difference between writing to a file and changing it? I'm told that th...

Code
Jul 2, 2010
Post comments count0
Post likes count1

Instead of trying to figure out what shortcut class to use, just ask the shell to do it for you

Raymond Chen
Raymond Chen

If a shell namespace item has the attribute, then it is a shortcut to another location. The most common type of shortcut is the file, which you can load by creating the object and using , but what if you have some other type of shortcut? How do you know what CLSID to use? Since anybody can create their own shortcut file types, a hard-coded li...

Code
Jul 1, 2010
Post comments count0
Post likes count1

What is the lpClass member of SHELLEXECUTEINFO used for?

Raymond Chen
Raymond Chen

A customer reported problems launching the default Web browser with the function: This fails with . If you don't pass the flag and leave , then the function will try to figure out what your refers to, looking at the file extension, looking for the file on the , and if all else fails, trying some autocorrection. In this case, the customer...

Code
Jun 28, 2010
Post comments count0
Post likes count1

How do I get a radio button control to render its text transparently?

Raymond Chen
Raymond Chen

Commenter Andrei asks via the Suggestion Box for help with making the text transparent using . "Instead of the radio button now there's a black background." Let's look at this problem in stages. First, let's ignore the transparent part and figure out how to render text without a black background. The background color of the text comes from the ...

Code
Jun 14, 2010
Post comments count0
Post likes count1

Annotating function parameters and using PREfast to check them

Raymond Chen
Raymond Chen

Via the suggestion box, Sys64738 asks, whether I think is a good C/C++ programming style to add IN and OUT to function prototypes. Remember, this is my opinion. Your opinion may validly differ. I would go beyond just IN and OUT and step up to SAL annotations, which describe the semantics of function parameters in more detail than simply IN and ...

Code