Showing tag results for Code

Oct 23, 2012
Post comments count0
Post likes count0

Diversion: Generating a random color from JavaScript

Raymond Chen
Raymond Chen

A colleague posed a little puzzle for a fun little app he was writing in HTML: He wanted to generate a random color. If you search around the intertubes, you can find several possible attempts at a solution, like this collection, and an interesting example that has trouble with the pigeonhole principle. The original function to generate a ra...

Code
Oct 19, 2012
Post comments count0
Post likes count0

Using WM_COPYDATA to marshal message parameters since the window manager otherwise doesn’t know how

Raymond Chen
Raymond Chen

Miral asks for the recommended way of passing messages across processes if they require custom marshaling. There is no one recommended way of doing the custom marshaling, although some are hackier than others. Probably the most architecturally beautiful way of doing it is to use a mechanism that does perform automatic marshaling, like COM and MI...

Code
Oct 11, 2012
Post comments count0
Post likes count0

Combo boxes have supported incremental searching for quite some time now

Raymond Chen
Raymond Chen

Back in August 2007, I promised to post a program the following day but it appears that I never did. Oops. I discovered this as I went through my "things to blog about" pile and figured better late than never. Though five years late is pretty bad. Here's a program which fills a combo box with some strings. Run this program and start typing: "...

Code
Oct 5, 2012
Post comments count0
Post likes count0

How do I override the default icon selection algorithm?

Raymond Chen
Raymond Chen

The usual way of loading an icon from a resource is to use the or function and letting the window manager's icon selection algorithm decide which image to use based on the images available in the icon, the desired icon size, and the current color depth. A customer wanted to override that algorithm, because the window manager uses the current dis...

Code
Oct 4, 2012
Post comments count0
Post likes count0

Why does RegOpenKey sometimes (but not always) fail if I use two backslashes instead of one?

Raymond Chen
Raymond Chen

A customer reported that on Windows XP, they observed that their program would very rarely get the error when they passed two backslashes instead of one to the function: After removing C++ escapes, the resulting string passed to is The failure was very sporadic and not reproducible under controlled conditions. Well, first of all, d...

Code
Oct 3, 2012
Post comments count0
Post likes count0

How do I suppress the default animation that occurs when I hide or show a window?

Raymond Chen
Raymond Chen

A customer wanted to know how they can disable the default fade-in/fade-out animation that occurs when a window is hidden or shown. "I don't want to use because that causes my window to disappear from the taskbar. I tried but that affects the entire desktop and is too jarring. We want to suppress the effect because our program replaces one windo...

Code
Sep 27, 2012
Post comments count0
Post likes count0

Why aren't environment variables being expanded in my RGS file?

Raymond Chen
Raymond Chen

A customer was having trouble with their RGS file. I want to include the below line in a .rgs file: When I do this, registering of the dll fails with 80002009. Any help? If I change it to then the registration succeeds (but of course now contains a hard-coded path). A common problem people have when asking a question is assuming that th...

Code
Sep 26, 2012
Post comments count0
Post likes count0

Sabotaging yourself: Closing a handle and then using it

Raymond Chen
Raymond Chen

A customer reported a problem with the function: I have a DLL with an function and an function. The code goes like this: Under certain conditions, the function is called twice, and the function is correspondingly called twice. Under these conditions, if I run the code on a single-processor system with hyperthreading disabled, then every...

Code
Sep 21, 2012
Post comments count0
Post likes count0

How can I implement SAFEARRAY.ToString() without going insane?

Raymond Chen
Raymond Chen

A colleague needed some help with manipulating s. I have some generic code to execute WMI queries and store the result as strings. Normally, does the work, but doesn't know how to convert arrays (e.g. ). And there doesn't seem to be an easy way to convert the array element-by-element because expects a pointer to an object of the underlying ty...

Code