⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cframe.cpp

📁 英文版的 想要的话可以下载了 为大家服务
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
 * CFRAME.CPP
 * Sample Code Class Libraries
 *
 * Generic CFrame class that manages either SDI or MDI clients as
 * well as typical File, Edit, Window, and Help commands.
 *
 * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
 *
 * Kraig Brockschmidt, Microsoft
 * Internet  :  kraigb@microsoft.com
 * Compuserve:  >INTERNET:kraigb@microsoft.com
 */


#include <windows.h>
#include <memory.h>

extern "C"
    {
    #include <commdlg.h>
    }

#include "classlib.h"



/*
 * CFrame::CFrame
 * CFrame::~CFrame
 *
 * Constructor Parameters:
 *  hInst           HINSTANCE from WinMain
 *  hInstPrev       HINSTANCE from WinMain
 *  pszCmdLine      LPSTR from WinMain
 *  nCmdShow        int from WinMain
 */

CFrame::CFrame(HINSTANCE hInst, HINSTANCE hInstPrev
    , LPSTR pszCmdLine, int nCmdShow)
    : CWindow(hInst)
    {
    m_hInstPrev =hInstPrev;
    m_nCmdShow  =nCmdShow;

   #ifdef WIN32
    //This gives us the Unicode version if necessary
    m_pszCmdLine=GetCommandLine();
   #else
    m_pszCmdLine=pszCmdLine;
   #endif

    m_ppszCmdArgs=NULL;
    m_cCmdArgs=0;
    m_fCmdsParsed=FALSE;

    m_fLastEnable=(BOOL)-1; //Uninitialized
    m_fLastPaste =(BOOL)-1; //Uninitialized

    m_phMenu=NULL;
    m_hBmp  =NULL;
    m_pST   =NULL;

    m_pTB   =NULL;
    m_pSL   =NULL;
    m_pCL   =NULL;
    return;
    }



CFrame::~CFrame(void)
    {
    m_fClosing=TRUE;

    //Accelerators freed automatically.

    //Free the toolbar bitmaps
    if (NULL!=m_hBmp)
        DeleteObject(m_hBmp);

    if (NULL!=m_pCL)
        delete m_pCL;

    if (NULL!=m_pSL)
        delete m_pSL;

    if (NULL!=m_pTB)
        delete m_pTB;

    //Free the menu handle array
    if (NULL!=m_phMenu)
        delete []((UINT *)m_phMenu);

    //Free the stringtable.
    if (NULL!=m_pST)
        delete m_pST;

    //Free the command-line argument pointer array
    if (NULL!=m_ppszCmdArgs)
        delete []m_ppszCmdArgs;

    m_fClosing=FALSE;
    return;
    }


/*
 * CFrame::ParseCommandLine
 *
 * Purpose:
 *  Before other initialization, parse the command line arguments
 *  since derived classes may need the arguments before calling
 *  Init below.
 *
 * Return Value:
 *  BOOL            TRUE if parsing succeeded, FALSE otherwise.
 */

BOOL CFrame::ParseCommandLine(void)
    {
    LPTSTR     *ppsz=NULL;
    LPTSTR      psz, pszT;
    int         cArgs=0;

    if (m_fCmdsParsed)
        return TRUE;

    psz=PszWhiteSpaceScan(m_pszCmdLine, TRUE);

   #ifdef WIN32
    //Skip the first argument which is the EXE name in Win32
    psz=PszWhiteSpaceScan(psz, FALSE);
    psz=PszWhiteSpaceScan(psz, TRUE);
   #endif

    for (pszT=psz; *pszT!=0; )
        {
        cArgs++;

        //Skip to the end of this argument
        pszT=PszWhiteSpaceScan(pszT, FALSE);

        //Stop if we hit the end of the string
        if ((TCHAR)0==*pszT)
            break;

        //Skip whitespace to the next argument
        pszT=PszWhiteSpaceScan(pszT, TRUE);
        }

    /*
     * Now allocate a pointer array to each argument in the
     * command line and null terminate each argument.
     */
    if (0!=cArgs)
        {
        int i;

        ppsz=new LPTSTR[cArgs];

        if (NULL==ppsz)
            return FALSE;

        for (i=0; i < cArgs; i++)
            {
            ppsz[i]=psz;

            psz=PszWhiteSpaceScan(psz, FALSE);

            if ((TCHAR)0!=*psz)
                pszT=psz;

            psz=PszWhiteSpaceScan(psz, TRUE);
            *pszT=(TCHAR)0;
            }
        }

    m_ppszCmdArgs=ppsz;
    m_cCmdArgs=cArgs;
    m_fCmdsParsed=TRUE;
    return TRUE;
    }





