Showing tag results for Code

Sep 23, 2004
Post comments count0
Post likes count0

How to host an IContextMenu, part 3 – Invocation location

Raymond Chen
Raymond Chen

One of the bugs you may have noticed in our first attempt at displaying the context menu to the user is that the Properties dialog doesn't show up at the point you clicked. The Properties dialog isn't psychic; it doesn't know where the original mouse click occurred. You have to tell it. CMINVOKECOMMANDINFOEX info = { 0 }; ...

Code
Sep 22, 2004
Post comments count0
Post likes count0

How to host an IContextMenu, part 2 – Displaying the context menu

Raymond Chen
Raymond Chen

Instead of invoking a fixed verb, we'll ask the user to choose from the context menu and invoke the result. Make these changes to the OnContextMenu function: #define SCRATCH_QCM_FIRST 1 #define SCRATCH_QCM_LAST 0x7FFF #undef HANDLE_WM_CONTEXTMENU #define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \ ((fn)((hwnd), (HWND)(wParam), GET...

Code
Sep 21, 2004
Post comments count0
Post likes count0

Pitfalls in handling the WM_CONTEXTMENU message

Raymond Chen
Raymond Chen

Before we continue with our IContextMenu discussion, I need to take a little side trip and discuss the subtleties of the WM_CONTEXTMENU message. First, a correction to the existing <windowsx.h> header file: #undef HANDLE_WM_CONTEXTMENU #define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \ ((fn)((hwnd), (HWND)(wParam), GET_X_LPAR...

Code
Sep 20, 2004
Post comments count0
Post likes count1

How to host an IContextMenu, part 1 – Initial foray

Raymond Chen
Raymond Chen

Most documentation describes how to plug into the shell context menu structure and be a context menu provider. If you read the documentation from the other side, then you also see how to host the context menu. (This is the first of an eleven-part series with three digressions. Yes, eleven parts—sorry for all you folks who are in it just fo...

Code
Sep 16, 2004
Post comments count0
Post likes count0

What happens when you specify RegexOptions.ECMAScript?

Raymond Chen
Raymond Chen

The flag changes the behavior of .NET regular expressions. One of the changes I had discussed earlier was with respect to matching digits. For those who want to know more, a summary of the differences is documented in MSDN under the devious title "ECMAScript vs. Canonical Matching Behavior". Apparently some people had trouble finding that page...

Code
Sep 15, 2004
Post comments count0
Post likes count1

Interlocked operations don’t solve everything

Raymond Chen
Raymond Chen

Interlocked operations are a high-performance way of updating DWORD-sized or pointer-sized values in an atomic manner. Note, however, that this doesn't mean that you can avoid the critical section. For example, suppose you have a critical section that protects a variable, and in some other part of the code, you want to update the variable atomi...

Code
Sep 9, 2004
Post comments count0
Post likes count0

Why isn’t the original window order always preserved when you undo a Show Desktop?

Raymond Chen
Raymond Chen

A commenter asked why the original window order is not always preserved when you undo a Show Desktop. The answer is "Because the alternative is worse." Guaranteeing that the window order is restored can result in Explorer hanging. When the windows are restored when you undo a Show Desktop, Explorer goes through and asks each window that it...

Code
Sep 7, 2004
Post comments count0
Post likes count0

Converting a byte[] to a System.String

Raymond Chen
Raymond Chen

For some reason, this question gets asked a lot. How do I convert a byte[] to a System.String? (Yes, this is a CLR question. Sorry.) You can use String System.Text.UnicodeEncoding.GetString() which takes a byte[] array and produces a string. Note that this is not the same as just blindly copying the bytes from the byte[] array into a hunk of ...

Code
Sep 3, 2004
Post comments count0
Post likes count0

Even in computing, simultaneity is relative

Raymond Chen
Raymond Chen

Einstein discovered that simultaneity is relative. This is also true of computing. People will ask, "Is it okay to do X on one thread and Y on another thread simultaneously?" Here are some examples: You can answer this question knowing nothing about the internal behavior of those operations. All you need to know are some physics and the ...

Code
Sep 1, 2004
Post comments count0
Post likes count0

How to find the Internet Explorer binary

Raymond Chen
Raymond Chen

For some reason, some people go to enormous lengths to locate the Internet Explorer binary so they can launch it with some options. The way to do this is not to do it. If you just pass "IEXPLORE.EXE" to the ShellExecute function [link fixed 9:41am], it will go find Internet Explorer and run it. ShellExecute(NULL, "open", "iexplore.exe", ...

Code