Index: trunk/ab5.0/abdev/abdev/Common.h
===================================================================
--- trunk/ab5.0/abdev/abdev/Common.h	(revision 691)
+++ trunk/ab5.0/abdev/abdev/Common.h	(revision 697)
@@ -345,4 +345,23 @@
 };
 
+struct FILEIDENTITY{
+	DWORD VolumeSerialNumber;
+	DWORD FileIndexHigh;
+	DWORD FileIndexLow;
+};
+
+inline bool IsFileIdentityValid(FILEIDENTITY const& fi){
+	return fi.VolumeSerialNumber != 0
+		&& fi.FileIndexHigh != 0
+		&& fi.FileIndexLow != 0;
+}
+
+inline bool operator ==(FILEIDENTITY const& lhs, FILEIDENTITY const& rhs)
+{
+	return lhs.VolumeSerialNumber == rhs.VolumeSerialNumber
+		&& lhs.FileIndexHigh == rhs.FileIndexHigh
+		&& lhs.FileIndexLow == rhs.FileIndexLow;
+}
+
 struct MDIINFO{
 	HWND hwnd;
@@ -350,4 +369,5 @@
 	std::string title;
 	std::string path;
+	FILEIDENTITY FileIdentity;
 
 	union{
@@ -577,5 +597,5 @@
 void ResetState_DocMenu(void);
 void DuplicateTitleCheck(char *lpszTitle);
-HWND NewTextEditWindow(char *filepath,_int8 DocumentType,COLORREF TabColor=TABCOLOR_GRAY);
+HWND NewTextEditWindow(char const *filepath,_int8 DocumentType,COLORREF TabColor=TABCOLOR_GRAY);
 void CloseDocWindow(int WndNum);
 void ResizeTextEditWnd(HWND hwnd,int cx,int cy);
Index: trunk/ab5.0/abdev/abdev/FileOperation.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/FileOperation.cpp	(revision 691)
+++ trunk/ab5.0/abdev/abdev/FileOperation.cpp	(revision 697)
@@ -298,5 +298,5 @@
 
 	// TODO:
-	char *OpenFileName = const_cast<char *>(filePath.c_str());
+	char const *OpenFileName = filePath.c_str();
 
 	i=GetFileExtension(OpenFileName);
Index: trunk/ab5.0/abdev/abdev/abdev.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/abdev.cpp	(revision 691)
+++ trunk/ab5.0/abdev/abdev/abdev.cpp	(revision 697)
@@ -3,4 +3,7 @@
 #include "abdev.h"
 
+#ifdef _DEBUG
+#include <crtdbg.h>
+#endif
 
 #if defined HeapAlloc
@@ -731,5 +734,13 @@
 	}
 }
-HWND NewTextEditWindow(char *filepath,_int8 DocumentType,COLORREF TabColor)
+
+//たぶんこれでは全然足りない
+inline void PathNormalize(char *buf, size_t bufSize, const char *path)
+{
+	DWORD shortFilepathLen = GetShortPathName(path, buf, bufSize);
+	std::replace(buf, buf + shortFilepathLen, '/', '\\');
+}
+
+HWND NewTextEditWindow(const char *filepath,_int8 DocumentType,COLORREF TabColor)
 {
 	int i;
@@ -739,13 +750,47 @@
 	int iCharCode=NKF_SHIFT_JIS;
 	int iLfCode=LFCODE_CRLF;
+	FILEIDENTITY fileIdentity = {0};
 
 	if(filepath){
+		HANDLE hFile=CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
+		if(hFile==INVALID_HANDLE_VALUE){
+			sprintf(str,STRING_ERROR_CANT_FILEOPEN,filepath);
+			::MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
+			return 0;
+		}
+		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;
+			length=fi.nFileSizeLow;
+		}
+		else{
+			length=GetFileSize(hFile,NULL);
+		}
 
 		//すでに指定されたファイルが開かれている場合
 		hChild=::GetWindow(hClient,GW_CHILD);
+		char shortFilepath[MAX_PATH];
+		PathNormalize(shortFilepath, MAX_PATH, filepath);
 		while(hChild){
 			i=GetWndNum(hChild);
 			if(IS_DOCUMENT_TEXT(MdiInfo[i]->DocType)){
-				if(lstrcmpi(MdiInfo[i]->path.c_str(),filepath)==0) break;
+				if(IsFileIdentityValid(fileIdentity)&&IsFileIdentityValid(MdiInfo[i]->FileIdentity)
+					&& fileIdentity==MdiInfo[i]->FileIdentity)
+				{
+					break;
+				}
+				else{
+					char shortPathnameDoc[MAX_PATH];
+					PathNormalize(shortPathnameDoc, MAX_PATH, MdiInfo[i]->path.c_str());
+					if(_strcmpi(shortFilepath,shortPathnameDoc)==0)
+						break;
+				}
 			}
 			hChild=::GetNextWindow(hChild,GW_HWNDNEXT);
@@ -761,14 +806,4 @@
 		//ファイル読み込み（正常に読み込めるかの確認も含む）
 		//////////////////////////////////////////////////////
-
-		HANDLE hFile;
-		hFile=CreateFile(filepath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
-		if(hFile==INVALID_HANDLE_VALUE){
-			sprintf(str,STRING_ERROR_CANT_FILEOPEN,filepath);
-			::MessageBox(hOwner,str,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
-			return 0;
-		}
-		int length;
-		length=GetFileSize(hFile,NULL);
 
 		char *temp;
@@ -882,5 +917,5 @@
 
 	mdic.style |= WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
-	hChild=(HWND)SendMessage(hClient,WM_MDICREATE,0,(long)&mdic);	//ウィンドウ作成
+	hChild=(HWND)SendMessage(hClient,WM_MDICREATE,0,reinterpret_cast<LPARAM>(&mdic));	//ウィンドウ作成
 
 	//TextEditorコントロールを設置
@@ -893,40 +928,42 @@
 
 	//ウィンドウのID登録
-	MdiInfo.push_back( new MDIINFO() );
+	MDIINFO *pmi = new MDIINFO();
+	MdiInfo.push_back( pmi );
 	i = MdiInfo.size()-1;
-	MdiInfo[i]->hwnd=hChild;
-	MdiInfo[i]->DocType=DocumentType;
+	pmi->hwnd=hChild;
+	pmi->DocType=DocumentType;
 	DuplicateTitleCheck(str);
-	MdiInfo[i]->title = str;
+	pmi->title = str;
+	pmi->FileIdentity = fileIdentity;
 	if(filepath)
 	{
-		MdiInfo[i]->path = filepath;
+		pmi->path = filepath;
 	}
 	else
 	{
-		MdiInfo[i]->path = "";
-	}
-
-	MdiInfo[i]->pMdiTextEdit = new CMdiTextEdit( MdiInfo[i] );
-
-	MdiInfo[i]->pMdiTextEdit->hEdit=hEdit;
-	MdiInfo[i]->pMdiTextEdit->pobj_WebResult=new CWebResult(hChild);
-	MdiInfo[i]->pMdiTextEdit->pobj_Ruler=new CRuler(hChild,MdiInfo[i]);
-	MdiInfo[i]->pMdiTextEdit->hIcon=shfi.hIcon;
-	MdiInfo[i]->pMdiTextEdit->buffer=buffer;
-	MdiInfo[i]->pMdiTextEdit->pColorRef=(COLORREF *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(COLORREF)*lstrlen(buffer));
-	MdiInfo[i]->pMdiTextEdit->iUnderStart=-1;
-	MdiInfo[i]->pMdiTextEdit->iUnderEnd=-1;
-	MdiInfo[i]->pMdiTextEdit->StartCaretPos.x=0;
-	MdiInfo[i]->pMdiTextEdit->StartCaretPos.y=0;
-	MdiInfo[i]->pMdiTextEdit->EndCaretPos.x=0;
-	MdiInfo[i]->pMdiTextEdit->EndCaretPos.y=0;
-	MdiInfo[i]->pMdiTextEdit->Temp_UpDown_CaretXPos=-1;
-	MdiInfo[i]->pMdiTextEdit->bAutoScroll=0;
-	MdiInfo[i]->pMdiTextEdit->iWidth_ControlTabSpace=
-		GetControlTabSpace(i,&MdiInfo[i]->pMdiTextEdit->iLineNumberTextCount);
-	MdiInfo[i]->pMdiTextEdit->iCharCode=iCharCode;
-	MdiInfo[i]->pMdiTextEdit->iLfCode=iLfCode;
-	MdiInfo[i]->IndentStr=0;
+		pmi->path = "";
+	}
+
+	pmi->pMdiTextEdit = new CMdiTextEdit( MdiInfo[i] );
+
+	pmi->pMdiTextEdit->hEdit=hEdit;
+	pmi->pMdiTextEdit->pobj_WebResult=new CWebResult(hChild);
+	pmi->pMdiTextEdit->pobj_Ruler=new CRuler(hChild,pmi);
+	pmi->pMdiTextEdit->hIcon=shfi.hIcon;
+	pmi->pMdiTextEdit->buffer=buffer;
+	pmi->pMdiTextEdit->pColorRef=(COLORREF *)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,sizeof(COLORREF)*lstrlen(buffer));
+	pmi->pMdiTextEdit->iUnderStart=-1;
+	pmi->pMdiTextEdit->iUnderEnd=-1;
+	pmi->pMdiTextEdit->StartCaretPos.x=0;
+	pmi->pMdiTextEdit->StartCaretPos.y=0;
+	pmi->pMdiTextEdit->EndCaretPos.x=0;
+	pmi->pMdiTextEdit->EndCaretPos.y=0;
+	pmi->pMdiTextEdit->Temp_UpDown_CaretXPos=-1;
+	pmi->pMdiTextEdit->bAutoScroll=0;
+	pmi->pMdiTextEdit->iWidth_ControlTabSpace=
+		GetControlTabSpace(i,&pmi->pMdiTextEdit->iLineNumberTextCount);
+	pmi->pMdiTextEdit->iCharCode=iCharCode;
+	pmi->pMdiTextEdit->iLfCode=iLfCode;
+	pmi->IndentStr=0;
 
 
@@ -1453,5 +1490,8 @@
 	return RegisterClassEx(&wcl);
 }
-int PASCAL WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int ShowCmd){
+int PASCAL WinMain(HINSTANCE hThisInst,HINSTANCE,LPSTR lpCmdLine,int ShowCmd){
+#ifdef _DEBUG
+	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+#endif
 	int i,i2,IsStr;
 	char str[MAX_PATH],str2[MAX_PATH],dummy[1024];
Index: trunk/ab5.0/abdev/abdev/include/MainFrame.h
===================================================================
--- trunk/ab5.0/abdev/abdev/include/MainFrame.h	(revision 691)
+++ trunk/ab5.0/abdev/abdev/include/MainFrame.h	(revision 697)
@@ -34,5 +34,5 @@
 
 	// 生成された
-	::LRESULT OnCreate( ::UINT msg, ::WPARAM wParam, ::LPARAM lParam, ::BOOL& handled );
+	::LRESULT OnCreate( ::CREATESTRUCT const* );
 
 	// OSが終了する
@@ -255,5 +255,5 @@
 	// メッセージマップ
 	BEGIN_MSG_MAP( MainFrame )
-		MESSAGE_HANDLER( WM_CREATE, OnCreate )
+		MSG_WM_CREATE( OnCreate )
 		MSG_WM_SIZE( OnSize )
 		MSG_WM_QUERYENDSESSION( OnQueryEndSession )
Index: trunk/ab5.0/abdev/abdev/include/ProjectManager/ProjectManager.h
===================================================================
--- trunk/ab5.0/abdev/abdev/include/ProjectManager/ProjectManager.h	(revision 691)
+++ trunk/ab5.0/abdev/abdev/include/ProjectManager/ProjectManager.h	(revision 697)
@@ -14,5 +14,5 @@
 	}
 
-	void Load( char *path );
+	void Load( char const *path );
 	void Save();
 	bool Close();
Index: trunk/ab5.0/abdev/abdev/src/MainFrame.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/src/MainFrame.cpp	(revision 691)
+++ trunk/ab5.0/abdev/abdev/src/MainFrame.cpp	(revision 697)
@@ -171,5 +171,5 @@
 }
 
