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.

352 lines
9.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: sampcpl.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #define INITGUID
  11. #include "Sampcpl.h"
  12. #include <prsht.h>
  13. #include "resource.h"
  14. BOOL WINAPI IsPlatformNT();
  15. /*****************************************************************************
  16. *
  17. * Globals
  18. *
  19. *****************************************************************************/
  20. // Reference counter for the whole library
  21. DWORD g_cRef;
  22. // DLL module instance
  23. HINSTANCE g_hInst;
  24. // Can we use UNICODE APIs
  25. BOOL g_NoUnicodePlatform = TRUE;
  26. // Is COM initialized
  27. BOOL g_COMInitialized = FALSE;
  28. //
  29. PSTI g_pSti = NULL;
  30. /*****************************************************************************
  31. *
  32. * Code
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36. *
  37. * @doc INTERNAL
  38. *
  39. * @func BOOL | DllEntryPoint |
  40. *
  41. * Called to notify the DLL about various things that can happen.
  42. *
  43. * We are not interested in thread attaches and detaches,
  44. * so we disable thread notifications for performance reasons.
  45. *
  46. * @parm HINSTANCE | hinst |
  47. *
  48. * The instance handle of this DLL.
  49. *
  50. * @parm DWORD | dwReason |
  51. *
  52. * Notification code.
  53. *
  54. * @parm LPVOID | lpReserved |
  55. *
  56. * Not used.
  57. *
  58. * @returns
  59. *
  60. * Returns <c TRUE> to allow the DLL to load.
  61. *
  62. *****************************************************************************/
  63. extern "C"
  64. DLLEXPORT
  65. BOOL APIENTRY
  66. DllEntryPoint(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  67. {
  68. switch (dwReason) {
  69. case DLL_PROCESS_ATTACH:
  70. g_hInst = hinst;
  71. ::DisableThreadLibraryCalls(hinst);
  72. // Set global flags
  73. g_NoUnicodePlatform = !IsPlatformNT();
  74. break;
  75. case DLL_PROCESS_DETACH:
  76. if (g_cRef) {
  77. }
  78. break;
  79. }
  80. return 1;
  81. }
  82. extern "C"
  83. DLLEXPORT
  84. BOOL WINAPI
  85. DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  86. {
  87. return DllEntryPoint(hinst, dwReason, lpReserved);
  88. }
  89. INT_PTR
  90. CALLBACK
  91. USDSampPropDialog(
  92. HWND hwnd,
  93. UINT uMessage,
  94. WPARAM wp,
  95. LPARAM lp
  96. )
  97. {
  98. PSTI_DEVICE_INFORMATION psdi;
  99. HRESULT hres;
  100. switch (uMessage)
  101. {
  102. case WM_INITDIALOG:
  103. // On WM_INITDIALOG, the LPARAM points at the PROPSHEETPAGE that created
  104. // us. We walk down to the lParam member to find the pointer to this
  105. // STI device.
  106. TCHAR szPath[MAX_PATH];
  107. // Request STI interface pointer
  108. g_pSti = NULL;
  109. hres = ::StiCreateInstance(::GetModuleHandle(NULL),
  110. STI_VERSION,
  111. &g_pSti,
  112. NULL);
  113. psdi = (PSTI_DEVICE_INFORMATION) ((LPPROPSHEETPAGE) lp) -> lParam;
  114. SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) psdi);
  115. *szPath = TEXT('\0');
  116. #ifndef UNICODE
  117. WideCharToMultiByte(CP_ACP, 0,
  118. psdi->pszPortName,-1,
  119. szPath,sizeof(szPath),
  120. NULL,NULL);
  121. #else
  122. lstrcpy(szPath,psdi->pszPortName);
  123. #endif
  124. Edit_SetText(GetDlgItem(hwnd,IDC_EDIT_PATH),szPath);
  125. Edit_LimitText(GetDlgItem(hwnd,IDC_EDIT_PATH), MAX_PATH);
  126. return TRUE;
  127. case WM_COMMAND:
  128. {
  129. if (GET_WM_COMMAND_ID(wp,lp) == IDC_BUTTON_BROWSE &&
  130. GET_WM_COMMAND_CMD(wp,lp) == BN_CLICKED) {
  131. static TCHAR szAppFilter[]=TEXT("Files\0*.*\0All Files\0*.*\0");
  132. TCHAR szFileName[MAX_PATH];
  133. OPENFILENAME ofn;
  134. DWORD dwLastError;
  135. szFileName[0] = TEXT('\0');
  136. /* prompt user for file to open */
  137. ofn.lStructSize = sizeof(OPENFILENAME);
  138. ofn.hwndOwner = hwnd;
  139. ofn.hInstance = NULL;
  140. ofn.lpstrFilter = szAppFilter;
  141. ofn.lpstrCustomFilter = NULL;
  142. ofn.nMaxCustFilter = 0;
  143. ofn.nFilterIndex = 0;
  144. ofn.lpstrFile = szFileName;
  145. ofn.nMaxFile = sizeof(szFileName);
  146. ofn.lpstrFileTitle = NULL;
  147. ofn.nMaxFileTitle = 0;
  148. ofn.lpstrInitialDir = NULL;
  149. ofn.lpstrTitle = NULL;
  150. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER;
  151. ofn.nFileOffset = 0;
  152. ofn.nFileExtension = 0;
  153. ofn.lpstrDefExt = NULL;
  154. ofn.lCustData = 0;
  155. ofn.lpfnHook = NULL;
  156. ofn.lpTemplateName = NULL;
  157. if (GetOpenFileName(&ofn)) {
  158. Edit_SetText(GetDlgItem(hwnd,IDC_EDIT_PATH),szFileName);
  159. }
  160. else {
  161. dwLastError = ::GetLastError();
  162. }
  163. return TRUE;
  164. }
  165. else
  166. if (GET_WM_COMMAND_ID(wp,lp) == IDC_EDIT_PATH &&
  167. GET_WM_COMMAND_CMD(wp,lp) == EN_CHANGE ) {
  168. // Enable Apply button
  169. SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
  170. return TRUE;
  171. }
  172. }
  173. break;
  174. case WM_DESTROY:
  175. // Destroy things
  176. g_pSti->Release();
  177. g_pSti = NULL;
  178. break;
  179. case WM_NOTIFY:
  180. {
  181. LPNMHDR lpnmh = (LPNMHDR) lp;
  182. if ( lpnmh -> code == PSN_APPLY ) {
  183. // Write path to the registry
  184. psdi = (PSTI_DEVICE_INFORMATION)GetWindowLong(hwnd, DWLP_USER);
  185. if (psdi && g_pSti) {
  186. TCHAR szPath[MAX_PATH];
  187. WCHAR wszPath[MAX_PATH];
  188. szPath[0] = '\0';
  189. wszPath[0] = L'\0';
  190. g_pSti->WriteToErrorLog(STI_TRACE_INFORMATION,
  191. L"Writing new path to the registry for Sample USD"
  192. );
  193. GetWindowText(GetDlgItem(hwnd,IDC_EDIT_PATH),szPath,sizeof(szPath));
  194. if (*szPath) {
  195. HRESULT hres;
  196. STI_DEVICE_INFORMATION sdiNew;
  197. STI_DEVICE_INFORMATION *psdiNew = &sdiNew;
  198. CopyMemory(psdiNew,psdi,sizeof(STI_DEVICE_INFORMATION));
  199. #ifndef UNICODE
  200. MultiByteToWideChar(CP_ACP, 0,
  201. szPath,-1,
  202. wszPath,sizeof(wszPath));
  203. #else
  204. lstrcpy(wszPath,szPath);
  205. #endif
  206. psdiNew->pszPortName = wszPath;
  207. hres = g_pSti->SetupDeviceParameters(psdiNew);
  208. if (!SUCCEEDED(hres)) {
  209. g_pSti->WriteToErrorLog(STI_TRACE_ERROR,
  210. L"Could not save new port name"
  211. );
  212. }
  213. }
  214. }
  215. }
  216. }
  217. default: ;
  218. }
  219. return FALSE;
  220. }
  221. PROPSHEETPAGE psp = {sizeof psp, PSP_DEFAULT };
  222. typedef BOOL (WINAPI *ADDER)(HPROPSHEETPAGE hpsp, LPARAM lp);
  223. extern "C"
  224. BOOL
  225. WINAPI
  226. EnumStiPropPages(
  227. PSTI_DEVICE_INFORMATION psdi,
  228. ADDER adder,
  229. LPARAM lp
  230. ) {
  231. psp.hInstance = g_hInst;
  232. psp.pszTemplate = MAKEINTRESOURCE(IDD_PAGE_GENERAL);
  233. psp.pfnDlgProc = USDSampPropDialog;
  234. psp.lParam = (LPARAM) psdi;
  235. HPROPSHEETPAGE hpsp = CreatePropertySheetPage(&psp);
  236. if (!hpsp || !(*adder)(hpsp, lp)) {
  237. if (hpsp) {
  238. DestroyPropertySheetPage(hpsp);
  239. }
  240. return FALSE; // We failed to add anything...
  241. }
  242. return TRUE;
  243. }
  244. BOOL WINAPI
  245. IsPlatformNT(
  246. VOID
  247. )
  248. {
  249. OSVERSIONINFO ver;
  250. BOOL bReturn = FALSE;
  251. ZeroMemory(&ver,sizeof(ver));
  252. ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  253. if(!GetVersionEx(&ver)) {
  254. bReturn = FALSE;
  255. }
  256. else {
  257. switch(ver.dwPlatformId) {
  258. case VER_PLATFORM_WIN32_WINDOWS:
  259. bReturn = FALSE;
  260. break;
  261. case VER_PLATFORM_WIN32_NT:
  262. bReturn = TRUE;
  263. break;
  264. default:
  265. bReturn = FALSE;
  266. break;
  267. }
  268. }
  269. return bReturn;
  270. } // endproc