Showing tag results for Code

Jul 12, 2007
Post comments count0
Post likes count0

If you want a modeless dialog, then create a modeless dialog already

Raymond Chen
Raymond Chen

Somebody I'd never heard of sent me email with a general programming question. (This is one of the top ways of instantly making me not interested in talking to you.) I have a modal dialog box which I hide with , and I want to enable the parent window so the parent window will get focus and keyboard input. Is this possible? If so, how do I do it?...

Code
Jul 11, 2007
Post comments count0
Post likes count0

How to check for errors from SetFilePointer

Raymond Chen
Raymond Chen

The function reports an error in two different ways, depending on whether you passed as the parameter. The documentation in MSDN is correct, but I've discovered that people prefer when I restate the same facts in a different way, so here comes the tabular version of the documentation. I'd show some sample code, but the documentation in MSDN ...

Code
Jul 10, 2007
Post comments count0
Post likes count0

The forgotten common controls: The ShowHideMenuCtl function

Raymond Chen
Raymond Chen

The function is one of those functions everybody tries to pretend doesn't exist. You thought was bad; is even worse. The idea behind was that you had a window with a menu as well as controls, and some of the menu items were checkable, indicating whether the corresponding control should be shown. For example, on your View menu you might have...

Code
Jul 5, 2007
Post comments count0
Post likes count0

QueryPerformanceCounter is not a source for unique identifiers

Raymond Chen
Raymond Chen

This article happened to catch my eye: I needed to generate some unique number in my application. I could use GUID, but it was too large for me (I need to keep lots of unique identifiers). I found something like this: This code generates Int64 (long) unique number (at least I hope it is unique). The uniqueness is in the scope of process. So...

Code
Jul 3, 2007
Post comments count0
Post likes count0

If the system says that an embedded string could not be converted from Unicode to ANSI, maybe it's trying to tell you something

Raymond Chen
Raymond Chen

It's probably trying to tell you that an embedded string could not be converted from Unicode to ANSI. One of our programs is throwing the exception "Type could not be marshaled because an embedded string could not be converted from Unicode to ANSI." It happens only if we use the Chinese version of the program. Why are we getting this exception? ...

Code
Jun 29, 2007
Post comments count0
Post likes count0

Don't forget to pass the current directory along with the command line to your single-instance program

Raymond Chen
Raymond Chen

If you make a single-instance program, and somebody runs a second copy of the program and passes a command line, the most common way of handling this is to hand the command line to the first copy of the program and let the first copy deal with it. When you do this, don't forget about the current directory. If somebody passes a relative path to t...

Code
Jun 27, 2007
Post comments count0
Post likes count0

Those who do not understand the dialog manager are doomed to reimplement it, badly

Raymond Chen
Raymond Chen

A customer wanted to alter the behavior of a multi-line edit control so that it did not treat a press of the Tab key as a request to insert a tab character but rather treated it as a normal dialog navigation key. The approach the customer took was to subclass the edit control and intercept the Tab key: There are many things wrong with this appr...

Code
Jun 26, 2007
Post comments count0
Post likes count0

Why do DLGC_WANTALLKEYS and DLGC_WANTMESSAGE have the same value?

Raymond Chen
Raymond Chen

From a purely theoretical point of view, there is only one "want" code you really need: . All the others are just conveniences. For example, returning means "I want this message if it is an arrow key; otherwise, I don't care." It lets you write instead of the more cumbersome (but equivalent) Similarly, is equivalent to returning if the me...

Code
May 31, 2007
Post comments count0
Post likes count0

Visual C++ 2005 will generate manifests for you

Raymond Chen
Raymond Chen

New in Visual C++ 2005 is the ability to specify a manifest dependency via a directive. This greatly simplifies using version 6 of the shell common controls. You just have to drop the line into your program and the linker will do the rest. Note that the processor architecture is hard-coded into the above directive, which means that if ...

Code
May 29, 2007
Post comments count0
Post likes count0

Psychic debugging: Why does FormatMessage say the resource couldn't be found?

Raymond Chen
Raymond Chen

Solving this next problem should be a snap with your nascent psychic powers: I'm trying use to load a resource string with one insertion in it, and this doesn't work for some reason. The string is "Blah blah blah %1. Blah blah blah." The call to fails, and returns . What am I doing wrong? Hint: Take a closer look at the parameter . Hint&...

Code