Showing tag results for Code

Apr 30, 2010
Post comments count0
Post likes count0

If it's not yours, then don't mess with it without permission from the owner

Raymond Chen
Raymond Chen

It's surprising how many principles of real life also apply to computer programming. For example, one of the rules of thumb for real life is that is that if something doesn't belong to you, then you shouldn't mess with it unless you have permission from the owner. If you want to ride Jimmy's bike, then you need to have Jimmy's permission. Even if J...

Code
Apr 29, 2010
Post comments count0
Post likes count0

A short puzzle about heap expansion

Raymond Chen
Raymond Chen

At the 2008 PDC, somebody stopped by the Ask the Experts table with a question about the heap manager. I don't understand why the heap manager is allocating a new segment. I allocated a bunch of small blocks, then freed nearly all of them. And then when my program makes a large allocation, it allocates a new segment instead of reusing the mem...

Code
Apr 23, 2010
Post comments count0
Post likes count0

Why can't I get my regular expression pattern to match words that begin with %?

Raymond Chen
Raymond Chen

A customer asked for help writing a regular expression that, in the customer's words, matched the string when it appeared as a standalone word. One of the things that people often forget to do when asking a question is to describe the things that they tried and what the results were. This is important information to include, because it saves th...

Code
Apr 16, 2010
Post comments count0
Post likes count0

The mysterious stock bitmap: There's no way to summon it, but it shows up in various places

Raymond Chen
Raymond Chen

A number of stock GDI objects are made available by the function, but one stock GDI object that is mysteriously missing is the stock bitmap. You can't summon the stock bitmap, but it manages to show up in various places, some of them perhaps unexpected. The stock bitmap is a monochrome 1×1 bitmap which GDI uses in various places where it ...

Code
Apr 14, 2010
Post comments count0
Post likes count0

When you create an object with constraints, you have to make sure everybody who uses the object understands those constraints

Raymond Chen
Raymond Chen

Here's a question that came from a customer. This particular example involves managed code, but don't let that distract you from the point of the exercise. I am trying to create a object using the constructor that takes an as input. In my .cs file, I create the native file handle using , as shown below. Then I create the object as so: ...

Code
Apr 12, 2010
Post comments count0
Post likes count1

How do I switch a window between normal and fullscreen?

Raymond Chen
Raymond Chen

Frederic Delhoume wants to know if there is a simple example of code that switches an application from windowed to fullscreen. He then included a code fragment that did some crazy things with parent windows and hiding and showing. You're making it way, way harder than it needs to be. Let's start with our scratch program and make these changes:...

Code
Apr 9, 2010
Post comments count0
Post likes count0

Why can't you use WM_CTLCOLORSTATIC to change the color of a SS_BLACKRECT?

Raymond Chen
Raymond Chen

If you specify one of the static control styles which draw a frame or rectangle the control will be drawn with the corresponding color (which, as we saw last time, isn't actually black, gray, or white). If you try to customize the color by handling the message, you'll find that it has no effect. Well, yeah, because you said you wanted a black ...

Code
Apr 2, 2010
Post comments count0
Post likes count0

Why do non-folders in my shell namespace extension show up in the folder tree view?

Raymond Chen
Raymond Chen

A customer was having trouble with their shell namespace extension: When we click the [+] button next to our shell namespace extension in the folder tree view, the tree view shows both files and folders, even though it's supposed to show only folders. Our does return the correct values for (including it for the folders and omitting it for the n...

Code
Mar 29, 2010
Post comments count0
Post likes count0

What happens to the control names in the IDE when my program is running?

Raymond Chen
Raymond Chen

nick_journals demonstrates some confusion about names in source code and their relationship to runtime behavior. A topic I am particularly interested in is the naming of controls, how it works... Every control gets a name from a developer...via the IDE (e.g btnOK) When using this function: GetWindowLong(handle,GWL_ID) it doesn't return the n...

Code
Mar 26, 2010
Post comments count0
Post likes count0

WaitForInputIdle waits for any thread, which might not be the thread you care about

Raymond Chen
Raymond Chen

We saw last time that the function waits only once for a process to go input idle. Even if the process later stops processing messages, will return immediately and say, "Yeah, he's idle." The way a process is determined to be input idle is that it is waiting for user input when there is none. This translates into the process sitting in a functi...

Code