Source code of Windows XP (NT5)
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.

517 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxview.c
  5. Abstract:
  6. This file implements a simple TIFF image viewer.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Wesley Witt (wesw) 17-Feb-1996
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <tchar.h>
  16. #include "faxutil.h"
  17. #include "faxreg.h"
  18. extern WCHAR LastDir[MAX_PATH*2];
  19. extern DWORD CurrZoom;
  20. BOOL
  21. SaveWindowPlacement(
  22. HWND hwnd
  23. )
  24. {
  25. HKEY hKey;
  26. LONG rVal;
  27. WINDOWPLACEMENT wpl;
  28. wpl.length = sizeof(WINDOWPLACEMENT);
  29. if (!GetWindowPlacement( hwnd, &wpl )) {
  30. return FALSE;
  31. }
  32. rVal = RegCreateKey(
  33. HKEY_CURRENT_USER,
  34. REGKEY_FAXVIEW,
  35. &hKey
  36. );
  37. if (rVal != ERROR_SUCCESS) {
  38. DebugPrint(( TEXT("could not create/open registry key") ));
  39. return FALSE;
  40. }
  41. rVal = RegSetValueEx(
  42. hKey,
  43. REGVAL_WINDOW_PLACEMENT,
  44. 0,
  45. REG_BINARY,
  46. (LPBYTE) &wpl,
  47. sizeof(WINDOWPLACEMENT)
  48. );
  49. if (rVal != ERROR_SUCCESS) {
  50. DebugPrint(( TEXT("could not set registry value") ));
  51. return FALSE;
  52. }
  53. rVal = RegSetValueEx(
  54. hKey,
  55. REGVAL_LAST_ZOOM,
  56. 0,
  57. REG_DWORD,
  58. (LPBYTE) &CurrZoom,
  59. sizeof(CurrZoom)
  60. );
  61. if (rVal != ERROR_SUCCESS) {
  62. DebugPrint(( TEXT("could not set registry value") ));
  63. return FALSE;
  64. }
  65. rVal = RegSetValueEx(
  66. hKey,
  67. REGVAL_LAST_DIR,
  68. 0,
  69. REG_SZ,
  70. (LPBYTE) LastDir,
  71. StringSize( LastDir )
  72. );
  73. if (rVal != ERROR_SUCCESS) {
  74. DebugPrint(( TEXT("could not set registry value") ));
  75. return FALSE;
  76. }
  77. RegCloseKey( hKey );
  78. return TRUE;
  79. }
  80. BOOL
  81. QueryWindowPlacement(
  82. HWND hwnd
  83. )
  84. {
  85. HKEY hKey;
  86. LONG rVal;
  87. DWORD RegType;
  88. DWORD RegSize;
  89. WINDOWPLACEMENT wpl;
  90. rVal = RegCreateKey(
  91. HKEY_CURRENT_USER,
  92. REGKEY_FAXVIEW,
  93. &hKey
  94. );
  95. if (rVal != ERROR_SUCCESS) {
  96. DebugPrint(( TEXT("could not create/open registry key") ));
  97. return FALSE;
  98. }
  99. RegSize = sizeof(WINDOWPLACEMENT);
  100. rVal = RegQueryValueEx(
  101. hKey,
  102. REGVAL_WINDOW_PLACEMENT,
  103. 0,
  104. &RegType,
  105. (LPBYTE) &wpl,
  106. &RegSize
  107. );
  108. RegSize = sizeof(CurrZoom);
  109. rVal = RegQueryValueEx(
  110. hKey,
  111. REGVAL_LAST_ZOOM,
  112. 0,
  113. &RegType,
  114. (LPBYTE) &CurrZoom,
  115. &RegSize
  116. );
  117. if (rVal != ERROR_SUCCESS) {
  118. CurrZoom = 0;
  119. }
  120. RegSize = sizeof(LastDir);
  121. rVal = RegQueryValueEx(
  122. hKey,
  123. REGVAL_LAST_DIR,
  124. 0,
  125. &RegType,
  126. (LPBYTE) LastDir,
  127. &RegSize
  128. );
  129. RegCloseKey( hKey );
  130. if (rVal != ERROR_SUCCESS) {
  131. DebugPrint(( TEXT("Could not query registry value, ec=0x%08x"), rVal ));
  132. return FALSE;
  133. }
  134. return SetWindowPlacement( hwnd, &wpl );
  135. }
  136. BOOL
  137. IsItOkToAskForDefault(
  138. VOID
  139. )
  140. {
  141. HKEY hKey;
  142. LONG rVal;
  143. DWORD Ask;
  144. DWORD RegType;
  145. DWORD RegSize;
  146. rVal = RegCreateKey(
  147. HKEY_CURRENT_USER,
  148. REGKEY_FAXVIEW,
  149. &hKey
  150. );
  151. if (rVal != ERROR_SUCCESS) {
  152. DebugPrint(( TEXT("could not create/open registry key") ));
  153. return TRUE;
  154. }
  155. RegSize = sizeof(DWORD);
  156. rVal = RegQueryValueEx(
  157. hKey,
  158. REGVAL_DONT_ASK,
  159. 0,
  160. &RegType,
  161. (LPBYTE) &Ask,
  162. &RegSize
  163. );
  164. if (rVal != ERROR_SUCCESS) {
  165. DebugPrint(( TEXT("Could not query registry value, ec=0x%08x"), rVal ));
  166. Ask = 1;
  167. }
  168. return Ask;
  169. }
  170. BOOL
  171. SetAskForViewerValue(
  172. DWORD Ask
  173. )
  174. {
  175. HKEY hKey;
  176. LONG rVal;
  177. rVal = RegCreateKey(
  178. HKEY_CURRENT_USER,
  179. REGKEY_FAXVIEW,
  180. &hKey
  181. );
  182. if (rVal != ERROR_SUCCESS) {
  183. DebugPrint(( TEXT("could not create/open registry key") ));
  184. return TRUE;
  185. }
  186. rVal = RegSetValueEx(
  187. hKey,
  188. REGVAL_DONT_ASK,
  189. 0,
  190. REG_DWORD,
  191. (LPBYTE) &Ask,
  192. sizeof(DWORD)
  193. );
  194. if (rVal != ERROR_SUCCESS) {
  195. DebugPrint(( TEXT("could not set registry value") ));
  196. return FALSE;
  197. }
  198. RegCloseKey( hKey );
  199. return TRUE;
  200. }
  201. BOOL
  202. IsFaxViewerDefaultViewer(
  203. VOID
  204. )
  205. {
  206. WCHAR ValueBuf[64];
  207. LONG Size;
  208. Size = sizeof(ValueBuf);
  209. RegQueryValue(
  210. HKEY_CLASSES_ROOT,
  211. L".tif",
  212. ValueBuf,
  213. &Size
  214. );
  215. if (wcscmp( ValueBuf, L"Fax Document" ) == 0) {
  216. return TRUE;
  217. }
  218. return FALSE;
  219. }
  220. BOOL
  221. CreateFileAssociation(
  222. LPWSTR FileExtension,
  223. LPWSTR FileAssociationName,
  224. LPWSTR FileAssociationDescription,
  225. LPWSTR OpenCommand,
  226. LPWSTR PrintCommand,
  227. LPWSTR PrintToCommand,
  228. LPWSTR FileName,
  229. DWORD IconIndex
  230. )
  231. {
  232. LONG rVal = 0;
  233. HKEY hKey = NULL;
  234. HKEY hKeyOpen = NULL;
  235. HKEY hKeyPrint = NULL;
  236. HKEY hKeyPrintTo = NULL;
  237. HKEY hKeyIcon = NULL;
  238. DWORD Disposition = 0;
  239. WCHAR Buffer[MAX_PATH*2];
  240. rVal = RegCreateKeyEx(
  241. HKEY_CLASSES_ROOT,
  242. FileExtension,
  243. 0,
  244. NULL,
  245. 0,
  246. KEY_ALL_ACCESS,
  247. NULL,
  248. &hKey,
  249. &Disposition
  250. );
  251. if (rVal != ERROR_SUCCESS) {
  252. goto exit;
  253. }
  254. rVal = RegSetValueEx(
  255. hKey,
  256. NULL,
  257. 0,
  258. REG_SZ,
  259. (LPBYTE) FileAssociationName,
  260. StringSize( FileAssociationName )
  261. );
  262. if (rVal != ERROR_SUCCESS) {
  263. goto exit;
  264. }
  265. RegCloseKey( hKey );
  266. rVal = RegCreateKeyEx(
  267. HKEY_CLASSES_ROOT,
  268. FileAssociationName,
  269. 0,
  270. NULL,
  271. 0,
  272. KEY_ALL_ACCESS,
  273. NULL,
  274. &hKey,
  275. &Disposition
  276. );
  277. if (rVal != ERROR_SUCCESS) {
  278. goto exit;
  279. }
  280. rVal = RegSetValueEx(
  281. hKey,
  282. NULL,
  283. 0,
  284. REG_SZ,
  285. (LPBYTE) FileAssociationDescription,
  286. StringSize( FileAssociationDescription )
  287. );
  288. if (rVal != ERROR_SUCCESS) {
  289. goto exit;
  290. }
  291. rVal = RegCreateKeyEx(
  292. hKey,
  293. L"Shell\\Open\\Command",
  294. 0,
  295. NULL,
  296. 0,
  297. KEY_ALL_ACCESS,
  298. NULL,
  299. &hKeyOpen,
  300. &Disposition
  301. );
  302. if (rVal != ERROR_SUCCESS) {
  303. goto exit;
  304. }
  305. rVal = RegSetValueEx(
  306. hKeyOpen,
  307. NULL,
  308. 0,
  309. REG_EXPAND_SZ,
  310. (LPBYTE) OpenCommand,
  311. StringSize( OpenCommand )
  312. );
  313. if (rVal != ERROR_SUCCESS) {
  314. goto exit;
  315. }
  316. if (PrintCommand) {
  317. rVal = RegCreateKeyEx(
  318. hKey,
  319. L"Shell\\Print\\Command",
  320. 0,
  321. NULL,
  322. 0,
  323. KEY_ALL_ACCESS,
  324. NULL,
  325. &hKeyPrint,
  326. &Disposition
  327. );
  328. if (rVal != ERROR_SUCCESS) {
  329. goto exit;
  330. }
  331. rVal = RegSetValueEx(
  332. hKeyPrint,
  333. NULL,
  334. 0,
  335. REG_EXPAND_SZ,
  336. (LPBYTE) PrintCommand,
  337. StringSize( PrintCommand )
  338. );
  339. if (rVal != ERROR_SUCCESS) {
  340. goto exit;
  341. }
  342. }
  343. if (PrintToCommand) {
  344. rVal = RegCreateKeyEx(
  345. hKey,
  346. L"Shell\\Printto\\Command",
  347. 0,
  348. NULL,
  349. 0,
  350. KEY_ALL_ACCESS,
  351. NULL,
  352. &hKeyPrintTo,
  353. &Disposition
  354. );
  355. if (rVal != ERROR_SUCCESS) {
  356. goto exit;
  357. }
  358. rVal = RegSetValueEx(
  359. hKeyPrintTo,
  360. NULL,
  361. 0,
  362. REG_EXPAND_SZ,
  363. (LPBYTE) PrintToCommand,
  364. StringSize( PrintToCommand )
  365. );
  366. if (rVal != ERROR_SUCCESS) {
  367. goto exit;
  368. }
  369. }
  370. if (FileName) {
  371. rVal = RegCreateKeyEx(
  372. hKey,
  373. L"DefaultIcon",
  374. 0,
  375. NULL,
  376. 0,
  377. KEY_ALL_ACCESS,
  378. NULL,
  379. &hKeyIcon,
  380. &Disposition
  381. );
  382. if (rVal != ERROR_SUCCESS) {
  383. goto exit;
  384. }
  385. wsprintf( Buffer, L"%s,%d", FileName, IconIndex );
  386. rVal = RegSetValueEx(
  387. hKeyIcon,
  388. NULL,
  389. 0,
  390. REG_EXPAND_SZ,
  391. (LPBYTE) Buffer,
  392. StringSize( Buffer )
  393. );
  394. if (rVal != ERROR_SUCCESS) {
  395. goto exit;
  396. }
  397. }
  398. exit:
  399. RegCloseKey( hKey );
  400. RegCloseKey( hKeyOpen );
  401. RegCloseKey( hKeyPrint );
  402. RegCloseKey( hKeyPrintTo );
  403. RegCloseKey( hKeyIcon );
  404. return rVal == ERROR_SUCCESS;
  405. }
  406. BOOL
  407. MakeFaxViewerDefaultViewer(
  408. VOID
  409. )
  410. {
  411. CreateFileAssociation(
  412. L".tif",
  413. L"Fax Document",
  414. L"Fax Document",
  415. L"%SystemRoot%\\system32\\FaxView.exe \"%1\"",
  416. L"%SystemRoot%\\system32\\FaxView.exe -p \"%1\"",
  417. L"%SystemRoot%\\system32\\FaxView.exe -pt \"%1\" \"%2\" \"%3\" \"%4\"",
  418. L"%SystemRoot%\\system32\\FaxView.exe",
  419. 0
  420. );
  421. CreateFileAssociation(
  422. L".tiff",
  423. L"Fax Document",
  424. L"Fax Document",
  425. L"%SystemRoot%\\system32\\FaxView.exe \"%1\"",
  426. L"%SystemRoot%\\system32\\FaxView.exe -p \"%1\"",
  427. L"%SystemRoot%\\system32\\FaxView.exe -pt \"%1\" \"%2\" \"%3\" \"%4\"",
  428. L"%SystemRoot%\\system32\\FaxView.exe",
  429. 0
  430. );
  431. return TRUE;
  432. }