home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include "FMain.h"
- #include "UPTShellUtils.hpp"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "UPTShellControls"
- #pragma link "UPTTreeList"
- #pragma resource "*.dfm"
- TfrmMain *frmMain;
- //---------------------------------------------------------------------------
- __fastcall TfrmMain::TfrmMain(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::MakeNewFile()
- {
- static int FileNumber = 0;
- try {
- PTShellList1->Options = PTShellList1->Options >> ptsloDynamicRefresh;
- // We will handle the refreshing ourselves, so turn off automatic mode for now.
-
- FCreatingFile = true;
- // This flag is checked in the OnInsert event handler.
-
- FileNumber++;
- // Give the file a unique number.
-
- FNewFileName = Uptshellutils::EnsureTrailingCharDB(PTShellList1->Folder->PathName,'\\') +
- "NewFile"+IntToStr(FileNumber);
- // EnsureTrailingCharDB is a double-byte safe function that makes sure the last character
- // in the string is the passed character '\' in this case. Most folders don't end with a '\',
- // but root drive folders (c:\) do. Using this function we can get the path name into a
- // consistent format to which we can append the file name.}
-
- ShowMessage( FNewFileName );
-
- delete( new TFileStream(FNewFileName, fmCreate | fmOpenWrite | fmShareDenyNone) );
- // Create the new file stream, free it straight away. This will create an empty file.
-
- if (IsWin95() && PTShellList1->Folder->IdList == NULL)
- Sleep(2000);
- // Under Windows 95 (and variants) the desktop virtual folder is very slow in registering the
- // presence of the new file.
-
- PTShellList1->RefreshItems();
- // Before this returns, the OnInsert item will be called 1..n times.
-
- FCreatingFile = false;
- PTShellList1->Options = PTShellList1->Options << ptsloDynamicRefresh;
- }
- catch(...) {
- FCreatingFile = false;
- PTShellList1->Options = PTShellList1->Options << ptsloDynamicRefresh;
- throw;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::PTShellList1Insert(TObject *Sender,
- TListItem *Item)
- {
- if (FCreatingFile &&
- AnsiCompareFileName(PTShellList1->GetDataFromItem(Item)->PathName, FNewFileName)==0 )
- {
- Item->MakeVisible(false);
- // Make the item fully visible.
-
- Item->EditCaption();
-
- FCreatingFile = false;
- // Since we only added one file, we don't need to check any more.
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmMain::btnCreateClick(TObject *Sender)
- {
- MakeNewFile();
- }
- //---------------------------------------------------------------------------
-