📄 windowmanager.cpp
字号:
{
MDIMessage(WM_MDITILE, MDITILE_VERTICAL);
}
*/
/*void CWindowDlg::OnMinimize()
{
int nItems = m_wndList.GetCount();
if (nItems != LB_ERR && nItems > 0)
{
m_wndList.SetRedraw(FALSE);
for (int i = nItems - 1; i >= 0; i--)
{
if (m_wndList.GetSel(i) > 0)
{
HWND hWnd = reinterpret_cast < HWND>(m_wndList.GetItemData(i));
::ShowWindow(hWnd, SW_MINIMIZE);
}
}
m_wndList.SetRedraw(TRUE);
}
FillWindowList();
SelActive();
UpdateButtons();
}
*/
/*void CWindowDlg::OnCascade()
{
MDIMessage(WM_MDICASCADE, 0);
}*/
/////////////////////////////////////////////////////////////////////////////
// CMDIClient
CMDIClient::CMDIClient() : m_sizeClient(0, 0), m_bFullScreen(FALSE),
m_bFirstTime(TRUE), m_bBkBitmap(TRUE)
{
m_hMenuWindow = 0;
m_pMDIFrame = NULL;
m_bToolBarVisible = FALSE;
m_bStatusBarVisible = FALSE;
m_bMaxChild = FALSE;
// m_pwndFullScrnToolBar = NULL;
m_strWindows ="&Windows...";
/* m_hMenuWindow = 0;
m_strWindows.LoadString(IDS_WINDOW_MANAGE);
m_pMDIFrame = NULL;
m_crBkColor = GetSysColor(COLOR_DESKTOP);
m_crLogoColor = GetSysColor(COLOR_BTNFACE);
m_bToolBarVisible = FALSE;
m_bStatusBarVisible = FALSE;
m_bMaxChild = FALSE;
m_pwndFullScrnToolBar = NULL;
*/
// Do defaults settings
Defaults();
////////////////
// Create the default font, Times New Roman is most common
// CWindowDC wndDC(CWnd::GetDesktopWindow());
// int nFontSize = -MulDiv(18, wndDC.GetDeviceCaps(LOGPIXELSY), 72);
// m_fontLogo.CreateFont(nFontSize,
// 0, 0, 0,
// FW_BOLD,
// FALSE, FALSE, FALSE,
// ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
// FIXED_PITCH | FF_ROMAN,
// _T("Times New Roman"));
// Now do the registry stuff here...
CWinApp* pApp = AfxGetApp();
m_bMaxChild = pApp->GetProfileInt(szSection, szChildWinPos, m_bMaxChild);
// Load the logo font
{
// BOOL bSuccess = FALSE;
// LOGFONT* plf = new LOGFONT;
// UINT dwSize = sizeof(LOGFONT);
// bSuccess = pApp->GetProfileBinary(szSection, szLogoFont, (BYTE**)&plf, &dwSize);
// if (bSuccess)
// {
// m_fontLogo.Detach();
// m_fontLogo.CreateFontIndirect(plf);
// }
//
// delete plf;
}
// m_bBkBitmap = pApp->GetProfileInt(szSection, szBkBitmap, (int)m_bBkBitmap);
// m_crLogoColor = pApp->GetProfileInt(szSection, szLogoColor, (int)m_crLogoColor);
// m_crBkColor = pApp->GetProfileInt(szSection, szBackColor, (int)m_crBkColor);
SetBkColor(m_crBkColor);
// m_enuDispType = (DispType)pApp->GetProfileInt(szSection, szDispType, (int)m_enuDispType);
SetDispType(m_enuDispType);
// if (m_strFileName.IsEmpty())
// {
// m_strFileName = pApp->GetProfileString(szSection, szFileName, (LPCTSTR)m_strFileName);
// SetBitmap(m_strFileName);
// }
}
CMDIClient::~CMDIClient()
{
}
BEGIN_MESSAGE_MAP(CMDIClient, CWnd)
//{{AFX_MSG_MAP(CMDIClient)
ON_MESSAGE(WM_MDIREFRESHMENU, OnRefreshMenu)
ON_MESSAGE(WM_MDISETMENU, OnSetMenu)
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_WINDOW_MANAGE, OnWindowManage)
ON_COMMAND(ID_WINDOW_NEXT, OnWindowNext)
ON_COMMAND(ID_WINDOW_PREVIOUS, OnWindowPrevious)
ON_COMMAND(ID_WINDOW_SAVE_ALL, OnWindowSaveAll)
ON_COMMAND(ID_WINDOW_CLOSE_ALL, OnWindowCloseAll)
ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullscreen)
ON_UPDATE_COMMAND_UI(ID_VIEW_FULLSCREEN, OnUpdateViewFullscreen)
ON_COMMAND(ID_VIEW_VIEWTAB, OnTabView)
ON_UPDATE_COMMAND_UI(ID_VIEW_VIEWTAB, OnUpdateTabView)
ON_UPDATE_COMMAND_UI(ID_WINDOW_MANAGE, OnUpdateWindowManage)
ON_WM_PAINT()
ON_WM_DESTROY()
ON_MESSAGE(WM_MDICREATE, OnMDICreate)
ON_MESSAGE(WM_MDIDESTROY, OnMDIDestroy)
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI(ID_WINDOW_NEXT, OnUpdateWindowManage) // Just cheating!!!
ON_UPDATE_COMMAND_UI(ID_WINDOW_PREVIOUS, OnUpdateWindowManage)
ON_UPDATE_COMMAND_UI(ID_WINDOW_SAVE_ALL, OnUpdateWindowManage)
ON_UPDATE_COMMAND_UI(ID_WINDOW_CLOSE_ALL, OnUpdateWindowManage)
END_MESSAGE_MAP()
BOOL CMDIClient::SubclassMDIClient(CMDIFrameWnd* pMDIFrameWnd,
CViewManager* pViewManager, UINT uID)
{
// Subclass the MDI client window
VERIFY(this->SubclassWindow(pMDIFrameWnd->m_hWndMDIClient));
pViewManager->CreateViewManager(pMDIFrameWnd, uID);
m_pViewManager = pViewManager;
m_pMDIFrame = reinterpret_cast < CMyMainFrameClass*>(pMDIFrameWnd); // TODO
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMDIClient message handlers
void CMDIClient::OnTabView()
{
ASSERT(m_pMDIFrame != NULL);
ASSERT(m_pViewManager != NULL);
m_pMDIFrame->ShowControlBar(m_pViewManager,
(m_pViewManager->GetStyle() & WS_VISIBLE) == 0, FALSE);
}
void CMDIClient::OnUpdateTabView(CCmdUI* pCmdUI)
{
ASSERT(m_pMDIFrame != NULL);
ASSERT(m_pViewManager != NULL);
pCmdUI->SetCheck((m_pViewManager->GetStyle() & WS_VISIBLE) != 0);
}
LRESULT CMDIClient::OnSetMenu(WPARAM wParam, LPARAM lParam)
{
// LRESULT lResult = Default(); // This does not prevent level 4 warning...
//LRESULT lResult = DefWindowProc(WM_MDISETMENU, wParam, lParam);
// Remember Window submenu handle
m_hMenuWindow = reinterpret_cast < HMENU>(lParam);
// Refresh window submenu
// SendMessage(WM_MDIREFRESHMENU);
CMDIFrameWndEx* pFrame =(CMDIFrameWndEx*) GetParentFrame();
if ( !pFrame->m_bInPlace )
{
VERIFY( pFrame->m_wndMenuBar.SetMenu( ( HMENU )wParam ) );
wParam = 0;
}
return DefWindowProc( WM_MDISETMENU, wParam, lParam );
// return lResult;
}
LRESULT CMDIClient::OnRefreshMenu(WPARAM wParam, LPARAM lParam)
{
// LRESULT lResult = Default(); // This does not prevent level 4 warning...
LRESULT lResult = DefWindowProc(WM_MDIREFRESHMENU, wParam, lParam);
HMENU hMenu = m_hMenuWindow;
if (hMenu != NULL)
{
UINT uState = ::GetMenuState(hMenu, AFX_IDM_FIRST_MDICHILD + 9, MF_BYCOMMAND);
if (uState == 0xFFFFFFFF)
uState = 0;
// Remove old MDI 'Windows...' command
while (::RemoveMenu(hMenu, AFX_IDM_FIRST_MDICHILD + 9, MF_BYCOMMAND))
;
// Remove 'Windows' command
while (::RemoveMenu(hMenu, ID_WINDOW_MANAGE, MF_BYCOMMAND))
;
::AppendMenu(hMenu, MF_STRING | uState, ID_WINDOW_MANAGE, m_strWindows);
}
return lResult;
}
void CMDIClient::OnWindowManage()
{
ManageWindows(m_pMDIFrame);
}
void CMDIClient::OnUpdateWindowManage(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pViewManager->GetWindowNum());
}
void CMDIClient::ManageWindows(CMDIFrameWnd* pMDIFrame)
{
CWindowDlg dlg(pMDIFrame);
dlg.DoModal();
}
void CMDIClient::ManageWindows(CMDIFrameWnd* pMDIFrame, CWnd* pParentWnd)
{
CWindowDlg dlg(pMDIFrame, pParentWnd);
dlg.DoModal();
}
BOOL CMDIClient::OnEraseBkgnd(CDC* pDC)
{
UNREFERENCED_PARAMETER(pDC); // clear that level 4 warning...
return TRUE;
}
void CMDIClient::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
// if the app is just starting up, save the window
// dimensions and get out
if ((m_sizeClient.cx == 0) &&(m_sizeClient.cy == 0))
{
m_sizeClient.cx = cx;
m_sizeClient.cy = cy;
return;
}
// if the size hasn't changed, break and pass to default
if ((m_sizeClient.cx == cx) &&(m_sizeClient.cy == cy))
{
return;
}
// window size has changed so save new dimensions and force
// entire background to redraw, including icon backgrounds
m_sizeClient.cx = cx;
m_sizeClient.cy = cy;
RedrawWindow(NULL, NULL,
RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW | RDW_ALLCHILDREN);
return;
}
void CMDIClient::OnRButtonDown(UINT nFlags, CPoint point)
{
CWnd::OnRButtonDown(nFlags, point);
}
LRESULT CMDIClient::OnMDICreate(WPARAM wParam, LPARAM lParam)
{
HWND hWnd = reinterpret_cast < HWND>(DefWindowProc(WM_MDICREATE, wParam, lParam));
CMDIChildWnd *pChild = static_cast < CMDIChildWnd*>(FromHandle(hWnd));
//if (!m_bFullScreen && m_pViewManager->GetWindowNum() > 0)
//{//
// CMDIChildWnd* pActiveChild = m_pMDIFrame->MDIGetActive();
// DWORD dwStyle = ::GetWindowLong(pActiveChild->m_hWnd, GWL_STYLE);
// m_bMaxChild =(dwStyle & WS_MAXIMIZE) ? TRUE : FALSE;
//}
//if (m_bFirstTime && m_bMaxChild)
// m_pMDIFrame->MDIMaximize(pChild);
//else if (m_bMaxChild && m_pViewManager->GetWindowNum() == 0)
// m_pMDIFrame->MDIMaximize(pChild);
// Thank you Andrew Lazarus, he provided the cool tip ...
// pChild->GetDlgItem(AFX_IDW_PANE_FIRST)) to obtain the view just created.
m_pViewManager->AddView(_T(""),
static_cast < CView *>(pChild->GetDlgItem(AFX_IDW_PANE_FIRST)));
return (LRESULT) hWnd;
}
LRESULT CMDIClient::OnMDIDestroy(WPARAM wParam, LPARAM lParam)
{
try
{
CMDIChildWnd* pChild =
static_cast<CMDIChildWnd*>(FromHandle(reinterpret_cast < HWND>(wParam)));
//if(!pChild)
// It will be useful to save the state of the last child window closed and
// use this for displaying the next window...
//if (m_pViewManager->GetWindowNum() == 1)
// {
// DWORD dwStyle = ::GetWindowLong(pChild->m_hWnd, GWL_STYLE);
// Save the necessary options for later restoration process
///// m_bMaxChild =(dwStyle & WS_MAXIMIZE) ? TRUE : FALSE;
// AfxGetApp()->WriteProfileInt(szSection, szChildWinPos, m_bMaxChild);
// }
m_pViewManager->RemoveView(static_cast < CView*>(pChild->GetDlgItem(AFX_IDW_PANE_FIRST)));
}
catch(CException *e)
{
e->Delete();
MessageBox("Close Window Error");
}
return DefWindowProc(WM_MDIDESTROY, wParam, lParam);
}
void CMDIClient::OnWindowNext()
{
m_pMDIFrame->MDINext();
}
void CMDIClient::OnWindowPrevious()
{
ASSERT(::IsWindow(m_hWnd));
::SendMessage(m_pMDIFrame->m_hWndMDIClient, WM_MDINEXT, 0, 1);
}
void CMDIClient::OnWindowSaveAll()
{
CDocumentList CurDocList;
// save all modified documents, prompting the user if necessary for filename
CDocument* pDoc = CurDocList.GetNextDocument();
while (pDoc != NULL)
{
if (pDoc->IsModified())
pDoc->DoFileSave();
pDoc = CurDocList.GetNextDocument(); // VC++5.0 will not support this in the
// while() statement -- Thanks Ivan Zhakov.
}
}
void CMDIClient::OnWindowCloseAll()
{
CDocumentList CurDocList;
// save all modified documents, prompting the user if necessary for filename
CDocument* pDoc = CurDocList.GetNextDocument();
while (pDoc != NULL)
{
if (pDoc->IsModified())
pDoc->DoFileSave();
pDoc = CurDocList.GetNextDocument(); // VC++5.0 will not support this in the
// while() statement -- Thanks Ivan Zhakov.
}
// now close all the open documents
AfxGetApp()->CloseAllDocuments(FALSE);
}
void CMDIClient::OnViewFullscreen()
{
if (m_bFullScreen)
{
//m_pMDIFrame->ShowControlBar(&m_pMDIFrame->m_wndToolBar, m_bToolBarVisible, FALSE);
// m_pMDIFrame->ShowControlBar(&m_pMDIFrame->m_wndStatusBar, m_bStatusBarVisible, FALSE);
// m_pMDIFrame->DockControlBar(&m_pMDIFrame->m_wndViewManager, AFX_IDW_DOCKBAR_TOP);
m_pMDIFrame->ShowControlbarBen();
FullScreenOff();
}
else
{
// available only if there is an active doc
CMDIChildWnd* pChild = m_pMDIFrame->MDIGetActive();
DWORD dwStyle = 0;
if (pChild != NULL)
{
dwStyle = ::GetWindowLong(pChild->m_hWnd, GWL_STYLE);
}
else
return;
// Save the necessary options for later restoration process
m_bMaxChild =(dwStyle & WS_MAXIMIZE) ? TRUE : FALSE;
m_bToolBarVisible =((m_pMDIFrame->m_wndToolBar.IsWindowVisible()) != 0);
m_bStatusBarVisible =((m_pMDIFrame->m_wndStatusBar.IsWindowVisible()) != 0);
m_pMDIFrame->GetWindowRect(&m_rcMainFrame);
CRect rcBar;
m_pMDIFrame->m_wndViewManager.GetWindowRect(rcBar);
int cxScrn = ::GetSystemMetrics(SM_CXSCREEN);
int cyScrn = ::GetSystemMetrics(SM_CYSCREEN);
// Float the tab control bar, and hide the toolbar and status bars
// m_pMDIFrame->FloatControlBar(&m_pMDIFrame->m_wndViewManager,
// CPoint((cxScrn - rcBar.Width())/2, cyScrn - rcBar.Height() * 3));
//m_pMDIFrame->ShowControlBar(&m_pMDIFrame->m_wndToolBar, FALSE, FALSE);
//m_pMDIFrame->ShowControlBar(&m_pMDIFrame->m_wndStatusBar, FALSE, FALSE);
m_pMDIFrame->HideControlbarBen();
FullScreenOn();
}
}
void CMDIClient::OnUpdateViewFullscreen(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bFullScreen);
// if (m_pViewManager->GetWindowNum() == 0 && !m_bFullScreen)
// pCmdUI->Enable(m_pViewManager->GetWindowNum());
}
void CMDIClient::FullScreenOn()
{
// The full screen toolbar array! The array form was chosen just in case
// you wish to add more buttons to the floating toolbar
UINT uIDToolBar[] =
{
ID_VIEW_FULLSCREEN
};
// 1. Get the child window and hide it to avoid flicker.
CMDIChildWnd* pChild = m_pMDIFrame->MDIGetActive();
if (pChild != NULL)
pChild->ShowWindow(SW_HIDE);
// 2. Remove the caption of the main window and resize it to the full screen
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -