Startup Cop

PC Magazine

  PC Tech

Take Charge of Windows Start-up


Using Startup Cop

The Start-up Programs

Saving Profiles

The Restore Profile Tab

Startup Cop and Windows 98

Inside Startup Cop

Disabling and Removing Items

Reading and Writing Shortcuts

Simulating Context Help

  Startup Cop
Take Charge of Windows Start-up
Simulating Context Help

Continued from Reading and Writing Shortcuts

Startup Cop's detail window looks like the kind of pop-up window that you get by calling the WinHelp() API function and passing the flag HELP_CONTEXTPOPUP. This type of window floats near the item it explains, with a drop-shadow to its right and below it. However, this is not how it was created; the appearance is simulated.

The TExpForm object, defined in the module Expformu.pas, is a descendant of the standard TForm that encapsulates the ability to display a start-up item's details in a simulated help-context pop-up window. To create a simple pop-up window with no border, no title bar, and no system menu, I overrode the CreateParams() method of the TExpForm. After calling the inherited CreateParams() method, the overriding method sets the window style to simply WS_POPUP. When the window loses focus, it receives a WM_KILLFOCUS message, and responds by closing. It also closes if the user presses any key, or clicks anywhere within the window.

The most difficult feature to emulate was the drop shadow. Careful examination revealed that a help-context pop-up window has a shadow that is six pixels wide, and composed of alternating black and transparent pixels that are arranged in a checkerboard pattern. The TExpForm duplicates this effect by painting the whole shadow area black and using the SetWindowRgn() API function to make portions of the window transparent. A region is a Windows structure that defines an area on the screen. The area doesn't have to be rectangular, and need not even be one continuous piece. The region for a TExpForm consists of the main rectangle and many, many individual pixels that form the shadow.

Building up a region from individual pixels is a tedious process that can take a significant amount of time. The size of the TExpForm changes to fit its contents, so it wasn't possible to just define the shadow region once at program start-up. Instead, when the program starts it builds a region called bShadow that consists of every other pixel in a 40-by-6 rectangle, and another called sShadow that consists of every other pixel in a 6-by-40 rectangle. The former is used to build the bottom shadow, and the latter the side shadow.

The main program calls TExpForm's SetItem() method to fill the detail window with the current start-up item's data. After filling in the various text labels with data, the SetItem() method adjusts the detail window's size to fit the data. It then tweaks the window size so that the sum of the height and width is an odd number; this is necessary to make the shadows mesh properly.

Once the window size is established, the program builds a region defining what parts of the detail window will be visible, and what parts will be transparent. It starts with a rectangular region the same size and shape as the detail window. It then uses the CombineRgn() API function to extend the region with a copy of the bottom shadow region just below the main rectangle and offset six pixels to the right. Then it repeatedly moves its copy of the bottom shadow 40 pixels to the right and adds it to the growing region, stopping when the full width of the window has been reached. It builds the side shadow in the same way, and passes the region thus created to the SetWindowRgn() API function. The resulting window looks remarkably like a help-context pop-up.

Startup Cop makes it easy to start Windows with a minimal number of preloaded applications, and this in itself is useful. But you'll appreciate it most when you encounter problems at start-up. It lets you see at a glance what programs are loading, and disable them with a mouse click.

More Utilities

Published in the 4/20/99 issue of PC Magazine.