Click here to Skip to main content
15,897,181 members
Articles / Mobile Apps

Window Tabs (WndTabs) Add-In for DevStudio

Rate me:
Please Sign up or sign in to vote.
5.00/5 (37 votes)
11 Jul 2002 366.2K   7.3K   94  
Window and File Management add-in for Visual C++
/***************************************************************************/
/* NOTE:                                                                   */
/* This document is copyright (c) by Oz Solomonovich.  All non-commercial  */
/* use is allowed, as long as this document not altered in any way, and    */
/* due credit is given.                                                    */
/***************************************************************************/

// AddInInt.cpp : implementation file

/*  Commands Exported By WndTabs Through AddInComm
    ==============================================

    Commands are case-insensitive.


    === IsSubclassed

        Syntax:  IsSubclassed hwnd_in_hex

        Params:  hwnd_in_hex is a window handle in hex.

        Returns:  1  subclassed by WndTabs
                  0  not subclassed by WndTabs
                 -1  error
                 
        Use this command to check if a certain window is currently subclassed
        by WndTabs.


    === Subclass

        Syntax:  Subclass hwnd_in_hex

        Params:  hwnd_in_hex is the handle of the window to subclass, in hex.

        Returns:  1  subclassing was successful
                  0  no subclassing occurred (no error)
                 -1  general error
                 -2  already subclassed
                 -3  subclassing failed
                 -4  illegal window
                 
        Use this command to re-subclass windows that were unsubclassed using 
        the "Unsubclass" command.  No other windows should be used.


    === Unsubclass

        Syntax:  Unsubclass hwnd_in_hex

        Params:  hwnd_in_hex is the handle of the window to unsubclass, in 
                    hex.

        Returns:  1  unsubclassing was successful
                  0  no unsubclassing occurred (no error)
                 -1  general error
                 -2  already unsubclassed
                 -3  unsubclassing failed
                 -4  illegal window
                 
        Use this command to unsubclass windows that were subclassed by 
        WndTabs.  You should then re-subclass the windows using the 
        "Subclass" command.  Leaving a window unsubclassed can cause 
        instability, so re-subclass before DevStudio regains control.
*/

#include "stdafx.h"
#include "WndTabs.h"
#include "TabManagerWindow.h"
#include "DSWindow.h"
#include "DevStudioWnd.h"

#define ERR_SUCCESS             1
#define ERR_PARVE               0
#define ERR_GENERR             -1
#define ERR_ALREADYCLASSED     -2
#define ERR_CLASSINGFAILED     -3
#define ERR_ILLEGALWIN         -4

static CSubclassWnd **ppSubclassed[] =
{
    (CSubclassWnd **)(&pGlobalActiveDSWindow), 
    (CSubclassWnd **)(&pGlobalActiveManager), 
    (CSubclassWnd **)(&g_pDevStudioWnd)
};


int OnIsSubclassed(LPCTSTR pParams)
{
    HWND hWnd;

    if (sscanf(pParams, "%x", &hWnd) != 1)
        return ERR_GENERR;

    if (hWnd)
    {
        for (int i = 0; i < countof(ppSubclassed); i++)
        {
            if (*ppSubclassed[i]  &&  hWnd == (**ppSubclassed[i]).m_hWnd)
                return 1;
        }
    }

    return 0;
}

int SubclassFns(LPCTSTR pParams, bool bDoSubclass)
{
    int             iRetVal = ERR_PARVE;
    HWND            hWnd;
    CSubclassWnd *  pWnd = NULL;

    if (sscanf(pParams, "%x", &hWnd) != 1)
        return ERR_GENERR;

    if (hWnd)
    {
        for (int i = 0; i < countof(ppSubclassed); i++)
        {
            if (*ppSubclassed[i]  &&  
                hWnd == (**ppSubclassed[i]).m_Saved_hWnd)
            {
                pWnd = *ppSubclassed[i];
                break;
            }
        }
        if (!pWnd)
        {
            iRetVal = ERR_ILLEGALWIN;
            TRACE("WndTabs: Unknown window handle passed to On%subclass, "
                  "HWND=%p", (bDoSubclass? "S" : "Uns"), hWnd);
        }
    }

    if (pWnd)
    {
        if (pWnd->m_bIsSubclassed == bDoSubclass)
        {
            iRetVal = ERR_ALREADYCLASSED;
        }
        else
        {
            if (bDoSubclass)
                pWnd->DoSubclass();
            else
                pWnd->DoUnsubclass();

            iRetVal = (pWnd->m_bIsSubclassed == bDoSubclass)? 
                ERR_SUCCESS : ERR_CLASSINGFAILED;
        }
    }

    return iRetVal;
}

int OnSubclass(LPCTSTR pParams)
{
    return SubclassFns(pParams, true);
}

int OnUnsubclass(LPCTSTR pParams)
{
    return SubclassFns(pParams, false);
}

struct command_t
{
    LPCTSTR pName;
    int (*pFn)(LPCTSTR pParams);
};

static command_t commands[] = 
{
    { "IsSubclassed",   OnIsSubclassed },
    { "Subclass",       OnSubclass },
    { "Unsubclass",     OnUnsubclass },

    // short hand for for debugging  *** will be removed in release
    { "IS", OnIsSubclassed },
    { "S",  OnSubclass },
    { "U",  OnUnsubclass }
};


// callback for AddInComm
int AddInCallback(LPCTSTR pCmd)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    char buf[1024];
    int i, p;

    // isolate command string (command string -> buf)
    p = 0;
    while (pCmd[p]  &&   isspace(pCmd[p])) p++;
    while (pCmd[p]  &&  !isspace(pCmd[p])) p++;
    strncpy(buf, pCmd, p);
    buf[p] = '\0';

    // see if it's a known command
    for (i = 0; i < countof(commands); i++)
    {
        if (_tcsicmp(buf, commands[i].pName) == 0)
        {
            // trim white space from beginning of params
            while (pCmd[p]  &&  isspace(pCmd[p])) p++;
   
            return (commands[i].pFn(pCmd + p));
        }
    }

    return -1;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Experion
Canada Canada
You may know Oz from his WndTabs days. Oz has long since left client side development to work on web technologies and to consult in the R&D management field.

Comments and Discussions