// SubwayDlg.cpp : implementation file // #include "stdafx.h" #include "CityLoop.h" #include "CityLoopDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CCityLoopDlg dialog CCityLoopDlg::CCityLoopDlg(CWnd* pParent /*=NULL*/) : CDialog(CCityLoopDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCityLoopDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CCityLoopDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_WM_WINDOWPOSCHANGED() END_MESSAGE_MAP() // CCityLoopDlg message handlers BOOL CCityLoopDlg::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_toolbox.Create(48,this); m_toolbox.Resize(); m_toolbox.ShowWindow(SW_SHOW); CStation* Parliament = new CStation(_T("Parliament"),1); CStation* Treasury = new CStation(_T("Treasury"),2); CStation* Flinders = new CStation(_T("Flinders"),3); CStation* Spencer = new CStation(_T("Spencer"),4); CStation* Lonsdale = new CStation(_T("Lonsdale"),5); CStation* Central = new CStation(_T("Central"),6); m_network.Add(Parliament); m_network.Add(Treasury); m_network.Add(Flinders); m_network.Add(Spencer); m_network.Add(Lonsdale); m_network.Add(Central); m_network.Add(new CTrain(&m_network,1,7,Treasury)); m_network.Add(new CTrain(&m_network,2,8,Spencer)); m_network.Add(new CTrain(&m_network,3,9,Central)); CRect pc; m_panel.Create(48, this); m_panel.GetWindowRect(pc); m_network.Create(48 + pc.Height(), this); m_network.Resize(); m_network.ShowWindow(SW_SHOW); m_panel.Resize(); m_panel.ShowWindow(SW_SHOW); return TRUE; // return TRUE unless you set the focus to a control } void CCityLoopDlg::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 CCityLoopDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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(); } } void CCityLoopDlg::Quit() { m_network.Terminate(); OnCancel(); } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CCityLoopDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CCityLoopDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos) { CDialog::OnWindowPosChanged(lpwndpos); m_network.Resize(); m_toolbox.Resize(); m_panel.Resize(); } void CCityLoopDlg::DoMsgs() { MSG msg = {0}; while(::PeekMessage( &msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, QS_ALLINPUT | PM_REMOVE)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } } LRESULT CCityLoopDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { static int count = 0; // TODO: Add your specialized code here and/or call the base class if(message == WM_SUBWAY) { if(++count > 20) { DoMsgs(); count = 0; } if(m_network.IsRunning()) m_panel.UpdateTimeTable(wParam); return 0; } return CDialog::WindowProc(message, wParam, lParam); }