www.gusucode.com > VC++动画窗口以及位图上下文菜单源代码源码程序 > VC++动画窗口以及位图上下文菜单源代码源码程序\code\job.cpp
// job.cpp : Defines the class behaviors for the application. // Download by http://www.NewXing.com #include "stdafx.h" #include "job.h" #include "MainFrm.h" #include "jobDoc.h" #include "jobView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CJobApp BEGIN_MESSAGE_MAP(CJobApp, CWinApp) //{{AFX_MSG_MAP(CJobApp) ON_COMMAND(ID_APP_ABOUT, OnAppAbout) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP // Standard file based document commands ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) // Standard print setup command ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CJobApp construction CJobApp::CJobApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance } ///////////////////////////////////////////////////////////////////////////// // The one and only CJobApp object CJobApp theApp; ///////////////////////////////////////////////////////////////////////////// // CJobApp initialization BOOL CJobApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate; pDocTemplate = new CSingleDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CJobDoc), RUNTIME_CLASS(CMainFrame), // main SDI frame window RUNTIME_CLASS(CJobView)); AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The one and only window has been initialized, so show and update it. m_pMainWnd->ShowWindow(SW_SHOW); m_pMainWnd->UpdateWindow(); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // 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: CRgn m_rgnWnd; //{{AFX_MSG(CAboutDlg) afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnButton1(); afx_msg void OnButton2(); virtual BOOL OnInitDialog(); //}}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) ON_WM_SETCURSOR() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CJobApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CJobApp message handlers BOOL CAboutDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { // TODO: Add your message handler code here and/or call default CRect rcButton1,rcButton2,rcButton3; CPoint ptCursor; CWnd *pStatic1=GetDlgItem(IDC_BUTTON1); CWnd *pStatic2=GetDlgItem(IDC_BUTTON2); CWnd *pStatic3=GetDlgItem(IDOK); pStatic1->GetWindowRect (rcButton1); pStatic2->GetWindowRect (rcButton2); pStatic3->GetWindowRect (rcButton3); GetCursorPos(&ptCursor); if (rcButton1.PtInRect (ptCursor)|| rcButton2.PtInRect (ptCursor)||rcButton3.PtInRect(ptCursor)) { CWinApp *pApp=AfxGetApp(); HICON hIconBang=pApp->LoadCursor(IDC_CURSOR1); SetCursor(hIconBang); return TRUE; } else return CDialog::OnSetCursor(pWnd, nHitTest, message); } void CAboutDlg::OnButton1() { // TODO: Add your control notification handler code here char szMailAddress[80]; strcpy(szMailAddress,"mailto:chenzhen1745@sohu.com"); ShellExecute(NULL, "open", szMailAddress, NULL, NULL, SW_SHOWNORMAL); } void CAboutDlg::OnButton2() { // TODO: Add your control notification handler code here char szURL[80]; strcpy(szURL,"http://fei8.51.net"); ShellExecute(NULL, "open", szURL, NULL, NULL, SW_SHOWNORMAL); } BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here // TODO: Add extra initialization here // 设置窗口标题为“椭圆窗口”,虽然对话框没有标题条, // 但在任务条的按钮中仍需要标题 SetWindowText(_T("椭圆窗口")); // 取得屏幕宽、高 int cxScreen = ::GetSystemMetrics(SM_CXSCREEN); int cyScreen = ::GetSystemMetrics(SM_CYSCREEN); // 设置椭圆X、Y方向的半径 int nEllipseWidth = cxScreen/2; int nEllipseHeight = cyScreen/5; // 将窗口大小设为宽nEllipseWidth,高nEllipseHeight // 并移至左上角 MoveWindow(0, 0, nEllipseWidth, nEllipseHeight); // 创建椭圆区域m_rgnWnd m_rgnWnd.CreateEllipticRgn(0, 0, nEllipseWidth, nEllipseHeight); // 将m_rgnWnd设置为窗口区域 SetWindowRgn((HRGN)m_rgnWnd, TRUE); CenterWindow(); //使窗口运行时居于屏幕正中央 return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }