📄 pmsysdlg.cpp
字号:
// PMSysDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PMSys.h"
#include "PMSysDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CPMSysDlg dialog
CPMSysDlg::CPMSysDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPMSysDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPMSysDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPMSysDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPMSysDlg)
DDX_Control(pDX, IDCANCEL, m_cancel);
DDX_Control(pDX, IDC_BTN_SUBMIT, m_btn_submit);
DDX_Control(pDX, IDC_LOGIN_FRAME, m_login_frame);
DDX_Control(pDX, IDC_EDT_NAME, m_edt_name);
DDX_Control(pDX, IDC_EDT_PWD, m_edt_pwd);
DDX_Control(pDX, IDC_EDT_STATUS, m_edt_status);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPMSysDlg, CDialog)
//{{AFX_MSG_MAP(CPMSysDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_MI_INFOCOLLECT, OnMiInfocollect)
ON_BN_CLICKED(IDC_BTN_SUBMIT, OnBtnSubmit)
ON_MESSAGE(WM_USR_LOGIN,OnUsrLogin)
ON_NOTIFY(MCN_SELECT, IDC_MONTHCALENDAR1, OnSelectMonthcalendar1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPMSysDlg message handlers
BOOL CPMSysDlg::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);
}
}
//初始化,菜单失效
CMenu* pDialogMenu = GetMenu();
pDialogMenu->EnableMenuItem(ID_MI_INFOCOLLECT,MF_GRAYED);
pDialogMenu->EnableMenuItem(ID_MI_CALENDER,MF_GRAYED);
pDialogMenu->EnableMenuItem(ID_MI_NOTEBOOK,MF_GRAYED);
pDialogMenu->EnableMenuItem(ID_MI_ALARMCLOCK,MF_GRAYED);
pDialogMenu->EnableMenuItem(ID_MI_ADDRESSLIST,MF_GRAYED);
pDialogMenu->EnableMenuItem(ID_MI_PREFERENCE,MF_GRAYED);
// 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
// TODO: Add extra initialization here
//工具条的创建和显示
//主工具条
if (!m_tool_bar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_tool_bar.LoadToolBar(IDR_MAINBAR))
{
TRACE0("Failed to create toolbar\n");
return false; // fail to create
}
m_tool_bar.ShowWindow(SW_SHOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
//初始化,按钮失效
UINT iButtonID;
UINT iButtonStyle;
int iButtonImage;
m_tool_bar.GetButtonInfo(0, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = TBBS_DISABLED;
m_tool_bar.SetButtonInfo(0, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(1, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = TBBS_DISABLED;
m_tool_bar.SetButtonInfo(1, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(2, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = TBBS_DISABLED;
m_tool_bar.SetButtonInfo(2, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = TBBS_DISABLED;
m_tool_bar.SetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(4, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = TBBS_DISABLED;
m_tool_bar.SetButtonInfo(4, iButtonID, iButtonStyle,iButtonImage);
//资料收集工具条
if (!m_tool_bar_infocollet.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_tool_bar_infocollet.LoadToolBar(IDR_INFOCOLLECT))
{
TRACE0("Failed to create toolbar\n");
return false; // fail to create
}
m_tool_bar_infocollet.ShowWindow(SW_HIDE);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
//其他工具条
//主要界面的控制
m_edt_status.ShowWindow(SW_HIDE);
m_login_frame.ShowWindow(SW_SHOW);
m_edt_name.ShowWindow(SW_SHOW);
m_edt_pwd.ShowWindow(SW_SHOW);
m_btn_submit.ShowWindow(SW_SHOW);
m_cancel.ShowWindow(SW_SHOW);
// logined = false;
return TRUE; // return TRUE unless you set the focus to a control
}
void CPMSysDlg::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 CPMSysDlg::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 CPMSysDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPMSysDlg::OnMiInfocollect()
{
// TODO: Add your command handler code here
//这里改变工具条的显示
if(bToolShow!=1)
{
m_tool_bar.ShowWindow(SW_HIDE);
m_tool_bar_infocollet.ShowWindow(SW_SHOW);
bToolShow = 1;
}
else
{
m_tool_bar_infocollet.ShowWindow(SW_HIDE);
m_tool_bar.ShowWindow(SW_SHOW);
bToolShow = 0;
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
}
void CPMSysDlg::OnBtnSubmit()
{
// TODO: Add your control notification handler code here
CString input_name,input_pwd;
m_edt_name.GetWindowText(input_name);
m_edt_pwd.GetWindowText(input_pwd);
BOOL bLogin=FALSE;
if(!(input_name.IsEmpty() || input_pwd.IsEmpty()))
bLogin = cmd_op.UserLogin(input_name,input_pwd);
if(bLogin) {
//抛出消息,处理。
AfxMessageBox("登录成功");
this->PostMessage(WM_USR_LOGIN,0,0);
}
else
AfxMessageBox("登录失败");
}
void CPMSysDlg::OnUsrLogin(WPARAM wParam, LPARAM lParam)
{
CMenu* pDialogMenu = GetMenu();
pDialogMenu->EnableMenuItem(ID_MI_INFOCOLLECT,MF_ENABLED);
pDialogMenu->EnableMenuItem(ID_MI_CALENDER,MF_ENABLED);
pDialogMenu->EnableMenuItem(ID_MI_NOTEBOOK,MF_ENABLED);
pDialogMenu->EnableMenuItem(ID_MI_ALARMCLOCK,MF_ENABLED);
pDialogMenu->EnableMenuItem(ID_MI_ADDRESSLIST,MF_ENABLED);
pDialogMenu->EnableMenuItem(ID_MI_PREFERENCE,MF_ENABLED);
UINT iButtonID;
UINT iButtonStyle;
int iButtonImage;
m_tool_bar.GetButtonInfo(0, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = 0;
m_tool_bar.SetButtonInfo(0, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(1, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = 0;
m_tool_bar.SetButtonInfo(1, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(2, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = 0;
m_tool_bar.SetButtonInfo(2, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = 0;
m_tool_bar.SetButtonInfo(3, iButtonID, iButtonStyle,iButtonImage);
m_tool_bar.GetButtonInfo(4, iButtonID, iButtonStyle,iButtonImage);
iButtonStyle = 0;
m_tool_bar.SetButtonInfo(4, iButtonID, iButtonStyle,iButtonImage);
//主要界面的控制
m_edt_status.ShowWindow(SW_SHOW);
m_login_frame.ShowWindow(SW_HIDE);
m_edt_name.ShowWindow(SW_HIDE);
m_edt_pwd.ShowWindow(SW_HIDE);
m_btn_submit.ShowWindow(SW_HIDE);
m_cancel.ShowWindow(SW_HIDE);
// logined = true;
}
void CPMSysDlg::OnSelectMonthcalendar1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
// if(logined)
AfxMessageBox("您可以根据书中分析内容添加相应的功能");
// else
// AfxMessageBox("请先登录,测试用户名和密码均为Admin");
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -