Showing tag results for Code

Oct 16, 2013
Post comments count0
Post likes count1

Why does my window get a WM_ACTIVATE message when it isn't active?

Raymond Chen

Say you launch a program, and for whatever reason the program takes a long time to start up, so you start doing something else, say launching Calculator and balancing your checkbook. Eventually, the program you launched a while back gets itself off the ground and creates its main window. And the window sits in the background (since the window manag...

Code
Oct 11, 2013
Post comments count0
Post likes count1

C++ corner case: You can implement pure virtual functions in the base class

Raymond Chen

In our discussion , we saw that you can declare a pure virtual function with the syntax, and if you try to call one of these functions from the base class, you will get the dreaded R6025 - pure virtual function call error. In that article, I wrote that a pure virtual function is "a method which is declared by the base class, but for which no i...

Code
Oct 10, 2013
Post comments count0
Post likes count1

How do I find out what size the window manager would have chosen for my window?

Raymond Chen

We saw some time ago how the window manager decides where to place a newly-created window if you pass the values when creating the window. But what if you want to filter the values first? If you pass an explicit upper left corner but pass for the width and height, then the bottom right corner will be down near the bottom right corner of the scre...

Code
Oct 9, 2013
Post comments count0
Post likes count1

Using the TAB key to navigate in non-dialogs, redux

Raymond Chen

You want to use the TAB key to navigate through a non-dialog, so you call in your message loop, but it doesn't work! The problem here is that you are passing the wrong window handle to . The first parameter to is the dialog-like window you want to be able to navigate through. But the code above passes the window that received the message, so...

Code
Oct 7, 2013
Post comments count0
Post likes count1

Printing the contents of the clipboard as text to stdout

Raymond Chen

The takes its stdin and puts it on the clipboard. But how do you get it out? That's today's Little Program. (I guess we could call it .) Okay, what do we have here? We open the clipboard and try to get the Unicode text on it. We then look for the null terminator within the first 0x10000000 bytes. Why do I stop at 256MB? Because I'm lazy and ...

Code
Oct 4, 2013
Post comments count0
Post likes count1

What's the difference between CopyIcon and DuplicateIcon?

Raymond Chen

There are two functions that can be used to create one icon that is identical to another. One of them is . The other is . What's the difference? There isn't any difference. Both functions clone an icon. In fact, their implementations are basically line-for-line identical. Originally, there was just one function to clone an icon: . Windows 3...

Code
Oct 3, 2013
Post comments count0
Post likes count1

The relationship between module resources and resource-derived objects in 32-bit Windows

Raymond Chen

Last time, we saw how 16-bit Windows converted resources attached to an EXE or DLL file (which I called module resources for lack of a better term) to user interface resources. As a refresher: During the conversion from 16-bit Windows to 32-bit Windows, some of these rules changed. Specifically, icons, cursors, and accelerator tables are no long...

Code
Oct 2, 2013
Post comments count0
Post likes count1

The relationship between module resources and resource-derived objects in 16-bit Windows

Raymond Chen

As we saw last time, in 16-bit Windows, resources attached to an EXE or DLL file (which I called module resources for lack of a better term) were recorded in memory as discardable global memory blocks, and the window manager accessed them directly as needed. For example, if you had an icon or a cursor, the or was really a resource handle, and wh...

Code
Sep 30, 2013
Post comments count0
Post likes count1

Playing a sound every time the foreground window changes

Raymond Chen

Today's Little Program plays a little sound every time the foreground window changes. One of my colleagues wondered if such a program was possible, "so that I stop accidentally typing the second halves of paragraphs into windows that pop up and steal focus." It's not clear whether this program will actually solve the bigger problem, but it was fun...

Code