📄 cepropertysheet.cpp
字号:
// CePropertySheet.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "CePropertySheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
PFNPROPSHEETCALLBACK CCePropertySheet::m_pCallBack = NULL;
CString CCePropertySheet::m_strLink;
CString CCePropertySheet::m_strTitle;
//---------------------------------------------------------------------------
//
// CCePropertySheet
//
//---------------------------------------------------------------------------
IMPLEMENT_DYNAMIC(CCePropertySheet, CPropertySheet)
CCePropertySheet::CCePropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
: CPropertySheet (nIDCaption, pParentWnd, iSelectPage),
m_pWndEmptyCB (NULL)
{
m_strTitle.LoadString(nIDCaption);
HookCallback();
}
CCePropertySheet::CCePropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
: CPropertySheet (pszCaption, pParentWnd, iSelectPage),
m_pWndEmptyCB (NULL)
{
m_strTitle = pszCaption;
HookCallback();
}
CCePropertySheet::~CCePropertySheet()
{
//
// Thanks, Daniel!
//
if(m_pWndEmptyCB)
delete m_pWndEmptyCB;
}
BEGIN_MESSAGE_MAP(CCePropertySheet, CPropertySheet)
//{{AFX_MSG_MAP(CCePropertySheet)
ON_WM_INITMENUPOPUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CCePropertySheet::CePropertySheetCallBack
//
// The property sheet callback
//
int CALLBACK CCePropertySheet::CePropertySheetCallBack(HWND hWnd, UINT message, LPARAM lParam)
{
if(message == PSCB_GETLINKTEXT)
{
if(!m_strLink.IsEmpty())
{
LPTSTR pBuf = (LPTSTR)lParam;
wcscpy(pBuf, m_strLink);
}
}
else if(message == PSCB_GETTITLE)
{
if(!m_strTitle.IsEmpty())
{
LPTSTR pBuf = (LPTSTR)lParam;
wcscpy(pBuf, m_strTitle);
}
}
return (m_pCallBack)(hWnd, message, lParam);
}
// CCePropertySheet::HookCallback
//
// Hooks the MFC property sheet callback function
//
void CCePropertySheet::HookCallback()
{
m_pCallBack = m_psh.pfnCallback;
m_psh.pfnCallback = CePropertySheetCallBack;
}
//---------------------------------------------------------------------------
//
// CCePropertySheet virtual methods
//
//---------------------------------------------------------------------------
// CCePropertySheet::OnInitDialog
//
// Initialize the dialog.
// Create the empty command bar.
//
BOOL CCePropertySheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();
//
// Create the empty command bar.
// Code provided by Vassili Philippov.
//
m_pWndEmptyCB = new CCeCommandBar;
if(m_pWndEmptyCB != NULL)
{
m_pWndEmptyCB->CreateEx(this);
}
return bResult;
}
//---------------------------------------------------------------------------
//
// CCePropertySheet message handlers
//
//---------------------------------------------------------------------------
// CCePropertySheet::OnInitMenuPopup
//
// Handle menus in the command bar
// This code was provided by Alexander Shargin, based on MFC's
//
void CCePropertySheet::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
{
if (bSysMenu)
return; // don't support system menu
ASSERT(pMenu != NULL);
// check the enabled state of various menu items
CCmdUI state;
state.m_pMenu = pMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
// determine if menu is popup in top-level menu and set m_pOther to
// it if so (m_pParentMenu == NULL indicates that it is secondary popup)
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
state.m_pParentMenu = pMenu; // parent == child for tracking popup
else if ((hParentMenu = ::WCE_FCTN(GetMenu)(m_hWnd)) != NULL)
{
CWnd* pParent = GetTopLevelParent();
// child windows don't have menus -- need to go to the top!
if (pParent != NULL &&
(hParentMenu = ::WCE_FCTN(GetMenu)(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::WCE_FCTN(GetMenuItemCount)(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pMenu->m_hMenu)
{
// when popup is found, m_pParentMenu is containing menu
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue; // menu separator or invalid cmd - ignore it
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
// possibly a popup menu, route to first item of that popup
state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL ||
(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue; // first item of popup can't be routed to
}
state.DoUpdate(this, FALSE); // popups are never auto disabled
}
else
{
// normal menu item
// Auto enable/disable if frame window has 'm_bAutoMenuEnable'
// set and command is _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(this, TRUE);
}
// adjust for menu deletions and additions
UINT nCount = pMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -