MainFrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:8k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- // This file is a part of the XTREME TOOLKIT PRO MFC class library.
- // (c)1998-2008 Codejock Software, All Rights Reserved.
- //
- // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
- // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
- // CONSENT OF CODEJOCK SOFTWARE.
- //
- // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
- // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
- // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
- // SINGLE COMPUTER.
- //
- // CONTACT INFORMATION:
- // support@codejock.com
- // http://www.codejock.com
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "TrayIconDemo.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_COMMAND(ID_VIEW_THEME_OFFICEXP, OnViewThemeOfficeXP)
- ON_UPDATE_COMMAND_UI(ID_VIEW_THEME_OFFICEXP, OnUpdateViewThemeOfficeXP)
- ON_COMMAND(IDR_RESTORE, OnRestore)
- ON_COMMAND(ID_PROPERTIES, OnProperties)
- ON_COMMAND(ID_APP_EXIT, OnAppExit)
- //}}AFX_MSG_MAP
- ON_WM_CLOSE()
- ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
- ON_MESSAGE(TIN_XT_TRAYICON, OnTrayIconNotify)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- static UINT icoArray[] =
- {
- IDI_ICON2,
- IDI_ICON3,
- IDI_ICON4,
- IDI_ICON5
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // initialize themes.
- m_iTheme = m_regMgr.GetProfileInt(
- _T("Settings"), _T("Theme"), xtThemeOfficeXP);
- }
- CMainFrame::~CMainFrame()
- {
- m_regMgr.WriteProfileInt(
- _T("Settings"), _T("Theme"), m_iTheme);
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- if (!InitCommandBars())
- return -1;
- CXTPCommandBars* pCommandBars = GetCommandBars();
- pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
- CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
- if (!pCommandBar ||
- !pCommandBar->LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1;
- }
- ((CXTPControlButton*)pCommandBar->GetControls()->GetAt(8))->SetStyle(xtpButtonIconAndCaption);
- // Load the previous state for command bars.
- LoadCommandBars(_T("CommandBars"));
- SetTheme(m_iTheme);
- // Create the tray icon.
- if (!m_TrayIcon.Create(
- _T("Power Tools for MFC!"), // Toolktip text
- this, // Parent window
- IDI_TRAYICON, // Icon resource ID
- IDR_POPUP_TRAY, // Resource ID of popup menu
- IDR_RESTORE, // Default menu item for popup menu
- false)) // True if default menu item is located by position
- {
- TRACE0("Failed to create tray iconn");
- return -1;
- }
- m_TrayIcon.SetAnimationIcons(
- icoArray, _countof(icoArray));
- // Display the properties dialog.
- ::PostMessage(m_hWnd, WM_COMMAND, ID_PROPERTIES, 0);
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- cs.lpszClass = _T("XTPMainFrame");
- CXTPDrawHelpers::RegisterWndClass(AfxGetInstanceHandle(), cs.lpszClass,
- CS_DBLCLKS, AfxGetApp()->LoadIcon(IDR_MAINFRAME));
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- void CMainFrame::OnRestore()
- {
- m_propDlg.MinMaxWindow();
- }
- void CMainFrame::SetTheme(int iTheme)
- {
- m_iTheme = iTheme;
- XTThemeManager()->SetTheme((XTThemeStyle)m_iTheme);
- XTPPaintManager()->SetTheme((XTPPaintTheme)m_iTheme);
- RedrawWindow( NULL, NULL,
- RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ALLCHILDREN );
- RecalcLayout();
- }
- void CMainFrame::OnViewThemeOfficeXP()
- {
- SetTheme((m_iTheme == xtThemeOfficeXP)? xtThemeDefault: xtThemeOfficeXP);
- }
- void CMainFrame::OnUpdateViewThemeOfficeXP(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_iTheme == xtThemeOfficeXP);
- }
- LRESULT CMainFrame::OnTrayIconNotify(WPARAM /*wParam*/, LPARAM lParam)
- {
- //UINT uID = (UINT)wParam; // resource ID of the tray icon.
- UINT uMouseMsg = (UINT)lParam; // mouse message that was sent.
- // We can let the tray icon control handle our context menu and
- // mouse double click events, but we want handle our balloon tip
- // notifications, so we will return 1 to let the tray icon control
- // know that we have handled these messages already...
- switch( uMouseMsg )
- {
- // Sent when the balloon is shown (balloons are queued).
- case NIN_BALLOONSHOW:
- {
- }
- return 1;
- // Sent when the balloon disappears-for example, when the
- // icon is deleted. This message is not sent if the balloon
- // is dismissed because of a timeout or a mouse click.
- case NIN_BALLOONHIDE:
- {
- }
- return 1;
- // Sent when the balloon is dismissed because of a timeout.
- case NIN_BALLOONTIMEOUT:
- {
- }
- return 1;
- // Sent when the balloon is dismissed because of a mouse click.
- case NIN_BALLOONUSERCLICK:
- {
- CXTHyperLink hyperlink;
- hyperlink.GotoURL(_T("http://www.codejock.com/"));
- }
- return 1;
- case WM_RBUTTONUP:
- {
- CMenu menu;
- if (!menu.LoadMenu(IDR_POPUP_TRAY)) {
- return 0;
- }
- CMenu* pSubMenu = menu.GetSubMenu(0);
- if (pSubMenu == NULL) {
- return 0;
- }
- ::SetMenuDefaultItem(pSubMenu->m_hMenu, IDR_RESTORE, FALSE);
- // Display the menu at the current mouse location. There's a "bug"
- // (Microsoft calls it a feature) in Windows 95 that requires calling
- // SetForegroundWindow. To find out more, search for Q135788 in MSDN.
- //
- CPoint pos;
- GetCursorPos(&pos);
- ::SetForegroundWindow(m_hWnd);
- CXTPCommandBars::TrackPopupMenu(pSubMenu, 0, pos.x, pos.y,this);
- ::PostMessage(m_hWnd, WM_NULL, 0, 0);
- menu.DestroyMenu();
- }
- return 1;
- }
- return 0;
- }
- void CMainFrame::OnProperties()
- {
- // Display the properties dialog.
- m_propDlg.DoModal(this);
- }
- void CMainFrame::OnAppExit()
- {
- // if the properties dialog is open, close it...
- if (::IsWindow(m_propDlg.m_hWnd)) {
- ::SendMessage(m_propDlg.m_hWnd, WM_COMMAND, IDOK, 0);
- }
- // post a message to ourself to close
- ::PostMessage(m_hWnd, WM_CLOSE, 0, 0);
- }
- void CMainFrame::OnClose()
- {
- // Save the current state for command bars.
- SaveCommandBars(_T("CommandBars"));
- CFrameWnd::OnClose();
- }
- void CMainFrame::OnCustomize()
- {
- // get a pointer to the command bars object.
- CXTPCommandBars* pCommandBars = GetCommandBars();
- if (pCommandBars == NULL)
- return;
- // instanciate the customize dialog
- CXTPCustomizeSheet dlg(pCommandBars);
- // add the options page to the customize dialog.
- CXTPCustomizeOptionsPage pageOptions(&dlg);
- dlg.AddPage(&pageOptions);
- // add the commands page to the customize dialog.
- CXTPCustomizeCommandsPage* pPageCommands = dlg.GetCommandsPage();
- pPageCommands->AddCategories(IDR_MAINFRAME);
- // initialize the commands page page.
- pPageCommands->InsertAllCommandsCategory();
- pPageCommands->InsertBuiltInMenus(IDR_MAINFRAME);
- pPageCommands->InsertNewMenuCategory();
- // display the customize dialog.
- dlg.DoModal();
- }