📄 windowmanager.cpp
字号:
LONG dwStyle = ::GetWindowLong(m_pMDIFrame->m_hWnd, GWL_STYLE);
dwStyle &= ~WS_CAPTION;
::SetWindowLong(m_pMDIFrame->m_hWnd, GWL_STYLE, dwStyle);
// Now resize the main window
int cxScrn = ::GetSystemMetrics(SM_CXSCREEN);
int cyScrn = ::GetSystemMetrics(SM_CYSCREEN);
int cxBorder = ::GetSystemMetrics(SM_CXBORDER);
int cyBorder = ::GetSystemMetrics(SM_CYBORDER);
m_pMDIFrame->SetWindowPos(NULL, -cxBorder, -cyBorder, cxScrn + cxBorder * 2,
cyScrn + cyBorder * 2, SWP_NOZORDER);
// 3. Create the new full screen toolbar, for toggling on mode
/* m_pwndFullScrnToolBar = new CToolBar;
if (!m_pwndFullScrnToolBar->CreateEx(m_pMDIFrame, TBSTYLE_FLAT, WS_VISIBLE | CBRS_TOOLTIPS |
CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_FLOATING) ||
!m_pwndFullScrnToolBar->LoadToolBar(IDR_TABVIEW_MENU))
{
TRACE0(_T("Failed to create the full screen toolbar\n"));
return;
}
m_pwndFullScrnToolBar->SetButtons(uIDToolBar, sizeof(uIDToolBar) / sizeof(UINT));
// TCHAR szButText[] = _T("Full Screen");
// m_pwndFullScrnToolBar->SetButtonText(0, szButText); // TODO
m_pwndFullScrnToolBar->EnableDocking(0);
m_pwndFullScrnToolBar->SetWindowText(_T("Full Screen"));
CRect rcTB;
m_pwndFullScrnToolBar->GetItemRect(0, rcTB);
// position the full screen toolbar at some convenient location
m_pMDIFrame->FloatControlBar(m_pwndFullScrnToolBar,
CPoint(cxScrn - rcTB.Width() * 3,// /*cyScrn - ////
rcTB.Height() * 3));
*/
// 4. Remove the caption of the child window and display it
dwStyle = ::GetWindowLong(pChild->m_hWnd, GWL_STYLE);
dwStyle &= ~WS_CAPTION;
::SetWindowLong(pChild->m_hWnd, GWL_STYLE, dwStyle);
if (pChild != NULL)
pChild->ShowWindow(SW_SHOWMAXIMIZED);
m_pMDIFrame->RecalcLayout();
m_bFullScreen = TRUE;
}
void CMDIClient::FullScreenOff()
{
// if (m_pwndFullScrnToolBar != NULL)
// {
// m_pwndFullScrnToolBar->DestroyWindow();
// delete m_pwndFullScrnToolBar;
// }
// Hidding and showing the child window may not be the best solution,
// but it helps reducing the flicker
CMDIChildWnd* pChild = m_pMDIFrame->MDIGetActive();
if (pChild)
pChild->ShowWindow(SW_HIDE);
LONG dwStyle = ::GetWindowLong(m_pMDIFrame->m_hWnd, GWL_STYLE);
dwStyle |= WS_CAPTION;
::SetWindowLong(m_pMDIFrame->m_hWnd, GWL_STYLE, dwStyle);
m_pMDIFrame->MoveWindow(&m_rcMainFrame);
m_pMDIFrame->RecalcLayout();
if (pChild)
{
dwStyle = ::GetWindowLong(pChild->m_hWnd, GWL_STYLE);
dwStyle |= WS_CAPTION;
::SetWindowLong(pChild->m_hWnd, GWL_STYLE, dwStyle);
if (m_bMaxChild)
m_pMDIFrame->MDIMaximize(pChild);
else
m_pMDIFrame->MDIRestore(pChild);
pChild->ShowWindow(SW_SHOW);
}
m_bFullScreen = FALSE;
}
BOOL CMDIClient::PreTranslateMessage(MSG* pMsg)
{
// When there is an escape key toggle the full screen mode
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE && m_bFullScreen)
OnViewFullscreen();
return CWnd::PreTranslateMessage(pMsg);
}
void CMDIClient::SaveMainFrameState()
{
if (m_bFullScreen)
return;
CMDIChildWnd* pChild = m_pMDIFrame->MDIGetActive();
if (pChild)
{
// It will be useful to save the state of the last child window closed and
// use this for displaying the next window...
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);
}
// before it is destroyed, save the position of the window
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
if (m_pMDIFrame->GetWindowPlacement(&wp))
{
wp.flags = 0;
if (m_pMDIFrame->IsZoomed())
wp.flags |= WPF_RESTORETOMAXIMIZED;
// and write it to the registry
WriteWindowPlacement(&wp);
}
m_pMDIFrame->SaveBarState(AfxGetApp()->m_pszProfileName);
}
void CMDIClient::RestoreMainFrameState(UINT nCmdShow)
{
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
if (!ReadWindowPlacement(&wp))
{
m_pMDIFrame->ShowWindow(nCmdShow,"benben");
return;
}
if (nCmdShow != SW_SHOWNORMAL)
wp.showCmd = nCmdShow;
m_pMDIFrame->SetWindowPlacement(&wp);
m_pMDIFrame->ShowWindow(wp.showCmd,"benben");
m_pMDIFrame->LoadBarState(AfxGetApp()->m_pszProfileName);
}
void CMDIClient::OnPaint()
{
CPaintDC dc(this);
CRect rc;
GetClientRect(rc);
BOOL bDoBitBlt = TRUE;
if (!(HBITMAP)m_bkBitmap)
dc.FillRect(rc, &m_bkBrush);
if ((HBITMAP)m_bkBitmap)
{
CDC* pDC;
CDC memDC;
CBitmap bmp;
BOOL bUseMemDC =(GetDispType() != DISPTILE) ? TRUE : FALSE;
if (bUseMemDC)
{
if (GetDispType() != DISPSTRETCH)
bmp.CreateCompatibleBitmap(&dc, rc.right, rc.bottom);
else
bmp.CreateCompatibleBitmap(&dc, m_sizImage.cx, m_sizImage.cy);
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bmp);
pDC = &memDC;
}
else
pDC = &dc;
switch (GetDispType())
{
case DISPTILE:
{
CPoint point;
for (point.y = 0; point.y < rc.Height(); point.y += m_sizImage.cy)
for (point.x = 0; point.x < rc.Width(); point.x += m_sizImage.cx)
pDC->DrawState(point, m_sizImage, &m_bkBitmap, DST_BITMAP | DSS_NORMAL);
}
break;
case DISPCENTER:
{
pDC->FillRect(rc, &m_bkBrush);
CPoint point((rc.Width() - m_sizImage.cx) / 2,
(rc.Height() - m_sizImage.cy) / 2);
pDC->DrawState(point, m_sizImage, &m_bkBitmap, DST_BITMAP | DSS_NORMAL);
}
break;
case DISPSTRETCH:
{
memDC.DrawState(CPoint(0, 0), m_sizImage, &m_bkBitmap, DST_BITMAP | DSS_NORMAL);
dc.SetStretchBltMode(COLORONCOLOR);
dc.StretchBlt(0, 0, rc.right, rc.bottom, &memDC,
0, 0, m_sizImage.cx, m_sizImage.cy, SRCCOPY);
bDoBitBlt = FALSE;
}
break;
}
// Now is the time to draw the logo text at the bottom
if (!bDoBitBlt) // If not using memory DC, then grab a DC here
pDC = &dc;
PaintLogo(pDC);
if ((bUseMemDC == TRUE) && bDoBitBlt)
dc.BitBlt(0, 0, rc.right, rc.bottom, pDC, 0, 0, SRCCOPY);
}
else
{
CDC* pDC;
pDC = &dc;
PaintLogo(pDC);
}
}
BOOL CMDIClient::SetBitmap(LPCTSTR lpszFileName, UINT uFlags)
{
HANDLE hBitmap = ::LoadImage(AfxGetInstanceHandle(), lpszFileName,
IMAGE_BITMAP, 0, 0, uFlags | LR_LOADFROMFILE);
if (!hBitmap) // There were some problems during loading the image
return FALSE;
m_bkBitmap.DeleteObject();
m_bkBitmap.Attach((HBITMAP)hBitmap);
if (IsWindow(m_hWnd))
Invalidate();
m_strFileName = lpszFileName;
BITMAP bi;
m_bkBitmap.GetBitmap(&bi);
m_sizImage.cx = bi.bmWidth;
m_sizImage.cy = bi.bmHeight;
return TRUE;
}
BOOL CMDIClient::SetBitmap(UINT nBmpID, COLORMAP* pClrMap, int nCount)
{
m_bkBitmap.DeleteObject();
if (pClrMap == NULL)
{
if (m_bkBitmap.LoadBitmap(nBmpID) == FALSE)
return FALSE;
}
else
{
if (m_bkBitmap.LoadMappedBitmap(nBmpID, 0, pClrMap, nCount) == FALSE)
return FALSE;
}
BITMAP bi;
m_bkBitmap.GetBitmap(&bi);
m_sizImage.cx = bi.bmWidth;
m_sizImage.cy = bi.bmHeight;
if (IsWindow(m_hWnd))
Invalidate();
return TRUE;
}
void CMDIClient::SetBkColor(COLORREF crValue)
{
m_crBkColor = crValue;
m_bkBrush.DeleteObject();
m_bkBrush.CreateSolidBrush(m_crBkColor);
if (IsWindow(m_hWnd))
Invalidate();
}
void CMDIClient::SetLogoColor(COLORREF crValue)
{
m_crLogoColor = crValue;
if (IsWindow(m_hWnd))
Invalidate();
}
void CMDIClient::SetDispType(CMDIClient::DispType enuDispType)
{
m_enuDispType = enuDispType;
if (IsWindow(m_hWnd))
Invalidate();
}
void CMDIClient::SetLogoFont(CFont* pLogoFont)
{
ASSERT(pLogoFont);
LOGFONT lFont;
m_fontLogo.DeleteObject();
pLogoFont->GetLogFont(&lFont);
m_fontLogo.CreateFontIndirect(&lFont);
SetFont(&m_fontLogo);
if (IsWindow(m_hWnd))
Invalidate();
}
void CMDIClient::SetLogoFont(int nLogoWeight, BOOL bLogoItalic, BOOL bLogoUnderline)
{
// Free any memory currently used by the fonts.
m_fontLogo.DeleteObject();
// Get the current font
LOGFONT lFont;
CFont* pFont = GetFont();
if (pFont)
pFont->GetLogFont(&lFont);
else
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
lFont = ncm.lfMessageFont;
}
// Create the Logo font
lFont.lfWeight = static_cast<LONG>(nLogoWeight);
lFont.lfItalic = static_cast<BYTE>(bLogoItalic);
lFont.lfUnderline = static_cast<BYTE>(bLogoUnderline);
m_fontLogo.CreateFontIndirect(&lFont);
SetFont(&m_fontLogo);
if (IsWindow(m_hWnd))
Invalidate();
}
void CMDIClient::Defaults(BOOL bBkBitmap)
{
// m_hMenuWindow = 0;
// m_pMDIFrame = NULL;
m_bBkBitmap = bBkBitmap;
m_crBkColor = GetSysColor(COLOR_APPWORKSPACE);
m_crLogoColor = GetSysColor(COLOR_BTNFACE);
// m_bToolBarVisible = FALSE;
// m_bStatusBarVisible = FALSE;
// m_bMaxChild = FALSE;
// m_pwndFullScrnToolBar = NULL;
m_sizImage.cx = m_sizImage.cy = 0;
m_enuDispType = DISPCENTER;
// m_strWindows.LoadString(IDS_WINDOW_MANAGE);
m_strFileName.Empty();
// Create the default font, Times New Roman is most common
CWindowDC wndDC(CWnd::GetDesktopWindow());
int nFontSize = -24;//MulDiv(18, wndDC.GetDeviceCaps(LOGPIXELSY), 72);
if (m_fontLogo.m_hObject != NULL)
m_fontLogo.Detach();
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"));
if (IsWindow(m_hWnd))
SetFont(&m_fontLogo);
SetBkColor(m_crBkColor);
m_bkBitmap.DeleteObject();
if (IsWindow(m_hWnd))
Invalidate();
}
void CMDIClient::OnDestroy()
{
CWnd::OnDestroy();
CWinApp* pApp = AfxGetApp();
// if (m_fontLogo.m_hObject != NULL)
// {
// LOGFONT lf;
// m_fontLogo.GetLogFont(&lf);
// pApp->WriteProfileBinary(szSection, szLogoFont, (LPBYTE)&lf, sizeof(lf));
// }
// pApp->WriteProfileInt(szSection, szLogoColor, (int)m_crLogoColor);
// pApp->WriteProfileInt(szSection, szBackColor, (int)m_crBkColor);
// pApp->WriteProfileInt(szSection, szDispType, (int)m_enuDispType);
// pApp->WriteProfileInt(szSection, szBkBitmap, (int)m_bBkBitmap);
// if (!m_strFileName.IsEmpty())
// pApp->WriteProfileString(szSection, szFileName, (LPCTSTR)m_strFileName);
}
void CMDIClient::PaintLogo(CDC *pDC)
{
CRect rcDataBox;
CString strLogo = szLogoString;
TEXTMETRIC tm;
pDC->SetBkMode(OPAQUE);
CFont* oldFont = pDC->SelectObject(&m_fontLogo);
CRect st(0, 0, 0, 0);
CSize sz = pDC->GetTextExtent(strLogo, strLogo.GetLength());
// GetTextExtent calculates the size of the displayed logo
// which depends on the device context....
pDC->GetTextMetrics(&tm);
// Calculate the box size by subtracting the text width and height from the
// window size. Also subtract 20% of the average character size to keep the
// logo from printing into the borders...
GetClientRect(&rcDataBox);
rcDataBox.left = rcDataBox.right - sz.cx - tm.tmAveCharWidth / 2;
rcDataBox.top = rcDataBox.bottom - sz.cy - st.bottom - tm.tmHeight / 5;
CRect rcSave = rcDataBox;
pDC->SetBkMode(TRANSPARENT);
rcSave = rcDataBox;
// shift logo box right, and print black...
rcDataBox.left += tm.tmAveCharWidth / 5;
COLORREF oldColor = pDC->SetTextColor(RGB(0, 0, 0));
pDC->DrawText(strLogo, strLogo.GetLength(), &rcDataBox,
DT_VCENTER | DT_SINGLELINE | DT_CENTER);
rcDataBox = rcSave;
// shift logo box left and print white
rcDataBox.left -= tm.tmAveCharWidth / 5;
pDC->SetTextColor(RGB(255, 255, 255));
pDC->DrawText(strLogo, strLogo.GetLength(), &rcDataBox,
DT_VCENTER | DT_SINGLELINE | DT_CENTER);
// Restore original location and print in the button face color
rcDataBox = rcSave;
pDC->SetTextColor(m_crLogoColor);
pDC->DrawText(strLogo, strLogo.GetLength(), &rcDataBox,
DT_VCENTER | DT_SINGLELINE | DT_CENTER);
// restore the original properties and release resources...
pDC->SelectObject(oldFont);
pDC->SetTextColor(oldColor);
pDC->SetBkMode(OPAQUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -