1 // Windows/Control/PropertyPage.cpp 2 3 #include "StdAfx.h" 4 5 #ifndef _UNICODE 6 #include "../../Common/StringConvert.h" 7 #endif 8 9 #include "PropertyPage.h" 10 11 extern HINSTANCE g_hInstance; 12 #ifndef _UNICODE 13 extern bool g_IsNT; 14 #endif 15 16 namespace NWindows { 17 namespace NControl { 18 19 static INT_PTR APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) 20 { 21 CWindow tempDialog(dialogHWND); 22 if (message == WM_INITDIALOG) 23 tempDialog.SetUserDataLongPtr(((PROPSHEETPAGE *)lParam)->lParam); 24 CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr()); 25 if (dialog == NULL) 26 return FALSE; 27 if (message == WM_INITDIALOG) 28 dialog->Attach(dialogHWND); 29 try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); } 30 catch(...) { return TRUE; } 31 } 32 33 bool CPropertyPage::OnNotify(UINT /* controlID */, LPNMHDR lParam) 34 { 35 switch (lParam->code) 36 { 37 case PSN_APPLY: SetMsgResult(OnApply(LPPSHNOTIFY(lParam))); break; 38 case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive(LPPSHNOTIFY(lParam)))); break; 39 case PSN_SETACTIVE: SetMsgResult(OnSetActive(LPPSHNOTIFY(lParam))); break; 40 case PSN_RESET: OnReset(LPPSHNOTIFY(lParam)); break; 41 case PSN_HELP: OnNotifyHelp(LPPSHNOTIFY(lParam)); break; 42 default: return false; 43 } 44 return true; 45 } 46 47 INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title) 48 { 49 #ifndef _UNICODE 50 AStringVector titles; 51 #endif 52 #ifndef _UNICODE 53 CRecordVector<PROPSHEETPAGEA> pagesA; 54 #endif 55 CRecordVector<PROPSHEETPAGEW> pagesW; 56 57 unsigned i; 58 #ifndef _UNICODE 59 for (i = 0; i < pagesInfo.Size(); i++) 60 titles.Add(GetSystemString(pagesInfo[i].Title)); 61 #endif 62 63 for (i = 0; i < pagesInfo.Size(); i++) 64 { 65 const CPageInfo &pageInfo = pagesInfo[i]; 66 #ifndef _UNICODE 67 { 68 PROPSHEETPAGE page; 69 page.dwSize = sizeof(page); 70 page.dwFlags = PSP_HASHELP; 71 page.hInstance = g_hInstance; 72 page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID); 73 page.pszIcon = NULL; 74 page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; 75 76 if (titles[i].IsEmpty()) 77 page.pszTitle = NULL; 78 else 79 { 80 page.dwFlags |= PSP_USETITLE; 81 page.pszTitle = titles[i]; 82 } 83 page.lParam = (LPARAM)pageInfo.Page; 84 page.pfnCallback = NULL; 85 pagesA.Add(page); 86 } 87 #endif 88 { 89 PROPSHEETPAGEW page; 90 page.dwSize = sizeof(page); 91 page.dwFlags = PSP_HASHELP; 92 page.hInstance = g_hInstance; 93 page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID); 94 page.pszIcon = NULL; 95 page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; 96 97 if (pageInfo.Title.IsEmpty()) 98 page.pszTitle = NULL; 99 else 100 { 101 page.dwFlags |= PSP_USETITLE; 102 page.pszTitle = pageInfo.Title; 103 } 104 page.lParam = (LPARAM)pageInfo.Page; 105 page.pfnCallback = NULL; 106 pagesW.Add(page); 107 } 108 } 109 110 #ifndef _UNICODE 111 if (!g_IsNT) 112 { 113 PROPSHEETHEADER sheet; 114 sheet.dwSize = sizeof(sheet); 115 sheet.dwFlags = PSH_PROPSHEETPAGE; 116 sheet.hwndParent = hwndParent; 117 sheet.hInstance = g_hInstance; 118 AString titleA = GetSystemString(title); 119 sheet.pszCaption = titleA; 120 sheet.nPages = pagesInfo.Size(); 121 sheet.nStartPage = 0; 122 sheet.ppsp = &pagesA.Front(); 123 sheet.pfnCallback = NULL; 124 return ::PropertySheetA(&sheet); 125 } 126 else 127 #endif 128 { 129 PROPSHEETHEADERW sheet; 130 sheet.dwSize = sizeof(sheet); 131 sheet.dwFlags = PSH_PROPSHEETPAGE; 132 sheet.hwndParent = hwndParent; 133 sheet.hInstance = g_hInstance; 134 sheet.pszCaption = title; 135 sheet.nPages = pagesInfo.Size(); 136 sheet.nStartPage = 0; 137 sheet.ppsp = &pagesW.Front(); 138 sheet.pfnCallback = NULL; 139 return ::PropertySheetW(&sheet); 140 } 141 } 142 143 }} 144