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
- Click the link at the beginning of this topic to download the sample files.
- In Visual C++, open the project file Wins.dsp.
- Choose an appropriate configuration (Win32 Release is best if you plan to use this add-in).
- Click Rebuild All from the Build menu.
To run the add-in
- From the Tools menu, click Customize.
- Click the Add-ins and Macro Files tab.
- 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.
- 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:
- The Windows Manager button opens a dialog box that lets you look at all your windows, sort them according to file name, file extension, directory, time activated, rectangle coordinates (top, left, bottom, right), and rectangle coordinates in debug mode. It will let you do selections on this, invert selections, and select all. It will save selected files out to a .nfl (named file list) file, and let you reload .nfl files, opening windows as it does. You can minimize, close, or activate windows. The list persists through time, so you can close all windows, and then reopen them.
- The Refresh button updates all information; you lose debug rect and opened state though.
- Two check boxes are at the top of the dialog box. One turns on autosize, which will let you set a size that all activated windows will be set to. This is useful if you have a large monitor and windows open with too much white space. The other check box turns on the auto directory feature. This feature causes the currently active directory to follow the active window. If you open a file in c:\dir1, and one in c:\dir2, the current directory will switch from c:\dir1 to c:\dir2 as you activate c:\dir2's file(s), and so on.
- The Minimize Windows button minimizes all windows.
- The Set AutoSize button sets the size you expect activated windows to be based on the size of the currently active window if auto-size is set in the windows manager dialog box. If your current window is 400 pixels across when you click this button, the next window activated will automatically be sized to 400 pixels across.
- The Set All Visible button causes all windows on the screen to become visible. That is, docked windows, such as the output window, watch windows, or workspace windows will not obscure them. This is useful in debug mode and, in fact, will do a show next statement for you just in case the resize caused this to be off-window.
- The Close Debug Windows button closes all windows that are marked as opened in debug mode.
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