Index: trunk/ab5.0/abdev/abdev/Common.h
===================================================================
--- trunk/ab5.0/abdev/abdev/Common.h	(revision 698)
+++ trunk/ab5.0/abdev/abdev/Common.h	(revision 700)
@@ -949,5 +949,5 @@
 void GetItemClassName(char *buffer,int Control);
 void SaveWindowProgram();
-void SaveWindowFile( char *path, const ActiveBasic::PM::WindowInfos &windowInfos );
+void SaveWindowFile(char const *path, const ActiveBasic::PM::WindowInfos &windowInfos);
 _int8 OpenWindowFile(char *path);
 void GetDefaultWindowFont(LOGFONT *LogFont);
Index: trunk/ab5.0/abdev/abdev/FileOperation.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/FileOperation.cpp	(revision 698)
+++ trunk/ab5.0/abdev/abdev/FileOperation.cpp	(revision 700)
@@ -16,4 +16,7 @@
 			return;
 		}
+	}
+	else{
+		FindClose(hFind);
 	}
 }
@@ -334,5 +337,34 @@
 	return NewTextEditWindow(OpenFileName,DocumentType,TabColor);
 }
+
+BOOL GetFileInformationByHandleWrap(HANDLE hFile, BY_HANDLE_FILE_INFORMATION& fi){
+	typedef BOOL WINAPI GFIBH(HANDLE, LPBY_HANDLE_FILE_INFORMATION);
+	GFIBH *const pgfibh = reinterpret_cast<GFIBH*>(
+		GetProcAddress(GetModuleHandle("kernel32"), "GetFileInformationByHandle"));
+	if(pgfibh){
+		return pgfibh(hFile, &fi);
+	}
+	else{
+		SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+		return FALSE;
+	}
+}
+
+//重複チェック用のデータを設定
+void SetFileIdentity(FILEIDENTITY &fi, BY_HANDLE_FILE_INFORMATION const &bhfi){
+	fi.VolumeSerialNumber = bhfi.dwVolumeSerialNumber;
+	fi.FileIndexHigh = bhfi.nFileIndexHigh;
+	fi.FileIndexLow = bhfi.nFileIndexLow;
+}
+
+void SetFileIdentityFromFile(MDIINFO &mi, HANDLE hFile){
+	BY_HANDLE_FILE_INFORMATION fi;
+	if(GetFileInformationByHandleWrap(hFile, fi)){
+		SetFileIdentity(mi.FileIdentity, fi);
+	}
+}
+
 BOOL SaveDocument(HWND hChild,char *SaveFileName){	//ウィンドウからバッファを読み取り、ファイルに保存
+	//SaveFileNameがNULLのときは上書き保存を試みる。
 	extern LPSTR IconFileFilter;
 	extern HWND hClient,hDocCombo;
@@ -344,6 +376,5 @@
 	WndNum=GetWndNum(hChild);
 
-	char szOldTitle[MAX_PATH];
-	lstrcpy(szOldTitle,MdiInfo[WndNum]->title.c_str());
+	std::string oldTitle = MdiInfo[WndNum]->title;
 
 	if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD||MdiInfo[WndNum]->DocType==WNDTYPE_MENU){
@@ -353,6 +384,12 @@
 
 		if(projectInfo.ModifyOfMaterial){
-			sprintf(temporary,"%s%s.wnd",projectInfo.GetWorkDir().GetPath().c_str(),projectInfo.GetName().c_str());
-			SaveWindowFile( temporary, projectInfo.windowInfos );
+			std::string const& workDir = projectInfo.GetWorkDir().GetPath();
+			std::string const& projName = projectInfo.GetName();
+			std::string t;
+			t.reserve( workDir.size() + projName.size() + 4 );
+			t += workDir;
+			t += projName;
+			t += ".wnd";
+			SaveWindowFile( t.c_str(), projectInfo.windowInfos );
 
 			//.wbpファイルを生成
@@ -370,5 +407,4 @@
 				sprintf(str,STRING_FILE_OVERWRIDE,temporary);
 				if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
-					CloseHandle(fh);
 					return 0;
 				}
@@ -377,5 +413,5 @@
 
 			//ドキュメント セレクト コンボボックスから消去
-			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum]->title.c_str());
+			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
 			SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
 
@@ -387,6 +423,6 @@
 			lstrcat(str,str2);
 			MdiInfo[WndNum]->title = str;
-			SendMessage(hDocCombo,CB_ADDSTRING,0,(long)MdiInfo[WndNum]->title.c_str());
-			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum]->title.c_str());
+			SendMessage(hDocCombo,CB_ADDSTRING,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
+			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
 			SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
 
@@ -448,5 +484,6 @@
 			return 0;
 		}
-		WriteFile(fh,pBuf,lstrlen(pBuf),&dummy,NULL);
+		WriteFile(fh,pBuf,strlen(pBuf),&dummy,NULL);
+		SetFileIdentityFromFile(*MdiInfo[WndNum], fh);
 		CloseHandle(fh);
 
@@ -473,11 +510,11 @@
 			CloseHandle(fh);
 			MdiInfo[WndNum]->path = temporary;
-			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum]->title.c_str());
+			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
 			SendMessage(hDocCombo,CB_DELETESTRING,i2,0);
 			_splitpath(temporary,NULL,NULL,str,str2);
 			lstrcat(str,str2);
 			MdiInfo[WndNum]->title = str;
-			SendMessage(hDocCombo,CB_ADDSTRING,0,(long)MdiInfo[WndNum]->title.c_str());
-			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(long)MdiInfo[WndNum]->title.c_str());
+			SendMessage(hDocCombo,CB_ADDSTRING,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
+			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
 			SendMessage(hDocCombo,CB_SETCURSEL,i2,0);
 			SetWindowText(hChild,MdiInfo[WndNum]->title.c_str());
@@ -501,10 +538,10 @@
 	if(pobj_nv->bSaveTabToHead){
 		COLORREF color;
-		color=pobj_MainTab->GetItemColor(szOldTitle);
-		pobj_MainTab->DeleteItem( szOldTitle, false );
+		color=pobj_MainTab->GetItemColor(oldTitle.c_str());
+		pobj_MainTab->DeleteItem( oldTitle.c_str(), false );
 		pobj_MainTab->InsertItem( MdiInfo[WndNum]->title.c_str(), false, color );
 	}
 	else{
-		pobj_MainTab->RenameItem( szOldTitle, MdiInfo[WndNum]->title.c_str() );
+		pobj_MainTab->RenameItem( oldTitle.c_str(), MdiInfo[WndNum]->title.c_str() );
 	}
 
Index: trunk/ab5.0/abdev/abdev/IconEditor.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/IconEditor.cpp	(revision 698)
+++ trunk/ab5.0/abdev/abdev/IconEditor.cpp	(revision 700)
@@ -446,4 +446,6 @@
 	ResetState_DocMenu();
 }
+void SetFileIdentityFromFile(MDIINFO &mi, HANDLE hFile);
+
 void SaveIconFile(char *filepath,HWND hwnd){
 	int i,i2,WndNum;
@@ -526,4 +528,5 @@
 	}
 	WriteFile(hFile,buffer,i2,&dummy,NULL);
+	SetFileIdentityFromFile(*MdiInfo[WndNum], hFile);
 	CloseHandle(hFile);
 }
Index: trunk/ab5.0/abdev/abdev/TabCtrl.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/TabCtrl.cpp	(revision 698)
+++ trunk/ab5.0/abdev/abdev/TabCtrl.cpp	(revision 700)
@@ -234,8 +234,8 @@
 }
 
-COLORREF CMainTab::GetItemColor( char *ItemText ){
+COLORREF CMainTab::GetItemColor( char const *ItemText ){
 	//インデックスを取得
 	int index = SearchItemIndex( ItemText );
-	if( index == -1 ) return -1;
+	if( index == -1 ) return static_cast<COLORREF>(-1);
 
 	TC_ITEM tcItem;
Index: trunk/ab5.0/abdev/abdev/TabCtrl.h
===================================================================
--- trunk/ab5.0/abdev/abdev/TabCtrl.h	(revision 698)
+++ trunk/ab5.0/abdev/abdev/TabCtrl.h	(revision 700)
@@ -37,5 +37,5 @@
 	void NofityUnModifyDocument( const char *ItemText );
 
-	COLORREF GetItemColor( char *ItemText );
+	COLORREF GetItemColor( char const *ItemText );
 
 	void SelChangeEvent();
Index: trunk/ab5.0/abdev/abdev/WindowControl.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/WindowControl.cpp	(revision 698)
+++ trunk/ab5.0/abdev/abdev/WindowControl.cpp	(revision 700)
@@ -1653,5 +1653,5 @@
 	return i2;
 }
-void SaveWindowFile( char *path, const ActiveBasic::PM::WindowInfos &windowInfos )
+void SaveWindowFile( char const *path, const ActiveBasic::PM::WindowInfos &windowInfos )
 {
 	extern HANDLE hHeap;
Index: trunk/ab5.0/abdev/abdev/abdev.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/abdev.cpp	(revision 698)
+++ trunk/ab5.0/abdev/abdev/abdev.cpp	(revision 700)
@@ -739,6 +739,10 @@
 {
 	DWORD shortFilepathLen = GetShortPathName(path, buf, bufSize);
+	CharUpper(buf);
 	std::replace(buf, buf + shortFilepathLen, '/', '\\');
 }
+
+BOOL GetFileInformationByHandleWrap(HANDLE hFile, BY_HANDLE_FILE_INFORMATION& fi);
+void SetFileIdentity(FILEIDENTITY &mi, BY_HANDLE_FILE_INFORMATION const &bhfi);
 
 HWND NewTextEditWindow(const char *filepath,_int8 DocumentType,COLORREF TabColor)
@@ -761,12 +765,7 @@
 		DWORD length;
 
-		typedef BOOL WINAPI GFIBH(HANDLE, LPBY_HANDLE_FILE_INFORMATION);
 		BY_HANDLE_FILE_INFORMATION fi;
-		GFIBH *const pgfibh = reinterpret_cast<GFIBH*>(
-			GetProcAddress(GetModuleHandle("kernel32"), "GetFileInformationByHandle"));
-		if(pgfibh && pgfibh(hFile, &fi)){
-			fileIdentity.VolumeSerialNumber = fi.dwVolumeSerialNumber;
-			fileIdentity.FileIndexHigh = fi.nFileIndexHigh;
-			fileIdentity.FileIndexLow = fi.nFileIndexLow;
+		if(GetFileInformationByHandleWrap(hFile, fi)){
+			SetFileIdentity(fileIdentity, fi);
 			length=fi.nFileSizeLow;
 		}
@@ -807,6 +806,5 @@
 		//////////////////////////////////////////////////////
 
-		char *temp;
-		temp=(char *)HeapAlloc(hHeap,0,length+1);
+		char *temp=(char *)HeapAlloc(hHeap,0,length+1);
 		DWORD dw;
 		ReadFile(hFile,temp,length,&dw,NULL);