-::LRESULT MainFrame::OnCreate( ::UINT msg, ::WPARAM wParam, ::LPARAM lParam, ::BOOL& handled )
+::LRESULT MainFrame::OnCreate( ::CREATESTRUCT const* )
 {
 	// ウィンドウエリアマネージャに親ウィンドウを登録
@@ -207,5 +207,5 @@
 	extern WNDPROC oldMainFrameWndProc;
 	oldMainFrameWndProc = (WNDPROC)::GetWindowLong( hOwner, GWL_WNDPROC );
-	::SetWindowLong( hOwner, GWL_WNDPROC, (LONG)WindowFunc );
+	::SetWindowLongPtr( hOwner, GWL_WNDPROC, reinterpret_cast<LONG_PTR>(WindowFunc) );
 
 	SetupWindow(hOwner);
@@ -517,5 +517,5 @@
 void MainFrame::OnDropFiles( HDROP hDropInfo )
 {
-	int max = DragQueryFile(hDropInfo,-1,0,0);
+	int max = DragQueryFile(hDropInfo,static_cast<DWORD>(-1),0,0);
 	for(int i=0;i<max;i++){
 		char temporary[1024];
@@ -526,5 +526,5 @@
 }
 
-void MainFrame::OnPaint( HDC dummy )
+void MainFrame::OnPaint( HDC )
 {
 	PAINTSTRUCT ps;
@@ -1096,5 +1096,5 @@
 void CreateProcessWithStdHandle( const std::string &appPath, const std::string &cmdLine)
 {
-	std::string argsStr = (std::string)"\"" + appPath + "\" " + cmdLine;
+	std::string argsStr = "\"" + appPath + "\" " + cmdLine;
 	STARTUPINFO si;
 	PROCESS_INFORMATION pi;
@@ -1143,7 +1143,7 @@
 
 		if(IsNeedCompileForProject(1))
-			sprintf(temporary,"\"%s\" \"%s\" /debug /run /wnd:%08x",temp2,temp3,m_hWnd);
+			sprintf(temporary,"\"%s\" \"%s\" /debug /run /wnd:%p",temp2,temp3,m_hWnd);
 		else
-			sprintf(temporary,"\"%s\" \"%s\" /run /wnd:%08x",temp2,temp3,m_hWnd);
+			sprintf(temporary,"\"%s\" \"%s\" /run /wnd:%p",temp2,temp3,m_hWnd);
 
 		// DLLオプション
@@ -1169,7 +1169,7 @@
 		if(!SetRunning(hChild)) return;
 		if(IsNeedCompile(MdiInfo[GetWndNum(hChild)]->path,1))
-			sprintf(temporary,"\"%s\" /debug /run /wnd:%08x",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
+			sprintf(temporary,"\"%s\" /debug /run /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
 		else
-			sprintf(temporary,"\"%s\" /run /wnd:%08x",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
+			sprintf(temporary,"\"%s\" /run /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
 
 		//ブレークポイントをセーブ
@@ -1220,5 +1220,5 @@
 		lstrcpy( temp3, projectInfo.GetWorkDir().GetFullPath( temp3 ).c_str() );
 
-		sprintf(temporary,"\"%s\" \"%s\" /debug /wnd:%08x",temp2,temp3,m_hWnd);
+		sprintf(temporary,"\"%s\" \"%s\" /debug /wnd:%p",temp2,temp3,m_hWnd);
 
 		//DLLオプション
@@ -1240,5 +1240,5 @@
 		//単独ソースコード
 		if(!SetRunning(hChild)) return;
-		sprintf(temporary,"\"%s\" /debug /wnd:%08x",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
+		sprintf(temporary,"\"%s\" /debug /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
 	}
 
@@ -1282,5 +1282,5 @@
 	if(idProcess==0) return;
 
-	sprintf(temporary,"/attach:%08x /wnd:%08x",idProcess,m_hWnd);
+	sprintf(temporary,"/attach:%08x /wnd:%p",idProcess,m_hWnd);
 
 	//コンパイルビューをクリップするかどうか
@@ -1340,5 +1340,5 @@
 		lstrcpy( temp3, projectInfo.GetWorkDir().GetFullPath( temp3 ).c_str() );
 
-		sprintf(temporary,"\"%s\" \"%s\" /wnd:%08x",temp2,temp3,m_hWnd);
+		sprintf(temporary,"\"%s\" \"%s\" /wnd:%p",temp2,temp3,m_hWnd);
 
 		//DLLオプション
@@ -1360,5 +1360,5 @@
 		//単独ソースコード
 		if(!SetRunning(hChild)) return;
-		sprintf(temporary,"\"%s\" /wnd:%08x",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
+		sprintf(temporary,"\"%s\" /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd);
 	}
 
@@ -1707,5 +1707,4 @@
 		{
 			HWND hChild=::GetWindow(hClient,GW_CHILD);
-			int WndNum=GetWndNum(hChild);
 
 			TC_ITEM tcItem;
Index: trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp	(revision 691)
+++ trunk/ab5.0/abdev/abdev/src/ProjectManager/ProjectManager.cpp	(revision 697)
@@ -5,5 +5,5 @@
 void OpenWorkfile( const std::string &path );
 
-void Project::Load( char *path )
+void Project::Load( char const *path )
 {
 	extern HANDLE hHeap;
