📄 xfloorwndctl.cpp
字号:
while (cont)
{
CString sItem, sName, sUser;
AfxExtractSubString(sItem, m_sPages, i, _cPagesSeparator);
AfxExtractSubString(sName, sItem, 0, TCHAR('\\'));
AfxExtractSubString(sUser, sItem, 1, TCHAR('\\'));
LPARAM lParam = atol((LPCTSTR)sUser);
if (cont = !sName.IsEmpty())
{
int nItem = i;
if (CFloorPageObject* pPage = GetPage(nItem))
pPage->SetName(sName);
else
AddPage(sName, &nItem);
SetUserData(nItem, lParam);
i++;
}
}
while (DeletePage(i));
SetModifiedFlag();
m_bAnimation = bSAnimation;
}
}
// Function name : CXFloorWndCtrl::GetUserData
// Description : Return the user data attached to a page nIndex
// Return type : long
// Argument : short nIndex
long CXFloorWndCtrl::GetUserData(short nIndex)
{
long lResult = -1;
if (CFloorPageObject* pPage = GetPage(nIndex))
lResult = pPage->GetUserData();
return lResult;
}
// Function name : CXFloorWndCtrl::SetUserData
// Description : Set the new user data to a page nIndex
// Return type : void
// Argument : short nIndex
// Argument : long nNewValue
void CXFloorWndCtrl::SetUserData(short nIndex, long nNewValue)
{
long lResult = 0;
if (CFloorPageObject* pPage = GetPage(nIndex))
pPage->SetUserData(nNewValue);
SetModifiedFlag();
}
// Function name : CXFloorWndCtrl::_Init
// Description :
// Return type : void
void CXFloorWndCtrl::_Init()
{
RecalcLayout();
int nIndex = 0;
CFloorPageObject* pPage = NULL;
while (pPage = GetPage(nIndex++))
pPage->SetRectClient(GetRectClient());
}
// Function name : CXFloorWndCtrl::_GetActivePage
// Description : Version 1.01
// Return type : short
short CXFloorWndCtrl::_GetActivePage()
{
return PtrPageToIndex(m_pActivePage);
}
// Function name : CXFloorWndCtrl::_GetPagesCount
// Description : Version 1.01
// Return type : long
long CXFloorWndCtrl::_GetPagesCount()
{
return GetCountPage();
}
// Function name : CXFloorWndCtrl::_IsPage
// Description : Version 1.01
// Return type : BOOL
// Argument : short nIndex
BOOL CXFloorWndCtrl::_IsPage(short nIndex)
{
return GetPage(nIndex) != NULL;
}
// Function name : CXFloorWndCtrl::_GetLeftTopPage
// Description : Version 1.01
// Return type : long
// Argument : short nIndex
long CXFloorWndCtrl::_GetLeftTopPage(short nIndex)
{
if (CFloorPageObject* pPage = GetPage(nIndex))
return MAKELPARAM(pPage->m_rect.TopLeft().x, pPage->m_rect.TopLeft().y);
return -1;
}
// Function name : CXFloorWndCtrl::_GetBottomRightPage
// Description : Version 1.01
// Return type : long
// Argument : short nIndex
long CXFloorWndCtrl::_GetBottomRightPage(short nIndex)
{
if (CFloorPageObject* pPage = GetPage(nIndex))
return MAKELPARAM(pPage->m_rect.BottomRight().x, pPage->m_rect.BottomRight().y);
return -1;
}
// Function name : CXFloorWndCtrl::WindowProc
// Description : Window procedure.
// This is very important for next controls that will be inserted in this control.
// To accepts some messages you need to insert here. See CReflectorWnd class
// Update : Version 1.01
// Return type : LRESULT
// Argument : UINT message
// Argument : WPARAM wParam
// Argument : LPARAM lParam
LRESULT CXFloorWndCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
UINT id = (UINT)wParam;
switch (message)
{
case WM_COMMAND:
{
id = LOWORD(wParam);
if ( HIWORD(wParam) == CBN_SELENDOK )
if ( id == ID_LABELCOMBO )
{
SetTimer(IDSTARTMOVELABEL, UPDATEIDSTARTMOVELABEL, NULL);
break;
}
}
case WM_NOTIFY:
case WM_DRAWITEM:
case WM_MEASUREITEM:
{
if (CWnd* pWnd = GetDlgItem((UINT)id))
if (::IsWindow(pWnd->m_hWnd))
return pWnd->SendMessage(message, wParam, lParam);
}
}
return COleControl::WindowProc(message, wParam, lParam);
}
// Function name : CXFloorWndCtrl::SetFont
// Description :
// Return type : void
// Argument : CWnd *pWindow
// Argument : COleControl *pControlSource
void CXFloorWndCtrl::SetFont(CWnd *pWindow, COleControl *pControlSource)
{
if (pWindow)
if (::IsWindow(pWindow->m_hWnd))
if (pControlSource)
{
IFontDisp* pFontDisp = pControlSource->GetFont();
IFont* pIFont = NULL;
if (SUCCEEDED(pFontDisp->QueryInterface(IID_IFont, (void**)&pIFont)))
{
if (pIFont)
{
HFONT hFont = NULL;
if (SUCCEEDED(pIFont->get_hFont(&hFont)))
pWindow->SetFont(CFont::FromHandle(hFont));
}
pFontDisp->Release();
}
}
}
// Function name : CXFloorWndCtrl::RefreshFontLabel
// Description : Called when something are change into font page
// Return type : void
// Argument : COleControl *pControl
void CXFloorWndCtrl::RefreshFontLabel(COleControl *pControl)
{
SetFont(GetComboBox(), pControl);
SetFont(GetLabelControl(), pControl);
}
// Function name : CXFloorWndCtrl::ChangeHeightLabel
// Description : return the rect of the page
// Return type : void
CRect CXFloorWndCtrl::ChangeHeightLabel(CSize s)
{
//This function must be called only if style of control is floor
CComboBox* pCombo = GetComboBox();
ASSERT (pCombo);
CTLabelComboBox* pLabelControl = GetLabelControl();
ASSERT (pLabelControl);
// Just do this
pCombo->MoveWindow(0,0, s.cx, m_nDYCombo);
CRect rect; pCombo->GetClientRect(rect);
m_nDYLabel = rect.Height() + 2;
CRect rResult = CRect(CPoint(0,0), CSize(s.cx, m_nDYLabel));
pLabelControl->MoveWindow(rResult);
return rResult;
}
// Function name : CXFloorWndCtrl::PrepareChangeStyle
// Description :
// Return type : void
void CXFloorWndCtrl::PrepareChangeStyle()
{
if (m_bAsPage)
{
// The new style is floor
if (GetComboBox())
GetComboBox()->DestroyWindow();
if (GetLabelControl())
GetLabelControl()->DestroyWindow();
ASSERT( !GetComboBox() );
}
else
if (m_hWnd)
{
if (!GetComboBox())
{
// The new style is label
VERIFY(m_cbPage.Create(CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, ID_LABELCOMBO));
m_lbPage.RegClassLabelEdit();
VERIFY(m_lbPage.Create(_T("TLabelEdit"), _T(""), WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, ID_LABEL));
m_lbPage.Init();
m_lbPage.AttachWindow(&m_cbPage);
OnBackColorChanged();
}
else
{
m_cbPage.ResetContent();
m_lbPage.SetWindowText(NULL);
}
RefreshFontLabel(this);
ASSERT( GetComboBox() );
}
}
// Function name : CXFloorWndCtrl::OnAsPageChanged
// Description : When user changes the style of control
// Return type : void
void CXFloorWndCtrl::OnAsPageChanged()
{
// Here we will remove old array of pages and will put the new one.
CArrayPage * pArPages = new CArrayPage();
BOOL bAutoDetach = CFloorPageObject::m_bAutoDetach;
CFloorPageObject::m_bAutoDetach = FALSE;
PrepareChangeStyle();
int nActivePage = -1;
for (int i = 0; i < m_pArPage->GetSize(); i++)
{
CFloorPageObject* pPage = (*m_pArPage)[i];
CFloorPageObject* pNewPage = NewPage(m_bAsPage, pPage->GetName());
pNewPage->m_pWndClient = pPage->m_pWndClient;
pArPages->Add(pNewPage);
if (pPage == m_pActivePage)
{
nActivePage = i;
m_pActivePage->OnDeactivateObject();
m_pActivePage = NULL;
}
delete pPage;
}
// Set the new one array of pages
delete m_pArPage;
m_pArPage = pArPages;
ActivatePage(nActivePage);
RecalcLayout();
CFloorPageObject::m_bAutoDetach = bAutoDetach;
SetModifiedFlag();
}
// Function name : CXFloorWndCtrl::NewPage
// Description : Create a new kind of page
// Return type : CFloorPageObject*
// Argument : BOOL bAsPage
// Argument : LPCTSTR lpszPageName
CFloorPageObject* CXFloorWndCtrl::NewPage(BOOL bAsPage, LPCTSTR lpszPageName)
{
return (bAsPage ? new CFloorPageObject(this, lpszPageName) : new CFloorLabelObject(this, lpszPageName));
}
// Function name : CXFloorWndCtrl::OnFontChanged
// Description : Refresh the font into CFloorLabelObject
// Return type : void
void CXFloorWndCtrl::OnFontChanged()
{
RefreshFontLabel(this);
RecalcLayout();
COleControl::OnFontChanged();
}
// Function name : CXFloorWndCtrl::OnCreate
// Description : Load the pages into control
// Return type : int
// Argument : LPCREATESTRUCT lpCreateStruct
int CXFloorWndCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
PrepareChangeStyle();
OnPagesChanged();
return 0;
}
// Function name : CXFloorWndCtrl::StyleAs
// Description :
// Return type : void
// Argument : BOOL bAsFloor
void CXFloorWndCtrl::StyleAs(BOOL bAsFloor)
{
m_bAsPage = bAsFloor;
OnAsPageChanged();
}
// Function name : CXFloorWndCtrl::GetHWnd
// Description :
// Return type : long
// Argument : long nIndex
long CXFloorWndCtrl::GetHWnd(long nIndex)
{
if (CFloorPageObject* pPage = GetPage(nIndex))
if (CWnd* pWnd = pPage->GetWindow())
return (long)pWnd->m_hWnd;
return NULL;
}
// Function name : CXFloorWndCtrl::GetComboBox
// Description : return NULL if combobox is not created....
// Return type : CComboBox*
CComboBox* CXFloorWndCtrl::GetComboBox()
{
if (::IsWindow(m_cbPage.m_hWnd))
return &m_cbPage;
return NULL;
}
// Function name : CXFloorWndCtrl::GetLabelControl
// Description : return NULL if labelcontrol is not created....
// Return type : CTLabelComboBox*
CTLabelComboBox* CXFloorWndCtrl::GetLabelControl()
{
if (::IsWindow(m_lbPage.m_hWnd))
return &m_lbPage;
return NULL;
}
// Function name : CXFloorWndCtrl::Lookup
// Description : Look for page pLabelObject in combobox
// Return type : int
// Argument : CFloorLabelObject *pLabelObject
int CXFloorWndCtrl::Lookup(CFloorLabelObject *pLabelObject)
{
CComboBox* pComboBox = GetComboBox();
int i = 0, n = pComboBox->GetCount();
for (i = 0; (i < n) && (((DWORD)pComboBox->GetItemData(i)) != (DWORD)pLabelObject); i++);
return i < n ? i : -1;
}
// Function name : CXFloorWndCtrl::OnBackColorChanged
// Description :
// Return type : void
void CXFloorWndCtrl::OnBackColorChanged()
{
if (CBrush* pBrush = &CTLabelEdit::m_brBkGnd)
{
pBrush->DeleteObject();
pBrush->CreateSolidBrush(TranslateColor(GetBackColor()));
if (CWnd* pLabel = GetLabelControl())
{
::SetClassLong(pLabel->m_hWnd, GCL_HBRBACKGROUND, (long)(HBRUSH)*pBrush);
pLabel->Invalidate();
}
}
COleControl::OnBackColorChanged();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -