Hi All
I am trying to find excel file is open or not through FindWindow function.
Code:
CWnd *pExal;
pExal = CWnd::FindWindow(NULL, _T("C:\test.xls"));
if(pExal == NULL){
AfxMessageBox("Couldn't find Excel file");
}
else
{
AfxMessageBox("Excel file is open");
}
In this code if file is open then show
Code:
pExal == NULL
nad if not open then also...
does excel state the file that is opened in the window's title? if so, you sure it doesn't contain anything else in the title? like - Microsoft - Excel. Also does it state the directory of the file opened?
In short this isn't reliable enough
A quick glance.
I really don't think you have to include C:\ in the window title to search for, so change it to :
Code:
CWnd *pExal;
pExal = CWnd::FindWindow(NULL, _T("Microsoft Excel - test.xls"));
if(pExal == NULL){
AfxMessageBox("Couldn't find Excel file");
}
else
{
AfxMessageBox("Excel file is open");
}
BTW, I think you need to supply Microsoft Excel in the ...
Quote:
Originally Posted by HanneSThEGreaT
A quick glance.
I really don't think you have to include C:\ in the window title to search for, so change it to :
Code:
CWnd *pExal;
pExal = CWnd::FindWindow(NULL, _T("Microsoft Excel - test.xls"));
if(pExal == NULL){
AfxMessageBox("Couldn't find Excel file");
}
else
{...
A good rule to follow when using FindWindow is to include the class name whenever possible. This allows the api to only look for windows matching the class name (and title if specified). When you supply the class name, you increase the chance of finding the correct window. Sure, it's unlikely that any other window will have 'Microsoft Excell' in the title, but it's a good practice to get into....
Quote:
Originally Posted by Arjay
Code:
HWND hWnd = ::FindWindow( _T("XLMAIN"), _T("Microsoft Excell - MySheet.xls [Compatibility Mode]") );
Thanks for reply
How can i use that.
Quote: Originally Posted by Arjay Code: HWND hWnd = ::FindWindow( _T("XLMAIN"), _T("Microsoft Excell - MySheet.xls [Compatibility Mode]") ); Thanks for reply How can i use that.
A good rule to follow when using FindWindow is to include the class name whenever possible. This allows the api to only look for windows matching the class name (and title if specified). When you supply the class name, you increase the chance of finding the correct window. Sure, it's unlikely that any other window will have 'Microsoft Excell' in the title, but it's a good practice to get into. For Excell 2007, the top level...
does excel state the file that is opened in the window's title? if so, you sure it doesn't contain anything else in the title? like - Microsoft - Excel. Also does it state the directory of the file opened? In short this isn't reliable enough
A quick glance. I really don't think you have to include C:\ in the window title to search for, so change it to : Code: CWnd *pExal; pExal = CWnd::FindWindow(NULL, _T("Microsoft Excel - test.xls")); if(pExal == NULL){ AfxMessageBox("Couldn't find Excel file"); } else { AfxMessageBox("Excel file is open"); } BTW, I think you need to supply Microsoft Excel in the string as well. Try...
Quote: Originally Posted by Arjay Code: HWND hWnd = ::FindWindow( _T("XLMAIN"), _T("Microsoft Excell - MySheet.xls [Compatibility Mode]") ); Thanks for reply How can i use that.
Related threads on "CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions":
Thread profile page for "FindWindow" on http://www.codeguru.com.
This report page is a snippet summary view from a single thread "FindWindow", located on the Message Board at http://www.codeguru.com.
This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity