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.

129 lines
3.0 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. #include "pch.hxx" // pch
  3. #pragma hdrstop
  4. #include "resource.h"
  5. #include "pgSveFil.h"
  6. CSaveToFilePg::CSaveToFilePg(
  7. LPPROPSHEETPAGE ppsp
  8. ) : WizardPage(ppsp, IDS_WIZSAVETOFILETITLE, IDS_WIZSAVETOFILESUBTITLE)
  9. {
  10. m_dwPageId = IDD_WIZSAVETOFILE;
  11. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  12. }
  13. CSaveToFilePg::~CSaveToFilePg(
  14. VOID
  15. )
  16. {
  17. }
  18. LRESULT
  19. CSaveToFilePg::OnInitDialog(
  20. HWND hwnd,
  21. WPARAM wParam,
  22. LPARAM lParam
  23. )
  24. {
  25. UpdateControls();
  26. return 1;
  27. }
  28. void CSaveToFilePg::UpdateControls()
  29. {
  30. // No options
  31. }
  32. LRESULT
  33. CSaveToFilePg::OnCommand(
  34. HWND hwnd,
  35. WPARAM wParam,
  36. LPARAM lParam
  37. )
  38. {
  39. LRESULT lResult = 1;
  40. WORD wNotifyCode = HIWORD(wParam);
  41. WORD wCtlID = LOWORD(wParam);
  42. HWND hwndCtl = (HWND)lParam;
  43. switch(wCtlID)
  44. {
  45. case IDC_BTNBROWSE:
  46. {
  47. // These commands require us to re-enable/disable the appropriate controls
  48. TCHAR szBuf[_MAX_PATH];
  49. TCHAR szBuf2[_MAX_PATH];
  50. TCHAR szDefaultName[_MAX_PATH];
  51. LoadString(g_hInstDll, IDS_DEFAULTSAVEFILENAME, szDefaultName, ARRAYSIZE(szDefaultName));
  52. TCHAR szFilterName[_MAX_PATH];
  53. TCHAR szTemp[_MAX_PATH];
  54. ZeroMemory(szFilterName, _MAX_PATH);
  55. LoadString(g_hInstDll, IDS_FILTERNAME, szFilterName, ARRAYSIZE(szFilterName));
  56. LoadString(g_hInstDll, IDS_FILTER, szTemp, ARRAYSIZE(szTemp));
  57. // Copy the extension to after the filter name
  58. lstrcpy(&szFilterName[lstrlen(szFilterName) + 1], szTemp);
  59. // Double NULL terminate it
  60. szFilterName[lstrlen(szFilterName) + 1 + lstrlen(szTemp) + 1] = 0;
  61. szFilterName[lstrlen(szFilterName) + 1 + lstrlen(szTemp) + 2] = 0;
  62. memset(szBuf, 0, ARRAYSIZE(szBuf));
  63. memset(szBuf2, 0, ARRAYSIZE(szBuf));
  64. wsprintf(szBuf, szDefaultName);
  65. OPENFILENAME ofn;
  66. memset(&ofn, 0, sizeof(ofn));
  67. ofn.lStructSize = sizeof(ofn);
  68. ofn.hwndOwner = m_hwnd;
  69. ofn.hInstance = g_hInstDll;
  70. ofn.lpstrFilter = szFilterName;
  71. ofn.lpstrCustomFilter = NULL;
  72. ofn.nMaxCustFilter = 0;
  73. ofn.nFilterIndex = 0;
  74. ofn.lpstrFile = szBuf;
  75. ofn.nMaxFile = _MAX_PATH;
  76. ofn.lpstrFileTitle = szBuf2;
  77. ofn.nMaxFileTitle = _MAX_PATH;
  78. ofn.lpstrInitialDir = NULL;
  79. ofn.lpstrTitle = NULL;
  80. ofn.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  81. ofn.nFileOffset = 0;
  82. ofn.nFileExtension = 0;
  83. ofn.lpstrDefExt = __TEXT("acw");
  84. ofn.lCustData = NULL;
  85. ofn.lpfnHook = NULL;
  86. ofn.lpTemplateName = NULL;
  87. BOOL bOk = GetSaveFileName(&ofn);
  88. if(bOk)
  89. {
  90. // Save the file to disk.
  91. HANDLE hFile = CreateFile(ofn.lpstrFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  92. if(hFile != INVALID_HANDLE_VALUE)
  93. {
  94. DWORD dwWritten;
  95. WriteFile(hFile, (LPCVOID)&g_Options.m_schemePreview, sizeof(g_Options.m_schemePreview), &dwWritten, NULL);
  96. CloseHandle(hFile);
  97. // TODO: Maybe go to the next page
  98. }
  99. else
  100. StringTableMessageBox(m_hwnd, IDS_WIZERRORSAVINGFILETEXT, IDS_WIZERRORSAVINGFILETITLE, MB_OK);
  101. }
  102. UpdateControls();
  103. lResult = 0;
  104. }
  105. break;
  106. default:
  107. break;
  108. }
  109. return lResult;
  110. }