xDialogDlg.cpp
上传用户:louyoung
上传日期:2007-01-02
资源大小:123k
文件大小:7k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // xDialogDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "xDialog.h"
- #include "xDialogDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXDialogDlg dialog
- CXDialogDlg::CXDialogDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CXDialogDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CXDialogDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CXDialogDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CXDialogDlg)
- DDX_Control(pDX, IDC_LIST_TEAMS, m_treeTeams);
- DDX_Control(pDX, IDC_TREE_EXPLORER, m_treeExplorer);
- DDX_Control(pDX, IDC_LIST_EVENTS, m_lbEvents);
- DDX_Control(pDX, IDC_TREE_WINDOWS, m_treeWindows);
- DDX_Control(pDX, IDC_XFLOORWNDCTRL, m_fw);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CXDialogDlg, CDialog)
- //{{AFX_MSG_MAP(CXDialogDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE_EXPLORER, OnItemexpandingTreeExplorer)
- ON_NOTIFY(NM_RCLICK, IDC_TREE_EXPLORER, OnRclickTreeExplorer)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXDialogDlg message handlers
- BOOL CXDialogDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- m_treeExplorer.PopulateTree();
- m_treeExplorer.EnableImages();
- m_treeWindows.Enum();
- InitTeams();
- // Atach window to XFloorWnd;
- LPARAM lParam = NULL;
- int i = 0;
- while ((lParam = m_fw.GetUserData(i)) > 0)
- m_fw.AttachWindow(i++, (long)GetDlgItem(lParam));
- m_fw.Init();
- m_fw.ActivatePage(0);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CXDialogDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CXDialogDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CXDialogDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- BEGIN_EVENTSINK_MAP(CXDialogDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CXDialogDlg)
- ON_EVENT(CXDialogDlg, IDC_XFLOORWNDCTRL, 1 /* ActivatePage */, OnActivatePageXfloorwndctrl, VTS_I2)
- ON_EVENT(CXDialogDlg, IDC_XFLOORWNDCTRL, -600 /* Click */, OnClickXfloorwndctrl, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CXDialogDlg::OnActivatePageXfloorwndctrl(short nIndex)
- {
- CString item;
- item.Format(_T("ActivatePage: %i, [%s]"), nIndex, m_fw.GetPageName(nIndex));
- m_lbEvents.InsertString(0, item);
- }
- void CXDialogDlg::OnClickXfloorwndctrl()
- {
- CString item;
- item.Format(_T("Click"));
- m_lbEvents.InsertString(0, item);
- }
- void CXDialogDlg::OnItemexpandingTreeExplorer(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- m_treeExplorer.FolderExpanding(pNMHDR, pResult);
- *pResult = 0;
- }
- void CXDialogDlg::OnRclickTreeExplorer(NMHDR* pNMHDR, LRESULT* pResult)
- {
- m_treeExplorer.FolderPopup(pNMHDR, pResult);
- *pResult = 0;
- }
- void CXDialogDlg::InitTeams()
- {
- m_treeTeams.InsertColumn(0, _T("Team"), LVCFMT_LEFT,192);
- m_treeTeams.InsertColumn(1, _T("Favorites"),LVCFMT_CENTER,48);
- m_treeTeams.AttachBitmap(1, IDB_CHECK);
- CString teams, favourite;
- if (teams.LoadString(IDS_TEAMS))
- {
- for (char g = 'A'; g <= 'H'; g++)
- m_treeTeams.InsertItem(m_treeTeams.GetItemCount(), _T("Group ") + CString(g));
- CString team, name, group;
- int i = 0;
- for (UINT iBitmap = IDB_BITMAP1; iBitmap <= IDB_BITMAP32; iBitmap++)
- {
- AfxExtractSubString(team, teams, iBitmap - IDB_BITMAP1);
- AfxExtractSubString(name, team, 0, TCHAR(';'));
- AfxExtractSubString(group, team, 1, TCHAR(';'));
- AfxExtractSubString(favourite, team, 2, TCHAR(';'));
- int nItem = m_treeTeams.InsertItem(m_treeTeams.GetItemCount(),_T("0:") + name);
- m_treeTeams.SetItemParent(nItem, group[0]-'A');
- m_treeTeams.SetItemText(nItem, 1, favourite);
- m_treeTeams.SetItemData(nItem, nItem + 1);
- m_treeTeams.AttachBitmapCell(nItem, 0, iBitmap, 25, 19);
- if (!favourite.IsEmpty())
- m_treeTeams.SetBoldRow(nItem + 1);
- }
- m_treeTeams.ExpandHeader();
- }
- }