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.

151 lines
4.8 KiB

  1. /* SAVEDLG.C
  2. Resident Code Segment // Tweak: make non-resident?
  3. Routines for Save Theme As dialog
  4. Frosting: Master Theme Selector for Windows '95
  5. Copyright (c) 1994-1999 Microsoft Corporation. All rights reserved.
  6. */
  7. // ---------------------------------------------
  8. // Brief file history:
  9. // Alpha:
  10. // Beta:
  11. // Bug fixes
  12. // ---------
  13. //
  14. // ---------------------------------------------
  15. #include "windows.h"
  16. #include "frost.h"
  17. #include "global.h"
  18. // Local Routines
  19. BOOL ValidateFilename(LPTSTR);
  20. INT_PTR FAR PASCAL SaveAsDlgProc(hDlg, message, wParam, lParam)
  21. HWND hDlg;
  22. UINT message;
  23. WPARAM wParam;
  24. LPARAM lParam;
  25. {
  26. switch (message) {
  27. case WM_INITDIALOG:
  28. // set max length for new theme name
  29. SendDlgItemMessage(hDlg, EC_THEME, EM_LIMITTEXT,
  30. (WPARAM)(MAX_PATHLEN-5), (LPARAM)0);
  31. // suggest a name for the new saved theme
  32. if (LoadString(hInstApp, STR_SUGGEST, szMsg, MAX_STRLEN))
  33. SetDlgItemText(hDlg, EC_THEME, (LPTSTR)szMsg);
  34. break;
  35. case WM_COMMAND:
  36. switch ((int)LOWORD(wParam)) {
  37. // watch as changes the edit control
  38. case EC_THEME:
  39. if (HIWORD(wParam) == EN_CHANGE) {
  40. // if changed, enable OK iff nonzero length filename
  41. EnableWindow(GetDlgItem(hDlg, IDOK),
  42. (BOOL) SendMessage((HWND)LOWORD(lParam),
  43. WM_GETTEXTLENGTH,
  44. (WPARAM)0, (LPARAM)0) );
  45. }
  46. else return (FALSE); // didn't really process msg EXIT
  47. break;
  48. // OK to go ahead and save the current settings as a new theme
  49. case IDOK:
  50. { // local variable scope
  51. TCHAR szNewFile[MAX_PATHLEN+1];
  52. // get new filename
  53. GetDlgItemText(hDlg, EC_THEME, (LPTSTR)szNewFile, MAX_PATHLEN-4);
  54. lstrcat((LPTSTR)szNewFile, (LPTSTR)szExt);
  55. // check whether they gave valid filename: chars + length
  56. if (!ValidateFilename((LPTSTR)szNewFile)) {
  57. // bad file: post message and put them back in save dlg
  58. /// *** DEBUG *** add messagebox here......................
  59. break; // couldn't use name EXIT
  60. }
  61. // gather the current windows settings and save them to a THM file
  62. WaitCursor();
  63. if (!GatherThemeToFile((LPTSTR)szNewFile)) {
  64. // out of disk space or some weird file or disk problem
  65. // *** DEBUG *** add messagebox here......................
  66. // could be that most saved OK and just one or some a problem?
  67. NormalCursor();
  68. break; // couldn't write to file somehow EXIT
  69. }
  70. NormalCursor();
  71. // clean up and add new filename to list in drop-down listbox
  72. lstrcpy((LPTSTR)szMsg, (LPTSTR)szNewFile);
  73. TruncateExt((LPCTSTR)szMsg);
  74. if (CB_ERRSPACE != (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  75. CB_INSERTSTRING,
  76. (WPARAM) -1, /* end of list */
  77. (LPARAM)(LPCTSTR)szMsg) ) {
  78. // get new theme count; ask rather than increment -- for failsafe
  79. iThemeCount = (int) SendDlgItemMessage(hWndApp, DDL_THEME,
  80. CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
  81. // select item just added and save index of selection
  82. iCurTheme = iThemeCount-1;
  83. SendDlgItemMessage(hWndApp, DDL_THEME,
  84. CB_SETCURSEL, (WPARAM)iCurTheme, (LPARAM)0);
  85. // update cur Theme file name to your new one
  86. lstrcpy((LPTSTR)szCurThemeFile, (LPTSTR)szThemeDir);
  87. lstrcat((LPTSTR)szCurThemeFile, (LPTSTR)szNewFile);
  88. // update checkboxes
  89. EnableThemeButtons();
  90. }
  91. // else not enuf mem to add new name to DDL; no biggie - already saved
  92. // (don't need to update preview, etc; was "cur settings" or prev same last)
  93. } // variable scope
  94. /* fall through */
  95. case IDCANCEL:
  96. EndDialog(hDlg,(int)LOWORD(wParam));
  97. break;
  98. default:
  99. return (FALSE);
  100. break;
  101. }
  102. break;
  103. default:
  104. return(FALSE);
  105. break;
  106. }
  107. return TRUE;
  108. }
  109. //
  110. // ValidateFilename
  111. // Check that this file and the current directory path together make
  112. // a valid filename.
  113. // Check for total length, legals chars, etc.
  114. //
  115. BOOL ValidateFilename(LPTSTR lpszFilename)
  116. {
  117. // first check for length
  118. if (lstrlen((LPTSTR)lpszFilename) + lstrlen((LPTSTR)szThemeDir) > MAX_PATHLEN)
  119. return (FALSE); // too long for Win95! EXIT
  120. // do ultimate test of name validity with openfile check
  121. // cleanup
  122. return (TRUE);
  123. }