// myMailServerDlg.cpp : implementation file // #include "stdafx.h" #include "myMailServer.h" #include "myMailServerDlg.h" #include "MyReceiveDlg.h" #include "MySendDlg.h" #include "MySetDlg.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() ///////////////////////////////////////////////////////////////////////////// // CMyMailServerDlg dialog CMyMailServerDlg::CMyMailServerDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyMailServerDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMyMailServerDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_mailServer = "pop.163.com"; m_mailUsr = "uutkuu@163.com"; m_mailPsd = "123456"; m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMyMailServerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyMailServerDlg) DDX_Control(pDX, IDC_INFO, m_bnInfo); DDX_Control(pDX, IDC_TITLE, m_bnTitle); DDX_Control(pDX, IDC_SET, m_bnSet); DDX_Control(pDX, IDC_SEND, m_bnSend); DDX_Control(pDX, IDC_RECEIVE, m_bnReceive); DDX_Control(pDX, IDC_EXIT, m_bnExit); DDX_Control(pDX, IDC_MAX, m_bnMax); DDX_Control(pDX, IDC_MIN, m_bnMin); DDX_Control(pDX, IDC_QUIT, m_bnQuit); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMyMailServerDlg, CDialog) //{{AFX_MSG_MAP(CMyMailServerDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_QUIT, OnQuit) ON_WM_CTLCOLOR() ON_BN_CLICKED(IDC_MIN, OnMin) ON_WM_LBUTTONDOWN() ON_BN_CLICKED(IDC_RECEIVE, OnReceive) ON_BN_CLICKED(IDC_EXIT, OnExit) ON_BN_CLICKED(IDC_SEND, OnSend) ON_BN_CLICKED(IDC_SET, OnSet) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyMailServerDlg message handlers BOOL CMyMailServerDlg::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 SetWindowText("Mail Server"); // TODO: Add extra initialization here m_bmBack.DeleteObject(); m_brBack.DeleteObject(); m_bmBack.LoadBitmap(IDB_MBACK1); //导入背景图片 m_brBack.CreatePatternBrush(&m_bmBack); //保存窗体背景图片,供OnCtlColor()调用 //SetDialogFace(); //设置对话框图片 CString strFontName = _T("隶书"); //设置IDC_BUTTON_EXIT按钮图片 m_bnQuit.SetBitmaps(IDB_QUIT_N, IDB_QUIT_C, IDB_QUIT_H); m_bnMin.SetBitmaps(IDB_MIN_N, IDB_MIN_C, IDB_MIN_H); m_bnMax.SetBitmaps(IDB_MAX_D,NULL,NULL,IDB_MAX_D); ////////////////////////////////////////////////////////////////////////// //set bitmap m_bnReceive.SetBitmaps(IDB_BLUE_N, NULL, IDB_BLUE_H); //位图 m_bnReceive.SetForceColor(RGB(255, 255, 0), RGB(255, 255, 255), RGB(255, 255, 255)); //文字颜色 m_bnReceive.SetSound(MAKEINTRESOURCE(IDR_WAVEMOVE), ::GetModuleHandle(NULL)); //动态 m_bnReceive.SetSound(MAKEINTRESOURCE(IDR_WAVECLICK), ::GetModuleHandle(NULL), TRUE); //按下声音 // m_bnReceive.SetFocusRectDeflateRect(12,12, FALSE); //焦点框与按钮边界距离 // m_bnReceive.SetDrawFocusRect(TRUE, FALSE); //画焦点(默认不画) m_bnReceive.SizeToContent(); //按钮自动适应第一个图片大小 m_bnReceive.SetWindowText(TEXT("收件箱")); //改变按钮显示文字 m_bnReceive.SetBtnCursor(IDC_CURSOR_HAND, FALSE); //按钮鼠标类型 // m_bnReceive.SetTextAlign(NL_ALIGN_CENTER, FALSE); //设置文字排列方式 //set font m_bnReceive .SetDrawText(TRUE, FALSE) //是否显示按钮文字 .SetFont3D(TRUE, 3, 2, FALSE) //显示文字3d效果 .SetText3DBKColor(RGB(95, 95, 95)) //3d阴影颜色 .SetFontBold(TRUE, FALSE) //粗体 .SetFontSize(18, FALSE) //字体大小 .SetFontName(strFontName) //字体名称 ; ////////////////////////////////////////////////////////////////////////// //set bitmap m_bnSend.SetBitmaps(IDB_BLUE_N, NULL, IDB_BLUE_H); //位图 m_bnSend.SetForceColor(RGB(255, 255, 0), RGB(255, 255, 255), RGB(255, 255, 255)); //文字颜色 m_bnSend.SetSound(MAKEINTRESOURCE(IDR_WAVEMOVE), ::GetModuleHandle(NULL)); //动态 m_bnSend.SetSound(MAKEINTRESOURCE(IDR_WAVECLICK), ::GetModuleHandle(NULL), TRUE); //按下声音 m_bnSend.SizeToContent(); //按钮自动适应第一个图片大小 m_bnSend.SetWindowText(TEXT("写邮件")); //改变按钮显示文字 m_bnSend.SetBtnCursor(IDC_CURSOR_HAND, FALSE); //按钮鼠标类型 // m_bnSend.SetTextAlign(NL_ALIGN_RIGHT, FALSE); //设置文字排列方式 //set font m_bnSend .SetDrawText(TRUE, FALSE) //是否显示按钮文字 .SetFont3D(TRUE, 3, 2, FALSE) //显示文字3d效果 .SetText3DBKColor(RGB(95, 95, 95)) //3d阴影颜色 .SetFontBold(TRUE, FALSE) //粗体 .SetFontSize(18, FALSE) //字体大小 .SetFontName(strFontName) //字体名称 ; ////////////////////////////////////////////////////////////////////////// //set bitmap m_bnSet.SetBitmaps(IDB_SET_N, IDB_SET_N, IDB_SET_H, IDB_SET_N); //位图 m_bnSet.SetForceColor(RGB(255, 255, 0), RGB(255, 255, 255), RGB(255, 255, 255), FALSE); //文字颜色 m_bnSet.SetSound(MAKEINTRESOURCE(IDR_WAVEMOVE), ::GetModuleHandle(NULL)); //动态 m_bnSet.SetSound(MAKEINTRESOURCE(IDR_WAVECLICK), ::GetModuleHandle(NULL), TRUE); //按下声音 m_bnSet.SizeToContent(); //按钮自动适应第一个图片大小 m_bnSet.SetBtnCursor(IDC_CURSOR_HAND, FALSE); //按钮鼠标类型 m_bnSet.SetWindowText(TEXT("设置")); //改变按钮显示文字 m_bnSet.SetTextAlign(NL_ALIGN_RIGHT, FALSE); //设置文字排列方式 //set font m_bnSet .SetDrawText(TRUE, FALSE) //是否显示按钮文字 .SetFont3D(TRUE, 3, 2, FALSE) //显示文字3d效果 .SetText3DBKColor(RGB(95, 95, 95), FALSE) //3d阴影颜色 .SetFontSize(12, FALSE) //字体大小 .SetFontName(strFontName) //字体名称 ; ////////////////////////////////////////////////////////////////////////// //set bitmap m_bnExit.SetBitmaps(IDB_EXIT_N, IDB_EXIT_N, IDB_EXIT_H, IDB_EXIT_N); //位图 m_bnExit.SetForceColor(RGB(255, 255, 0), RGB(255, 255, 255), RGB(255, 255, 255), FALSE); //文字颜色 m_bnExit.SetSound(MAKEINTRESOURCE(IDR_WAVEMOVE), ::GetModuleHandle(NULL)); //动态 m_bnExit.SetSound(MAKEINTRESOURCE(IDR_WAVECLICK), ::GetModuleHandle(NULL), TRUE); //按下声音 m_bnExit.SizeToContent(); //按钮自动适应第一个图片大小 m_bnExit.SetBtnCursor(IDC_CURSOR_HAND, FALSE); //按钮鼠标类型 m_bnExit.SetWindowText(TEXT("退出")); //改变按钮显示文字 m_bnExit.SetTextAlign(NL_ALIGN_LEFT, FALSE); //设置文字排列方式 //set font m_bnExit .SetDrawText(TRUE, FALSE) //是否显示按钮文字 .SetFont3D(TRUE, 3, 2, FALSE) //显示文字3d效果 .SetText3DBKColor(RGB(95, 95, 95), FALSE) //3d阴影颜色 .SetFontSize(12, FALSE) //字体大小 .SetFontName(strFontName) //字体名称 ; //----------------------其实不用象下面这么麻烦,CLabel类就很好用------------------------------- ////////////////////////////////////////////////////////////////////////// m_bnTitle.SetForceColor(RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255), FALSE); //文字颜色 m_bnExit.SetTextAlign(NL_ALIGN_LEFT, FALSE); //设置文字排列方式 m_bnTitle .SetDrawText(TRUE, FALSE) //是否显示按钮文字 .SetDrawTextAsDisable(FALSE, FALSE) //按定义色彩画失效文字 .SetFontBold(TRUE, FALSE) //粗体 .SetFont3D(TRUE, 2, 1, FALSE) //显示文字3d效果 .SetText3DBKColor(RGB(95, 95, 95), FALSE) //3d阴影颜色 .SetFontSize(16 , FALSE) //字体大小 .SetFontName(strFontName) //字体名称 ; ////////////////////////////////////////////////////////////////////////// // set btnInfo m_bnInfo.SetForceColor(RGB(0, 138, 260), RGB(0, 138, 260), RGB(0, 138, 260), FALSE); //文字颜色 m_bnInfo.SetTextAlign(NL_ALIGN_LEFT, FALSE); //设置文字排列方式 m_bnInfo .SetDrawText(TRUE, FALSE) //是否显示按钮文字 .SetDrawTextAsDisable(FALSE) //按定义色彩画失效文字 ; return TRUE; // return TRUE unless you set the focus to a control } void CMyMailServerDlg::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 CMyMailServerDlg::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 CMyMailServerDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMyMailServerDlg::OnQuit() { // TODO: Add your control notification handler code here OnOK(); } HBRUSH CMyMailServerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if(nCtlColor == CTLCOLOR_DLG ) { pDC->SetBkMode(TRANSPARENT); return m_brBack; } // TODO: Return a different brush if the default is not desired return hbr; } void CMyMailServerDlg::OnMin() { // TODO: Add your control notification handler code here ShowWindow(SW_MINIMIZE); } void CMyMailServerDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (point.y < 26) PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y)); CDialog::OnLButtonDown(nFlags, point); } void CMyMailServerDlg::OnReceive() { // TODO: Add your control notification handler code here OnOK(); CMyReceiveDlg dlg(m_mailServer,m_mailUsr,m_mailPsd); // dlg.m_strPsd = m_mailPsd; // dlg.m_strServer = m_mailServer; // dlg.m_strUser = m_mailUsr; dlg.DoModal(); } void CMyMailServerDlg::OnExit() { // TODO: Add your control notification handler code here OnOK(); } void CMyMailServerDlg::OnSend() { // TODO: Add your control notification handler code here OnOK(); CMySendDlg dlg; dlg.m_strSender = m_mailUsr; dlg.DoModal(); } void CMyMailServerDlg::OnSet() { // TODO: Add your control notification handler code here // OnOK(); CMySetDlg dlg; dlg.m_Server = m_mailServer; dlg.m_Psd = m_mailPsd; dlg.m_Usr = m_mailUsr; if(dlg.DoModal() == IDOK) { m_mailServer = dlg.m_Server; m_mailPsd = dlg.m_Psd; m_mailUsr = dlg.m_Usr; } }