// CDLG_Login.cpp: 实现文件 // #include "stdafx.h" #include "WeChats.h" #include "CDLG_Login.h" #include "afxdialogex.h" // CDLG_Login 对话框 IMPLEMENT_DYNAMIC(CDLG_Login, CDialogEx) CDLG_Login::CDLG_Login(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DLG_LOGIN, pParent) , m_strAccount(_T("admin")) , m_strPassword(_T("ly1234")) { } CDLG_Login::~CDLG_Login() { } void CDLG_Login::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Text(pDX, TX_ACCOUNT, m_strAccount); DDX_Text(pDX, TX_PASSWROD, m_strPassword); DDX_Control(pDX, ST_ACCOUNT, m_stAccount); DDX_Control(pDX, ST_PASSWORD, m_stPassWord); DDX_Control(pDX, IDCANCEL, m_btnCancel); DDX_Control(pDX, IDOK, m_btnLogin); } BEGIN_MESSAGE_MAP(CDLG_Login, CDialogEx) ON_WM_ERASEBKGND() ON_WM_PAINT() END_MESSAGE_MAP() // CDLG_Login 消息处理程序 BOOL CDLG_Login::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 InitAllCtrl(); AdjustControl(); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } BOOL CDLG_Login::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 return TRUE; return CDialogEx::OnEraseBkgnd(pDC); } BOOL CDLG_Login::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 // TODO: 在此添加专用代码和/或调用基类 if (pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_hWnd) { pMsg->message = WM_NCLBUTTONDOWN; pMsg->wParam = HTCAPTION; } return CDialogEx::PreTranslateMessage(pMsg); } void CDLG_Login::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CDialogEx::OnPaint() //调整控件位置//////////////////////////// ChangeWindowRgn(); AdjustControl(); CRect rcClient; GetClientRect(&rcClient); //内存画图////////////////////////// CDC MemDC; MemDC.CreateCompatibleDC(&dc); CBitmap btScreen; btScreen.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height()); MemDC.SelectObject(&btScreen); btScreen.DeleteObject(); //画背景; MemDC.Rectangle(rcClient); MemDC.FillSolidRect(rcClient, RGB(91, 195, 252));//draw the backGround if (m_DLGBackground.m_hObject != 0) m_DLGBackground.ExtendDraw(&MemDC, rcClient, 0, 0); //重画控件///////////////////////// ReDrawCrl(&MemDC); //画到显示器上//////////////////////////// dc.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &MemDC, 0, 0, SRCCOPY); MemDC.DeleteDC(); } void CDLG_Login::InitAllCtrl() { CString strSkinpath = _T("Skin\\"); // 加载对话框背景图片; if (PathFileExists(strSkinpath + _T("登录窗口.bmp"))) m_DLGBackground.LoadImage(strSkinpath + _T("登录窗口.bmp")); else m_DLGBackground.LoadImage(strSkinpath + _T("dlgbk.bmp")); // 加载按钮背景图片; m_btnCancel.ShowOwnerText(); m_btnLogin.ShowOwnerText(); m_btnCancel.LoadImage(strSkinpath + _T("btn.bmp")); m_btnLogin.LoadImage(strSkinpath + _T("btn.bmp")); #if 0 // 在线版客户端不需要设置端口号与服务器地址; m_btnLoginSet.LoadImage(strSkinpath + _T("loginset.bmp")); #endif // 设置静态文本背景透明; m_stStudioID.SetTransparent(TRUE); m_stAccount.SetTransparent(TRUE); m_stPassWord.SetTransparent(TRUE); } void CDLG_Login::ChangeWindowRgn() // 清除不规则窗体的其他边角; { CRect rc; GetClientRect(&rc); CEnBitmap bmpWorkpanel; if (m_DLGBackground.m_hObject != NULL) m_DLGBackground.ExtendDrawImage(bmpWorkpanel, rc, 0, 0); if (m_hrgn) DeleteObject(m_hrgn); m_hrgn = bmpWorkpanel.BitmapToRegion(RGB(255, 0, 255)); SetWindowRgn(m_hrgn, TRUE); bmpWorkpanel.DeleteObject(); } void CDLG_Login::AdjustControl() { CRect rc; GetClientRect(&rc); int cx = rc.Width(); int cy = rc.Height(); #if 0 // 在线版客户端不需要设置端口号与服务器地址; // 登录设置按钮; m_btnLoginSet.SetWindowPos(NULL, cx - m_btnLoginSet.Width() - 5, 0, 0, 0, SWP_NOSIZE); #endif // 最小化按钮; /*m_btnMin.SetWindowPos(NULL, cx - m_btnClose.Width() - m_btnMin.Width() - 5, 0, 0, 0, SWP_NOSIZE); */ } void CDLG_Login::ReDrawCrl(CDC* pMemDC) { CRect rcClient; GetClientRect(&rcClient); static bool firstGetClientRect = true; static int preClientHeight = rcClient.Height(); static int preClientWidth = rcClient.Width(); if (firstGetClientRect) { firstGetClientRect = false; } if (firstGetClientRect || preClientHeight != rcClient.Height() || preClientWidth != rcClient.Width()) { preClientHeight = rcClient.Height(); preClientWidth = rcClient.Width(); CEnBitmap *bmpPaint = NULL; CImage *image = NULL; CRect rcIcon; CPoint ptText; CString strText; CRect rect; GetClientRect(&rect); int cx = rect.Width(); int cy = rect.Height(); bmpPaint = m_btnLogin.GetPaintBmp(); rect = m_btnLogin.GetRectInParent(); if (bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*pMemDC, rect, RGB(255, 0, 255)); bmpPaint = m_btnCancel.GetPaintBmp(); rect = m_btnCancel.GetRectInParent(); if (bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*pMemDC, rect, RGB(255, 0, 255)); } }