How to verify if a document is already open
Ari Villaca -- villaca@correionet.com.br
Saturday, January 18, 1997
Environment: MSVC 4.0/Win95
How can I use the filename parameter of the CWinApp::OpenDocumentFile(
LPCTSTR lpszFileName ) to verify if the related document is already opene=
d?
I need to make sure that short and long filenames are verifyed.
For example, if I have Test1.XXX opened, the file verification routine=20
should return TRUE for both C:\WorkSpace\Test1.XXX and
C:\WorkSp~1\Test1.XXX filenames.=20
Regards,
Ari
-------------------------------------------------------------------------=
---
-
Ari de Moura Villa=E7a
e-Mail: villaca@correionet.com.br
Av. Moraes Sales, 987 Apto.113 fone: +55 19 232-2440
13010-001 - Campinas, SP fax: +55 19 232-2440
Brasil
-------------------------------------------------------------------------=
---
Tim Hagemann -- Tim@way2.net
Tuesday, January 21, 1997
Ari,
you can do this by processing all document templates and all documents =
of this templates in a nested loop:
CYourApp::CheckIfLoaded(const char *f_Path)
{
POSITION l_tempPos,l_docPos;
for (l_tempPos =3D GetFirstDocTemplatePosition();l_tempPoss !=3D NULL;)
{
CDocumentTemplate *l_DocTempl =3D GetNextDocTemplate(l_tempPos)
for (l_docPos =3D l_DocTempl->GetFirstDocPosition();l_docPos !=3D =
NULL;)
{
CDocument* l_Doc =3D l_DocTempl->GetNextDoc(l_docPos);
ASSERT(l_Doc);
if (l_Doc->GetPathName =3D=3D f_Path) return TRUE;
}
}
return FALSE;
}
(I typed the code in my Mail Program - no compiler has ever seen it...)
I'm not sure about the long / short filenames. I my opinion, you only =
have to check for the long filename, cause this is the one used in =
Win32.
Tim Hagemann
ifa informationssysteme GmbH
Tim Hagemann -- Tim@way2.net
Tuesday, January 21, 1997
Ari,
you can do this by processing all document templates and all documents =
of this templates in a nested loop:
CYourApp::CheckIfLoaded(const char *f_Path)
{
POSITION l_tempPos,l_docPos;
for (l_tempPos =3D GetFirstDocTemplatePosition();l_tempPoss !=3D NULL;)
{
CDocumentTemplate *l_DocTempl =3D GetNextDocTemplate(l_tempPos)
for (l_docPos =3D l_DocTempl->GetFirstDocPosition();l_docPos !=3D =
NULL;)
{
CDocument* l_Doc =3D l_DocTempl->GetNextDoc(l_docPos);
ASSERT(l_Doc);
if (l_Doc->GetPathName =3D=3D f_Path) return TRUE;
}
}
return FALSE;
}
(I typed the code in my Mail Program - no compiler has ever seen it...)
I'm not sure about the long / short filenames. I my opinion, you only =
have to check for the long filename, cause this is the one used in =
Win32.
Tim Hagemann
ifa informationssysteme GmbH
Tim Hagemann -- Tim@way2.net
Thursday, January 23, 1997
Ari,
you can do this by processing all document templates and all documents
of
this templates in a nested loop:
CYourApp::CheckIfLoaded(const char *f_Path)
{
POSITION l_tempPos,l_docPos;
for (l_tempPos = GetFirstDocTemplatePosition();l_tempPoss != NULL;)
{
CDocumentTemplate *l_DocTempl = GetNextDocTemplate(l_tempPos)
for (l_docPos = l_DocTempl->GetFirstDocPosition();l_docPos != NULL;)
{
CDocument* l_Doc = l_DocTempl->GetNextDoc(l_docPos);
ASSERT(l_Doc);
if (l_Doc->GetPathName == f_Path) return TRUE;
}
}
return FALSE;
}
(I typed the code in my Mail Program - no compiler has ever seen it...)
I'm not sure about the long / short filenames. I my opinion, you only
have
to check for the long filename, cause this is the one used in Win32.
Tim Hagemann
ifa informationssysteme GmbH
Ari Villaca -- villaca@correionet.com.br
Sunday, January 26, 1997
Environment: MSVC 4.0 Windows 95
HI Tim,
Thanks for your replay to my question above.
My real problem was to expand a short filename to a long one. It's
interesting to note that in Windows 95 the filename you get in
CWinApp::m_lpCmdLine can be short or long depending the way you start you=
r
application. And you can start an application in many different ways in
Windows95.
Since CDocument::GetPathName returns the path name CWinApp::m_lpCmdLine
provided it is necessary, in Windows 95,
to expand the short filename and call CDocument::SetPathName before you
verify if a document is already opened.
Now I expand short filenames as follows (forgive me any typos,
cut-and-paste, translation from portuguese...):
//expands a short filename
//ex. given "c:\worksp~1\longfi~1.xxx" ExpandFileName returns
"c:\workspace\longfilename.xxx"
// given "c:\workspace\longfilename.xxx" ExpandFileName returns
"c:\workspace\longfilename.xxx"
CString CMyApp::ExpandFileName( CString sSupposedShortFileName )
{
WIN32_FIND_DATA FileData;
FileData.cFileName[0] =3D '\0';
CString sFileName =3D sSupposedShortFileName;
CString sTempFileName =3D "";
CString sExpandedFileName =3D "";
CString s1 =3D "";
while ( sFileName.GetLength() > 0 )
{
int i;
if ( ( i =3D sFileName.Find( '\\' ) ) !=3D -1 )
{
sTempFileName =3D sExpandedFileName + sFileName.Left( i );
sFileName =3D sFileName.Right( sFileName.GetLength() - i - 1);
FindFirstFile( sTempFileName, &FileData );
if ( FileData.cFileName[0] !=3D '\0' )
{
s1 =3D " ";
int j =3D 0;
while ( FileData.cFileName[j] !=3D '\0' )
{
s1.SetAt( 0, FileData.cFileName[j] );
sExpandedFileName +=3D s1;
j++;
}
}
else
sExpandedFileName =3D sTempFileName;
FileData.cFileName[0] =3D '\0';
sExpandedFileName +=3D " ";
sExpandedFileName.SetAt( sExpandedFileName.GetLength() - 1, '\\' );
}
else
{
sTempFileName =3D sExpandedFileName + sFileName;
sFileName =3D "";
FindFirstFile( sTempFileName, &FileData );
if ( FileData.cFileName[0] !=3D '\0' )
{
s1 =3D " ";
int j =3D 0;
while ( FileData.cFileName[j] !=3D '\0' )
{
s1.SetAt( 0, FileData.cFileName[j] );
sExpandedFileName +=3D s1;
j++;
}
}
else
sExpandedFileName =3D sTempFileName;
FileData.cFileName[0] =3D '\0';
}
}
return sExpandedFileName;
}
As usual, comments, enhancements, critics etc etc to method above are ver=
y
wellcome.
Best regards,
Ari
-------------------------------------------------------------------------=
---
-
Ari de Moura Villa=E7a
e-Mail: villaca@correionet.com.br
Av. Moraes Sales, 987 Apto.113 fone: +55 19 232-2440
13010-001 - Campinas, SP fax: +55 19 232-2440
Brasil
-------------------------------------------------------------------------=
---
| Вернуться в корень Архива
|