Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
4.2 KiB

  1. #include "precomp.hxx"
  2. #include "PropertyPage.h"
  3. void PropertyPage::FillPropSheetPage()
  4. {
  5. ZeroMemory(&psp, sizeof(psp));
  6. psp.dwSize = sizeof(psp);
  7. psp.dwFlags = PSP_USECALLBACK;
  8. psp.pszTemplate = MAKEINTRESOURCE(resID);
  9. psp.hInstance = hInstance;
  10. psp.lParam = (LPARAM) this;
  11. psp.pfnDlgProc = PropertyPageStaticDlgProc;
  12. psp.pfnCallback = PropertyPageStaticCallback;
  13. }
  14. HPROPSHEETPAGE PropertyPage::CreatePropertyPage()
  15. {
  16. HPROPSHEETPAGE hp;
  17. FillPropSheetPage();
  18. return ::CreatePropertySheetPage(&psp);
  19. }
  20. UINT CALLBACK PropertyPage::PropertyPageStaticCallback(HWND hwnd, UINT msg, LPPROPSHEETPAGE ppsp)
  21. {
  22. PropertyPage * pThis = (PropertyPage*) ppsp->lParam;
  23. switch (msg) {
  24. case PSPCB_CREATE:
  25. return pThis->CallbackCreate();
  26. case PSPCB_RELEASE:
  27. pThis->CallbackRelease();
  28. return FALSE; // return value ignored
  29. default:
  30. break;
  31. }
  32. return TRUE;
  33. }
  34. INT_PTR PropertyPage::PropertyPageStaticDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  35. {
  36. Dialog *pThis;
  37. pThis = (PropertyPage*) GetWindowLongPtr(hDlg, DWLP_USER);
  38. if (msg == WM_INITDIALOG) {
  39. pThis = (PropertyPage *) ((LPPROPSHEETPAGE)lParam)->lParam;
  40. SetWindowLongPtr(hDlg, DWLP_USER, (ULONG_PTR) pThis);
  41. return pThis->OnInitDialog(hDlg);
  42. }
  43. if (pThis) {
  44. return pThis->MainDlgProc(msg, wParam, lParam);
  45. }
  46. return FALSE;
  47. }
  48. INT_PTR PropertyPage::OnNotify(NMHDR * nmhdr)
  49. {
  50. INT_PTR res = Dialog::OnNotify(nmhdr);
  51. LPPSHNOTIFY lppsn = (LPPSHNOTIFY) nmhdr;
  52. switch (nmhdr->code) {
  53. case PSN_APPLY:
  54. OnApply(lppsn);
  55. return TRUE;
  56. case PSN_KILLACTIVE:
  57. OnKillActive(lppsn);
  58. return TRUE;
  59. case PSN_SETACTIVE:
  60. OnSetActive(lppsn);
  61. return TRUE;
  62. case PSN_HELP:
  63. OnHelp(lppsn);
  64. return TRUE;
  65. case PSN_RESET:
  66. OnReset(lppsn);
  67. return FALSE;
  68. case PSN_QUERYCANCEL:
  69. OnQueryCancel(lppsn);
  70. return TRUE;
  71. default:
  72. return FALSE;
  73. }
  74. }
  75. void PropertyPage::OnApply(LPPSHNOTIFY lppsn)
  76. {
  77. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  78. }
  79. void PropertyPage::OnSetActive(LPPSHNOTIFY lppsn)
  80. {
  81. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
  82. }
  83. void PropertyPage::OnKillActive(LPPSHNOTIFY lppsn)
  84. {
  85. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
  86. }
  87. void PropertyPage::OnQueryCancel(LPPSHNOTIFY lppsn)
  88. {
  89. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
  90. }
  91. void PropertyPage::SetModified(BOOL bChanged) {
  92. assert(::IsWindow(hDlg));
  93. assert(GetParent(hDlg) != NULL);
  94. UINT uMsg = bChanged ? PSM_CHANGED : PSM_UNCHANGED;
  95. ::SendMessage(GetParent(hDlg), uMsg, (WPARAM)hDlg, 0L);
  96. }
  97. //
  98. // SHBrowseForFolder callback
  99. //
  100. int
  101. CALLBACK
  102. BrowseCallback(
  103. HWND hwnd,
  104. UINT uMsg,
  105. LPARAM lParam,
  106. LPARAM lpData
  107. )
  108. {
  109. switch (uMsg)
  110. {
  111. case BFFM_INITIALIZED:
  112. // set the initial seclection to our default folder
  113. // (from the registry or SIDL_MYPICTURES).
  114. // the lpData points to the folder path.
  115. // It must contain a path.
  116. assert(lpData && _T('\0') != *((LPTSTR)lpData));
  117. SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
  118. break;
  119. case BFFM_VALIDATEFAILED:
  120. IdMessageBox(hwnd, IDS_ERROR_INVALID_FOLDER);
  121. return 1;
  122. default:
  123. break;
  124. }
  125. return 0;
  126. }
  127. extern HINSTANCE gHInst;
  128. int
  129. IdMessageBox(
  130. HWND hwnd,
  131. int MsgId,
  132. DWORD Options,
  133. int CaptionId
  134. )
  135. {
  136. TCHAR MsgText[MAX_PATH];
  137. TCHAR Caption[MAX_PATH];
  138. assert(MsgId);
  139. if (MsgId)
  140. LoadString(gHInst, MsgId, MsgText, sizeof(MsgText) / sizeof(TCHAR));
  141. else
  142. LoadString(gHInst, IDS_ERROR_UNKNOWN, MsgText, sizeof(MsgText) / sizeof(TCHAR));
  143. if (CaptionId)
  144. LoadString(gHInst, CaptionId, Caption, sizeof(Caption) / sizeof(TCHAR));
  145. else
  146. LoadString(gHInst, IDS_APPLETNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
  147. return MessageBox(hwnd, MsgText, Caption, Options);
  148. }