/*
 * CFrame::Init
 *
 * Purpose:
 *  Initializer for a CFrame object containing anything prone to
 *  failure.
 *
 * Parameters:
 *  pFI             PFRAMEINIT containing initialization parameters.
 *
 * Return Value:
 *  BOOL            TRUE if initialization succeeded, FALSE
 *                  otherwise. If FALSE is returned, the caller must
 *                  guarantee that the destructor is called promptly
 *                  to insure cleanup.
 */

BOOL CFrame::Init(PFRAMEINIT pFI)
    {
    RECT                rc;
    HMENU               hMenu;
    UINT                uTemp;
    TOOLDISPLAYDATA     tdd;

    m_fInit=TRUE;

    //1.  Create our stringtable
    m_pST=new CStringTable(m_hInst);

    if (!m_pST->Init(pFI->idsMin, pFI->idsMax))
        return FALSE;


    /*
     * 2.  Register the classes we need for this application.
     *     We have our main (frame) window, document windows (for
     *     either MDI or SDI, and Polyline windows which are the
     *     editing controls.  This separate virtual function allows
     *     applications to add additional classes.
     */
    if (NULL==m_hInstPrev)
        {
        if (!RegisterAllClasses())
            return FALSE;
        }


    /*
     * 3.  Create the main window, the toolbar, and the status line.
     */
    m_pCL=NULL;

    m_hWnd=CreateWindow(SZCLASSFRAME, PSZ(IDS_CAPTION)
        , WS_MINIMIZEBOX | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
        , pFI->x, pFI->y, pFI->cx, pFI->cy
        , NULL, NULL, m_hInst, this);

    if (NULL==m_hWnd)
        return FALSE;

    GetClientRect(m_hWnd, &rc);

    UIToolConfigureForDisplay(&tdd);
    m_dxB=tdd.cxButton;
    m_dyB=tdd.cyButton;
    m_cyBar=tdd.cyBar;

    m_pTB=new CToolBar(m_hInst);

    if (!m_pTB->Init(m_hWnd, ID_GIZMOBAR, m_cyBar))
        return FALSE;

    m_pSL=new CStatusLine(m_hInst);

    if (!m_pSL->Init(m_hWnd, ID_STATSTRIP, CYSTATSTRIP))
        return FALSE;


    //Initialize the status line for automated WM_MENUSELECT processing
    if (!m_pSL->MessageMap(m_hWnd, m_hInst, IDR_STATMESSAGEMAP
        , pFI->idsStatMin, pFI->idsStatMax, CCHMESSAGEMAX
        , pFI->idStatMenuMin, pFI->idStatMenuMax, ID_MESSAGEREADY
        , ID_MESSAGEEMPTY, ID_MENUSYS))
        return FALSE;

    rc.top+=m_cyBar;

    /*
     * 4.  Create the client window that owns documents.  This
     *     client also creates an advise sink and gives it to
     *     each document to notify the frame of events.
     *
     *     Also allocate space for the menu handle array and store
     *     the popup handles.  Get the menu handle of the Window
     *     menu specifically for later processing.
     */

    m_pCL=CreateCClient();
    hMenu=GetMenu(m_hWnd);

   #ifdef MDI
    //Save this for UpdateMenus.  Stays NULL in SDI
    m_hMenuWindow=GetSubMenu(hMenu, pFI->iPosWindowMenu);
   #endif

    if (!m_pCL->Init(m_hMenuWindow, &rc))
        return FALSE;

    m_phMenu=new HMENU[pFI->cMenus];

    for (uTemp=0; uTemp < pFI->cMenus; uTemp++)
        m_phMenu[uTemp]=GetSubMenu(hMenu, uTemp);


    /*
     * 5.  Initialize fancy things like the toolbar.  If a derived
     *     class wants more tool images, they can copy the first
     *     two in the standard image set and this code will still
     *     load it.  This code just won't reference it.
     */

    m_hBmp=LoadBitmap(m_hInst, MAKEINTRESOURCE(tdd.uIDImages));

    if (NULL==m_hBmp)
        return FALSE;

    //Create all the tools, and uninitialize working flags
    CreateToolbar();
    UpdateToolbar();
    m_fLastEnable=(BOOL)-1; //Uninitialized
    m_fLastPaste =(BOOL)-1; //Uninitialized

    m_hAccel=LoadAccelerators(m_hInst
        , MAKEINTRESOURCE(IDR_ACCELERATORS));

    if (NULL==m_hAccel)
        return FALSE;

    /*
     * 6.  In the default implementation PreShowInit does not do
     *     anything, but is called here to allow derivations to
     *     hook the function and modify m_nCmdShow before we
     *     call ShowWindow.  This is one such place where OLE affects
     *     a derivation, because servers will change m_nCmdShow to
     *     SW_HIDE if started with -Embedding.
     */
    if (!PreShowInit())
        return FALSE;


    /*
     * 7.  Handle window visibility appropriately after giving
     *     PreShowInit a chance to modify it.
     */
    ShowWindow(m_hWnd, m_nCmdShow);
    UpdateWindow(m_hWnd);


    /*
     * 8.  Parse the command line and take appropriate action.  The
     *     derived class may have called ParseCommandLine earlier, so
     *     m_fCmdsParsed tells us if we still need to call it.
     */
    if (!m_fCmdsParsed)
        ParseCommandLine();

    OpenInitialFiles();

    m_fInit=FALSE;
    return TRUE;
    }





