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.

1883 lines
66 KiB

  1. /* FROST.C
  2. Resident Code Segment
  3. WinMain()
  4. Main Window(Dlg) Proc
  5. FrostCommand()
  6. Small Resident UtilityRoutines
  7. Frosting: Master Theme Selector for Windows '95
  8. Copyright (c) 1994-1999 Microsoft Corporation. All rights reserved.
  9. */
  10. // ---------------------------------------------
  11. // Brief file history:
  12. // Alpha:
  13. // Beta:
  14. // Bug fixes
  15. // ---------
  16. //
  17. // ---------------------------------------------
  18. #define ROOTFILE 1
  19. #include "windows.h"
  20. #include "windowsx.h"
  21. #include <mbctype.h>
  22. #include "frost.h"
  23. #include "global.h"
  24. #include "..\inc\addon.h"
  25. #include "schedule.h"
  26. #include "htmlprev.h"
  27. #include "objbase.h"
  28. #include "cderr.h"
  29. #include "commdlg.h"
  30. /* Local Routines */
  31. BOOL FrostCommand(HWND, WPARAM, LPARAM);
  32. BOOL ResetTheThemeWorld(LPTSTR);
  33. BOOL InitThemeDDL(HWND);
  34. void NewSampleTitle(void);
  35. void EnableScreenSaverButton();
  36. BOOL FileSpecExists(LPTSTR szFilename);
  37. INT_PTR FAR PASCAL BPP_ChoiceDlg(HWND, UINT, WPARAM, LPARAM);
  38. // globals
  39. BOOL bNewSelection = TRUE;
  40. BOOL bAppliedOnce = FALSE; // have you applied any theme yet?
  41. BOOL gfCoInitDone = FALSE; // track state of OLE CoInitialize()
  42. BOOL bCB_SchedChange = FALSE; // User has toggled status of Schedule check
  43. BOOL bInGrphFilter = FALSE; // Currently in a Graphics filter?
  44. // virtual boolean: null theme name means Cur Win Settings, not from theme file
  45. #define bThemed (*szCurThemeFile)
  46. #define FROSTUNIQUEREPLY 1332 // twice 666
  47. POPUP_HELP_ARRAY phaMainWin[] = {
  48. { (DWORD)DDL_THEME, (DWORD)IDH_THEME_LIST },
  49. { (DWORD)PB_SAVE, (DWORD)IDH_THEME_SAVEAS },
  50. { (DWORD)PB_DELETE, (DWORD)IDH_THEME_DELETE },
  51. { (DWORD)PB_SCRSVR, (DWORD)IDH_THEME_PREVSCRN },
  52. { (DWORD)PB_POINTERS, (DWORD)IDH_THEME_PREVETC },
  53. { (DWORD)CB_SCRSVR, (DWORD)IDH_THEME_SCRNSAVER },
  54. { (DWORD)CB_SOUND, (DWORD)IDH_THEMES_SOUNDS },
  55. { (DWORD)CB_PTRS, (DWORD)IDH_THEME_POINTERS },
  56. { (DWORD)CB_WALL, (DWORD)IDH_THEME_WALLPAPER },
  57. { (DWORD)CB_ICONS, (DWORD)IDH_THEME_ICONS },
  58. { (DWORD)CB_COLORS, (DWORD)IDH_THEME_COLORS },
  59. { (DWORD)CB_FONTS, (DWORD)IDH_THEME_FONTS },
  60. { (DWORD)CB_BORDERS, (DWORD)IDH_THEME_BORDER },
  61. // { (DWORD)CB_ICONSIZE, (DWORD)IDH_THEME_ICON_SIZESPACE },
  62. { (DWORD)CB_SCHEDULE, (DWORD)IDH_THEME_ROTATE },
  63. { (DWORD)0, (DWORD)0 }, // double-null terminator
  64. };
  65. int WINAPI WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  66. HINSTANCE hInstance; /* current instance */
  67. HINSTANCE hPrevInstance; /* previous instance */
  68. LPSTR lpCmdLine; /* command line */
  69. int nCmdShow; /* show-window type (open/icon) */
  70. {
  71. MSG msg;
  72. HWND hWndPrev, hPopupWnd;
  73. TCHAR szMsg[MAX_MSGLEN+1];
  74. TCHAR szAppName[MAX_STRLEN+1];
  75. #ifdef UNICODE
  76. CHAR szMsgA[MAX_MSGLEN+1];
  77. CHAR szAppNameA[MAX_STRLEN+1];
  78. #endif
  79. OSVERSIONINFO osVerInfo;
  80. //
  81. // just checking on the debug facilities
  82. Assert(FALSE, TEXT("On_entry: WinMain\n"));
  83. #ifdef UNICODE
  84. // UNICODE Check -- if we're a UNICODE binary trying to run on Win9x
  85. // show error and bail out.
  86. if (!IsPlatformNT())
  87. {
  88. LoadStringA(hInstance, STR_APPNAME, szAppNameA, MAX_STRLEN); // title string
  89. LoadStringA(hInstance, STR_ERRNOUNICODE, szMsgA, MAX_STRLEN); // error string
  90. MessageBoxA(NULL, szMsgA, szAppNameA, MB_OK | MB_APPLMODAL | MB_ICONERROR);
  91. return FALSE;
  92. }
  93. #endif // UNICODE
  94. // Verify the OS version
  95. ZeroMemory(&osVerInfo, sizeof(osVerInfo));
  96. osVerInfo.dwOSVersionInfoSize = sizeof(osVerInfo);
  97. if (GetVersionEx(&osVerInfo))
  98. {
  99. // If NT, we need to be version 5.0 or later.
  100. if ((osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  101. (osVerInfo.dwMajorVersion < 5))
  102. {
  103. LoadString(hInstance, STR_APPNAME, szAppName, MAX_STRLEN); // title string
  104. LoadString(hInstance, STR_ERRNOUNICODE, szMsg, MAX_STRLEN); // error string
  105. MessageBox(NULL, szMsg, szAppName, MB_OK | MB_APPLMODAL | MB_ICONERROR);
  106. return FALSE;
  107. }
  108. // If Win9x, we need to be version 4.1 or later (Win98).
  109. if ((osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  110. ((osVerInfo.dwMajorVersion < 4) ||
  111. (osVerInfo.dwMajorVersion == 4) && (osVerInfo.dwMinorVersion < 10)))
  112. {
  113. LoadString(hInstance, STR_APPNAME, szAppName, MAX_STRLEN); // title string
  114. LoadString(hInstance, STR_ERRBAD9XVER, szMsg, MAX_STRLEN); // error string
  115. MessageBox(NULL, szMsg, szAppName, MB_OK | MB_APPLMODAL | MB_ICONERROR);
  116. return FALSE;
  117. }
  118. // If the Platform ID is not NT or WIN32 we will run and hope for the
  119. // best.
  120. }
  121. //
  122. // Prev instance check
  123. //
  124. // go see if there is already a window of this type
  125. LoadString(hInstance, STR_APPNAME, (LPTSTR)szMsg, MAX_STRLEN); // title string
  126. hWndPrev = FindWindow((LPTSTR)szClassName, NULL);
  127. // if you are not the first instance
  128. if (hWndPrev) {
  129. if (IsIconic(hWndPrev))
  130. ShowWindow(hWndPrev, SW_RESTORE);
  131. else {
  132. BringWindowToTop(hWndPrev);
  133. if ((hPopupWnd = GetLastActivePopup(hWndPrev)) != hWndPrev) {
  134. BringWindowToTop(hPopupWnd);
  135. hWndPrev = hPopupWnd;
  136. }
  137. SetForegroundWindow(hWndPrev);
  138. }
  139. // leave this barren place
  140. return FALSE; // ONLY ONE INSTANCE CAN RUN!
  141. }
  142. //
  143. // Initializations
  144. //
  145. // run this app!
  146. if (!InitFrost(hPrevInstance,
  147. hInstance,
  148. #ifdef UNICODE
  149. GetCommandLine(),
  150. #else
  151. lpCmdLine,
  152. #endif
  153. nCmdShow))
  154. {
  155. // Problems...
  156. NoMemMsg(STR_TO_RUN); // not enuf mem to run
  157. CleanUp(); // Release IThumbnail interface
  158. return (FALSE);
  159. }
  160. // InitFrost may return TRUE if we did something with the commandline, but
  161. // didn't put up any UI.
  162. if (hWndApp == NULL) {
  163. CleanUp(); // Release IThumbnail interface
  164. return (TRUE);
  165. }
  166. //
  167. // Main message loop
  168. //
  169. while (GetMessage(&msg, NULL, 0, 0)) {
  170. if (hWndApp)
  171. if (IsDialogMessage(hWndApp, &msg))
  172. continue; // spend most of our time skipping out here
  173. TranslateMessage(&msg); /* Translates virtual key codes */
  174. DispatchMessage(&msg); /* Dispatches message to window */
  175. }
  176. //
  177. // final exit cleanup
  178. //
  179. CleanUp(); // Release our IThumbnail interface for HTML wallpaper
  180. return (int)(msg.wParam); /* Returns the value from PostQuitMessage */
  181. }
  182. // PreviewDlgProc
  183. //
  184. // The main window (dialog) proc for the Frosting application.
  185. //
  186. INT_PTR FAR PASCAL PreviewDlgProc(hDlg, message, wParam, lParam)
  187. HWND hDlg;
  188. UINT message;
  189. WPARAM wParam;
  190. LPARAM lParam;
  191. {
  192. PAINTSTRUCT ps;
  193. HDC hdc;
  194. LPHELPINFO lphi;
  195. switch (message) {
  196. case WM_INITDIALOG:
  197. hWndApp = hDlg;
  198. // init case nomem flag
  199. bNoMem = FALSE;
  200. //
  201. // theme drop-down listbox inits
  202. bNoMem |= !InitThemeDDL(hDlg); // init contents, selection
  203. SendDlgItemMessage(hDlg, DDL_THEME, CB_SETEXTENDEDUI, TRUE, 0L);
  204. // update preview and checkboxes for cur theme selection
  205. //
  206. // other inits
  207. // rect for preview, adjusted to dlg-relative coords
  208. GetWindowRect(GetDlgItem(hDlg, RECT_PREVIEW), (LPRECT)&rView);
  209. MapWindowPoints(NULL, hDlg, (LPPOINT)&rView, 2);
  210. // kill it now that you've had your way with it
  211. DestroyWindow(GetDlgItem(hDlg, RECT_PREVIEW));
  212. // and rect within that rect for sample window
  213. GetWindowRect(GetDlgItem(hDlg, RECT_FAKEWIN), (LPRECT)&rFakeWin);
  214. MapWindowPoints(NULL, hDlg, (LPPOINT)&rFakeWin, 2);
  215. // actually, FakeWin painting is going to be relative to Preview area, so
  216. OffsetRect((LPRECT)&rFakeWin, -rView.left, -rView.top);
  217. // kill it now that you've had your way with it
  218. DestroyWindow(GetDlgItem(hDlg, RECT_FAKEWIN));
  219. // and another rect within Preview rect, for icons
  220. GetWindowRect(GetDlgItem(hDlg, RECT_ICONS), (LPRECT)&rPreviewIcons);
  221. MapWindowPoints(NULL, hDlg, (LPPOINT)&rPreviewIcons, 2);
  222. // actually, icons are going to be relative to Preview area too, so
  223. OffsetRect((LPRECT)&rPreviewIcons, -rView.left, -rView.top);
  224. // kill it now that you've had your way with it
  225. DestroyWindow(GetDlgItem(hDlg, RECT_ICONS));
  226. //
  227. // add What's This? to system menu: for some reason, can't have ? in title bar
  228. {
  229. HMENU hSysMenu;
  230. hSysMenu = GetSystemMenu(hDlg, FALSE);
  231. LoadString(hInstApp, STR_WHATSTHIS, szMsg, ARRAYSIZE(szMsg));
  232. InsertMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_STRING,
  233. SC_CONTEXTHELP, (LPTSTR)szMsg);
  234. InsertMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_SEPARATOR, 0, NULL);
  235. }
  236. // set init focus to theme drop-down listbox
  237. SetFocus(GetDlgItem(hDlg,DDL_THEME));
  238. // cleanup
  239. return (FALSE); // handled init ctl focus ourselves
  240. break;
  241. case WM_QUERYNEWPALETTE:
  242. case WM_PALETTECHANGED:
  243. if ((HWND)wParam != hDlg)
  244. InvalidateRect(hDlg, NULL, TRUE);
  245. break;
  246. case WM_PAINT:
  247. // different paint cases for icon and window
  248. if (IsIconic(hDlg))
  249. return (FALSE);
  250. hdc = BeginPaint(hDlg, &ps);
  251. // repaint the preview area with current theme
  252. PaintPreview(hDlg, hdc, &rView);
  253. // paint recessed edge around preview area
  254. DrawEdge(hdc, (LPRECT)&rView, EDGE_SUNKEN, BF_RECT);
  255. EndPaint(hDlg, &ps);
  256. break;
  257. case WM_COMMAND:
  258. return(FrostCommand(hDlg, wParam, lParam)); // process and ret EXIT
  259. break;
  260. case WM_CLOSE:
  261. // do the same things you do on Cancel
  262. FrostCommand(hDlg, MAKEWPARAM(IDCANCEL, 0), (LPARAM)0);
  263. break;
  264. case WM_DESTROY:
  265. if ( gfCoInitDone )
  266. CoUninitialize();
  267. PostQuitMessage(0);
  268. break;
  269. case WM_HELP:
  270. lphi = (LPHELPINFO)lParam;
  271. if (lphi->iContextType == HELPINFO_WINDOW) {
  272. // All of the help topics are in PLUS!.HLP except for the
  273. // Rotate theme checkbox is in PLUS!98.HLP.
  274. if (lphi->iCtrlId == CB_SCHEDULE) {
  275. WinHelp(lphi->hItemHandle, (LPTSTR)szHelpFile98, HELP_WM_HELP,
  276. (DWORD_PTR)((POPUP_HELP_ARRAY FAR *)phaMainWin));
  277. }
  278. else {
  279. WinHelp(lphi->hItemHandle, (LPTSTR)szHelpFile, HELP_WM_HELP,
  280. (DWORD_PTR)((POPUP_HELP_ARRAY FAR *)phaMainWin));
  281. }
  282. }
  283. break;
  284. case WM_CONTEXTMENU:
  285. // first check for main dlg window
  286. if ((HWND)wParam == hDlg) {
  287. POINT ptTest;
  288. RECT rCurTest; // cur screen coords of Preview area
  289. // inits
  290. ptTest.x = GET_X_LPARAM(lParam);
  291. ptTest.y = GET_Y_LPARAM(lParam);
  292. rCurTest = rView;
  293. MapWindowPoints(hDlg, NULL, (LPPOINT)&rCurTest, 2);
  294. // if it's a click in the preview area
  295. if (PtInRect((LPRECT)&rCurTest, ptTest)) {
  296. WinHelp(hDlg, (LPTSTR)szHelpFile, HELP_CONTEXTPOPUP,
  297. (DWORD)IDH_THEME_PREVIEW);
  298. return (TRUE);
  299. }
  300. }
  301. { // Scope for ptTest & rCurTest variables
  302. POINT ptTest;
  303. RECT rCurTest; // cur screen coords of Preview area
  304. // inits
  305. ptTest.x = GET_X_LPARAM(lParam);
  306. ptTest.y = GET_Y_LPARAM(lParam);
  307. GetWindowRect(GetDlgItem(hDlg, CB_SCHEDULE), (LPRECT)&rCurTest);
  308. // If user right clicked in CB_SCHEDULE area we need to load
  309. // the help topic from PLUS!98.HLP -- otherwise it comes from
  310. // PLUS!.HLP
  311. if (PtInRect((LPRECT)&rCurTest, ptTest)) {
  312. WinHelp((HWND)wParam, (LPTSTR)szHelpFile98, HELP_CONTEXTMENU,
  313. (DWORD_PTR)((POPUP_HELP_ARRAY FAR *)phaMainWin));
  314. }
  315. else {
  316. WinHelp((HWND)wParam, (LPTSTR)szHelpFile, HELP_CONTEXTMENU,
  317. (DWORD_PTR)((POPUP_HELP_ARRAY FAR *)phaMainWin));
  318. }
  319. } // End scope for ptTest & rCurTest variables
  320. break;
  321. default:
  322. return(FALSE); // didn't process message EXIT
  323. break;
  324. }
  325. return (TRUE); // did process message
  326. }
  327. // InitThemeDDL
  328. //
  329. // Inits or Re-Inits the theme drop-down listbox: clears and then
  330. // fills the Theme drop-down listbox with the titles of the
  331. // available themes in the CURRENT DIRECTORY as specified by global var.
  332. //
  333. // Uses: szCurDir[] to get directory to list
  334. // szCurThemeFile[] to tell whether to init selection
  335. // szCurThemeName[] to init selection if init'ing
  336. //
  337. // Assumes you've already made sure that curdir\themename == themefile
  338. // is a legit, existing file.
  339. //
  340. // Returns: success of initialization
  341. BOOL InitThemeDDL(HWND hdlg)
  342. {
  343. int iret;
  344. HWND hDDL;
  345. WIN32_FIND_DATA wfdFind;
  346. HANDLE hFind;
  347. //
  348. // inits
  349. hDDL = GetDlgItem(hdlg, DDL_THEME);
  350. // first get the directory for .THM files
  351. lstrcpy((LPTSTR)szMsg, (LPTSTR)szCurDir);
  352. lstrcat((LPTSTR)szMsg, (LPTSTR)TEXT("*"));
  353. lstrcat((LPTSTR)szMsg, (LPTSTR)szExt);
  354. //
  355. // Use FindFirstFile, FindNextFile, FindClose to enum THM files
  356. // and add each (cleaned-up) string to DDL
  357. // start find process
  358. hFind = FindFirstFile((LPCTSTR)szMsg, (LPWIN32_FIND_DATA)&wfdFind);
  359. #ifdef DEBUG
  360. //
  361. // hack so we can find files when debuging...
  362. //
  363. if (INVALID_HANDLE_VALUE == hFind) {
  364. lstrcpy(szThemeDir, TEXT("c:\\Program Files\\Plus!\\Themes\\"));
  365. lstrcpy(szMsg, szThemeDir);
  366. lstrcat(szMsg, TEXT("*"));
  367. lstrcat(szMsg, szExt);
  368. hFind = FindFirstFile((LPCTSTR)szMsg, (LPWIN32_FIND_DATA)&wfdFind);
  369. }
  370. #endif
  371. // if that got you a valid search handle and first file
  372. if (INVALID_HANDLE_VALUE != hFind) {
  373. // add each long filename string to ddl without extension
  374. do {
  375. // copy filename to buffer
  376. lstrcpy((LPTSTR)szMsg, (LPTSTR)wfdFind.cFileName);
  377. // remove extension
  378. TruncateExt((LPCTSTR)szMsg);
  379. // add to ddl
  380. iret = (int) SendMessage(hDDL, CB_ADDSTRING,
  381. (WPARAM)0, (LPARAM)(LPCTSTR)szMsg);
  382. if (iret == CB_ERRSPACE) {
  383. FindClose(hFind);
  384. return (FALSE); // prob low mem EXIT
  385. }
  386. }
  387. // get next file
  388. while (FindNextFile(hFind,(LPWIN32_FIND_DATA)&wfdFind));
  389. // just checking: only reason to fail is out of files?
  390. Assert(ERROR_NO_MORE_FILES == GetLastError(), TEXT("wrong error on FindNextFile() out of files\n"));
  391. // cleanup file search
  392. FindClose(hFind);
  393. }
  394. // else no THM files in that dir: just continue
  395. else {
  396. Assert(FALSE, TEXT("FindFirstFile() ret INVALID_HANDLE_VALUE: no THM files?\n"));
  397. }
  398. //
  399. // add init string to beginning of DDLbox: Current Windows Settings
  400. // note that INSERTSTRING doesn't force resort of list
  401. iret = (int) SendMessage(hDDL, CB_INSERTSTRING,
  402. (WPARAM)0, (LPARAM)(LPCTSTR)szCurSettings);
  403. if (iret == CB_ERRSPACE) return (FALSE);// prob low mem EXIT
  404. //
  405. // add second string iff you've already applied something to _have_
  406. // a previous Windows settings
  407. if (bAppliedOnce) {
  408. iret = (int) SendMessage(hDDL, CB_INSERTSTRING,
  409. (WPARAM)1, (LPARAM)(LPCTSTR)szPrevSettings);
  410. if (iret == CB_ERRSPACE) return (FALSE);// prob low mem EXIT
  411. }
  412. //
  413. // add final string: Other...
  414. iret = (int) SendMessage(hDDL, CB_INSERTSTRING,
  415. (WPARAM)-1, // end of list
  416. (LPARAM)(LPCTSTR)szOther);
  417. if (iret == CB_ERRSPACE) return (FALSE);// prob low mem EXIT
  418. //
  419. // cleanup
  420. // if "last theme applied" or first in new dir, it's already in global
  421. if (bThemed) {
  422. // look for cur theme name
  423. iCurTheme = (int)SendMessage(hDDL, CB_FINDSTRINGEXACT,
  424. (WPARAM) -1, /* start of list */
  425. (LPARAM)(LPCTSTR)szCurThemeName);
  426. if (CB_ERR == iCurTheme) {
  427. // shouldn't ever happen!! made sure file existed before setting globals
  428. Assert(0, TEXT("couldn't find cur theme name in ddl list we just made!\n"));
  429. iCurTheme = 0;
  430. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szNULL);
  431. lstrcpy((LPTSTR)szCurThemeName, (LPTSTR)szCurSettings);
  432. }
  433. }
  434. else {
  435. // select first item (CurWinSettings)
  436. iCurTheme = 0;
  437. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szNULL); // no cur THM file
  438. lstrcpy((LPTSTR)szCurThemeName, (LPTSTR)szCurSettings);
  439. }
  440. // select cur theme name
  441. SendMessage(hDDL, CB_SETCURSEL, (WPARAM)iCurTheme, (LPARAM)0);
  442. // dis/enable checkboxes/buttons for initial conditions
  443. EnableThemeButtons();
  444. RestoreCheckboxes();
  445. // (checkboxes don't work here, so called after ret from Inits)
  446. // keep track of what you did and leave
  447. iThemeCount = (int)SendMessage(hDDL, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  448. return (TRUE);
  449. }
  450. //
  451. // ResetTheThemeWorld
  452. //
  453. // With either the Other... selection from a new dir or with the SaveAs...
  454. // to a new dir, you have to reset the globals for files and dirs and
  455. // refresh the main window drop-down listbox. Do it all here.
  456. //
  457. // Input: full pathname of proposed new theme file.
  458. // Normal assumption is that this has been checked to exist and
  459. // be a legit theme file.
  460. //
  461. // Returns: BOOL success -- should always be TRUE
  462. // FALSE is a VERY dire situation, means you're screwed
  463. // and cannot do the basic reset for the app main window...
  464. //
  465. BOOL ResetTheThemeWorld(LPTSTR lpszNewThemeFile)
  466. {
  467. TCHAR szPrevFile[MAX_PATHLEN+1];
  468. // inits
  469. lstrcpy(szPrevFile, szCurThemeFile); // save for error case below
  470. // reset globals for dir and file
  471. lstrcpy(szCurThemeFile, lpszNewThemeFile);
  472. lstrcpy(szCurDir, lpszNewThemeFile);
  473. *(FileFromPath(szCurDir)) = 0;
  474. lstrcpy(szCurThemeName, FileFromPath(lpszNewThemeFile));
  475. TruncateExt(szCurThemeName);
  476. // empty drop-down listbox
  477. SendDlgItemMessage(hWndApp, DDL_THEME, CB_RESETCONTENT, 0L, 0L);
  478. // refill drop-down listbox and select new file
  479. if (!InitThemeDDL(hWndApp)) {
  480. // low mem or very unusual error case
  481. // post low-mem message
  482. NoMemMsg(STR_TO_LIST);
  483. // try to recover by going back to prev dir and theme
  484. lstrcpy(szCurThemeFile, szPrevFile);
  485. lstrcpy(szCurDir, szPrevFile);
  486. *(FileFromPath(szCurDir)) = 0;
  487. lstrcpy(szCurThemeName, FileFromPath(szPrevFile));
  488. TruncateExt(szCurThemeName);
  489. // go for it again
  490. if (!InitThemeDDL(hWndApp)) {
  491. // Very, very, very bad news.
  492. // No way to do the basic initialization of the main window...
  493. return (FALSE); // APOCALYPSE NOW EXIT
  494. }
  495. }
  496. return (TRUE);
  497. }
  498. // FrostCommand
  499. //
  500. // Main application (dialog) window control messages
  501. //
  502. BOOL FrostCommand(HWND hdlg, WPARAM wParam, LPARAM lParam)
  503. {
  504. INT_PTR iDlgRet;
  505. int index;
  506. BOOL bRet;
  507. int iPrevTheme;
  508. extern TCHAR szFrostSection[], szMagic[], szVerify[], szThemeBPP[];
  509. int iThemeBPP, iSysBPP;
  510. HDC hdc;
  511. static int sIndex = CB_ERR;
  512. static BOOL bChosen = TRUE;
  513. static BOOL bCanceled = FALSE;
  514. BOOL bChangeTheme = FALSE;
  515. TCHAR szThemesExe[MAX_PATH]; // Fully qualified path to Themes.exe
  516. switch ((int)LOWORD(wParam)) {
  517. case DDL_THEME:
  518. // The following abomination is here, to trick the combo box into working
  519. // in semi-intelligent way. The problem is, there is no consistancy in the
  520. // ordering of CBN_SELCHANGE messages and CBN_SELENDOK messages. This supplies
  521. // the proper functionality in most cases.
  522. switch (HIWORD(wParam))
  523. {
  524. case CBN_SELCHANGE:
  525. // User may have "chosen" a theme, or he/she might just be
  526. // cursoring passed this selection. This decision is based on
  527. // whether we have seen a CBN_SELENDOK message yet.
  528. sIndex = (int)SendMessage((HWND)(LOWORD(lParam)), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
  529. if (bChosen == TRUE && bCanceled == FALSE)
  530. {
  531. bChangeTheme = TRUE;
  532. }
  533. break;
  534. case CBN_DROPDOWN:
  535. // When the list is first dropped down, init all flags
  536. bChosen = FALSE;
  537. bCanceled = FALSE;
  538. bChangeTheme = FALSE;
  539. sIndex = CB_ERR;
  540. break;
  541. case CBN_SELENDOK:
  542. // The user has "chosen" a selection, if we have already recieved a
  543. // CBN_SELCHANGE notification, assume that this is a chosen theme.
  544. bChosen = TRUE;
  545. if (sIndex != CB_ERR && sIndex != iCurTheme)
  546. {
  547. bChangeTheme = TRUE;
  548. }
  549. break;
  550. case CBN_SELENDCANCEL:
  551. // The user has "canceled" the selection of a theme.
  552. bChosen = FALSE;
  553. bCanceled = TRUE;
  554. bChangeTheme = FALSE;
  555. // Pretty soon we are going to recieve a CBN_SELCHANGE notification,
  556. // that needs to be undone. This postevent will handle that.
  557. PostMessage((HWND)(LOWORD(lParam)), CB_SETCURSEL, (WPARAM)iCurTheme, (LPARAM)0);
  558. break;
  559. }
  560. if (bChangeTheme) {
  561. index = sIndex;
  562. bChangeTheme = FALSE;
  563. iPrevTheme = iCurTheme;
  564. iCurTheme = index;
  565. bNewSelection = TRUE;
  566. // meddle w/ cursor
  567. WaitCursor();
  568. //
  569. // action depends on selection
  570. // Four cases: Cur Win Settings, Prev Win Settings, Other... and normal.
  571. //
  572. // Current Windows settings case
  573. if (index == 0) {
  574. // clear pointer to cur file
  575. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szNULL); // no cur THM file
  576. lstrcpy((LPTSTR)szCurThemeName, (LPTSTR)szCurSettings);
  577. }
  578. //
  579. // Previous Windows settings case
  580. else if ((index == 1) && bAppliedOnce) {
  581. // create full pathname of prev settings file
  582. lstrcpy(szCurThemeFile, szThemeDir);
  583. lstrcat(szCurThemeFile, szPrevSettingsFilename);
  584. // use false name
  585. lstrcpy((LPTSTR)szCurThemeName, (LPTSTR)szPrevSettings);
  586. }
  587. //
  588. // Other... case
  589. else if (index == iThemeCount-1) {
  590. OPENFILENAME ofnOpen;
  591. TCHAR szOpenFile[MAX_PATHLEN+1];
  592. // save away those checkboxes
  593. if (bThemed)
  594. SaveCheckboxes();
  595. do {
  596. // inits
  597. lstrcpy(szOpenFile, TEXT("*")); // start w/ *.Theme
  598. lstrcat(szOpenFile, szExt);
  599. ofnOpen.lStructSize = sizeof(OPENFILENAME);
  600. ofnOpen.hwndOwner = hdlg;
  601. ofnOpen.lpstrFilter = szFileTypeDesc;
  602. ofnOpen.lpstrCustomFilter = (LPTSTR)NULL;
  603. ofnOpen.nMaxCustFilter = 0;
  604. ofnOpen.nFilterIndex = 1;
  605. ofnOpen.lpstrFile = szOpenFile;
  606. ofnOpen.nMaxFile = ARRAYSIZE(szOpenFile);
  607. ofnOpen.lpstrFileTitle = (LPTSTR)NULL; // szFileTitle;
  608. ofnOpen.nMaxFileTitle = 0; // sizeof(szFileTitle);
  609. ofnOpen.lpstrInitialDir = (LPTSTR)szCurDir;
  610. ofnOpen.lpstrTitle = (LPTSTR)szOpenTitle;
  611. ofnOpen.Flags = OFN_PATHMUSTEXIST |
  612. OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  613. #ifdef USECALLBACKS
  614. ofnOpen.Flags = OFN_PATHMUSTEXIST |
  615. OFN_ENABLEHOOK | OFN_FILEMUSTEXIST;
  616. ofnOpen.lpfnHook = FileOpenHookProc;
  617. #endif
  618. ofnOpen.lpstrDefExt = CharNext((LPTSTR)szExt);
  619. // call common dlg
  620. if (!GetOpenFileName((LPOPENFILENAME)&ofnOpen)) {
  621. // if they didn't open a file, could be hit cancel but
  622. // also check for lowmem return
  623. iDlgRet = (int)CommDlgExtendedError();
  624. if ((iDlgRet == CDERR_INITIALIZATION) ||
  625. (iDlgRet == CDERR_MEMALLOCFAILURE) ||
  626. (iDlgRet == CDERR_MEMLOCKFAILURE)
  627. )
  628. NoMemMsg(STR_TO_LIST);
  629. // revert to prev entry
  630. iCurTheme = iPrevTheme;
  631. // select old theme in list
  632. SendMessage((HWND)(LOWORD(lParam)), CB_SETCURSEL,
  633. (WPARAM)iCurTheme, (LPARAM)(LPCTSTR)NULL);
  634. // get out of this whole line of thought now
  635. return (TRUE); // no new file/dir to open EXIT
  636. }
  637. // get results and check that it is a valid theme file
  638. if (!IsValidThemeFile(szOpenFile)) {
  639. TCHAR szTemp[MAX_MSGLEN+1];
  640. // bad file: post msg before going back to common open
  641. LoadString(hInstApp, STR_ERRBADOPEN, (LPTSTR)szTemp, MAX_MSGLEN);
  642. wsprintf((LPTSTR)szMsg, (LPTSTR)szTemp, (LPTSTR)szOpenFile);
  643. MessageBox((HWND)hWndApp, (LPTSTR)szMsg, (LPTSTR)szAppName,
  644. MB_OK | MB_ICONERROR | MB_APPLMODAL);
  645. }
  646. }
  647. while (!IsValidThemeFile(szOpenFile));
  648. // now reset the DDL with new dir listing and select new file
  649. if (!ResetTheThemeWorld((LPTSTR)szOpenFile)) {
  650. // prob low mem on adding strs to combobox
  651. DestroyWindow(hdlg);
  652. break; // APOCALYPSE NOW EXIT
  653. }
  654. } // end Other... case
  655. //
  656. // normal theme selection case
  657. else { // NOT cur Windows settings
  658. // get new cur theme name and file and construct filename
  659. SendMessage((HWND)(LOWORD(lParam)), CB_GETLBTEXT, (WPARAM)index,
  660. (LPARAM)(LPCTSTR)szCurThemeName );
  661. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szCurDir);
  662. lstrcat((LPTSTR)szCurThemeFile, (LPTSTR)szCurThemeName);
  663. lstrcat((LPTSTR)szCurThemeFile, (LPTSTR)szExt);
  664. //
  665. // check that new theme file is valid theme file by looking for magic str
  666. if (!IsValidThemeFile((LPTSTR)szCurThemeFile)) { // magic str check
  667. //
  668. // NOT a valid theme file with the correct magic string!
  669. //
  670. TCHAR szTemp[MAX_MSGLEN+1];
  671. // post an error message
  672. LoadString(hInstApp, STR_ERRBADTHEME, (LPTSTR)szTemp, MAX_MSGLEN);
  673. wsprintf((LPTSTR)szMsg, (LPTSTR)szTemp, (LPTSTR)szCurThemeFile);
  674. MessageBox((HWND)hWndApp, (LPTSTR)szMsg, (LPTSTR)szAppName,
  675. MB_OK | MB_ICONERROR | MB_APPLMODAL);
  676. // remove entry from list
  677. SendMessage((HWND)(LOWORD(lParam)), CB_DELETESTRING,
  678. (WPARAM)index, (LPARAM)(LPCTSTR)NULL);
  679. // get new theme count; ask rather than decrement -- for failsafe
  680. iThemeCount = (int) SendMessage((HWND)(LOWORD(lParam)),
  681. CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  682. //
  683. // revert to prev entry
  684. iCurTheme = iPrevTheme;
  685. if (index < iPrevTheme) iCurTheme--;
  686. // get back old cur file and filename
  687. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szCurDir);
  688. SendMessage((HWND)(LOWORD(lParam)), CB_GETLBTEXT, (WPARAM)iCurTheme,
  689. (LPARAM)(LPCTSTR)(szCurThemeFile +
  690. lstrlen((LPTSTR)szCurThemeFile)) );
  691. lstrcat((LPTSTR)szCurThemeFile, (LPTSTR)szExt);
  692. // select old theme in list
  693. SendMessage((HWND)(LOWORD(lParam)), CB_SETCURSEL,
  694. (WPARAM)iCurTheme, (LPARAM)(LPCTSTR)NULL);
  695. // bad file selection didn't take EXIT
  696. NormalCursor();
  697. break;
  698. }
  699. }
  700. //
  701. // reset preview to new theme (or cur win settings if null)
  702. BuildPreviewBitmap((LPTSTR)szCurThemeFile);
  703. // dis/enable buttons and checkboxes from new global THM file
  704. EnableThemeButtons();
  705. // update preview title
  706. NewSampleTitle();
  707. // cleanup
  708. NormalCursor();
  709. }
  710. else
  711. return (FALSE); // didn't process message EXIT
  712. break;
  713. case PB_SAVE:
  714. #ifdef REVERT
  715. iDlgRet = DialogBox(hInstApp, MAKEINTRESOURCE(DLG_SAVE), hWndApp, SaveAsDlgProc);
  716. if (iDlgRet == -1)
  717. NoMemMsg(STR_TO_SAVE);
  718. #endif
  719. // do the save inline here with common dlg
  720. {
  721. OPENFILENAME ofnSave;
  722. TCHAR szSavedFile[MAX_PATHLEN+1];
  723. LPTSTR lpszTempExt;
  724. extern BOOL bReadOK, bWroteOK;
  725. BOOL fFilenameOk;
  726. // inits
  727. do
  728. {
  729. fFilenameOk = TRUE;
  730. lstrcpy((LPTSTR)szSavedFile, (LPTSTR)szNewFile); // start w/ suggested name
  731. ofnSave.lStructSize = sizeof(OPENFILENAME);
  732. ofnSave.hwndOwner = hdlg;
  733. ofnSave.lpstrFilter = szFileTypeDesc;
  734. ofnSave.lpstrCustomFilter = (LPTSTR)NULL;
  735. ofnSave.nMaxCustFilter = 0;
  736. ofnSave.nFilterIndex = 1;
  737. ofnSave.lpstrFile = szSavedFile;
  738. ofnSave.nMaxFile = ARRAYSIZE(szSavedFile);
  739. ofnSave.lpstrFileTitle = (LPTSTR)NULL; // szFileTitle;
  740. ofnSave.nMaxFileTitle = 0; // sizeof(szFileTitle);
  741. ofnSave.lpstrInitialDir = (LPTSTR)szCurDir;
  742. ofnSave.lpstrTitle = (LPTSTR)szSaveTitle;
  743. ofnSave.Flags = OFN_OVERWRITEPROMPT |
  744. OFN_HIDEREADONLY;
  745. ofnSave.lpstrDefExt = CharNext((LPTSTR)szExt);
  746. // call common dlg
  747. if (!GetSaveFileName((LPOPENFILENAME)&ofnSave)) {
  748. // if they didn't save a file, check for lowmem return
  749. iDlgRet = (int)CommDlgExtendedError();
  750. if ((iDlgRet == CDERR_INITIALIZATION) ||
  751. (iDlgRet == CDERR_MEMALLOCFAILURE) ||
  752. (iDlgRet == CDERR_MEMLOCKFAILURE)
  753. )
  754. NoMemMsg(STR_TO_SAVE);
  755. return (TRUE); // no file to save EXIT
  756. }
  757. //
  758. // process new filename by saving theme to file
  759. // get new cur dir and set global
  760. // if different than cur cur dir, first refill listbox
  761. // enforce extension
  762. lpszTempExt = (LPTSTR)(szSavedFile + lstrlen((LPTSTR)szSavedFile)
  763. - lstrlen((LPTSTR)szExt));
  764. if (2 != CompareString( LOCALE_USER_DEFAULT,
  765. NORM_IGNOREWIDTH | NORM_IGNORECASE,
  766. lpszTempExt, lstrlen((LPTSTR)szExt),
  767. (LPTSTR)szExt, lstrlen((LPTSTR)szExt) )
  768. ) {
  769. // COMMON DLG BUG: since we have a 5-letter extension, we
  770. // sometimes get foo.theme and sometimes (if they type "foo")
  771. // get foo.the. Until that is fixed, here's a decent workaround.
  772. // Strips their ext if they say foo.txt, or foo.bar.
  773. // just get rid of vestigal other ext if any
  774. TruncateExt((LPCTSTR)szSavedFile);
  775. lstrcat((LPTSTR)szSavedFile, (LPTSTR)szExt);
  776. // Because the commond dlg does not handle 5-letter extensions
  777. // properly we need to verify that the file does not already exist
  778. // and if it does make sure the user really wants to overwrite it.
  779. if (FileSpecExists(szSavedFile))
  780. {
  781. TCHAR szTitle[MAX_MSGLEN+1];
  782. TCHAR szText[MAX_PATHLEN+MAX_MSGLEN+1];
  783. TCHAR szTemp[MAX_MSGLEN+1];
  784. // show the file name
  785. LoadString(hInstApp, STR_SAVETITLE, szTitle, MAX_MSGLEN);
  786. lstrcpy(szText, szSavedFile);
  787. // Do you want to replace existing?
  788. LoadString(hInstApp, STR_FILEEXISTS, szTemp, MAX_MSGLEN);
  789. lstrcat(szText, szTemp);
  790. if (IDYES != MessageBox(hdlg, szText, szTitle, MB_YESNO |
  791. MB_ICONEXCLAMATION | MB_DEFBUTTON2))
  792. {
  793. fFilenameOk = FALSE;
  794. }
  795. }
  796. }
  797. } while (!fFilenameOk);
  798. // gather the current windows settings and save them to a THM file
  799. WaitCursor();
  800. GatherThemeToFile(szSavedFile);
  801. NormalCursor();
  802. if (!bWroteOK) {
  803. TCHAR szTemp[MAX_MSGLEN+1];
  804. // out of disk space or some weird file or disk problem
  805. // could be that most saved OK and just one or some a problem?
  806. LoadString(hInstApp, STR_ERRCANTSAVE, (LPTSTR)szTemp, MAX_MSGLEN);
  807. wsprintf((LPTSTR)szMsg, (LPTSTR)szTemp, (LPTSTR)FileFromPath(szSavedFile));
  808. MessageBox((HWND)hWndApp, (LPTSTR)szMsg, (LPTSTR)szAppName,
  809. MB_OK | MB_ICONERROR | MB_APPLMODAL);
  810. break; // couldn't write to file somehow EXIT
  811. }
  812. //
  813. // OK, you have a full pathname of the file that you have
  814. // successfully saved.
  815. //
  816. // You need to look
  817. // at the directory that you saved it in and see if it is different
  818. // than the current directory. If it is, we need to do a whole
  819. // world change: clear out the combobox and refill it, then select
  820. // the new file. If the dir is the same (the common case), we just
  821. // need to select it carefully in the list and update a global or two.
  822. //
  823. // get new dir
  824. lstrcpy((LPTSTR)szMsg, (LPTSTR)szSavedFile);
  825. *(FileFromPath(szMsg)) = 0;
  826. // compare new dir to cur dir
  827. if (!lstrcmp(szMsg, szCurDir)) {
  828. //
  829. // Yes, you are still in the same dir as cur dir
  830. // clean up and add new filename to list in drop-down listbox
  831. lstrcpy((LPTSTR)szMsg, (LPTSTR)FileFromPath(szSavedFile));
  832. TruncateExt((LPCTSTR)szMsg);
  833. // check first if the same name is already there
  834. iDlgRet = (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  835. CB_FINDSTRINGEXACT,
  836. (WPARAM) -1, /* start of list */
  837. (LPARAM)(LPCTSTR)szMsg);
  838. if ((CB_ERR != iDlgRet) && // found the exact string!
  839. !((iDlgRet == 1) && bAppliedOnce) // don't delete 1-index PrevWinSettings
  840. && iDlgRet) { // don't delete 0-index CurWinSettings
  841. // delete the previous
  842. SendDlgItemMessage(hWndApp, DDL_THEME, CB_DELETESTRING,
  843. (WPARAM)iDlgRet, (LPARAM)0);
  844. // get new theme count; ask rather than decrement -- for failsafe
  845. iThemeCount = (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  846. CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  847. }
  848. // do the add
  849. if (CB_ERRSPACE != (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  850. CB_INSERTSTRING,
  851. // add before Other...
  852. // always at least CurWinSet and Other...
  853. // so iThemeCount always >= 2
  854. (WPARAM) iThemeCount - 1,
  855. (LPARAM)(LPCTSTR)szMsg) ) {
  856. // get new theme count; ask rather than increment -- for failsafe
  857. iThemeCount = (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  858. CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  859. // select item just added and save index of selection
  860. iCurTheme = iThemeCount-2; // one less than last 0-based item
  861. SendDlgItemMessage(hWndApp, DDL_THEME,
  862. CB_SETCURSEL, (WPARAM)iCurTheme, (LPARAM)0);
  863. // update cur Theme file name etc to your new one
  864. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szSavedFile);
  865. lstrcpy(szCurThemeName, FileFromPath(szCurThemeFile));
  866. TruncateExt(szCurThemeName);
  867. // update checkboxes
  868. EnableThemeButtons();
  869. }
  870. // else not enuf mem to add new name to DDL; no biggie - already saved
  871. }
  872. else {
  873. //
  874. // You are in a new dir that needs to be made the cur dir
  875. // now reset the DDL with new dir listing and select new file
  876. if (!ResetTheThemeWorld((LPTSTR)szSavedFile)) {
  877. // save away those checkboxes
  878. if (bThemed)
  879. SaveCheckboxes();
  880. // You've cleared the list of themes but can't re-init it.
  881. // prob low mem on adding strs to combobox
  882. DestroyWindow(hdlg);
  883. break; // APOCALYPSE NOW EXIT
  884. }
  885. }
  886. // (don't need to update preview, etc; was "cur settings" or prev same last)
  887. } // end variable scope
  888. break;
  889. case PB_DELETE:
  890. { // var scope
  891. TCHAR szTemp[MAX_MSGLEN+1];
  892. int iret;
  893. HWND hDDL;
  894. // confirm delete cur theme
  895. LoadString(hInstApp, STR_CONFIRM_DEL, (LPTSTR)szTemp, MAX_MSGLEN);
  896. wsprintf((LPTSTR)szMsg, (LPTSTR)szTemp, (LPTSTR)szCurThemeName);
  897. iret = MessageBox((HWND)hWndApp, (LPTSTR)szMsg, (LPTSTR)szAppName,
  898. MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL);
  899. // if they confirmed Yes, Do the evil deed
  900. if (iret == IDYES) {
  901. // do the file deletion
  902. iret = DeleteFile((LPTSTR)szCurThemeFile);
  903. // if successfully disposed of unwanted file
  904. if (iret) {
  905. // get dropdown lb
  906. hDDL = GetDlgItem(hWndApp, DDL_THEME);
  907. // remove name from dropdown lb
  908. SendMessage(hDDL, CB_DELETESTRING,
  909. (WPARAM)iCurTheme, (LPARAM)(LPCTSTR)NULL);
  910. // get new theme count; ask rather than decrement -- for failsafe
  911. iThemeCount = (int) SendMessage(hDDL, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  912. // select first in list: Cur Win Settings
  913. SendMessage(hDDL, CB_SETCURSEL, (WPARAM)0, (LPARAM)(LPCTSTR)NULL);
  914. iCurTheme = 0;
  915. // recurse to catch updated selection
  916. SendMessage(hWndApp, WM_COMMAND, MAKEWPARAM(DDL_THEME, CBN_SELENDOK),
  917. MAKELPARAM(hDDL, 0));
  918. }
  919. // otherwise, inform them that the file was too strong to kill
  920. else {
  921. LoadString(hInstApp, STR_ERRCANTDEL, (LPTSTR)szTemp, MAX_MSGLEN);
  922. wsprintf((LPTSTR)szMsg, (LPTSTR)szTemp, (LPTSTR)szCurThemeName);
  923. MessageBox((HWND)hWndApp, (LPTSTR)szMsg, (LPTSTR)szAppName,
  924. MB_OK | MB_ICONERROR | MB_APPLMODAL);
  925. }
  926. }
  927. } // var scope
  928. break;
  929. case PB_SCRSVR:
  930. { // var scope
  931. extern TCHAR szSS_Section[];
  932. extern TCHAR szSS_Key[];
  933. extern TCHAR szSS_File[];
  934. extern TCHAR szCP_DT[];
  935. extern TCHAR szSS_Active[];
  936. BOOL bScrSaveActive = FALSE;
  937. STARTUPINFO StartupInfo;
  938. PROCESS_INFORMATION ProcessInformation;
  939. // first check if the scr saver is active
  940. if (bThemed) { // get from theme
  941. TCHAR szSSName[MAX_MSGLEN+1];
  942. GetPrivateProfileString((LPTSTR)szSS_Section, (LPTSTR)szSS_Key,
  943. (LPTSTR)szNULL,
  944. (LPTSTR)szSSName, MAX_MSGLEN,
  945. (LPTSTR)szCurThemeFile);
  946. if (*szSSName != TEXT('\0'))
  947. bScrSaveActive = TRUE;
  948. }
  949. else // get from cur system settings
  950. SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,
  951. (LPVOID)&bScrSaveActive, FALSE);
  952. // then continue if active
  953. if (bScrSaveActive) {
  954. // get the theme
  955. if (bThemed) { // get from cur theme file
  956. GetPrivateProfileString((LPTSTR)szSS_Section, (LPTSTR)szSS_Key,
  957. (LPTSTR)szNULL,
  958. (LPTSTR)szMsg, MAX_MSGLEN,
  959. (LPTSTR)szCurThemeFile);
  960. // expand filename string as necessary
  961. InstantiatePath((LPTSTR)szMsg, MAX_MSGLEN);
  962. // search for file if necessary
  963. ConfirmFile((LPTSTR)szMsg, TRUE);
  964. // in this case, if not found shouldn't be here; and just
  965. // won't run below. still need to search, with replacement
  966. }
  967. else { // get from system
  968. GetPrivateProfileString((LPTSTR)szSS_Section, (LPTSTR)szSS_Key,
  969. (LPTSTR)szNULL,
  970. (LPTSTR)szMsg, MAX_MSGLEN,
  971. (LPTSTR)szSS_File);
  972. }
  973. // run it now!
  974. wsprintf(pValue,TEXT("%s /s"), (LPTSTR)szMsg);
  975. // WinExec(pValue, SW_NORMAL);
  976. ZeroMemory(&StartupInfo, sizeof(StartupInfo));
  977. StartupInfo.cb = sizeof(StartupInfo);
  978. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  979. StartupInfo.wShowWindow = (WORD)SW_NORMAL;
  980. CreateProcess(NULL,
  981. pValue,
  982. NULL,
  983. NULL,
  984. FALSE,
  985. 0,
  986. NULL,
  987. NULL,
  988. &StartupInfo,
  989. &ProcessInformation);
  990. }
  991. else {
  992. Assert(0, TEXT("Got scrsaver button push with no active scrsaver!\n"));
  993. }
  994. } // var scope
  995. break;
  996. case PB_POINTERS:
  997. iDlgRet = DoEtcDlgs(hdlg);
  998. if (!iDlgRet)
  999. NoMemMsg(STR_TO_PREVIEW);
  1000. break;
  1001. //
  1002. // check boxes are auto, but need to update preview and Apply button dep on cb states
  1003. case CB_SCHEDULE:
  1004. // Flag that SCHEDULE checkbox changed so Apply gets activated.
  1005. // get controlling checkboxes' current states in bCBStates[]
  1006. SaveCheckboxes();
  1007. // Set the SCHEDULE changed flag.
  1008. bCB_SchedChange = TRUE;
  1009. // Enable the Apply button if appropriate.
  1010. if (bCB_SchedChange) EnableWindow(GetDlgItem(hWndApp, PB_APPLY), TRUE);
  1011. break;
  1012. // these checkboxes affect the "live" preview
  1013. case CB_WALL :
  1014. case CB_ICONS :
  1015. case CB_COLORS :
  1016. case CB_FONTS :
  1017. case CB_BORDERS :
  1018. // get controlling checkboxes' current states in bCBStates[]
  1019. SaveCheckboxes();
  1020. // force new repaint with diff checkboxes
  1021. BuildPreviewBitmap((LPTSTR)szCurThemeFile);
  1022. // fall through for all-checkbox processing
  1023. case CB_SCRSVR :
  1024. case CB_SOUND :
  1025. case CB_PTRS :
  1026. // case CB_ICONSIZE:
  1027. // apply button only enabled if at least one checkbox is checked
  1028. // Note that IsAnyBoxChecked() ignores CB_SCHEDULE.
  1029. EnableWindow(GetDlgItem(hWndApp, PB_APPLY), IsAnyBoxChecked());
  1030. // new checkbox lineup counts as something new
  1031. bNewSelection = TRUE;
  1032. break;
  1033. case IDOK:
  1034. // PLUS98 BUG 1093
  1035. // If we're in a graphics filter we want to ignore this button
  1036. // press -- processing it will fault.
  1037. if (bInGrphFilter) return (FALSE);
  1038. // Has the user toggled the SCHEDULE checkbox?
  1039. // Note this code is duplicated in the PB_APPLY section below.
  1040. if (bCB_SchedChange) {
  1041. if (bCBStates[FC_SCHEDULE]) {
  1042. // We need to add the Themes task to Task Scheduler. Check
  1043. // to see if TS is running.
  1044. if (!IsTaskSchedulerRunning()) {
  1045. // TS isn't running, so start it.
  1046. if (!StartTaskScheduler(TRUE /*prompt user*/)) {
  1047. // Task Scheduler failed to start or the user opted
  1048. // to not start it. STS() already gave an error but
  1049. // we need to uncheck the SCHEDULE cb.
  1050. CheckDlgButton(hdlg, CB_SCHEDULE, BST_UNCHECKED);
  1051. SaveCheckboxes();
  1052. }
  1053. // Task Scheduler started so add Themes task if it doesn't
  1054. // already exist
  1055. else if (!IsThemesScheduled()) {
  1056. GetModuleFileName(hInstApp, (LPTSTR)szThemesExe, MAX_PATH);
  1057. if (!AddThemesTask(szThemesExe, TRUE /*Show errors*/)) {
  1058. //An error occurred adding the task. ATT() already gave
  1059. //user an error. Clear and save CB_SCHEDULE;
  1060. CheckDlgButton(hdlg, CB_SCHEDULE, BST_UNCHECKED);
  1061. SaveCheckboxes();
  1062. }
  1063. // Assume Themes task was added OK
  1064. }
  1065. // Themes.job is already there, so do nothing
  1066. }
  1067. // Assume TS is already running so add our monthly task
  1068. else if (!IsThemesScheduled()) {
  1069. GetModuleFileName(hInstApp, (LPTSTR)szThemesExe, MAX_PATH);
  1070. if (!AddThemesTask(szThemesExe, TRUE /*Show errors*/)) {
  1071. //An error occurred adding the task. ATT() already gave
  1072. //user an error. Clear and save CB_SCHEDULE;
  1073. CheckDlgButton(hdlg, CB_SCHEDULE, BST_UNCHECKED);
  1074. SaveCheckboxes();
  1075. }
  1076. // Assume Themes task was added OK
  1077. }
  1078. // else Themes.job is already there, so do nothing
  1079. }
  1080. // Gotta delete Themes.job but if TS ain't runnin' we can't do that
  1081. // through the TS api.
  1082. else {
  1083. if (IsTaskSchedulerRunning()) DeleteThemesTask();
  1084. else HandDeleteThemesTask();
  1085. }
  1086. bCB_SchedChange = FALSE;
  1087. } // Endif bCB_SchedChange
  1088. // check if anything new since last Apply
  1089. if (!bNewSelection)
  1090. goto NoApplyNeeded;
  1091. // else continue with the apply
  1092. case PB_APPLY:
  1093. // PLUS98 BUG 1093
  1094. // If we're in a graphics filter we want to ignore this button
  1095. // press -- processing it will fault.
  1096. if (bInGrphFilter) return FALSE;
  1097. // Has the user toggled the SCHEDULE checkbox?
  1098. // Note this code is duplicated in the IDOK section above.
  1099. if (bCB_SchedChange) {
  1100. if (bCBStates[FC_SCHEDULE]) {
  1101. // We need to add the Themes task to Task Scheduler. Check
  1102. // to see if TS is running.
  1103. if (!IsTaskSchedulerRunning()) {
  1104. // TS isn't running, so start it.
  1105. if (!StartTaskScheduler(TRUE /*prompt user*/)) {
  1106. // Task Scheduler failed to start or the user opted
  1107. // to not start it. STS() already gave an error but
  1108. // we need to uncheck the SCHEDULE cb.
  1109. CheckDlgButton(hdlg, CB_SCHEDULE, BST_UNCHECKED);
  1110. SaveCheckboxes();
  1111. }
  1112. // Task Scheduler started so add Themes task if it doesn't
  1113. // already exist
  1114. else if (!IsThemesScheduled()) {
  1115. GetModuleFileName(hInstApp, (LPTSTR)szThemesExe, MAX_PATH);
  1116. if (!AddThemesTask(szThemesExe, TRUE /*Show errors*/)) {
  1117. //An error occurred adding the task. ATT() already gave
  1118. //user an error. Clear and save CB_SCHEDULE;
  1119. CheckDlgButton(hdlg, CB_SCHEDULE, BST_UNCHECKED);
  1120. SaveCheckboxes();
  1121. }
  1122. // Assume Themes task was added OK
  1123. }
  1124. // Themes.job is already there, so do nothing
  1125. }
  1126. // Assume TS is already running so add our monthly task
  1127. else if (!IsThemesScheduled()) {
  1128. GetModuleFileName(hInstApp, (LPTSTR)szThemesExe, MAX_PATH);
  1129. if (!AddThemesTask(szThemesExe, TRUE /*Show errors*/)) {
  1130. //An error occurred adding the task. ATT() already gave
  1131. //user an error. Clear and save CB_SCHEDULE;
  1132. CheckDlgButton(hdlg, CB_SCHEDULE, BST_UNCHECKED);
  1133. SaveCheckboxes();
  1134. }
  1135. // Assume Themes task was added OK
  1136. }
  1137. // else Themes.job is already there, so do nothing
  1138. }
  1139. // Gotta delete Themes.job but if TS ain't runnin' we can't do that
  1140. // through the TS api.
  1141. else {
  1142. if (IsTaskSchedulerRunning()) DeleteThemesTask();
  1143. else HandDeleteThemesTask();
  1144. }
  1145. bCB_SchedChange = FALSE;
  1146. } // Endif bCB_SchedChange
  1147. // if there is a theme selected, apply it now
  1148. if (bThemed) {
  1149. // Make sure there is even enough space to do theme
  1150. // Complain, if there is a problem
  1151. if (! CheckSpace (hdlg, TRUE)) // definition in Regutils.c
  1152. break;
  1153. //
  1154. // first, check whether there is a problem with the theme bit depth
  1155. // check for theme BPP vs. system, saved to global bool
  1156. iThemeBPP = GetPrivateProfileInt((LPTSTR)szFrostSection, (LPTSTR)szThemeBPP,
  1157. 0, (LPTSTR)szCurThemeFile);
  1158. hdc = GetDC(NULL);
  1159. iSysBPP = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
  1160. ReleaseDC(NULL, hdc);
  1161. bLowColorProblem = iThemeBPP > iSysBPP;
  1162. // if there is a potential problem, then ask what to do first
  1163. if (bLowColorProblem && !bNeverCheckBPP &&
  1164. ( IsDlgButtonChecked(hdlg, CB_ICONS) ||
  1165. IsDlgButtonChecked(hdlg, CB_COLORS) ) ) {
  1166. iDlgRet = DialogBox(hInstApp, MAKEINTRESOURCE(DLG_BPPCHOICE), hWndApp, BPP_ChoiceDlg);
  1167. if (iDlgRet == -1) {
  1168. NoMemMsg(STR_TO_APPLY);
  1169. break; // low mem EXIT
  1170. }
  1171. if (iDlgRet == IDCANCEL) {
  1172. break; // user chicken EXIT
  1173. }
  1174. }
  1175. // meddle w/ cursor
  1176. WaitCursor();
  1177. // check if color-depth problem and they asked for nothing applied
  1178. if (bLowColorProblem && (fLowBPPFilter == APPLY_NONE))
  1179. break; // chickened out completely no work EXIT
  1180. // get controlling checkboxes' current states in bCBStates[]
  1181. SaveCheckboxes();
  1182. // Now, see if color-depth problem and they asked for just some applied
  1183. if (bLowColorProblem && (fLowBPPFilter == APPLY_SOME)) {
  1184. // apply filter
  1185. bCBStates[FC_PTRS] = FALSE;
  1186. bCBStates[FC_ICONS] = FALSE;
  1187. bCBStates[FC_COLORS] = FALSE;
  1188. RestoreCheckboxes();
  1189. }
  1190. //
  1191. // OK, you're really going to Apply. If this is your first,
  1192. // then save a memory of your virginal state, for user to
  1193. // savor later if desired.
  1194. if (!bAppliedOnce) {
  1195. TCHAR szPrevThemePath[MAX_PATHLEN+1];
  1196. extern BOOL bWroteOK;
  1197. INT_PTR iret;
  1198. // create full pathname of temp file for orig settings
  1199. lstrcpy(szPrevThemePath, szThemeDir);
  1200. lstrcat(szPrevThemePath, szPrevSettingsFilename);
  1201. // save a theme with original windows settings
  1202. GatherThemeToFile(szPrevThemePath);
  1203. // if saved OK
  1204. if (bWroteOK) {
  1205. // add an item to the list for it
  1206. iret = SendDlgItemMessage(hdlg, DDL_THEME, CB_INSERTSTRING,
  1207. (WPARAM)1, (LPARAM)(LPCTSTR)szPrevSettings);
  1208. if (iret != CB_ERRSPACE) {
  1209. // don't care if you actually _apply_ OK; you've added the item
  1210. bAppliedOnce = TRUE;
  1211. // get new ddl index for our current theme
  1212. iCurTheme = (int)SendDlgItemMessage(hWndApp, DDL_THEME,
  1213. CB_FINDSTRINGEXACT, (WPARAM)-1, /* start of list */
  1214. (LPARAM)(LPCTSTR)szCurThemeName);
  1215. // get new theme count; ask rather than increment -- for failsafe
  1216. iThemeCount = (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  1217. CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  1218. }
  1219. // else you couldn't add, just don't get this feature
  1220. }
  1221. // else you never get a prev win settings item this session...
  1222. }
  1223. //
  1224. // apply settings from cur theme file to registry/system
  1225. bRet = ApplyThemeFile((LPTSTR)szCurThemeFile);
  1226. // restore cursor
  1227. NormalCursor();
  1228. // check whether there was any problem applying the theme
  1229. if (!bRet) {
  1230. #if 0 // DavidBa decided it was too irksome to post err to user 4/17/95
  1231. TCHAR szErrStr[MAX_MSGLEN+1];
  1232. TCHAR szFileDispStr[MAX_MSGLEN+1];
  1233. // tell the user there was a problem; but we did our best; keep on trucking
  1234. LoadString(hInstApp, STR_ERRAPPLY, (LPTSTR)szErrStr, MAX_MSGLEN);
  1235. lstrcpy((LPTSTR)szFileDispStr, (LPTSTR)szCurThemeFile);
  1236. TruncateExt((LPTSTR)szFileDispStr);
  1237. wsprintf((LPTSTR)szMsg, (LPTSTR)szErrStr, FileFromPath((LPTSTR)szFileDispStr));
  1238. MessageBox((HWND)hWndApp, (LPTSTR)szMsg, (LPTSTR)szAppName,
  1239. MB_OK | MB_ICONWARNING | MB_APPLMODAL);
  1240. #endif
  1241. }
  1242. // save theme file to "last applied" slot in registry
  1243. if (!((iCurTheme == 1) && bAppliedOnce)) { // don't save PrevWinSettings
  1244. LONG lret;
  1245. HKEY hKey;
  1246. extern TCHAR szPlus_CurTheme[];
  1247. lret = RegOpenKeyEx(HKEY_CURRENT_USER, szPlus_CurTheme,
  1248. (DWORD)0, KEY_SET_VALUE, (PHKEY)&hKey );
  1249. if (lret != ERROR_SUCCESS) {
  1250. DWORD dwDisposition;
  1251. Assert(FALSE, TEXT("couldn't RegOpenKey save theme file\n"));
  1252. lret = RegCreateKeyEx( HKEY_CURRENT_USER, szPlus_CurTheme,
  1253. (DWORD)0, (LPTSTR)szNULL, REG_OPTION_NON_VOLATILE,
  1254. KEY_SET_VALUE, (LPSECURITY_ATTRIBUTES)NULL,
  1255. (PHKEY)&hKey, (LPDWORD)&dwDisposition );
  1256. }
  1257. // if open or create worked
  1258. if (lret == ERROR_SUCCESS) {
  1259. lret = RegSetValueEx(hKey, (LPTSTR)NULL, // default value
  1260. 0,
  1261. (DWORD)REG_SZ,
  1262. (LPBYTE)szCurThemeFile,
  1263. (DWORD)( SZSIZEINBYTES((LPTSTR)szCurThemeFile) + 1 ));
  1264. RegCloseKey(hKey);
  1265. }
  1266. Assert(lret == ERROR_SUCCESS, TEXT("couldn't open, set or create Registry save theme file\n"));
  1267. } // end if not prev settings case
  1268. // reset dirty/etc flags
  1269. bNewSelection = FALSE;
  1270. } // end if bThemed
  1271. SaveStates(); // remember things to registry
  1272. // OK falls through, Apply doesn't
  1273. if ((int)LOWORD(wParam) == PB_APPLY) {
  1274. // Gray the Apply button & make it so it's not the Default button
  1275. EnableWindow(GetDlgItem(hWndApp, PB_APPLY), FALSE);
  1276. SendDlgItemMessage(hWndApp, PB_APPLY, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, MAKELPARAM(TRUE,0));
  1277. // Set Focus to the OK button
  1278. SetFocus(GetDlgItem(hWndApp, IDOK));
  1279. // Make the OK button the Default button
  1280. SendMessage(hWndApp, DM_SETDEFID, IDOK, 0);
  1281. break; // just apply and then EXIT without closing
  1282. }
  1283. // else fall through (from IDOK)
  1284. case IDCANCEL:
  1285. // PLUS98 BUG 1093
  1286. // If we're in a graphics filter we want to ignore this button
  1287. // press -- processing it will fault.
  1288. if (bInGrphFilter) return FALSE;
  1289. // my one unstructured jump in the whole code!
  1290. // From IDOK above only
  1291. NoApplyNeeded:
  1292. // From IDOK above only
  1293. WaitCursor();
  1294. DestroyWindow(hWndApp); // TUBE THE APPLICATION NOW
  1295. if (bAppliedOnce) {
  1296. TCHAR szPrevThemePath[MAX_PATHLEN+1];
  1297. DWORD dwIndex = 0;
  1298. TCHAR szWVFile[MAX_PATH];
  1299. // Delete the previous temp file before we exit
  1300. lstrcpy(szPrevThemePath, szThemeDir);
  1301. lstrcat(szPrevThemePath, szPrevSettingsFilename);
  1302. DeleteFile(szPrevThemePath);
  1303. // Delete any WebView files that were created for the
  1304. // previous theme as well
  1305. for (dwIndex = 0; dwIndex < MAX_WVNAMES; dwIndex++) {
  1306. if (GetWVFilename(szPrevThemePath,
  1307. szWVNames[dwIndex],
  1308. szWVFile)) {
  1309. DeleteFile(szWVFile);
  1310. }
  1311. }
  1312. }
  1313. CloseFrost(); // final cleanups
  1314. NormalCursor();
  1315. break;
  1316. default:
  1317. return (FALSE); // didn't process message EXIT
  1318. break;
  1319. }
  1320. // normal case
  1321. return (TRUE);
  1322. }
  1323. #ifdef USECALLBACKS
  1324. //
  1325. // FileXXXXHookProc
  1326. //
  1327. // Callbacks from the common file open and save dialogs.
  1328. //
  1329. // Return: FALSE to allow standard processing; TRUE to inhibit.
  1330. // (except for WM_INITDIALOG which gets processed first)
  1331. //
  1332. UINT_PTR FAR PASCAL FileOpenHookProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
  1333. {
  1334. switch (msg) {
  1335. case WM_INITDIALOG:
  1336. return (TRUE); // special case
  1337. break;
  1338. case WM_COMMAND:
  1339. // this is where you preprocess the file selection
  1340. if (wparam == IDOK) {
  1341. }
  1342. break;
  1343. default:
  1344. break;
  1345. }
  1346. return (FALSE); // allow standard processing in common dialog
  1347. }
  1348. #endif
  1349. //
  1350. // EnableThemeButtons
  1351. //
  1352. // Utility routine to enable/disable
  1353. // OK
  1354. // Apply
  1355. // Checkboxes
  1356. // SaveAs...
  1357. // Delete
  1358. //
  1359. // Also do the screen saver button
  1360. //
  1361. // There are two cases: you have selected a THM file, or you have selected
  1362. // the "Current Windows settings" item.
  1363. //
  1364. // Uses: global szCurThemeFile to get current THM file
  1365. //
  1366. //#define CBON(x); EnableWindow(GetDlgItem(hWndApp,x),TRUE);CheckDlgButton(hWndApp,x,TRUE);
  1367. #define CBON(x); EnableWindow(GetDlgItem(hWndApp,x),TRUE);
  1368. #define CBOFF(x); EnableWindow(GetDlgItem(hWndApp,x),FALSE);
  1369. void FAR EnableThemeButtons()
  1370. {
  1371. int iCheck;
  1372. //
  1373. // always in any case get scr saver button state updated
  1374. EnableScreenSaverButton();
  1375. // Always in any case enable the SCHEDULE check box
  1376. EnableWindow(GetDlgItem(hWndApp, CB_SCHEDULE), TRUE);
  1377. //
  1378. // null THM file ==> Cur Win Settings
  1379. if (!bThemed) {
  1380. //
  1381. // BUTTONS
  1382. // enable SaveAs button, disable Delete
  1383. EnableWindow(GetDlgItem(hWndApp, PB_SAVE), TRUE);
  1384. EnableWindow(GetDlgItem(hWndApp, PB_DELETE), FALSE);
  1385. // disable OK and Apply buttons
  1386. // EnableWindow(GetDlgItem(hWndApp, IDOK), FALSE); // removed as per davidba 4/95
  1387. EnableWindow(GetDlgItem(hWndApp, PB_APPLY), FALSE);
  1388. //
  1389. // CHECKBOXES: first remember and then just uncheck and disable all
  1390. SaveCheckboxes();
  1391. for (iCheck = 0; iCheck < sizeof(iCBIDs)/sizeof(int); iCheck ++) {
  1392. CBOFF(iCBIDs[iCheck]);
  1393. }
  1394. // Always in any case enable the SCHEDULE check box
  1395. EnableWindow(GetDlgItem(hWndApp, CB_SCHEDULE), TRUE);
  1396. }
  1397. //
  1398. // else normal THM file case
  1399. else {
  1400. // can't do this anymore because also need xtion from/to
  1401. // iCurTheme == 1, PrevWinSettings
  1402. #ifdef OLDCODE
  1403. // first check whether you are already in the normal case!
  1404. if (IsWindowEnabled(GetDlgItem(hWndApp, iCBIDs[0])))
  1405. return; // NO WORK EXIT
  1406. #endif
  1407. //
  1408. // BUTTONS
  1409. // EnableWindow(GetDlgItem(hWndApp, PB_SAVE), TRUE); // as per DB 1/95
  1410. EnableWindow(GetDlgItem(hWndApp, PB_SAVE), FALSE); // as per DB 4/95
  1411. EnableWindow(GetDlgItem(hWndApp, PB_DELETE), TRUE);
  1412. // enable OK and Apply buttons
  1413. // EnableWindow(GetDlgItem(hWndApp, IDOK), TRUE); // as per DB 4.95
  1414. //
  1415. // CHECKBOXES: enable and and then restore checkstates
  1416. for (iCheck = 0; iCheck < sizeof(iCBIDs)/sizeof(int); iCheck ++) {
  1417. CBON(iCBIDs[iCheck]);
  1418. }
  1419. // APPLY BUTTON depends on checkboxes!
  1420. // Note that IsAnyBoxChecked ignores CB_SCHEDULE.
  1421. EnableWindow(GetDlgItem(hWndApp, PB_APPLY), IsAnyBoxChecked());
  1422. }
  1423. //
  1424. // special case:
  1425. // iCurTheme == 1 ==> Prev Win Settings
  1426. if ((iCurTheme == 1) && bAppliedOnce) {
  1427. // disable SaveAs button, disable Delete
  1428. EnableWindow(GetDlgItem(hWndApp, PB_SAVE), FALSE);
  1429. EnableWindow(GetDlgItem(hWndApp, PB_DELETE), FALSE);
  1430. }
  1431. }
  1432. void EnableScreenSaverButton()
  1433. {
  1434. BOOL bScrSaveActive = FALSE;
  1435. extern TCHAR szSS_Section[];
  1436. extern TCHAR szSS_Key[];
  1437. // get scr saver state
  1438. if (bThemed) { // normal theme case
  1439. TCHAR szSSName[MAX_MSGLEN+1];
  1440. GetPrivateProfileString((LPTSTR)szSS_Section, (LPTSTR)szSS_Key,
  1441. (LPTSTR)szNULL,
  1442. (LPTSTR)szSSName, MAX_MSGLEN,
  1443. (LPTSTR)szCurThemeFile);
  1444. if (*szSSName != TEXT('\0'))
  1445. bScrSaveActive = TRUE;
  1446. }
  1447. else // cur win settings case
  1448. SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,
  1449. (LPVOID)&bScrSaveActive, FALSE);
  1450. // with screensaver status, enable scr saver button correctly
  1451. EnableWindow(GetDlgItem(hWndApp, PB_SCRSVR), bScrSaveActive);
  1452. }
  1453. //
  1454. // Just updates the title at the bottom of the preview area with
  1455. // the current theme name.
  1456. //
  1457. void NewSampleTitle(void)
  1458. {
  1459. if (*szCurThemeFile)
  1460. wsprintf((LPTSTR)szMsg, (LPTSTR)szPreviewTitle, (LPTSTR)szCurThemeName);
  1461. else // current windows settings case
  1462. szMsg[0] = 0;
  1463. SetWindowText(GetDlgItem(hWndApp,TEXT_VIEW), (LPTSTR)szMsg);
  1464. }
  1465. BOOL bDontChecked;
  1466. INT_PTR FAR PASCAL BPP_ChoiceDlg(hDlg, message, wParam, lParam)
  1467. HWND hDlg;
  1468. UINT message;
  1469. WPARAM wParam;
  1470. LPARAM lParam;
  1471. {
  1472. switch (message) {
  1473. case WM_INITDIALOG:
  1474. CheckRadioButton(hDlg, RB_ALL, RB_NONE, RB_SOME);
  1475. bDontChecked = FALSE;
  1476. break;
  1477. case WM_COMMAND:
  1478. switch ((int)LOWORD(wParam)) {
  1479. // watch as changes the radio buttons
  1480. case RB_ALL :
  1481. case RB_SOME:
  1482. case RB_NONE:
  1483. if (IsDlgButtonChecked(hDlg, RB_NONE)) {
  1484. // save check state of cbox, before....
  1485. bDontChecked = IsDlgButtonChecked(hDlg, CB_CUT_IT_OUT);
  1486. // ... turning it off and greying it
  1487. CheckDlgButton(hDlg, CB_CUT_IT_OUT, FALSE);
  1488. EnableWindow(GetDlgItem(hDlg, CB_CUT_IT_OUT), FALSE);
  1489. }
  1490. else {
  1491. // if it WAS disabled, enable check box and restore check state
  1492. if (!IsWindowEnabled(GetDlgItem(hDlg, CB_CUT_IT_OUT))) {
  1493. EnableWindow(GetDlgItem(hDlg, CB_CUT_IT_OUT), TRUE);
  1494. if (bDontChecked)
  1495. CheckDlgButton(hDlg, CB_CUT_IT_OUT, TRUE);
  1496. }
  1497. }
  1498. break;
  1499. case IDCANCEL:
  1500. fLowBPPFilter = APPLY_ALL;
  1501. EndDialog(hDlg,IDCANCEL);
  1502. break;
  1503. case IDOK:
  1504. // first, check the never-again checkbox
  1505. if (!IsWindowEnabled(GetDlgItem(hDlg, CB_CUT_IT_OUT)))
  1506. bNeverCheckBPP = FALSE;
  1507. else
  1508. bNeverCheckBPP = IsDlgButtonChecked(hDlg, CB_CUT_IT_OUT);
  1509. // get the apply filter
  1510. if (IsDlgButtonChecked(hDlg, RB_ALL))
  1511. fLowBPPFilter = APPLY_ALL;
  1512. else if (IsDlgButtonChecked(hDlg, RB_SOME))
  1513. fLowBPPFilter = APPLY_SOME;
  1514. else
  1515. fLowBPPFilter = APPLY_NONE;
  1516. EndDialog(hDlg,(int)LOWORD(wParam));
  1517. break;
  1518. default:
  1519. return (FALSE);
  1520. break;
  1521. }
  1522. break;
  1523. default:
  1524. return(FALSE);
  1525. break;
  1526. }
  1527. return TRUE;
  1528. }
  1529. #ifndef UNICODE
  1530. // THIS CODE IS NOT CURRENTLY USED.
  1531. // Standard entry code yanked from runtime libs to avoid having to link those
  1532. // libs. Shrinks binary by a few K.
  1533. int _stdcall ModuleEntry(void)
  1534. {
  1535. int i;
  1536. STARTUPINFO si;
  1537. LPSTR pszCmdLine = GetCommandLine();
  1538. if ( *pszCmdLine == (CHAR)'\"') {
  1539. /*
  1540. * Scan, and skip over, subsequent characters until
  1541. * another double-quote or a null is encountered.
  1542. */
  1543. while ( *++pszCmdLine && (*pszCmdLine
  1544. != (CHAR)'\"') );
  1545. /*
  1546. * If we stopped on a double-quote (usual case), skip
  1547. * over it.
  1548. */
  1549. if ( *pszCmdLine == (CHAR)'\"' )
  1550. pszCmdLine++;
  1551. }
  1552. else {
  1553. while (*pszCmdLine > (CHAR)' ')
  1554. pszCmdLine++;
  1555. }
  1556. /*
  1557. * Skip past any white space preceeding the second token.
  1558. */
  1559. while (*pszCmdLine && (*pszCmdLine <= (CHAR)' ')) {
  1560. pszCmdLine++;
  1561. }
  1562. si.dwFlags = 0;
  1563. GetStartupInfoA(&si);
  1564. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  1565. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  1566. ExitProcess(i);
  1567. return i; // We never comes here.
  1568. }
  1569. #endif
  1570. //
  1571. // Determine if a specified file already exists in the specified path
  1572. //
  1573. BOOL FileSpecExists(LPTSTR szFilename)
  1574. {
  1575. WIN32_FIND_DATA findData;
  1576. HANDLE hFind;
  1577. BOOL fExists = FALSE;
  1578. hFind = FindFirstFile(szFilename, &findData);
  1579. if (hFind != INVALID_HANDLE_VALUE)
  1580. {
  1581. fExists = TRUE; // Something is there
  1582. FindClose(hFind);
  1583. }
  1584. return fExists;
  1585. }