1
0

pageInfo.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "./pageInfo.h"
  2. #include "./common.h"
  3. #include "./loginGui.h"
  4. #include "../resource.h"
  5. static HRESULT CALLBACK LoginPageInfo_CreateInstance(HWND hwnd, HWND hLoginbox, LoginPage **instance)
  6. {
  7. if (NULL == instance) return E_POINTER;
  8. if (NULL == hwnd || NULL == hLoginbox) return E_INVALIDARG;
  9. *instance = new LoginPageInfo(hwnd, hLoginbox);
  10. if (NULL == instance) return E_OUTOFMEMORY;
  11. return S_OK;
  12. }
  13. LoginPageInfo::LoginPageInfo(HWND hwnd, HWND hLoginbox)
  14. : LoginPage(hwnd, hLoginbox)
  15. {
  16. }
  17. LoginPageInfo::~LoginPageInfo()
  18. {
  19. }
  20. HWND LoginPageInfo::CreatePage(HWND hLoginbox, HWND hParent)
  21. {
  22. return LoginPage::CreatePage(hLoginbox, MAKEINTRESOURCE(IDD_PAGE_INFO),
  23. hParent, NULL, LoginPageInfo_CreateInstance);
  24. }
  25. void LoginPageInfo::UpdateLayout(BOOL fRedraw)
  26. {
  27. LoginPage::UpdateLayout(fRedraw);
  28. RECT pageRect;
  29. if (FALSE == GetPageRect(&pageRect))
  30. return;
  31. HWND hMessage = GetDlgItem(hwnd, IDC_MESSAGE);
  32. if (NULL == hMessage) return;
  33. INT cx, cy;
  34. cx = pageRect.right - pageRect.left;
  35. HDC hdc = GetDCEx(hMessage, NULL, DCX_CACHE | DCX_NORESETATTRS);
  36. if (NULL != hdc)
  37. {
  38. HFONT fontControl = (HFONT)SendMessage(hMessage, WM_GETFONT, 0, 0L);
  39. HFONT fontOrig = (HFONT)SelectObject(hdc, fontControl);
  40. INT maxWidth = LoginBox_GetAveStrWidth(hdc, 80);
  41. if (cx > maxWidth) cx = maxWidth;
  42. SelectObject(hdc, fontOrig);
  43. ReleaseDC(hMessage, hdc);
  44. }
  45. LoginBox_GetWindowTextSize(hMessage, cx, &cx, &cy);
  46. if(cy > (pageRect.bottom - pageRect.top))
  47. cy = pageRect.bottom - pageRect.top;
  48. RECT messageRect;
  49. GetWindowRect(hMessage, &messageRect);
  50. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&messageRect, 2);
  51. if (messageRect.left != pageRect.left ||
  52. messageRect.top != pageRect.top ||
  53. (messageRect.right - messageRect.left) != cx ||
  54. (messageRect.bottom - messageRect.top) != cy)
  55. {
  56. SetWindowPos(hMessage, NULL, pageRect.left, pageRect.top, cx, cy,
  57. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
  58. if (FALSE != fRedraw)
  59. {
  60. HRGN rgn1 = CreateRectRgnIndirect(&messageRect);
  61. HRGN rgn2 = CreateRectRgn(pageRect.left, pageRect.top, pageRect.left + cx, pageRect.top + cy);
  62. CombineRgn(rgn1, rgn1, rgn2, RGN_OR);
  63. RedrawWindow(hwnd, NULL, rgn1, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_ERASENOW | RDW_VALIDATE | RDW_ALLCHILDREN);
  64. DeleteObject(rgn1);
  65. DeleteObject(rgn2);
  66. }
  67. }
  68. }
  69. BOOL LoginPageInfo::OnInitDialog(HWND hFocus, LPARAM param)
  70. {
  71. HFONT fontText = NULL;
  72. LoginGuiObject *loginGui;
  73. if (SUCCEEDED(LoginGuiObject::QueryInstance(&loginGui)))
  74. {
  75. fontText = loginGui->GetTextFont();
  76. loginGui->Release();
  77. }
  78. if (NULL != fontText)
  79. {
  80. HWND hMessage = GetDlgItem(hwnd, IDC_MESSAGE);
  81. if (NULL != hMessage)
  82. SendMessage(hMessage, WM_SETFONT, (WPARAM)fontText, 0L);
  83. }
  84. LoginPage::OnInitDialog(hFocus, param);
  85. return FALSE;
  86. }
  87. void LoginPageInfo::OnSetMessage(LPCWSTR pszMessage)
  88. {
  89. HWND hMessage = GetDlgItem(hwnd, IDC_MESSAGE);
  90. if (NULL != hMessage)
  91. {
  92. SetWindowText(hMessage, pszMessage);
  93. INT showWindow = (NULL != pszMessage && L'\0' != *pszMessage) ? SW_SHOWNA : SW_HIDE;
  94. ShowWindow(hMessage, showWindow);
  95. }
  96. }
  97. INT_PTR LoginPageInfo::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  98. {
  99. switch(uMsg)
  100. {
  101. case NLPIM_SETMESSAGE: OnSetMessage((LPCWSTR)lParam); return TRUE;
  102. }
  103. return __super::DialogProc(uMsg, wParam, lParam);
  104. }