ShellNewDlg.h
上传用户:hy_wanghao
上传日期:2007-01-08
资源大小:279k
文件大小:6k
- #if !defined(AFX_PROPFILE_H__20010103_C70B_4547_8230_0080AD509054__INCLUDED_)
- #define AFX_PROPFILE_H__20010103_C70B_4547_8230_0080AD509054__INCLUDED_
- #pragma once
- #include "Folder.h"
- // The ShellNew wizard.
- //
- // It is a regular ATL dialog implementation.
- // The wizard-look comes from the dialog template, not Windows.
- class CShellNewDlg :
- public CDialogImpl<CShellNewDlg>
- {
- public:
- enum {IDD = IDD_NEWSHELL};
- BEGIN_MSG_MAP(CShellNewDlg)
- MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
- MESSAGE_HANDLER(WM_HSCROLL, OnSizeChange)
- COMMAND_ID_HANDLER(IDOK, OnOk)
- COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
- COMMAND_ID_HANDLER(IDC_ADFFILE, OnChange)
- COMMAND_ID_HANDLER(IDC_HARDDISK, OnChange)
- COMMAND_ID_HANDLER(IDC_PRESETSIZE, OnPresetChange)
- COMMAND_ID_HANDLER(IDC_CUSTOMSIZE, OnChange)
- END_MSG_MAP()
- CResString<64> m_sLabel;
- TCHAR m_szTargetFile[MAX_PATH];
- void _Init(LPCTSTR szTargetName)
- {
- ATLASSERT(szTargetName);
- ATLASSERT(_tcslen(szTargetName)>0);
- m_sLabel.LoadString(IDS_DISKLABEL);
- _tcscpy( m_szTargetFile, szTargetName );
- }
- LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
- {
- CheckDlgButton(IDC_ADFFILE, BST_CHECKED);
- CheckDlgButton(IDC_PRESETSIZE, BST_CHECKED);
- SendDlgItemMessage(IDC_SIZESLIDER, TBM_SETRANGE, FALSE, MAKELONG(1, 9));
- SendDlgItemMessage(IDC_SIZESLIDER, TBM_SETPOS, TRUE, 1);
- SetDlgItemInt(IDC_DISKSIZE, 2, FALSE);
- EnableButtons();
- return 0;
- }
- LRESULT OnOk(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- bool bFloppy = IsDlgButtonChecked(IDC_ADFFILE)==BST_CHECKED;
- bool bHD = IsDlgButtonChecked(IDC_HIGHDENSITY)==BST_CHECKED;
-
- long lSize = GetDlgItemInt(IDC_DISKSIZE, NULL, FALSE);
- bool bFFS = IsDlgButtonChecked(IDC_FFS)==BST_CHECKED;
- bool bInternational = IsDlgButtonChecked(IDC_INTERNATIONAL)==BST_CHECKED;
- bool bCache = IsDlgButtonChecked(IDC_CACHE)==BST_CHECKED;
- bool bBoot = IsDlgButtonChecked(IDC_BOOT)==BST_CHECKED;
- if( !bFloppy ) {
- if( lSize<2 || lSize>2047 ) {
- CResString<64> sCaption(IDS_ERROR);
- CResString<200> sText(IDS_SIZETOOBIG);
- MessageBox(sText, sCaption, MB_ICONWARNING | MB_OK);
- return 0;
- }
- }
- // Before we continue, we would like to have the wait cursor
- ::EnableWindow(GetDlgItem(IDOK), FALSE);
- ::EnableWindow(GetDlgItem(IDCANCEL), FALSE);
- CWaitCursor wait;
- // Get the new device flags
- int iFlags = 0;
- if( bFFS ) iFlags |= FSMASK_FFS;
- if( bInternational ) iFlags |= FSMASK_INTL;
- if( bCache ) iFlags |= FSMASK_DIRCACHE;
- // Create a new harddrive or floppy...
- Device *dev = NULL;
- if( bFloppy ) {
- dev = adfCreateDumpDevice(m_szTargetFile, 80, 2, bHD ? 22 : 11);
- if( dev==NULL ) goto error;
- if( adfCreateFlop(dev, m_sLabel, iFlags)!=RC_OK ) goto error;
- }
- else {
- dev = adfCreateDumpDevice(m_szTargetFile, (lSize*1024*1024)/LOGICAL_BLOCK_SIZE, 1, 1);
- if( dev==NULL ) goto error;
- if( adfCreateHdFile(dev, m_sLabel, iFlags)!=RC_OK ) goto error;
- }
- // Install bootblock
- if( bFloppy && bBoot ) {
- Volume *vol = adfMount(dev, 0, FALSE);
- if( vol==NULL ) goto error;
-
- TCHAR szBootBlockFile[MAX_PATH];
- ::GetModuleFileName(_Module.GetModuleInstance(), szBootBlockFile, MAX_PATH);
- ::PathRemoveFileSpec(szBootBlockFile);
- ::PathAppend(szBootBlockFile, _T("stdboot.bbk"));
- CFile f;
- if( f.Open(szBootBlockFile) ) {
- BYTE bData[1024];
- if( f.Read(bData, 1024) ) {
- adfInstallBootBlock(vol, bData);
- }
- f.Close();
- }
- adfUnMount(vol);
- }
- adfUnMountDev(dev);
- // Let Shell update its display
- ::SHChangeNotify(SHCNE_CREATE, SHCNF_PATH | SHCNF_FLUSH, m_szTargetFile, NULL);
- EndDialog(wID);
- return 0;
- error:
- if( dev!=NULL ) adfUnMountDev(dev);
- ::EnableWindow(GetDlgItem(IDOK), TRUE);
- ::EnableWindow(GetDlgItem(IDCANCEL), TRUE);
- ::MessageBeep(MB_ICONERROR);
- return 0;
- }
- LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- EndDialog(wID);
- return 0;
- }
- LRESULT OnPresetChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
- {
- OnSizeChange(0,0,0,bHandled);
- EnableButtons();
- return 0;
- }
- LRESULT OnChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
- {
- EnableButtons();
- return 0;
- }
- LRESULT OnSizeChange(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
- {
- long lShift = SendDlgItemMessage(IDC_SIZESLIDER, TBM_GETPOS, 0,0);
- long lSize = 1 << lShift;
- SetDlgItemInt(IDC_DISKSIZE, lSize, FALSE);
- return 0;
- }
- void EnableButtons()
- {
- BOOL bFloppy = IsDlgButtonChecked(IDC_ADFFILE)==BST_CHECKED;
- ::EnableWindow(GetDlgItem(IDC_HIGHDENSITY), bFloppy);
- ::EnableWindow(GetDlgItem(IDC_BOOT), bFloppy);
- ::EnableWindow(GetDlgItem(IDC_PRESETSIZE), !bFloppy);
- ::EnableWindow(GetDlgItem(IDC_CUSTOMSIZE), !bFloppy);
- BOOL bPresetSize = IsDlgButtonChecked(IDC_PRESETSIZE)==BST_CHECKED;
- ::EnableWindow(GetDlgItem(IDC_SIZESLIDER), !bFloppy && bPresetSize);
- SendDlgItemMessage(IDC_DISKSIZE, EM_SETREADONLY, (!bFloppy && !bPresetSize)==FALSE, 0);
-
- ::EnableWindow(GetDlgItem(IDOK), TRUE);
- ::EnableWindow(GetDlgItem(IDCANCEL), TRUE);
- }
- };
- #endif // !defined(AFX_PROPFILE_H__20010103_C70B_4547_8230_0080AD509054__INCLUDED_)