Showing tag results for Code

Nov 19, 2004
Post comments count0
Post likes count0

The various ways of sending a message

Raymond Chen

There are several variations on the SendMessage function, but some are special cases of others. The simplest version is SendMessage itself, which sends a message and waits indefinitely for the response. The next level up is SendMessageTimeout which sends a message and waits for the response or until a certain amount of time has elapsed. Send...

Code
Nov 17, 2004
Post comments count0
Post likes count0

How do I break an integer into its component bytes?

Raymond Chen

Warning: .NET content ahead. For some reason, this gets asked a lot. To break an integer into its component bytes, you can use the BitConverter.GetBytes method: int i = 123456; byte[] bytes = BitConverter.GetBytes(i); After this code fragment, the byte array contains { 0x40, 0xE2, 0x01, 0x00 }. Update 11am: The endian-ness of th...

Code
Nov 11, 2004
Post comments count0
Post likes count0

Advantages of knowing your x86 machine code

Raymond Chen

Next time you find yourself debugging in assembly language (which for some of us is the only way we debug), here are some machine code tricks you may wish to try out: 90 This is the single-byte NOP opcode. If you want to patch out code and don't want to think about it, just whack some 90's over it. To undo it, you have to patch the or...

Code
Oct 25, 2004
Post comments count0
Post likes count1

Accessing the current module’s HINSTANCE from a static library

Raymond Chen

If you're writing a static library, you may have need to access the HINSTANCE of the module that you have been linked into. You could require that the module that links you in pass the HINSTANCE to a special initialization function, but odds are that people will forget to do this. If you are using a Microsoft linker, you can take advantage of a ...

Code
Oct 21, 2004
Post comments count0
Post likes count0

Let WMI do the heavy lifting of determining system information

Raymond Chen

Windows Management Instrumentation is a scriptable interface to configuration information. This saves you the trouble of having to figure it out yourself. For example, here's a little program that enumerates all the CPUs in your system and prints some basic information about them. var locator = WScript.CreateObject("WbemScripting.SWbemLocator...

Code
Oct 18, 2004
Post comments count0
Post likes count0

Implementing higher-order clicks

Raymond Chen

Another question people ask is "How do I do triple-click or higher?" Once you see the algorithm for double-clicks, extending it to higher order clicks should be fairly natural. The first thing you probably should do is to remove the CS_DBLCLKS style from your class because you want to do multiple-click management manually. Next, you can simply...

Code
Oct 15, 2004
Post comments count0
Post likes count0

Logical consequences of the way Windows converts single-clicks into double-clicks

Raymond Chen

First, I'm going to refer you to the MSDN documentation on mouse clicks, since that's the starting point. I'm going to assume that you know the mechanics of how single-clicks are converted to double-clicks. Okay, now that you've read it, let's talk about some logical consequences of that article and what it means for the way you design your use...

Code
Oct 7, 2004
Post comments count0
Post likes count0

How to host an IContextMenu, part 11 – Composite extensions – composition

Raymond Chen

Okay, now that we have two context menu handlers we want to compose (namely, the "real" one from the shell namespace and a "fake" one that contains bonus commands we want to add), we can use merge them together by means of a composite context menu handler. The kernel of the composite context menu is to multiplex multiple context menus onto a sin...

Code
Oct 4, 2004
Post comments count0
Post likes count0

How to host an IContextMenu, part 9 – Adding custom commands

Raymond Chen

The indexMenu, idCmdFirst and idCmdLast parameters to the IContextMenu::QueryContextMenu method allow you, the host, to control where in the context menu the IContextMenu will insert its commands. To illustrate this, let's put two bonus commands on our context menu, with the boring names "Top" and "Bottom". We need to reserve some space in our ...

Code