123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- #include "stdafx.h"
- #include "resource.h"
- #include "WindowManager.h"
- #include "ViewManager.h"
- //#include "PopupMenu.h"
- #include "MainFrm.h" // TODO: include your main window frame header file here.
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // Globals
- // Please change this to a more useful logo text for your application
- static TCHAR szLogoString[] = _T("");
- // Helpers for saving/restoring window state
- static TCHAR szSection[] = _T("Settings");
- static TCHAR szWindowPos[] = _T("WindowPos");
- static TCHAR szFormat[] = _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
- static BOOL ReadWindowPlacement(LPWINDOWPLACEMENT pwp)
- {
- CString strBuffer = AfxGetApp()->GetProfileString(szSection, szWindowPos);
- if (strBuffer.IsEmpty())
- return FALSE;
- WINDOWPLACEMENT wp;
- int nRead = _stscanf(strBuffer, szFormat,
- &wp.flags, &wp.showCmd,
- &wp.ptMinPosition.x, &wp.ptMinPosition.y,
- &wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
- &wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
- &wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom);
- if (nRead != 10)
- return FALSE;
- wp.length = sizeof wp;
- *pwp = wp;
- return TRUE;
- }
- static void WriteWindowPlacement(LPWINDOWPLACEMENT pwp)
- // write a window placement to settings section of app's ini file
- {
- TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
- wsprintf(szBuffer, szFormat,
- pwp->flags, pwp->showCmd,
- pwp->ptMinPosition.x, pwp->ptMinPosition.y,
- pwp->ptMaxPosition.x, pwp->ptMaxPosition.y,
- pwp->rcNormalPosition.left, pwp->rcNormalPosition.top,
- pwp->rcNormalPosition.right, pwp->rcNormalPosition.bottom);
- AfxGetApp()->WriteProfileString(szSection, szWindowPos, szBuffer);
- }
- ///////////////////////////////////////////////////////////
- // CDocumentList: class implementation
- CDocumentList::CDocumentList()
- {
- CWinApp* pApp = AfxGetApp();
- ASSERT_VALID(pApp);
- // Get the first document template position and iterate through the document template
- POSITION posDocTemplate = pApp->GetFirstDocTemplatePosition();
- while (posDocTemplate != NULL)
- {
- // For each document template object found ...
- CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posDocTemplate);
- ASSERT_VALID(pDocTemplate);
- ASSERT_KINDOF(CDocTemplate, pDocTemplate);
- // ...iterate through the template's document list
- POSITION posDocument = pDocTemplate->GetFirstDocPosition();
- while (posDocument != NULL)
- {
- // And for each document object found...
- CDocument* pDoc = pDocTemplate->GetNextDoc(posDocument);
- ASSERT_VALID(pDoc);
- ASSERT_KINDOF(CDocument, pDoc);
- // ...add the document pointer to the list
- AddTail(pDoc);
- }
- }
- // Finally, set the position of the first list member as the current
- m_CurPosInDocList = GetHeadPosition();
- }
- CDocumentList::~CDocumentList()
- {
- // Out of scope or deleted, remove all document templates...
- RemoveAll();
- //...set the current position to NULL.
- m_CurPosInDocList = NULL;
- }
- CDocument* CDocumentList::GetNextDocument()
- {
- if (m_CurPosInDocList == NULL)
- return NULL;
- CDocument* pDoc = GetNext(m_CurPosInDocList);
- ASSERT_VALID(pDoc);
- ASSERT_KINDOF(CDocument, pDoc);
- return pDoc;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWindowDlg dialog
- CWindowDlg::CWindowDlg(CMDIFrameWnd * pMDIFrame)
- : CDialog(CWindowDlg::IDD, pMDIFrame)
- {
- m_pMDIFrame = pMDIFrame;
- //{{AFX_DATA_INIT(CWindowDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CWindowDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CWindowDlg)
- DDX_Control(pDX, IDC_WINDOWLIST_LIST, m_wndList);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CWindowDlg, CDialog)
- //{{AFX_MSG_MAP(CWindowDlg)
- ON_BN_CLICKED(IDC_WINDOWLIST_CLOSE, OnClose)
- ON_LBN_SELCHANGE(IDC_WINDOWLIST_LIST, OnSelChange)
- ON_BN_CLICKED(IDC_WINDOWLIST_SAVE, OnSave)
- ON_BN_CLICKED(IDC_WINDOWLIST_ACTIVATE, OnActivate)
- ON_WM_DRAWITEM()
- ON_BN_CLICKED(IDC_WINDOWLIST_TILEHORZ, OnTileHorz)
- ON_BN_CLICKED(IDC_WINDOWLIST_MINIMIZE, OnMinimize)
- ON_BN_CLICKED(IDC_WINDOWLIST_TILEVERT, OnTileVert)
- ON_BN_CLICKED(IDC_WINDOWLIST_CASCADE, OnCascade)
- ON_LBN_DBLCLK(IDC_WINDOWLIST_LIST, OnActivate)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWindowDlg message handlers
-
- BOOL CWindowDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- FillWindowList();
- SelActive();
- UpdateButtons();
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CWindowDlg::OnClose()
- {
- int nItems = m_wndList.GetCount();
- if (nItems != LB_ERR && nItems > 0)
- {
- HWND hMDIClient = m_pMDIFrame->m_hWndMDIClient;
-
- 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));
- ::SendMessage(hWnd, WM_CLOSE, static_cast<WPARAM>(0), static_cast<LPARAM>(0));
- if(::GetParent(hWnd) == hMDIClient)
- break;
- }
- }
- m_wndList.SetRedraw(TRUE);
- }
- FillWindowList();
- SelActive();
- UpdateButtons();
- }
- void CWindowDlg::OnSelChange()
- {
- UpdateButtons();
- }
- // Enables/Disables states of buttons
- void CWindowDlg::UpdateButtons()
- {
- int nSel=m_wndList.GetSelCount();
- GetDlgItem(IDC_WINDOWLIST_CLOSE)->EnableWindow(nSel > 0);
- GetDlgItem(IDC_WINDOWLIST_SAVE)->EnableWindow(nSel > 0);
- GetDlgItem(IDC_WINDOWLIST_TILEHORZ)->EnableWindow(nSel >= 2);
- GetDlgItem(IDC_WINDOWLIST_TILEVERT)->EnableWindow(nSel >= 2);
- GetDlgItem(IDC_WINDOWLIST_CASCADE)->EnableWindow(nSel >= 2);
- GetDlgItem(IDC_WINDOWLIST_MINIMIZE)->EnableWindow(nSel > 0);
- GetDlgItem(IDC_WINDOWLIST_ACTIVATE)->EnableWindow(nSel == 1);
- }
- // Selects currently active window in listbox
- void CWindowDlg::SelActive()
- {
- int nItems = m_wndList.GetCount();
- if (nItems != LB_ERR && nItems > 0)
- {
-
- m_wndList.SetRedraw(FALSE);
- m_wndList.SelItemRange(FALSE, 0, nItems - 1);
-
- HWND hwndActive = reinterpret_cast<HWND>(::SendMessage(m_pMDIFrame->m_hWndMDIClient,
- WM_MDIGETACTIVE, 0, 0));
-
- for (int i = 0; i < nItems; i++)
- {
- if ((HWND) m_wndList.GetItemData(i) == hwndActive)
- {
- m_wndList.SetSel(i);
- break;
- }
- }
- m_wndList.SetRedraw(TRUE);
- }
- }
- // Saves selected documents
- void CWindowDlg::OnSave()
- {
- int nItems = m_wndList.GetCount();
- if (nItems != LB_ERR && nItems > 0)
- {
- for (int i = 0; i < nItems; i++)
- {
- if (m_wndList.GetSel(i) > 0)
- {
- HWND hWnd = reinterpret_cast<HWND>(m_wndList.GetItemData(i));
- CWnd* pWnd = CWnd::FromHandle(hWnd);
- CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CFrameWnd, pWnd);
- if (pFrame != NULL)
- {
- CDocument* pDoc = pFrame->GetActiveDocument();
- if (pDoc != NULL)
- pDoc->SaveModified();
- }
- }
- }
- }
- FillWindowList();
- SelActive();
- UpdateButtons();
- }
- void CWindowDlg::OnActivate()
- {
- if (m_wndList.GetSelCount() == 1)
- {
- int index;
- if (m_wndList.GetSelItems(1, &index) == 1)
- {
- DWORD dw = m_wndList.GetItemData(index);
- if (dw != LB_ERR)
- {
-
- WINDOWPLACEMENT wndpl;
- ::GetWindowPlacement(reinterpret_cast<HWND>(dw), &wndpl);
- if (wndpl.showCmd == SW_SHOWMINIMIZED)
- ::ShowWindow(reinterpret_cast<HWND>(dw), SW_RESTORE);
- ::SendMessage(m_pMDIFrame->m_hWndMDIClient, WM_MDIACTIVATE,
- static_cast<WPARAM>(dw), 0);
- EndDialog(IDOK);
- }
- }
- }
- }
- // Refresh windows list
- void CWindowDlg::FillWindowList(void)
- {
- m_wndList.SetRedraw(FALSE);
- m_wndList.ResetContent();
- HWND hwndT;
- hwndT = ::GetWindow(m_pMDIFrame->m_hWndMDIClient, GW_CHILD);
- while (hwndT != NULL)
- {
- TCHAR szWndTitle[_MAX_PATH];
- ::GetWindowText(hwndT, szWndTitle, sizeof(szWndTitle)/sizeof(szWndTitle[0]));
- int index=m_wndList.AddString(szWndTitle);
- m_wndList.SetItemData(index, reinterpret_cast<DWORD>(hwndT));
- hwndT = ::GetWindow(hwndT, GW_HWNDNEXT);
- }
- m_wndList.SetRedraw(TRUE);
- }
- // Draws listbox item
- void CWindowDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDIS)
- {
- if (nIDCtl == IDC_WINDOWLIST_LIST)
- {
- if (lpDIS->itemID == LB_ERR)
- return;
-
- HBRUSH brBackground;
- RECT rcTemp = lpDIS->rcItem;
- HDC hDC = lpDIS->hDC;
- COLORREF clText;
- if (lpDIS->itemState & ODS_SELECTED)
- {
- brBackground = GetSysColorBrush (COLOR_HIGHLIGHT);
- clText = GetSysColor(COLOR_HIGHLIGHTTEXT);
- }
- else
- {
- brBackground = GetSysColorBrush (COLOR_WINDOW);
- clText = GetSysColor(COLOR_WINDOWTEXT);
- }
- if (lpDIS->itemAction & (ODA_DRAWENTIRE | ODA_SELECT))
- FillRect(hDC, &rcTemp, brBackground);
-
- int OldBkMode = ::SetBkMode(hDC, TRANSPARENT);
- COLORREF clOldText = ::SetTextColor(hDC, clText);
- TCHAR szBuf[1024];
- ::SendMessage(lpDIS->hwndItem, LB_GETTEXT, static_cast<WPARAM>(lpDIS->itemID),
- reinterpret_cast<LPARAM>(szBuf));
-
- int h = rcTemp.bottom - rcTemp.top;
- rcTemp.left += h + 4;
- DrawText(hDC, szBuf, -1, &rcTemp, DT_LEFT | DT_VCENTER |
- DT_NOPREFIX | DT_SINGLELINE);
- HICON hIcon = reinterpret_cast<HICON>
- (::GetClassLong(reinterpret_cast<HWND>(lpDIS->itemData), GCL_HICONSM));
- /*AfxGetApp()->LoadStandardIcon(IDI_HAND);*/
- //(HICON) ::SendMessage((HWND) lpDIS->itemData,WM_GETICON,(WPARAM)ICON_BIG,(LPARAM) 0);
- rcTemp.left = lpDIS->rcItem.left;
- ::DrawIconEx(hDC, rcTemp.left + 2, rcTemp.top, hIcon, h, h, 0, 0, DI_NORMAL);
-
- ::SetTextColor(hDC, clOldText);
- ::SetBkMode(hDC, OldBkMode);
-
- if (lpDIS->itemAction & ODA_FOCUS)
- DrawFocusRect(hDC, &lpDIS->rcItem);
- return;
- }
- CDialog::OnDrawItem(nIDCtl, lpDIS);
- }
- void CWindowDlg::MDIMessage(UINT uMsg, WPARAM flag)
- {
- int nItems = m_wndList.GetCount();
- if (nItems != LB_ERR && nItems > 0)
- {
- HWND hMDIClient = m_pMDIFrame->m_hWndMDIClient;
- ::LockWindowUpdate(hMDIClient);
- for (int i = nItems - 1; i >= 0; i--)
- {
- HWND hWnd = reinterpret_cast<HWND>(m_wndList.GetItemData(i));
- if (m_wndList.GetSel(i) > 0)
- ::ShowWindow(hWnd, SW_RESTORE);
- else
- ::ShowWindow(hWnd, SW_MINIMIZE);
- }
- ::SendMessage(hMDIClient, uMsg, flag, 0);
- ::LockWindowUpdate(NULL);
- }
- }
- void CWindowDlg::OnTileHorz()
- {
- MDIMessage(WM_MDITILE, MDITILE_HORIZONTAL);
- }
- void CWindowDlg::OnTileVert()
- {
- 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_hMenuWindow = 0;
- m_strWindows.LoadString(IDS_WINDOW_MANAGE);
- m_pMDIFrame = NULL;
- m_crBkColor = GetSysColor(WHITE_BRUSH);
- m_bToolBarVisible = FALSE;
- m_bStatusBarVisible = FALSE;
- m_bMaxChild = FALSE;
- m_pwndFullScrnToolBar = NULL;
- m_bMaxChild = AfxGetApp()->GetProfileInt(_T("Settings"), _T("TVChildWinState"), m_bMaxChild);
- }
- 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_VIEW_VIEWTAB, OnTabView)
- ON_UPDATE_COMMAND_UI(ID_VIEW_VIEWTAB, OnUpdateTabView)
- ON_UPDATE_COMMAND_UI(ID_WINDOW_MANAGE, OnUpdateWindowManage)
- 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)
- {
- #if 0
- // 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);
- return lResult;
- #endif
- return 0;
- }
- LRESULT CMDIClient::OnRefreshMenu(WPARAM wParam, LPARAM lParam)
- {
- #if 0
- // 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;
- #endif
- return 0;
- }
- 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();
- }
- BOOL CMDIClient::OnEraseBkgnd(CDC* pDC)
- {
- CRect rect;
- GetClientRect(&rect);
-
- // Paint the background color
- if (m_crBkColor != 0)
- {
- CBrush NewBrush(m_crBkColor);
- pDC->SetBrushOrg(0, 0);
-
- CBrush* pOldBrush = static_cast<CBrush*>(pDC->SelectObject(&NewBrush));
- pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
- pDC->SelectObject(pOldBrush);
- NewBrush.DeleteObject();
- }
- CRect rcDataBox;
- //CString strLogo = MAKEINTRESOURCE( IDS_COMPANY_NAME );
- CString strLogo = "";
- CFont fontLogo;
- TEXTMETRIC tm;
-
- int fontSize = -MulDiv(18, pDC->GetDeviceCaps(LOGPIXELSY), 72);
-
- // Could be any TrueType font, but Times New Roman is most common
- fontLogo.CreateFont(fontSize, 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"));
-
- pDC->SetBkMode(OPAQUE);
-
- CFont* oldFont = pDC->SelectObject(&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(GetSysColor(COLOR_BTNFACE));
- 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);
- fontLogo.DeleteObject();
-
- ReleaseDC(pDC);
-
- 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)
- {
- // TODO: Add your message handler code here and/or call default
- // A simple demo...
- POINT ptScreen = point;
- // Convert the mouse point to screen coordinates since that is what is used by
- // the TrackPopupMenu() function.
- ClientToScreen(&ptScreen);
- // NOTE: This is an application menu, do not destroy it here!!!
- 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_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)
- {
- CMDIChildWnd* pChild =
- static_cast<CMDIChildWnd*>(FromHandle(reinterpret_cast<HWND>(wParam)));
- // 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(_T("Settings"), _T("TVChildWinState"), m_bMaxChild);
- }
- m_pViewManager->RemoveView(static_cast<CView*>(pChild->GetDlgItem(AFX_IDW_PANE_FIRST)));
- //return TRUE;
- 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);
- }
- BOOL CMDIClient::PreTranslateMessage(MSG* pMsg)
- {
- // When there is an escape key toggle the full screen mode
-
- return CWnd::PreTranslateMessage(pMsg);
- }
|