Wins: Uses Automation to List and Control Windows

Click to open or copy the Wins project files.

Wins is a window manager that you can use to find, minimize, make visible, activate, and close windows, and also close any windows opened in a debug session. It will create files that, when loaded, will open selected windows.

Wins was built using the ATL COM AppWizard with the Support MFC option. The code that does the work with Automation objects is in WindowsList.cpp. It has some functions you may be able to reuse. For example, FindDoc, given a path to a document, returns a pointer to an IGenericDocument interface, opening it if requested.

Wins also demonstrates how to add sorting to a list control and handling various messages from the list control that are mirrored. MyListCtrl.cpp has some useful functions for using list controls.

To build the sample

  1. Click the link at the beginning of this topic to download the sample files.

  2. In Visual C++, open the project file Wins.dsp.

  3. Choose an appropriate configuration (Win32 Release is best if you plan to use this add-in).

  4. Click Rebuild All from the Build menu.

To run the add-in

  1. From the Tools menu, click Customize.

  2. Click the Add-ins and Macro Files tab.

  3. Select the Wins.dll file or browse for it. See Tips for Using Add-ins.

    Visual C++ will load the add-in. When you close the Customize dialog box, the Wins toolbar will appear.

  4. Run the Wins add-in by clicking the toolbar button. Clicking this button opens a dialog box. Wins is a window manager with controls that represent various window management functions:

This sample demonstrates the following keywords:

CTime::GetCurrentTime; CTime::Format; CRegKey::QueryValue; CRegKey::Create; CRegKey::SetValue, ITextSelection, IApplication, CRegKey; ITextSelection::get_TopLine; CComPtr, CComQIPtr, ITextDocument::get_FullName; CComBSTR; IDocuments::get__NewEnum; IEnumVARIANT::Next; CComVariant; IGenericWindow::get_Width; IGenericWindow::get_Height; IGenericWindow::get_Left; IGenericWindow::get_Top; IGenericWindow::put_Width; IGenericWindow::put_Height; IGenericWindow::put_Left; IGenericWindow::put_Top; CRect::IntersectRect; CRect::SetRect; CRect::OffsetRect; IWindows::get__NewEnum; IDebugger::ShowNextStatement; IDebugger::get_State; IGenericWindow::get_Caption; IGenericWindow::get_Width; IGenericWindow::get_WindowState; IGenericWindow::put_WindowState; IApplication::get_Windows; IApplicationEvents::DocumentOpen; IApplicationEvents::DocumentSave; IApplicationEvents::WorkspaceOpen; IApplicationEvents::WindowActivate; CToolTipCtrl::SetToolInfo; CListCtrl::SortItems; window; minimize; close; list; sort; addin; customize; IGenericDocument; IDocuments; CComVariant; IWindows