/*
 * CFrame::CreateCClient
 *
 * Purpose:
 *  Creates a CClient object for use in this frame.  This function
 *  is overrided by derived classes to create a different type of
 *  CClient.
 *
 * Return Value:
 *  PCClient         Pointer to the new CClient object.
 */

PCClient CFrame::CreateCClient(void)
    {
    return new CClient(m_hInst, this);
    }







/*
 * CFrame::RegisterAllClasses
 *
 * Purpose:
 *  Registers all classes used in this application.
 *
 * Return Value:
 *  BOOL            TRUE if registration succeeded, FALSE otherwise.
 */

BOOL CFrame::RegisterAllClasses(void)
    {
    WNDCLASS        wc;

    //Field that are the same for all windows.
    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.hInstance     = m_hInst;
    wc.cbClsExtra    = 0;

    //Register the Frame window
    wc.lpfnWndProc   = FrameWndProc;
    wc.cbWndExtra    = CBFRAMEWNDEXTRA;
    wc.hIcon         = LoadIcon(m_hInst, TEXT("Icon"));
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
    wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU);
    wc.lpszClassName = SZCLASSFRAME;

    if (!RegisterClass(&wc))
        return FALSE;

   #ifndef MDI
    wc.lpfnWndProc   = SDIClientWndProc;
    wc.cbWndExtra    = CBCLIENTWNDEXTRA;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = SZCLASSSDICLIENT;

    if (!RegisterClass(&wc))
        return FALSE;
   #endif

    wc.lpfnWndProc   = DocumentWndProc;
    wc.cbWndExtra    = CBDOCUMENTWNDEXTRA;
    wc.hIcon         = LoadIcon(m_hInst
                           , MAKEINTRESOURCE(IDR_DOCUMENTICON));
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = SZCLASSDOCUMENT;

    if (!RegisterClass(&wc))
        return FALSE;

    return TRUE;
    }





/*
 * CFrame::PreShowInit
 *
 * Purpose:
 *  Called from Init before intially showing the window.  We do
 *  whatever else we want here, modifying nCmdShow as necessary
 *  which affects ShowWindow in Init.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -