CDLG_Login.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // CDLG_Login.cpp: 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WeChats.h"
  5. #include "CDLG_Login.h"
  6. #include "afxdialogex.h"
  7. // CDLG_Login 对话框
  8. IMPLEMENT_DYNAMIC(CDLG_Login, CDialogEx)
  9. CDLG_Login::CDLG_Login(CWnd* pParent /*=nullptr*/)
  10. : CDialogEx(IDD_DLG_LOGIN, pParent)
  11. , m_strAccount(_T("admin"))
  12. , m_strPassword(_T("ly1234"))
  13. {
  14. }
  15. CDLG_Login::~CDLG_Login()
  16. {
  17. }
  18. void CDLG_Login::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialogEx::DoDataExchange(pDX);
  21. DDX_Text(pDX, TX_ACCOUNT, m_strAccount);
  22. DDX_Text(pDX, TX_PASSWROD, m_strPassword);
  23. DDX_Control(pDX, ST_ACCOUNT, m_stAccount);
  24. DDX_Control(pDX, ST_PASSWORD, m_stPassWord);
  25. DDX_Control(pDX, IDCANCEL, m_btnCancel);
  26. DDX_Control(pDX, IDOK, m_btnLogin);
  27. }
  28. BEGIN_MESSAGE_MAP(CDLG_Login, CDialogEx)
  29. ON_WM_ERASEBKGND()
  30. ON_WM_PAINT()
  31. END_MESSAGE_MAP()
  32. // CDLG_Login 消息处理程序
  33. BOOL CDLG_Login::OnInitDialog()
  34. {
  35. CDialogEx::OnInitDialog();
  36. // TODO: 在此添加额外的初始化
  37. InitAllCtrl();
  38. AdjustControl();
  39. return TRUE; // return TRUE unless you set the focus to a control
  40. // 异常: OCX 属性页应返回 FALSE
  41. }
  42. BOOL CDLG_Login::OnEraseBkgnd(CDC* pDC)
  43. {
  44. // TODO: 在此添加消息处理程序代码和/或调用默认值
  45. return TRUE;
  46. return CDialogEx::OnEraseBkgnd(pDC);
  47. }
  48. BOOL CDLG_Login::PreTranslateMessage(MSG* pMsg)
  49. {
  50. // TODO: 在此添加专用代码和/或调用基类
  51. // TODO: 在此添加专用代码和/或调用基类
  52. if (pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_hWnd)
  53. {
  54. pMsg->message = WM_NCLBUTTONDOWN;
  55. pMsg->wParam = HTCAPTION;
  56. }
  57. return CDialogEx::PreTranslateMessage(pMsg);
  58. }
  59. void CDLG_Login::OnPaint()
  60. {
  61. CPaintDC dc(this); // device context for painting
  62. // TODO: 在此处添加消息处理程序代码
  63. // 不为绘图消息调用 CDialogEx::OnPaint()
  64. //调整控件位置////////////////////////////
  65. ChangeWindowRgn();
  66. AdjustControl();
  67. CRect rcClient;
  68. GetClientRect(&rcClient);
  69. //内存画图//////////////////////////
  70. CDC MemDC;
  71. MemDC.CreateCompatibleDC(&dc);
  72. CBitmap btScreen;
  73. btScreen.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
  74. MemDC.SelectObject(&btScreen);
  75. btScreen.DeleteObject();
  76. //画背景;
  77. MemDC.Rectangle(rcClient);
  78. MemDC.FillSolidRect(rcClient, RGB(91, 195, 252));//draw the backGround
  79. if (m_DLGBackground.m_hObject != 0)
  80. m_DLGBackground.ExtendDraw(&MemDC, rcClient, 0, 0);
  81. //重画控件/////////////////////////
  82. ReDrawCrl(&MemDC);
  83. //画到显示器上////////////////////////////
  84. dc.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &MemDC, 0, 0, SRCCOPY);
  85. MemDC.DeleteDC();
  86. }
  87. void CDLG_Login::InitAllCtrl()
  88. {
  89. CString strSkinpath = _T("Skin\\");
  90. // 加载对话框背景图片;
  91. if (PathFileExists(strSkinpath + _T("登录窗口.bmp")))
  92. m_DLGBackground.LoadImage(strSkinpath + _T("登录窗口.bmp"));
  93. else
  94. m_DLGBackground.LoadImage(strSkinpath + _T("dlgbk.bmp"));
  95. // 加载按钮背景图片;
  96. m_btnCancel.ShowOwnerText();
  97. m_btnLogin.ShowOwnerText();
  98. m_btnCancel.LoadImage(strSkinpath + _T("btn.bmp"));
  99. m_btnLogin.LoadImage(strSkinpath + _T("btn.bmp"));
  100. #if 0 // 在线版客户端不需要设置端口号与服务器地址;
  101. m_btnLoginSet.LoadImage(strSkinpath + _T("loginset.bmp"));
  102. #endif
  103. // 设置静态文本背景透明;
  104. m_stStudioID.SetTransparent(TRUE);
  105. m_stAccount.SetTransparent(TRUE);
  106. m_stPassWord.SetTransparent(TRUE);
  107. }
  108. void CDLG_Login::ChangeWindowRgn() // 清除不规则窗体的其他边角;
  109. {
  110. CRect rc;
  111. GetClientRect(&rc);
  112. CEnBitmap bmpWorkpanel;
  113. if (m_DLGBackground.m_hObject != NULL)
  114. m_DLGBackground.ExtendDrawImage(bmpWorkpanel, rc, 0, 0);
  115. if (m_hrgn)
  116. DeleteObject(m_hrgn);
  117. m_hrgn = bmpWorkpanel.BitmapToRegion(RGB(255, 0, 255));
  118. SetWindowRgn(m_hrgn, TRUE);
  119. bmpWorkpanel.DeleteObject();
  120. }
  121. void CDLG_Login::AdjustControl()
  122. {
  123. CRect rc;
  124. GetClientRect(&rc);
  125. int cx = rc.Width();
  126. int cy = rc.Height();
  127. #if 0 // 在线版客户端不需要设置端口号与服务器地址;
  128. // 登录设置按钮;
  129. m_btnLoginSet.SetWindowPos(NULL, cx - m_btnLoginSet.Width() - 5, 0, 0, 0, SWP_NOSIZE);
  130. #endif
  131. // 最小化按钮;
  132. /*m_btnMin.SetWindowPos(NULL, cx - m_btnClose.Width() - m_btnMin.Width() - 5, 0, 0, 0, SWP_NOSIZE);
  133. */
  134. }
  135. void CDLG_Login::ReDrawCrl(CDC* pMemDC)
  136. {
  137. CRect rcClient;
  138. GetClientRect(&rcClient);
  139. static bool firstGetClientRect = true;
  140. static int preClientHeight = rcClient.Height();
  141. static int preClientWidth = rcClient.Width();
  142. if (firstGetClientRect)
  143. {
  144. firstGetClientRect = false;
  145. }
  146. if (firstGetClientRect || preClientHeight != rcClient.Height() || preClientWidth != rcClient.Width())
  147. {
  148. preClientHeight = rcClient.Height();
  149. preClientWidth = rcClient.Width();
  150. CEnBitmap *bmpPaint = NULL;
  151. CImage *image = NULL;
  152. CRect rcIcon;
  153. CPoint ptText;
  154. CString strText;
  155. CRect rect;
  156. GetClientRect(&rect);
  157. int cx = rect.Width();
  158. int cy = rect.Height();
  159. bmpPaint = m_btnLogin.GetPaintBmp();
  160. rect = m_btnLogin.GetRectInParent();
  161. if (bmpPaint->m_hObject != 0)
  162. bmpPaint->TransparentBlt(*pMemDC, rect, RGB(255, 0, 255));
  163. bmpPaint = m_btnCancel.GetPaintBmp();
  164. rect = m_btnCancel.GetRectInParent();
  165. if (bmpPaint->m_hObject != 0)
  166. bmpPaint->TransparentBlt(*pMemDC, rect, RGB(255, 0, 255));
  167. }
  168. }