📄 cclient.cpp
字号:
/*
* CCLIENT.CPP
* Sample Code Class Libraries
*
* Implementation of the CClient class that handles an SDI or MDI
* client area window.
*
* 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 "classlib.h"
#include <dbgout.h>
/*
* CClient::CClient
* CClient::~CClient
*
* Constructor Parameters:
* hInst HINSTANCE of the application.
* pFR PCFrame of the frame object.
*/
CClient::CClient(HINSTANCE hInst, PCFrame pFR)
: CWindow(hInst)
{
m_pFR=pFR;
m_cDoc=0;
m_pDocLast=NULL;
m_hListDocs=NULL;
m_pAdv=NULL;
return;
}
CClient::~CClient(void)
{
if (NULL!=m_hListDocs)
DestroyWindow(m_hListDocs);
if (NULL!=m_pAdv)
delete m_pAdv;
return;
}
/*
* CClient::Init
*
* Purpose:
* Creates a client area window sensitive to SDI or MDI
* (compile-time) as well as performng other internal
* initialization.
*
* Parameters:
* hMenuWindow HWND of the Window menu on the frame.
* pRect LPRECT containing the desired window rectangle.
*
* Return Value:
* BOOL TRUE if the function succeeded, FALSE otherwise.
*/
BOOL CClient::Init(HMENU hMenuWindow, LPRECT pRect)
{
HWND hWndFrame;
LPTSTR pszClass;
DWORD dwStyle;
CLIENTCREATESTRUCT ccs;
hWndFrame=m_pFR->Window();
#ifdef MDI
ccs.hWindowMenu =hMenuWindow;
ccs.idFirstChild=ID_MDICHILDMIN;
pszClass=TEXT("mdiclient");
dwStyle=MDIS_ALLCHILDSTYLES;
#else
//SDI
pszClass=SZCLASSSDICLIENT;
dwStyle=0L;
#endif
m_hWnd=CreateWindow(pszClass, pszClass, dwStyle | WS_CHILD
| WS_CLIPCHILDREN | WS_VISIBLE | WS_CLIPSIBLINGS
, pRect->left, pRect->top, pRect->right-pRect->left
, pRect->bottom-pRect->top, hWndFrame, NULL, m_hInst
, &ccs);
if (NULL==m_hWnd)
return FALSE;
//Create the hidden listbox for managing our list of documents
m_hListDocs=CreateWindow(TEXT("listbox"), TEXT("Document List")
, WS_POPUP | LBS_OWNERDRAWFIXED, 0, 0, 100, 100
, HWND_DESKTOP, NULL, m_hInst, NULL);
if (NULL==m_hListDocs)
return FALSE;
/*
* Create an advise sink for the frame. If this fails, then
* we'll just do without it.
*/
m_pAdv=new CDocumentAdviseSink(m_pFR);
return TRUE;
}
/*
* CClient::CreateDoc (Internal)
* CClient::CreateCDocument (Virtual)
*
* Purpose:
* Constructs a new document. This function is overridable so an
* app can use the default CClient but create a derived document
* class.
*
* Parameters:
* None
*
* Return Value:
* PCDocument Pointer to the new document object.
*/
PCDocument CClient::CreateDoc(void)
{
PCDocument pDoc;
pDoc=CreateCDocument();
m_pDocLast=pDoc;
return pDoc;
}
PCDocument CClient::CreateCDocument(void)
{
return new CDocument(m_hInst, m_pFR, m_pAdv);
}
/*
* CClient::Frame
* CClient::DocumentCount
* CClient::DocumentList
*
* Purpose:
* Trivial members to provide public access to various members.
*/
PCFrame CClient::Frame(void)
{
return m_pFR;
}
UINT CClient::DocumentCount(void)
{
return m_cDoc;
}
HWND CClient::DocumentList(void)
{
return m_hListDocs;
}
/*
* CClient::TranslateAccelerator
*
* Purpose:
* Provides an isolated system accelerator translation as necessary
* for the client window. In MDI this calls TranslateMDISysAccel
* but is a NOP in SDI.
*
* Parameters:
* pMsg LPMSG to the message from GetMessage
*
* Return Value:
* BOOL TRUE if the accelerator was translated and
* processed, FALSE otherwise.
*/
BOOL CClient::TranslateAccelerator(LPMSG pMsg)
{
#ifdef MDI
return TranslateMDISysAccel(m_hWnd, pMsg);
#else
return FALSE;
#endif
}
/*
* CClient::DefFrameProc
*
* Purpose:
* Encapsulates which default message procedure to call for a frame
* window: SDI (DefWindowProc) or MDI (DefFrameProc).
*
* Parameters:
* hWnd HWND of the frame
* iMsg UINT of the message
* wParam WPARAM of the message
* lParam LPARAM of the message
*
* Return Value:
* LRESULT Return value for the message.
*/
LRESULT CClient::DefaultFrameProc(HWND hWnd, UINT iMsg, WPARAM wParam
, LPARAM lParam)
{
#ifdef MDI
return (DefFrameProc(hWnd, m_hWnd, iMsg, wParam, lParam));
#else
return (DefWindowProc(hWnd, iMsg, wParam, lParam));
#endif
}
/*
* CClient::OnWindowCommand
*
* Purpose:
* Handles Window menu commands for MDI situations. This is a NOP
* in SDI.
*
* Parameters:
* uCommand UINT command to execute:
* WM_MDICASCADE
* WM_MDITILE
* WM_MDIICONARRANGE
*
* uOption UINT optional parameter for WM_MDITILE, either
* MDITILE_HORIZONTAL or MDITILE_VERTICAL.
*
* Return Value:
* None
*/
void CClient::OnWindowCommand(UINT uCommand, UINT uOption)
{
SendMessage(m_hWnd, uCommand, (WPARAM)uOption, 0L);
return;
}
/*
* CClient::OnSize
*
* Purpose:
* Handles resizing the client window when the frame is resized.
*
* Parameters:
* x, y UINT new location of the window.
* cx, cy UINT new dimensions of the window.
*
* Return Value:
* None
*/
void CClient::OnSize(UINT x, UINT y, UINT cx, UINT cy)
{
SetWindowPos(m_hWnd, NULL, x, y, cx, cy
, SWP_NOZORDER | SWP_NOACTIVATE);
return;
}
/*
* CClient::NewDocument
*
* Purpose:
* Creates a new blank document in the client space. See
* CloseDocument for the opposite effect.
*
* Parameters:
* fVisible BOOL indicating if the document is to be visible
* or not.
*
* Return Value:
* PCDocument Pointer to the new document object.
*/
PCDocument CClient::NewDocument(BOOL fVisible)
{
MDICREATESTRUCT mcs;
HWND hWndDoc;
PCDocument pDoc, pDocTemp;
DOCUMENTINIT di;
BOOL fCreate=TRUE;
#ifdef MDI
DWORD dw;
#endif
#ifdef MDI
//In MDI we create a new CDocument
pDoc=CreateDoc(); //This could create a derived class...
#else
//In SDI we close the one we have and create a new one.
pDoc=ActiveDocument();
if (NULL!=pDoc)
CloseDocument(pDoc);
pDoc=CreateDoc();
#endif
if (NULL==pDoc)
return NULL;
if (fCreate)
{
/*
* We implement this by having the client window actually
* create the windows instead of using the CDocument
* initializer. Reason being is that we ask the client to
* actually create the window using WM_MDICREATE (which works
* for our SDI client as well. Since we need to conditionally
* compile for MDI or SDI here, we create a window before
* calling the document constructor.
*/
mcs.szTitle=TEXT("");
mcs.szClass=SZCLASSDOCUMENT;
mcs.hOwner =m_hInst;
mcs.lParam =(LPARAM)pDoc;
mcs.x =CW_USEDEFAULT;
mcs.cx=CW_USEDEFAULT;
mcs.y =CW_USEDEFAULT;
mcs.cy=CW_USEDEFAULT;
/*
* Set the style of the window, controlling visiblity.
* WS_CLIPCHILDREN is important to prevent unnecessary
* flashing of document contents that we'll usually fill
* with some editor window.
*/
#ifdef MDI
mcs.style=WS_CHILD | WS_SYSMENU | WS_CAPTION
| WS_CLIPSIBLINGS| WS_THICKFRAME | WS_MINIMIZEBOX
| WS_MAXIMIZEBOX| WS_CLIPCHILDREN
| ((fVisible) ? WS_VISIBLE : 0L);
//If the current document is maxmized, maximize this one
#ifdef WIN32
pDocTemp=ActiveDocument();
if (NULL!=pDocTemp)
{
dw=GetWindowLong(pDocTemp->Window(), GWL_STYLE);
mcs.style |= (dw & WS_MAXIMIZE);
}
#else
pDocTemp=NULL;
dw=SendMessage(m_hWnd, WM_MDIGETACTIVE, 0, 0L);
if (HIWORD(dw))
mcs.style |= WS_MAXIMIZE;
#endif //WIN32
#else
mcs.style=WS_CHILD | WS_CLIPCHILDREN
| ((fVisible) ? WS_VISIBLE : 0L);
#endif //MDI
//Tell the Client window to create the child
hWndDoc=(HWND)(UINT)SendMessage(m_hWnd, WM_MDICREATE, 0
, (LONG)&mcs);
di.idsMin=IDS_STANDARDDOCMIN;
di.idsMax=IDS_STANDARDDOCMAX;
di.hWndDoc=hWndDoc;
if (!pDoc->Init(&di))
{
if (m_pDocLast==pDoc)
m_pDocLast=NULL;
SendMessage(m_hWnd, WM_MDIDESTROY, (WPARAM)hWndDoc, 0L);
delete pDoc;
return NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -