Index: trunk/ab5.0/abdev/abdev/Debugger.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/Debugger.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/Debugger.cpp	(revision 705)
@@ -485,5 +485,4 @@
 	}
 
-	HANDLE hFile;
 	char temporary[MAX_PATH];
 	GetTempPath(MAX_PATH,temporary);
@@ -494,8 +493,11 @@
 	sprintf(temporary,"%sab_breakpoint.tmp",pj_editor_Dir);
 
-	hFile=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL);
+	ATL::CHandle hFile(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL));
+	if(hFile==INVALID_HANDLE_VALUE){
+		hFile.Detach();
+		return;
+	}
 	DWORD dwAccBytes;
 	WriteFile(hFile,buffer,lstrlen(buffer),&dwAccBytes,NULL);
-	CloseHandle(hFile);
 
 	HeapDefaultFree(buffer);
Index: trunk/ab5.0/abdev/abdev/DocumentAdvice.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/DocumentAdvice.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/DocumentAdvice.cpp	(revision 705)
@@ -186,7 +186,7 @@
 			if(i3==MdiInfo.size()){
 				//ファイルから開く
-				HANDLE fh;
-				fh=CreateFile(temporary,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+				ATL::CHandle fh(CreateFile(temporary,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
 				if(fh==INVALID_HANDLE_VALUE){
+					fh.Detach();
 					goto finish;
 				}
@@ -198,5 +198,4 @@
 				temp3[FileSize]=0;
 
-				CloseHandle(fh);
 			}
 			else{
Index: trunk/ab5.0/abdev/abdev/FileOperation.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/FileOperation.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/FileOperation.cpp	(revision 705)
@@ -27,8 +27,8 @@
 	DWORD dw;
 	char *buffer,temporary[MAX_PATH];
-	HANDLE hFile;
-
-	hFile=CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+
+	ATL::CHandle hFile(CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
 	if(hFile==INVALID_HANDLE_VALUE){
+		hFile.Detach();
 		//"\"%s\" ファイルの読み込みに失敗しました。"
 		sprintf(temporary,STRING_ERROR_CANT_FILEOPEN,path.c_str());
@@ -41,31 +41,29 @@
 	ReadFile(hFile,buffer,i,&dw,0);
 	buffer[dw]=0;
-	CloseHandle(hFile);
 	return buffer;
 }
 char *ReadBuffer_NonErrMsg( const std::string &path ){
 	extern HANDLE hHeap;
-	int i;
 	DWORD dw;
-	char *buffer;
-	HANDLE hFile;
-
-	hFile=CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	if(hFile==INVALID_HANDLE_VALUE) return 0;
-	i=GetFileSize(hFile,0);
-	buffer=(char *)HeapAlloc(hHeap,0,i+1);
+
+	ATL::CHandle hFile(CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+	if(hFile==INVALID_HANDLE_VALUE){
+		hFile.Detach();
+		return 0;
+	}
+	int i=GetFileSize(hFile,0);
+	char *buffer=(char *)HeapAlloc(hHeap,0,i+1);
 	ReadFile(hFile,buffer,i,&dw,0);
 	buffer[dw]=0;
-	CloseHandle(hFile);
 	return buffer;
 }
 _int8 WriteBuffer(const std::string &path,const char *buffer,int length, bool isEnableError)
 {
-	HANDLE hFile;
 	DWORD dw;
-	hFile=CreateFile(path.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+	ATL::CHandle hFile(CreateFile(path.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL));
 	if(hFile==INVALID_HANDLE_VALUE){
+		hFile.Detach();
+
 		char temporary[MAX_PATH];
-
 		if( isEnableError ){
 			//"\"%s\" ファイルへの書き込みに失敗しました。"
@@ -76,5 +74,4 @@
 	}
 	if(length) WriteFile(hFile,buffer,length,&dw,NULL);
-	CloseHandle(hFile);
 	return 1;
 }
@@ -371,5 +368,4 @@
 	int WndNum,i2;
 	char temporary[MAX_PATH],str[MAX_PATH],str2[32];
-	HANDLE fh;
 	DWORD dummy;
 
@@ -404,11 +400,14 @@
 		if(SaveFileName){
 			lstrcpy(temporary,SaveFileName);
-			if((fh=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE){
-				sprintf(str,STRING_FILE_OVERWRIDE,temporary);
-				if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
-					return 0;
+			{
+				ATL::CHandle fh(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL));
+				if(fh==INVALID_HANDLE_VALUE){
+					fh.Detach();
+					sprintf(str,STRING_FILE_OVERWRIDE,temporary);
+					if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
+						return 0;
+					}
 				}
 			}
-			CloseHandle(fh);
 
 			//ドキュメント セレクト コンボボックスから消去
@@ -478,13 +477,15 @@
 		////////////////////////
 
-		fh=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
-		if(fh==INVALID_HANDLE_VALUE){
-			sprintf(str,STRING_ERROR_CANT_FILESAVE,temporary);
-			MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONSTOP);
-			return 0;
-		}
-		WriteFile(fh,pBuf,strlen(pBuf),&dummy,NULL);
-		SetFileIdentityFromFile(*MdiInfo[WndNum], fh);
-		CloseHandle(fh);
+		{
+			ATL::CHandle fh(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL));
+			if(fh==INVALID_HANDLE_VALUE){
+				fh.Detach();
+				sprintf(str,STRING_ERROR_CANT_FILESAVE,temporary);
+				MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONSTOP);
+				return 0;
+			}
+			WriteFile(fh,pBuf,strlen(pBuf),&dummy,NULL);
+			SetFileIdentityFromFile(*MdiInfo[WndNum], fh);
+		}
 
 
@@ -501,12 +502,14 @@
 		if(SaveFileName){
 			lstrcpy(temporary,SaveFileName);
-			if((fh=CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))==INVALID_HANDLE_VALUE){
-				sprintf(str,STRING_FILE_OVERWRIDE,temporary);
-				if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
-					CloseHandle(fh);
-					return 0;
+			{
+				ATL::CHandle fh(CreateFile(temporary,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL));
+				if(fh==INVALID_HANDLE_VALUE){
+					fh.Detach();
+					sprintf(str,STRING_FILE_OVERWRIDE,temporary);
+					if(MessageBox(hOwner,str,APPLICATION_NAME,MB_YESNO|MB_ICONINFORMATION)==IDNO){
+						return 0;
+					}
 				}
 			}
-			CloseHandle(fh);
 			MdiInfo[WndNum]->path = temporary;
 			i2=SendMessage(hDocCombo,CB_FINDSTRINGEXACT,0,(LONG_PTR)MdiInfo[WndNum]->title.c_str());
Index: trunk/ab5.0/abdev/abdev/FileTree.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/FileTree.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/FileTree.cpp	(revision 705)
@@ -11,5 +11,4 @@
 	int i;
 	char temporary[MAX_PATH];
-	HANDLE hFile;
 	FILETIME LastWriteTime,LocalTime;
 	SYSTEMTIME SystemTime;
@@ -31,6 +30,7 @@
 
 				//最終更新日時を表示
-				hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+				ATL::CHandle hFile(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
 				if(hFile==INVALID_HANDLE_VALUE){
+					hFile.Detach();
 					//"エラー"
 					lstrcpy(temporary,STRING_ERROR);
@@ -54,5 +54,4 @@
 						SystemTime.wHour,SystemTime.wMinute,SystemTime.wSecond,
 						SystemTime.wYear,SystemTime.wMonth,SystemTime.wDay);
-					CloseHandle(hFile);
 				}
 				SetDlgItemText(hwnd,IDC_UPDATE_TIME,temporary);
Index: trunk/ab5.0/abdev/abdev/IconEditor.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/IconEditor.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/IconEditor.cpp	(revision 705)
@@ -263,17 +263,18 @@
 
 		//ファイル読み込み（正常に読み込めるかの確認も含む）
-		HANDLE hFile;
-		DWORD dw;
-		hFile=CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-		if(hFile==INVALID_HANDLE_VALUE){
-			//"\"%s\" ファイルの読み込みに失敗しました。"
-			sprintf(str,STRING_ERROR_CANT_FILEOPEN,filepath);
-			MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
-			return;
-		}
-		i=GetFileSize(hFile,NULL);
-		buffer=(char *)HeapAlloc(hHeap,0,i+1);
-		ReadFile(hFile,buffer,i,&dw,NULL);
-		CloseHandle(hFile);
+		{
+			DWORD dw;
+			ATL::CHandle hFile(CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+			if(hFile==INVALID_HANDLE_VALUE){
+				hFile.Detach();
+				//"\"%s\" ファイルの読み込みに失敗しました。"
+				sprintf(str,STRING_ERROR_CANT_FILEOPEN,filepath);
+				MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
+				return;
+			}
+			i=GetFileSize(hFile,NULL);
+			buffer=(char *)HeapAlloc(hHeap,0,i+1);
+			ReadFile(hFile,buffer,i,&dw,NULL);
+		}
 
 		ICONDIR *pIconDir;
@@ -518,8 +519,8 @@
 
 	//ファイルへ書き込み
-	HANDLE hFile;
 	DWORD dummy;
-	hFile=CreateFile(filepath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+	ATL::CHandle hFile(CreateFile(filepath,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL));
 	if(hFile==INVALID_HANDLE_VALUE){
+		hFile.Detach();
 		//"\"%s\" ファイルへの書き込みに失敗しました。"
 		sprintf(temporary,STRING_ERROR_CANT_FILESAVE,filepath);
@@ -529,5 +530,4 @@
 	WriteFile(hFile,buffer,i2,&dummy,NULL);
 	SetFileIdentityFromFile(*MdiInfo[WndNum], hFile);
-	CloseHandle(hFile);
 }
 
Index: trunk/ab5.0/abdev/abdev/ProjectControl.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/ProjectControl.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/ProjectControl.cpp	(revision 705)
@@ -827,11 +827,10 @@
 	//保存
 	sprintf(temporary,"%s%s.pj",dir,NewProjectInfo.name);
-	if(hFind=FindFirstFile(temporary,&wfd)){
-		if(hFind!=INVALID_HANDLE_VALUE){
-			FindClose(hFind);
-
-			//"指定したディレクトリにはすでにプロジェクトが存在します。上書きしますか？"
-			if(MessageBox(hOwner,STRING_ERROR_PROJECT_OVERWRITE,APPLICATION_NAME,MB_YESNO|MB_ICONEXCLAMATION)==IDNO) return;
-		}
+	hFind=FindFirstFile(temporary,&wfd);
+	if(hFind!=INVALID_HANDLE_VALUE){
+		FindClose(hFind);
+
+		//"指定したディレクトリにはすでにプロジェクトが存在します。上書きしますか？"
+		if(MessageBox(hOwner,STRING_ERROR_PROJECT_OVERWRITE,APPLICATION_NAME,MB_YESNO|MB_ICONEXCLAMATION)==IDNO) return;
 	}
 	if(!WriteBuffer(temporary,buffer,i)) return;
@@ -1812,8 +1811,9 @@
 	BOOST_FOREACH( const ActiveBasic::PM::FM::File &file, folder.files )
 	{
-		HANDLE hFile=CreateFile(file.GetFullPath().c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
 		FILETIME sourceTime;
-		GetFileTime(hFile,NULL,NULL,&sourceTime);
-		CloseHandle(hFile);
+		{
+			ATL::CHandle hFile(CreateFile(file.GetFullPath().c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+			GetFileTime(hFile,NULL,NULL,&sourceTime);
+		}
 
 		if(sourceTime.dwHighDateTime>exeTime.dwHighDateTime||
@@ -1827,5 +1827,5 @@
 BOOL IsNeedCompileForProject(BOOL bDebug){
 	char temporary[MAX_PATH];
-	HANDLE hFind,hFile;
+	HANDLE hFind;
 	WIN32_FIND_DATA wfd;
 	FILETIME SourceTime,ExeTime;
@@ -1839,7 +1839,8 @@
 	FindClose(hFind);
 
-	hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	GetFileTime(hFile,NULL,NULL,&ExeTime);
-	CloseHandle(hFile);
+	{
+		ATL::CHandle hFile(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+		GetFileTime(hFile,NULL,NULL,&ExeTime);
+	}
 
 	if( IsNeedCompileForProject( projectInfo.fileSystem.root, ExeTime ) )
@@ -1852,7 +1853,8 @@
 		lstrcpy(temporary,"CallBack.wbp");
 		lstrcpy( temporary, projectInfo.GetWorkDir().GetFullPath( temporary ).c_str() );
-		hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-		GetFileTime(hFile,NULL,NULL,&SourceTime);
-		CloseHandle(hFile);
+		{
+			ATL::CHandle hFile(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+			GetFileTime(hFile,NULL,NULL,&SourceTime);
+		}
 		if(SourceTime.dwHighDateTime>ExeTime.dwHighDateTime||
 			SourceTime.dwHighDateTime==ExeTime.dwHighDateTime&&
@@ -1862,7 +1864,8 @@
 		lstrcpy(temporary,"MakeWindow.wbp");
 		lstrcpy( temporary, projectInfo.GetWorkDir().GetFullPath( temporary ).c_str() );
-		hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-		GetFileTime(hFile,NULL,NULL,&SourceTime);
-		CloseHandle(hFile);
+		{
+			ATL::CHandle hFile(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+			GetFileTime(hFile,NULL,NULL,&SourceTime);
+		}
 		if(SourceTime.dwHighDateTime>ExeTime.dwHighDateTime||
 			SourceTime.dwHighDateTime==ExeTime.dwHighDateTime&&
Index: trunk/ab5.0/abdev/abdev/SubOperation.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/SubOperation.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/SubOperation.cpp	(revision 705)
@@ -1001,16 +1001,17 @@
 	//256色の標準パレットを読み込む
 	extern RGBQUAD DefaultColorTable256[256];
-	HANDLE hFile;
-	DWORD dw;
 	const std::string pltPath = ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\8bit.plt";
-	hFile=CreateFile(pltPath.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	if(hFile==INVALID_HANDLE_VALUE){
-		//"\"%s\" ファイルの読み込みに失敗しました。"
-		sprintf(str,STRING_ERROR_CANT_FILEOPEN,temporary);
-		MessageBox(NULL,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
-		return 0;
-	}
-	ReadFile(hFile,DefaultColorTable256,sizeof(RGBQUAD)*256,&dw,NULL);
-	CloseHandle(hFile);
+	{
+		ATL::CHandle hFile(CreateFile(pltPath.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+		if(hFile==INVALID_HANDLE_VALUE){
+			hFile.Detach();
+			//"\"%s\" ファイルの読み込みに失敗しました。"
+			sprintf(str,STRING_ERROR_CANT_FILEOPEN,temporary);
+			MessageBox(NULL,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
+			return 0;
+		}
+		DWORD dw;
+		ReadFile(hFile,DefaultColorTable256,sizeof(RGBQUAD)*256,&dw,NULL);
+	}
 
 
@@ -1267,5 +1268,5 @@
 {
 	char temporary[MAX_PATH],temp2[MAX_PATH],temp3[MAX_PATH];
-	HANDLE hFind,hFile;
+	HANDLE hFind;
 	WIN32_FIND_DATA wfd;
 	FILETIME SourceTime,ExeTime;
@@ -1281,11 +1282,12 @@
 	FindClose(hFind);
 
-	hFile=CreateFile(filepath.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	GetFileTime(hFile,NULL,NULL,&SourceTime);
-	CloseHandle(hFile);
-
-	hFile=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	GetFileTime(hFile,NULL,NULL,&ExeTime);
-	CloseHandle(hFile);
+	{
+		CHandle hFile(CreateFile(filepath.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+		GetFileTime(hFile,NULL,NULL,&SourceTime);
+	}
+	{
+		CHandle hFile(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+		GetFileTime(hFile,NULL,NULL,&ExeTime);
+	}
 
 	if(SourceTime.dwHighDateTime<ExeTime.dwHighDateTime) return 0;
Index: trunk/ab5.0/abdev/abdev/abdev.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/abdev.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/abdev.cpp	(revision 705)
@@ -757,6 +757,7 @@
 
 	if(filepath){
-		HANDLE hFile=CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+		ATL::CHandle hFile(CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
 		if(hFile==INVALID_HANDLE_VALUE){
+			hFile.Detach();
 			sprintf(str,STRING_ERROR_CANT_FILEOPEN,filepath);
 			::MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
@@ -809,5 +810,4 @@
 		DWORD dw;
 		ReadFile(hFile,temp,length,&dw,NULL);
-		CloseHandle(hFile);
 		for(i=0;i<length;i++){
 			if(temp[i]=='\0') temp[i]=' ';
Index: trunk/ab5.0/abdev/abdev/include/WindowComponents/MdiChild.h
===================================================================
--- trunk/ab5.0/abdev/abdev/include/WindowComponents/MdiChild.h	(revision 700)
+++ trunk/ab5.0/abdev/abdev/include/WindowComponents/MdiChild.h	(revision 705)
@@ -20,5 +20,5 @@
     END_MSG_MAP()
 
-    LRESULT OnCreate(LPCREATESTRUCT lpcs){
+    LRESULT OnCreate(LPCREATESTRUCT){
         SetMsgHandled(false);
         return 1;
Index: trunk/ab5.0/abdev/abdev/src/MainFrame.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/src/MainFrame.cpp	(revision 700)
+++ trunk/ab5.0/abdev/abdev/src/MainFrame.cpp	(revision 705)
@@ -549,9 +549,13 @@
 	//エラー部分を反転表示
 	DWORD AccBytes;
-	HANDLE fh;
-	sprintf(temporary,"%spgm.tmp",pj_editor_Dir);
-	fh=CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-	ReadFile(fh,temporary,MAX_PATH,&AccBytes,NULL);
-	CloseHandle(fh);
+	{
+		sprintf(temporary,"%spgm.tmp",pj_editor_Dir);
+		ATL::CHandle fh(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL));
+		if(fh==INVALID_HANDLE_VALUE){
+			fh.Detach();
+			return 0;
+		}
+		ReadFile(fh,temporary,MAX_PATH,&AccBytes,NULL);
+	}
 	temporary[AccBytes]=0;
 	HWND hChild=::GetWindow(hClient,GW_CHILD);
@@ -1111,4 +1115,6 @@
 
 	CreateProcess( NULL, args, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi );
+	CloseHandle( pi.hProcess );
+	CloseHandle( pi.hThread );
 }
 
@@ -1130,8 +1136,14 @@
 		sprintf(temporary,"%s\r\n%s",projectInfo.szExePath,projectInfo.szCmdLine);
 		sprintf(temp2,"%spgm.tmp",pj_editor_Dir);
-		HANDLE hFile=CreateFile(temp2,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL);
-		DWORD dwAccessBytes;
-		WriteFile(hFile,temporary,lstrlen(temporary),&dwAccessBytes,NULL);
-		CloseHandle(hFile);
+		{
+			ATL::CHandle hFile(CreateFile(temp2,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL));
+			if(hFile==INVALID_HANDLE_VALUE){
+				hFile.Detach();
+				MessageBox(TEXT("デバッグ用ファイルを開けませんでした。"));
+				return;
+			}
+			DWORD dwAccessBytes;
+			WriteFile(hFile,temporary,lstrlen(temporary),&dwAccessBytes,NULL);
+		}
 
 		//ソースファイル名をtemp2へ
