Showing tag results for Code

Oct 21, 2013
Post comments count0
Post likes count1

Opening and manipulating Internet Explorer windows programmatically

Raymond Chen

Today's Little Program takes the JavaScript application from a few years ago and converts it to C#. This was inspired by a customer who started with the question, "How can I close all Internet Explorer windows programmatically?" This was a strange request. After all, the user may be rather upset that their Amazon shopping spree was suddenly ter...

Code
Oct 18, 2013
Post comments count0
Post likes count1

The case of the redirected standard handles that won't close even though the child process has exited (and a smidge of Microspeak: reduction)

Raymond Chen

A customer had a supervisor process whose job is to launch two threads. Each thread in turn launches a child process, let's call them A and B, each with redirected standard handles. They spins up separate threads to read from the child processes' stdout in order to avoid deadlocks. What they've found is that even though child process&nbs...

CodeMicrospeak
Oct 17, 2013
Post comments count0
Post likes count1

What is the inverse of AdjustWindowRect and AdjustWindowRectEx?

Raymond Chen

We saw over a decade ago (my goodness I've been doing this way too long) that the and functions do not take menu wrapping into account because they don't take a window handle parameter, so they don't know what menu to test for wrapping. Still, they are useful functions if you aren't worried about menu wrapping because they let you do window siz...

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