📄 stfullscreen.cpp
字号:
#include "stdafx.h"
#include "STFullScreen.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// CSTFullScreen
//////////////////////////////////////////////////////////////////////
CSize CSTFullScreen::GetScreenSize()
{
CSize size;
CDC *pDC = AfxGetMainWnd()->GetDC();
size.cx = pDC->GetDeviceCaps(HORZRES);
size.cy = pDC->GetDeviceCaps(VERTRES);
AfxGetMainWnd()->ReleaseDC(pDC);
return size;
}
CRect CSTFullScreen::GetFullScreenWindowRect(DWORD dwFullScreenMode, BOOL bInFullSceenState)
{
#define MENU_HEIGHT 26
//By default window size equals to screen size
CSize size = GetScreenSize();
int top = 0;
//If command bar is shown then window height should be decreased
//by command bar height
if (!(dwFullScreenMode & FSF_HIDECOMMANDBAR) || !bInFullSceenState) {
size.cy -= MENU_HEIGHT;
}
//If task bar is shown then window height should be decreased by
//task bar height
if (!(dwFullScreenMode & FSF_HIDETASKBAR) || !bInFullSceenState) {
top += MENU_HEIGHT;
size.cy -= MENU_HEIGHT;
}
return CRect(CPoint(0, top), size);
}
BOOL CSTFullScreen::RefreshFullScreen(CWnd *pWnd, HWND hCommandBar, DWORD dwFullScreenMode, BOOL bInFullSceenState)
{
ASSERT(pWnd);
//Before hide command bar we should hipe SIP panel
if ((dwFullScreenMode & FSF_HIDECOMMANDBAR) && bInFullSceenState) {
SHSipPreference(pWnd->m_hWnd, SIP_FORCEDOWN);
}
//Get main window and check that it's foreground
CWnd *pMainWindow = AfxGetMainWnd();
ASSERT(pMainWindow);
if (pMainWindow==NULL) return FALSE;
pMainWindow->SetForegroundWindow();
HWND hWnd = pMainWindow->GetSafeHwnd();
CRect rect = GetFullScreenWindowRect(dwFullScreenMode, bInFullSceenState);
if ((dwFullScreenMode & FSF_HIDECOMMANDBAR) && bInFullSceenState) {
//Is command bar should be hidden then we should resize our window
//first to prevent blinking
pMainWindow->MoveWindow(rect);
::CommandBar_Show(hCommandBar, FALSE);
} else {
//Is command bar should be shown then we should show it and only then
//resize our window to prevent blinking
::CommandBar_Show(hCommandBar, TRUE);
pMainWindow->MoveWindow(rect);
}
if ((dwFullScreenMode & FSF_HIDETASKBAR) && bInFullSceenState) {
SHFullScreen(hWnd, SHFS_HIDETASKBAR);
} else {
SHFullScreen(hWnd, SHFS_SHOWTASKBAR);
}
if ((dwFullScreenMode & FSF_HIDESIPBUTTON) && bInFullSceenState) {
SHFullScreen(hWnd, SHFS_HIDESIPBUTTON);
} else {
SHFullScreen(hWnd, SHFS_SHOWSIPBUTTON);
}
if ((dwFullScreenMode & FSF_HIDESTARTICON) && bInFullSceenState) {
SHFullScreen(hWnd, SHFS_HIDESTARTICON);
} else {
SHFullScreen(hWnd, SHFS_SHOWSTARTICON);
}
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// CSTFullScreenIcon
//////////////////////////////////////////////////////////////////////
CSTFullScreenIcon::CSTFullScreenIcon()
: m_bIsToolbarIconSet(FALSE),
m_nIconPosition(FSI_BOTTOMLEFT),
m_hIcon(NULL),
m_pCommandBar(NULL)
{
}
CSTFullScreenIcon::~CSTFullScreenIcon()
{
}
BEGIN_MESSAGE_MAP(CSTFullScreenIcon, CWnd)
//{{AFX_MSG_MAP(CSTFullScreenIcon)
ON_WM_PAINT()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CSTFullScreenIcon::OnPaint()
{
CPaintDC dc(this);
if (m_hIcon!=NULL) {
dc.DrawIcon(CPoint(0,0), m_hIcon);
} else {
dc.MoveTo(2,2);
dc.LineTo(15,15);
dc.MoveTo(2,14);
dc.LineTo(15, 1);
}
}
void CSTFullScreenIcon::OnLButtonUp(UINT nFlags, CPoint point)
{
if (GetParent()) {
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(ID_SWITCH_FULLSCREEN, 0), 0);
}
CWnd::OnLButtonUp(nFlags, point);
}
void CSTFullScreenIcon::InsertIconInDialogToolbar(CCeCommandBar *pCb)
{
if (m_bIsToolbarIconSet) {
//If the icon is already inserted in the command bar then nothing to do
return;
}
m_pCommandBar = pCb;
CToolBarCtrl &cbc = m_pCommandBar->GetToolBarCtrl();
//Checks if the button is already inserted then nothing to do
if (cbc.GetButtonCount()>0) {
TBBUTTON firstButton;
cbc.GetButton(0, &firstButton);
if (firstButton.idCommand==ID_SWITCH_FULLSCREEN) {
m_bIsToolbarIconSet = true;
return;
}
}
CImageList *pCommandBarImageList = cbc.GetImageList();
if (pCommandBarImageList==NULL) {
pCommandBarImageList = new CImageList();
pCommandBarImageList->Create(16, 16, ILC_COLORDDB, 2, 1);
cbc.SetImageList(pCommandBarImageList);
}
int nCommandBarImageListPosition = pCommandBarImageList->Add(m_hIcon);
TBBUTTON iconInfo;
iconInfo.fsState = TBSTATE_ENABLED;
iconInfo.fsStyle = TBSTYLE_BUTTON;
iconInfo.iBitmap = nCommandBarImageListPosition;
iconInfo.idCommand = ID_SWITCH_FULLSCREEN;
iconInfo.iString = 0;
cbc.InsertButton(0, &iconInfo);
m_pCommandBar->SetSizes(CSize(23,22), CSize(16,16));
m_pCommandBar->RedrawWindow();
//Icon is inserted
m_bIsToolbarIconSet = true;
}
void CSTFullScreenIcon::SetIconPosition(UINT nIconPosition, DWORD dwFullScreenMode, BOOL bInFullSceenState)
{
m_nIconPosition = nIconPosition;
if (m_hWnd) {
MoveWindow(GetIconRectangle(dwFullScreenMode, bInFullSceenState));
}
}
CRect CSTFullScreenIcon::GetIconRectangle(DWORD dwFullScreenMode, BOOL bInFullSceenState)
{
CSize sizeScreen = CSTFullScreen::GetFullScreenWindowRect(dwFullScreenMode, bInFullSceenState).Size();
CSize sizeIcon = CSize(16, 16);
CRect rect;
switch (m_nIconPosition) {
case FSI_TOPLEFT:
rect = CRect(CPoint(0, 0), sizeIcon);
break;
case FSI_TOPRIGHT:
rect = CRect(CPoint(sizeScreen.cx-sizeIcon.cx, 0), sizeIcon);
break;
case FSI_BOTTOMLEFT:
rect = CRect(CPoint(0, sizeScreen.cy-sizeIcon.cy), sizeIcon);
break;
case FSI_BOTTOMRIGHT:
rect = CRect(CPoint(sizeScreen.cx-sizeIcon.cx, sizeScreen.cy-sizeIcon.cy), sizeIcon);
break;
default:
rect = CRect(CPoint(0, 0), sizeIcon);
}
return rect;
}
BOOL CSTFullScreenIcon::Create (LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, UINT nPosition, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
CRect rect = GetIconRectangle(FSF_FULLSCREEN, TRUE);
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
void CSTFullScreenIcon::SetIcon(HICON hIcon)
{
m_hIcon = hIcon;
if (m_hWnd) {
RedrawWindow();
}
if ((m_pCommandBar!=NULL) && (m_bIsToolbarIconSet)) {
CToolBarCtrl &cbc = m_pCommandBar->GetToolBarCtrl();
CImageList *pCommandBarImageList = cbc.GetImageList();
if (pCommandBarImageList==NULL) {
pCommandBarImageList = new CImageList();
pCommandBarImageList->Create(16, 16, ILC_COLORDDB, 2, 1);
cbc.SetImageList(pCommandBarImageList);
}
int nCommandBarImageListPosition = pCommandBarImageList->Add(m_hIcon);
TBBUTTON iconInfo;
iconInfo.fsState = TBSTATE_ENABLED;
iconInfo.fsStyle = TBSTYLE_BUTTON;
iconInfo.iBitmap = nCommandBarImageListPosition;
iconInfo.idCommand = ID_SWITCH_FULLSCREEN;
iconInfo.iString = 0;
cbc.DeleteButton(0);
cbc.InsertButton(0, &iconInfo);
m_pCommandBar->SetSizes(CSize(23,22), CSize(16,16));
m_pCommandBar->RedrawWindow();
}
}
//////////////////////////////////////////////////////////////////////
// CSTFullScreenDialogLite
//////////////////////////////////////////////////////////////////////
CSTFullScreenDialogLite::CSTFullScreenDialogLite(UINT nIDTemplate, CWnd* pParentWnd /*= NULL*/)
: CDialog(nIDTemplate, pParentWnd),
m_dwFullScreenMode(FSF_FULLSCREEN),
m_bInFullSceenState(TRUE)
{
}
BEGIN_MESSAGE_MAP(CSTFullScreenDialogLite, CDialog)
//{{AFX_MSG_MAP(CSTFullScreenDialogLite)
ON_WM_ACTIVATE()
ON_WM_DESTROY()
ON_MESSAGE(WM_USER_REFRESH_FULLSCREEN, OnFullScreenRefresh)
ON_COMMAND(ID_SWITCH_FULLSCREEN, OnFullScreenSwitch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CSTFullScreenDialogLite::RefreshFullScreen()
{
return CSTFullScreen::RefreshFullScreen(this, m_pWndEmptyCB->m_hWnd, m_dwFullScreenMode, m_bInFullSceenState);
}
BOOL CSTFullScreenDialogLite::OnInitDialog()
{
CDialog::OnInitDialog();
PostMessage(WM_USER_REFRESH_FULLSCREEN);
return TRUE;
}
void CSTFullScreenDialogLite::OnDestroy()
{
CDialog::OnDestroy();
}
void CSTFullScreenDialogLite::OnFullScreenSwitch()
{
SwitchFullScreenState();
}
void CSTFullScreenDialogLite::OnFullScreenRefresh(WPARAM wParam, LPARAM lParam)
{
RefreshFullScreen();
}
void CSTFullScreenDialogLite::SwitchFullScreenState()
{
m_bInFullSceenState = !m_bInFullSceenState;
RefreshFullScreen();
}
void CSTFullScreenDialogLite::SetFullScreenState(BOOL bFullScreen)
{
m_bInFullSceenState = bFullScreen;
}
BOOL CSTFullScreenDialogLite::GetFullScreenState()
{
return m_bInFullSceenState;
}
void CSTFullScreenDialogLite::SetFullScreenMode(DWORD dwFullScreenMode)
{
m_dwFullScreenMode = dwFullScreenMode;
}
DWORD CSTFullScreenDialogLite::GetFullScreenMode()
{
return m_dwFullScreenMode;
}
void CSTFullScreenDialogLite::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
if (nState!=WA_INACTIVE) {
PostMessage(WM_USER_REFRESH_FULLSCREEN);
}
}
int CSTFullScreenDialogLite::DoModal()
{
CString strParentClass;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -