KevinSimonson
2010-11-05 17:48:43 UTC
I posted an article a short while back where I said I had a working
program, that read data from a file and performed processing on that
data. My boss asked me to change it so that every fifteen minutes it
read a new line from the file and changed its processing to that new
line. So I put in a call to "SetTimer()" to bring about that change.
But when I built the project in Visual Studio 2010, I got a wierd
error message. Someone responded to my article suggesting I write a
small test program and see if I can capture the error message while
trying to compile _it_.
So I did; I wrote a program that uses "SetTimer()" to call a non-
static function just like my actual (somewhat complicated) project
does, but after a few glitches it actually compiled. So that approach
went nowhere.
So I'm going to list here the functions that I changed, and attach the
whole file to the bottom of this article. The error message itself
was: "1>c:\program files\microsoft visual studio 10.0\vc\include
\fstream(890): error C2248:
std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private
member declared in class 'std::basic_ios<_Elem,_Traits>'", and it gets
printed right after the build process tries to compile
"CtrlHomeSearch.cpp", the file I'm going to attach. The only changes
I made were to the header:
//
// CtrlHomeSearch.h
//
// Copyright (c) Shareaza Development Team, 2002-2008.
// This file is part of SHAREAZA (shareaza.sourceforge.net)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
//
#pragma once
#include "CtrlSchemaCombo.h"
#include "CtrlIconButton.h"
class CHomeSearchCtrl : public CWnd
{
DECLARE_DYNCREATE(CHomeSearchCtrl)
public:
CHomeSearchCtrl();
void OnSkinChange(COLORREF crWindow);
void Activate();
virtual BOOL Create(CWnd* pParentWnd, UINT nID);
virtual BOOL PreTranslateMessage(MSG* pMsg);
void Search( bool bAutostart, bool preset);
static CHomeSearchCtrl* chsObject;
protected:
CComboBox m_wndText;
CSchemaCombo m_wndSchema;
CIconButtonCtrl m_wndSearch;
CIconButtonCtrl m_wndAdvanced;
COLORREF m_crWindow;
void FillHistory();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnPaint();
afx_msg void OnCloseUpText();
afx_msg void OnSelChangeText();
afx_msg void OnSearchStart();
afx_msg void OnSearchAdvanced();
DECLARE_MESSAGE_MAP()
};
where I added the "chsObject" object, and in the implementation
methods "startNewSearch()" (which I added entirely):
void CALLBACK startNewSearch ( HWND hwnt
, UINT uMsg
, UINT idEvent
, DWORD dwTime)
{
CHomeSearchCtrl* hsc = (CHomeSearchCtrl *)
CHomeSearchCtrl::chsObject;
hsc->Search( true, true);
}
and "OnCreate()":
int CHomeSearchCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
chsObject = this;
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
CRect rc( 0, 0, 0, 0 );
if ( ! m_wndText.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|
WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWN,
rc, this, IDC_SEARCH_TEXT ) ) return -1;
if ( ! m_wndSchema.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP, rc, this,
IDC_SCHEMAS ) )
return -1;
m_wndSchema.SetDroppedWidth( SCHEMA_WIDTH );
LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
m_wndSchema.Load( Settings.Search.LastSchemaURI );
m_wndSearch.Create( rc, this, IDC_SEARCH_START, WS_TABSTOP |
BS_DEFPUSHBUTTON );
m_wndSearch.SetHandCursor( TRUE );
m_wndAdvanced.Create( rc, this, IDC_SEARCH_ADVANCED, WS_TABSTOP );
m_wndAdvanced.SetHandCursor( TRUE );
OnSkinChange( CoolInterface.m_crWindow );
FillHistory();
Search( true, true);
SetTimer( NULL, 0, startNewSearch);
return 0;
}
Then, like I said, I attempted to build my project, and it got to
compiling "CtrlHomeSearch.cpp", and the next thing it told me was the
error message I listed above, which was _not_ about
"CtrlHomeSearch.cpp" but was rather about "c:\program files\microsoft
visual studio 10.0\vc\include\fstream"! But it kept
"CtrlHomeSearch.cpp" from compiling; I checked for its ".obj" file,
and the build didn't generate one. Though the build appears to have
created ".obj" files for all the other files in my project.
Can anyone tell me what this error message means, and how I can fix my
program so that the build will compile it without generating such an
error message? Any information would be greatly appreciated.
Kevin S
############################################################################################
//
// CtrlHomeSearch.cpp
//
// Copyright (c) Shareaza Development Team, 2002-2009.
// This file is part of SHAREAZA (shareaza.sourceforge.net)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
//
#include "StdAfx.h"
#include "Shareaza.h"
#include "Settings.h"
#include "Schema.h"
#include "SchemaCache.h"
#include "QuerySearch.h"
#include "WndSearch.h"
#include "CoolInterface.h"
#include "CtrlHomeSearch.h"
#include "DlgNewSearch.h"
#include "Skin.h"
#include "DlgHelp.h"
#include "Security.h"
#include "Suffix.h"
#include <iostream>
#include <fstream>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BUTTON_WIDTH 140
#define SCHEMA_WIDTH 160
#define KW_LIMIT 500
IMPLEMENT_DYNCREATE(CHomeSearchCtrl, CWnd)
BEGIN_MESSAGE_MAP(CHomeSearchCtrl, CWnd)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_PAINT()
ON_CBN_CLOSEUP(IDC_SEARCH_TEXT, OnCloseUpText)
ON_CBN_SELCHANGE(IDC_SEARCH_TEXT, OnSelChangeText)
ON_COMMAND(IDC_SEARCH_START, OnSearchStart)
ON_COMMAND(IDC_SEARCH_ADVANCED, OnSearchAdvanced)
END_MESSAGE_MAP()
char** keyWordStrings;
int totalStrings;
int stringCount;
CHomeSearchCtrl* CHomeSearchCtrl::chsObject;
void findString ( int count
, char** strng
, ifstream kwFile)
{
char kwChar;
kwFile.get( kwChar);
if (kwFile.eof() || kwChar == '\n')
{ *strng = new char[ count + 1];
*strng[ count] = '\0';
}
else
{ findString( count + 1, strng, kwFile);
*strng[ count] = kwChar;
}
}
void findStrings ( int count
, ifstream kwFile)
{
if (kwFile.eof())
{ keyWordStrings = new char*[ count];
totalStrings = count;
}
else
{ char* strng;
findString( 0, &strng, kwFile);
findStrings( count + 1, kwFile);
keyWordStrings[ count] = strng;
}
}
/////////////////////////////////////////////////////////////////////////////
// CHomeSearchCtrl construction
CHomeSearchCtrl::CHomeSearchCtrl()
{
//strcpy( timedName, "C:\\KeyWordCheck\\timed_0000.Txt");
CSuffix::initialize();
ifstream kwFile( "C:\\KeyWordCheck\\keyWords.Txt");
findStrings( 0, kwFile);
kwFile.close();
stringCount = 0;
}
/////////////////////////////////////////////////////////////////////////////
// CHomeSearchCtrl message handlers
BOOL CHomeSearchCtrl::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
PostMessage( WM_COMMAND, MAKELONG( IDC_SEARCH_START, BN_CLICKED ),
(LPARAM)m_wndSearch.GetSafeHwnd() );
return TRUE;
}
return CWnd::PreTranslateMessage( pMsg );
}
BOOL CHomeSearchCtrl::Create(CWnd* pParentWnd, UINT nID)
{
CRect rect( 0, 0, 0, 0 );
return CWnd::CreateEx( WS_EX_CONTROLPARENT, NULL,
_T("CHomeSearchCtrl"),
WS_CHILD|WS_CLIPCHILDREN, rect, pParentWnd, nID );
}
void CHomeSearchCtrl::Search ( bool bAutostart
, bool preset)
{
CString strText, strURI, strEntry, strClear;
if (preset)
{
CString inputText( (LPCSTR) keyWordStrings[ stringCount]);
strText = inputText;
char lookName[ 36];
char* keyWords = keyWordStrings[ stringCount];
strcpy( lookName, "C:\\KeywordCheck\\KwLooking");
strcat( lookName, CSuffix::latest());
ofstream lookFile( lookName);
ofstream crrntFile( "KwCurrent.Txt");
lookFile << "Searching for a file with keywords \"" << keyWords <<
"\"."
<< endl;
lookFile.close();
cout << "Searching for a file with keywords \"" << keyWords << "\"."
<< endl;
lookName[ 32] = '\0';
crrntFile << lookName + 26 << ": " << keyWords;
crrntFile.close();
CSuffix::increment();
stringCount = (stringCount + 1) % totalStrings;
m_wndText.SetWindowText( strText);
}
else
{ m_wndText.GetWindowText( strText );
}
strText.TrimLeft();
strText.TrimRight();
LoadString( strClear, IDS_SEARCH_PAD_CLEAR_HISTORY );
if ( _tcscmp ( strClear , strText ) == 0 ) return;
// Check if user mistakenly pasted download link to search input box
if ( CShareazaApp::OpenURL( strText, TRUE, TRUE ) )
{
m_wndText.SetWindowText( _T("") );
return;
}
CSchemaPtr pSchema = m_wndSchema.GetSelected();
if ( pSchema != NULL ) strURI = pSchema->GetURI();
Settings.Search.LastSchemaURI = strURI;
CQuerySearchPtr pSearch = new CQuerySearch();
pSearch->m_bAutostart = bAutostart;
pSearch->m_sSearch = strText;
pSearch->m_pSchema = pSchema;
BOOL bValid = pSearch->CheckValid( false );
if ( ! bValid && bAutostart )
{
// Invalid search, open help window
CQuerySearch::SearchHelp();
}
else if ( AdultFilter.IsSearchFiltered( pSearch->m_sSearch ) &&
bAutostart )
{
// Adult search blocked, open help window
CHelpDlg::Show( _T("SearchHelp.AdultSearch") );
}
else
{
if ( bValid )
{
// Load all
CStringList oList;
for ( int i = 0; ; i++ )
{
strEntry.Format( _T("Search.%.2i"), i + 1 );
CString strValue( theApp.GetProfileString( _T("Search"),
strEntry ) );
if ( strValue.IsEmpty() )
break;
int lf = strValue.Find( _T('\n') );
if ( strText.CompareNoCase( ( lf != -1 ) ? strValue.Left( lf ) :
strValue ) )
oList.AddTail( strValue );
}
// Cut to 200 items
while ( oList.GetCount() >= 200 )
oList.RemoveTail();
// New one (at top)
oList.AddHead( strURI.IsEmpty() ? strText : ( strText + _T('\n') +
strURI ) );
// Save list
POSITION pos = oList.GetHeadPosition();
for ( int i = 0; pos; ++i )
{
strEntry.Format( _T("Search.%.2i"), i + 1 );
theApp.WriteProfileString( _T("Search"), strEntry,
oList.GetNext( pos ) );
}
FillHistory();
}
new CSearchWnd( pSearch );
}
m_wndText.SetWindowText( _T("") );
}
void CALLBACK startNewSearch ( HWND hwnt
, UINT uMsg
, UINT idEvent
, DWORD dwTime)
{
CHomeSearchCtrl* hsc = (CHomeSearchCtrl *)
CHomeSearchCtrl::chsObject;
hsc->Search( true, true);
}
int CHomeSearchCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
chsObject = this;
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
CRect rc( 0, 0, 0, 0 );
if ( ! m_wndText.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|
WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWN,
rc, this, IDC_SEARCH_TEXT ) ) return -1;
if ( ! m_wndSchema.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP, rc, this,
IDC_SCHEMAS ) )
return -1;
m_wndSchema.SetDroppedWidth( SCHEMA_WIDTH );
LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
m_wndSchema.Load( Settings.Search.LastSchemaURI );
m_wndSearch.Create( rc, this, IDC_SEARCH_START, WS_TABSTOP |
BS_DEFPUSHBUTTON );
m_wndSearch.SetHandCursor( TRUE );
m_wndAdvanced.Create( rc, this, IDC_SEARCH_ADVANCED, WS_TABSTOP );
m_wndAdvanced.SetHandCursor( TRUE );
OnSkinChange( CoolInterface.m_crWindow );
FillHistory();
Search( true, true);
SetTimer( NULL, 0, startNewSearch);
return 0;
}
void CHomeSearchCtrl::OnSkinChange(COLORREF crWindow)
{
m_crWindow = crWindow;
m_wndSearch.SetWindowText( LoadString( IDS_SEARCH_PANEL_START ) );
m_wndSearch.SetCoolIcon( ID_SEARCH_SEARCH, FALSE );
m_wndAdvanced.SetWindowText( LoadString( IDS_SEARCH_PANEL_ADVANCED )
+
_T('\x2026') );
m_wndAdvanced.SetCoolIcon( ID_SEARCH_DETAILS, FALSE );
LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
m_wndText.SetFont( &CoolInterface.m_fntNormal );
}
void CHomeSearchCtrl::FillHistory()
{
m_wndText.ResetContent();
// Load all
for ( int i = 0; ; i++ )
{
CString strEntry;
strEntry.Format( _T("Search.%.2i"), i + 1 );
CString strValue( theApp.GetProfileString( _T("Search"),
strEntry ) );
if ( strValue.IsEmpty() )
break;
int lf = strValue.Find( _T('\n') );
int nIndex = m_wndText.InsertString( i,
( lf != -1 ) ? strValue.Left( lf ) : strValue );
CSchemaPtr pSchema = ( lf != -1 ) ?
SchemaCache.Get( strValue.Mid( lf + 1 ) ) : NULL;
m_wndText.SetItemData( nIndex, (DWORD_PTR)pSchema );
}
m_wndText.SetItemData( m_wndText.AddString(
LoadString( IDS_SEARCH_PAD_CLEAR_HISTORY ) ), 0 );
}
void CHomeSearchCtrl::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize( nType, cx, cy );
CRect rcClient( 0, 0, cx, cy );
CRect rcItem;
rcClient.DeflateRect( 1, 1 );
rcClient.top += 18;
rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right -
BUTTON_WIDTH - 16, rcClient.top + 256 );
m_wndText.MoveWindow( &rcItem );
rcItem.SetRect( rcClient.right - BUTTON_WIDTH, rcClient.top - 2,
rcClient.right, rcClient.top + 22 );
m_wndSearch.MoveWindow( &rcItem );
rcClient.top += 32;
rcItem.SetRect( rcClient.right - BUTTON_WIDTH - 16 - SCHEMA_WIDTH,
rcClient.top, rcClient.right - BUTTON_WIDTH - 16, rcClient.top +
256 );
rcItem.left = max( rcItem.left, rcClient.left );
m_wndSchema.MoveWindow( &rcItem );
rcItem.SetRect( rcClient.right - BUTTON_WIDTH, rcClient.top,
rcClient.right, rcClient.top + 24 );
m_wndAdvanced.MoveWindow( &rcItem );
}
void CHomeSearchCtrl::OnPaint()
{
CRect rcClient, rcItem;
CPaintDC dc( this );
CString str;
GetClientRect( &rcClient );
rcClient.DeflateRect( 1, 1 );
CFont* pOldFont =
(CFont*)dc.SelectObject( &CoolInterface.m_fntBold );
dc.SetBkMode( OPAQUE );
dc.SetBkColor( m_crWindow );
dc.SetTextColor( 0 );
LoadString( str, IDS_SEARCH_PAD_WORDS );
rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right,
rcClient.top + 16 );
dc.ExtTextOut( rcItem.left + 2, rcItem.top + 2, ETO_CLIPPED|
ETO_OPAQUE, &rcItem, str, NULL );
dc.ExcludeClipRect( &rcItem );
rcClient.top += 18;
rcClient.top += 32;
rcItem.SetRect( rcClient.left, rcClient.top,
rcClient.right - BUTTON_WIDTH - 16 - SCHEMA_WIDTH - 8, rcClient.top
+ 22 );
LoadString( str, IDS_SEARCH_PAD_TYPE );
CSize sz = dc.GetTextExtent( str );
dc.ExtTextOut( rcItem.right - sz.cx, ( rcItem.top + rcItem.bottom ) /
2 - sz.cy / 2,
ETO_CLIPPED|ETO_OPAQUE, &rcItem, str, NULL );
dc.ExcludeClipRect( &rcItem );
dc.SelectObject( pOldFont );
GetClientRect( &rcClient );
dc.FillSolidRect( &rcClient, m_crWindow );
}
void CHomeSearchCtrl::OnCloseUpText()
{
int nSel = m_wndText.GetCurSel();
if ( nSel < 0 ) return;
if ( nSel == m_wndText.GetCount() - 1 )
{
m_wndText.SetWindowText( _T("") );
// Delete all
for ( int i = 0; ; i++ )
{
CString strEntry;
strEntry.Format( _T("Search.%.2i"), i + 1 );
CString strValue( theApp.GetProfileString( _T("Search"),
strEntry ) );
if ( strValue.IsEmpty() )
break;
theApp.WriteProfileString( _T("Search"), strEntry, NULL );
}
m_wndSchema.Select( (CSchemaPtr)NULL );
FillHistory();
}
else
{
m_wndSchema.Select( (CSchemaPtr)m_wndText.GetItemData( nSel ) );
}
}
void CHomeSearchCtrl::OnSelChangeText()
{
OnCloseUpText();
}
void CHomeSearchCtrl::OnSearchStart()
{
Search( true, false );
}
void CHomeSearchCtrl::OnSearchAdvanced()
{
Search( false, false );
}
void CHomeSearchCtrl::Activate()
{
FillHistory();
m_wndText.SetFocus();
}
program, that read data from a file and performed processing on that
data. My boss asked me to change it so that every fifteen minutes it
read a new line from the file and changed its processing to that new
line. So I put in a call to "SetTimer()" to bring about that change.
But when I built the project in Visual Studio 2010, I got a wierd
error message. Someone responded to my article suggesting I write a
small test program and see if I can capture the error message while
trying to compile _it_.
So I did; I wrote a program that uses "SetTimer()" to call a non-
static function just like my actual (somewhat complicated) project
does, but after a few glitches it actually compiled. So that approach
went nowhere.
So I'm going to list here the functions that I changed, and attach the
whole file to the bottom of this article. The error message itself
was: "1>c:\program files\microsoft visual studio 10.0\vc\include
\fstream(890): error C2248:
std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private
member declared in class 'std::basic_ios<_Elem,_Traits>'", and it gets
printed right after the build process tries to compile
"CtrlHomeSearch.cpp", the file I'm going to attach. The only changes
I made were to the header:
//
// CtrlHomeSearch.h
//
// Copyright (c) Shareaza Development Team, 2002-2008.
// This file is part of SHAREAZA (shareaza.sourceforge.net)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
//
#pragma once
#include "CtrlSchemaCombo.h"
#include "CtrlIconButton.h"
class CHomeSearchCtrl : public CWnd
{
DECLARE_DYNCREATE(CHomeSearchCtrl)
public:
CHomeSearchCtrl();
void OnSkinChange(COLORREF crWindow);
void Activate();
virtual BOOL Create(CWnd* pParentWnd, UINT nID);
virtual BOOL PreTranslateMessage(MSG* pMsg);
void Search( bool bAutostart, bool preset);
static CHomeSearchCtrl* chsObject;
protected:
CComboBox m_wndText;
CSchemaCombo m_wndSchema;
CIconButtonCtrl m_wndSearch;
CIconButtonCtrl m_wndAdvanced;
COLORREF m_crWindow;
void FillHistory();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnPaint();
afx_msg void OnCloseUpText();
afx_msg void OnSelChangeText();
afx_msg void OnSearchStart();
afx_msg void OnSearchAdvanced();
DECLARE_MESSAGE_MAP()
};
where I added the "chsObject" object, and in the implementation
methods "startNewSearch()" (which I added entirely):
void CALLBACK startNewSearch ( HWND hwnt
, UINT uMsg
, UINT idEvent
, DWORD dwTime)
{
CHomeSearchCtrl* hsc = (CHomeSearchCtrl *)
CHomeSearchCtrl::chsObject;
hsc->Search( true, true);
}
and "OnCreate()":
int CHomeSearchCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
chsObject = this;
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
CRect rc( 0, 0, 0, 0 );
if ( ! m_wndText.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|
WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWN,
rc, this, IDC_SEARCH_TEXT ) ) return -1;
if ( ! m_wndSchema.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP, rc, this,
IDC_SCHEMAS ) )
return -1;
m_wndSchema.SetDroppedWidth( SCHEMA_WIDTH );
LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
m_wndSchema.Load( Settings.Search.LastSchemaURI );
m_wndSearch.Create( rc, this, IDC_SEARCH_START, WS_TABSTOP |
BS_DEFPUSHBUTTON );
m_wndSearch.SetHandCursor( TRUE );
m_wndAdvanced.Create( rc, this, IDC_SEARCH_ADVANCED, WS_TABSTOP );
m_wndAdvanced.SetHandCursor( TRUE );
OnSkinChange( CoolInterface.m_crWindow );
FillHistory();
Search( true, true);
SetTimer( NULL, 0, startNewSearch);
return 0;
}
Then, like I said, I attempted to build my project, and it got to
compiling "CtrlHomeSearch.cpp", and the next thing it told me was the
error message I listed above, which was _not_ about
"CtrlHomeSearch.cpp" but was rather about "c:\program files\microsoft
visual studio 10.0\vc\include\fstream"! But it kept
"CtrlHomeSearch.cpp" from compiling; I checked for its ".obj" file,
and the build didn't generate one. Though the build appears to have
created ".obj" files for all the other files in my project.
Can anyone tell me what this error message means, and how I can fix my
program so that the build will compile it without generating such an
error message? Any information would be greatly appreciated.
Kevin S
############################################################################################
//
// CtrlHomeSearch.cpp
//
// Copyright (c) Shareaza Development Team, 2002-2009.
// This file is part of SHAREAZA (shareaza.sourceforge.net)
//
// Shareaza is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Shareaza is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Shareaza; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
//
#include "StdAfx.h"
#include "Shareaza.h"
#include "Settings.h"
#include "Schema.h"
#include "SchemaCache.h"
#include "QuerySearch.h"
#include "WndSearch.h"
#include "CoolInterface.h"
#include "CtrlHomeSearch.h"
#include "DlgNewSearch.h"
#include "Skin.h"
#include "DlgHelp.h"
#include "Security.h"
#include "Suffix.h"
#include <iostream>
#include <fstream>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BUTTON_WIDTH 140
#define SCHEMA_WIDTH 160
#define KW_LIMIT 500
IMPLEMENT_DYNCREATE(CHomeSearchCtrl, CWnd)
BEGIN_MESSAGE_MAP(CHomeSearchCtrl, CWnd)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_PAINT()
ON_CBN_CLOSEUP(IDC_SEARCH_TEXT, OnCloseUpText)
ON_CBN_SELCHANGE(IDC_SEARCH_TEXT, OnSelChangeText)
ON_COMMAND(IDC_SEARCH_START, OnSearchStart)
ON_COMMAND(IDC_SEARCH_ADVANCED, OnSearchAdvanced)
END_MESSAGE_MAP()
char** keyWordStrings;
int totalStrings;
int stringCount;
CHomeSearchCtrl* CHomeSearchCtrl::chsObject;
void findString ( int count
, char** strng
, ifstream kwFile)
{
char kwChar;
kwFile.get( kwChar);
if (kwFile.eof() || kwChar == '\n')
{ *strng = new char[ count + 1];
*strng[ count] = '\0';
}
else
{ findString( count + 1, strng, kwFile);
*strng[ count] = kwChar;
}
}
void findStrings ( int count
, ifstream kwFile)
{
if (kwFile.eof())
{ keyWordStrings = new char*[ count];
totalStrings = count;
}
else
{ char* strng;
findString( 0, &strng, kwFile);
findStrings( count + 1, kwFile);
keyWordStrings[ count] = strng;
}
}
/////////////////////////////////////////////////////////////////////////////
// CHomeSearchCtrl construction
CHomeSearchCtrl::CHomeSearchCtrl()
{
//strcpy( timedName, "C:\\KeyWordCheck\\timed_0000.Txt");
CSuffix::initialize();
ifstream kwFile( "C:\\KeyWordCheck\\keyWords.Txt");
findStrings( 0, kwFile);
kwFile.close();
stringCount = 0;
}
/////////////////////////////////////////////////////////////////////////////
// CHomeSearchCtrl message handlers
BOOL CHomeSearchCtrl::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
PostMessage( WM_COMMAND, MAKELONG( IDC_SEARCH_START, BN_CLICKED ),
(LPARAM)m_wndSearch.GetSafeHwnd() );
return TRUE;
}
return CWnd::PreTranslateMessage( pMsg );
}
BOOL CHomeSearchCtrl::Create(CWnd* pParentWnd, UINT nID)
{
CRect rect( 0, 0, 0, 0 );
return CWnd::CreateEx( WS_EX_CONTROLPARENT, NULL,
_T("CHomeSearchCtrl"),
WS_CHILD|WS_CLIPCHILDREN, rect, pParentWnd, nID );
}
void CHomeSearchCtrl::Search ( bool bAutostart
, bool preset)
{
CString strText, strURI, strEntry, strClear;
if (preset)
{
CString inputText( (LPCSTR) keyWordStrings[ stringCount]);
strText = inputText;
char lookName[ 36];
char* keyWords = keyWordStrings[ stringCount];
strcpy( lookName, "C:\\KeywordCheck\\KwLooking");
strcat( lookName, CSuffix::latest());
ofstream lookFile( lookName);
ofstream crrntFile( "KwCurrent.Txt");
lookFile << "Searching for a file with keywords \"" << keyWords <<
"\"."
<< endl;
lookFile.close();
cout << "Searching for a file with keywords \"" << keyWords << "\"."
<< endl;
lookName[ 32] = '\0';
crrntFile << lookName + 26 << ": " << keyWords;
crrntFile.close();
CSuffix::increment();
stringCount = (stringCount + 1) % totalStrings;
m_wndText.SetWindowText( strText);
}
else
{ m_wndText.GetWindowText( strText );
}
strText.TrimLeft();
strText.TrimRight();
LoadString( strClear, IDS_SEARCH_PAD_CLEAR_HISTORY );
if ( _tcscmp ( strClear , strText ) == 0 ) return;
// Check if user mistakenly pasted download link to search input box
if ( CShareazaApp::OpenURL( strText, TRUE, TRUE ) )
{
m_wndText.SetWindowText( _T("") );
return;
}
CSchemaPtr pSchema = m_wndSchema.GetSelected();
if ( pSchema != NULL ) strURI = pSchema->GetURI();
Settings.Search.LastSchemaURI = strURI;
CQuerySearchPtr pSearch = new CQuerySearch();
pSearch->m_bAutostart = bAutostart;
pSearch->m_sSearch = strText;
pSearch->m_pSchema = pSchema;
BOOL bValid = pSearch->CheckValid( false );
if ( ! bValid && bAutostart )
{
// Invalid search, open help window
CQuerySearch::SearchHelp();
}
else if ( AdultFilter.IsSearchFiltered( pSearch->m_sSearch ) &&
bAutostart )
{
// Adult search blocked, open help window
CHelpDlg::Show( _T("SearchHelp.AdultSearch") );
}
else
{
if ( bValid )
{
// Load all
CStringList oList;
for ( int i = 0; ; i++ )
{
strEntry.Format( _T("Search.%.2i"), i + 1 );
CString strValue( theApp.GetProfileString( _T("Search"),
strEntry ) );
if ( strValue.IsEmpty() )
break;
int lf = strValue.Find( _T('\n') );
if ( strText.CompareNoCase( ( lf != -1 ) ? strValue.Left( lf ) :
strValue ) )
oList.AddTail( strValue );
}
// Cut to 200 items
while ( oList.GetCount() >= 200 )
oList.RemoveTail();
// New one (at top)
oList.AddHead( strURI.IsEmpty() ? strText : ( strText + _T('\n') +
strURI ) );
// Save list
POSITION pos = oList.GetHeadPosition();
for ( int i = 0; pos; ++i )
{
strEntry.Format( _T("Search.%.2i"), i + 1 );
theApp.WriteProfileString( _T("Search"), strEntry,
oList.GetNext( pos ) );
}
FillHistory();
}
new CSearchWnd( pSearch );
}
m_wndText.SetWindowText( _T("") );
}
void CALLBACK startNewSearch ( HWND hwnt
, UINT uMsg
, UINT idEvent
, DWORD dwTime)
{
CHomeSearchCtrl* hsc = (CHomeSearchCtrl *)
CHomeSearchCtrl::chsObject;
hsc->Search( true, true);
}
int CHomeSearchCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
chsObject = this;
if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
CRect rc( 0, 0, 0, 0 );
if ( ! m_wndText.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_GROUP|
WS_VSCROLL|CBS_AUTOHSCROLL|CBS_DROPDOWN,
rc, this, IDC_SEARCH_TEXT ) ) return -1;
if ( ! m_wndSchema.Create( WS_CHILD|WS_VISIBLE|WS_TABSTOP, rc, this,
IDC_SCHEMAS ) )
return -1;
m_wndSchema.SetDroppedWidth( SCHEMA_WIDTH );
LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
m_wndSchema.Load( Settings.Search.LastSchemaURI );
m_wndSearch.Create( rc, this, IDC_SEARCH_START, WS_TABSTOP |
BS_DEFPUSHBUTTON );
m_wndSearch.SetHandCursor( TRUE );
m_wndAdvanced.Create( rc, this, IDC_SEARCH_ADVANCED, WS_TABSTOP );
m_wndAdvanced.SetHandCursor( TRUE );
OnSkinChange( CoolInterface.m_crWindow );
FillHistory();
Search( true, true);
SetTimer( NULL, 0, startNewSearch);
return 0;
}
void CHomeSearchCtrl::OnSkinChange(COLORREF crWindow)
{
m_crWindow = crWindow;
m_wndSearch.SetWindowText( LoadString( IDS_SEARCH_PANEL_START ) );
m_wndSearch.SetCoolIcon( ID_SEARCH_SEARCH, FALSE );
m_wndAdvanced.SetWindowText( LoadString( IDS_SEARCH_PANEL_ADVANCED )
+
_T('\x2026') );
m_wndAdvanced.SetCoolIcon( ID_SEARCH_DETAILS, FALSE );
LoadString( m_wndSchema.m_sNoSchemaText, IDS_SEARCH_PANEL_AFT );
m_wndText.SetFont( &CoolInterface.m_fntNormal );
}
void CHomeSearchCtrl::FillHistory()
{
m_wndText.ResetContent();
// Load all
for ( int i = 0; ; i++ )
{
CString strEntry;
strEntry.Format( _T("Search.%.2i"), i + 1 );
CString strValue( theApp.GetProfileString( _T("Search"),
strEntry ) );
if ( strValue.IsEmpty() )
break;
int lf = strValue.Find( _T('\n') );
int nIndex = m_wndText.InsertString( i,
( lf != -1 ) ? strValue.Left( lf ) : strValue );
CSchemaPtr pSchema = ( lf != -1 ) ?
SchemaCache.Get( strValue.Mid( lf + 1 ) ) : NULL;
m_wndText.SetItemData( nIndex, (DWORD_PTR)pSchema );
}
m_wndText.SetItemData( m_wndText.AddString(
LoadString( IDS_SEARCH_PAD_CLEAR_HISTORY ) ), 0 );
}
void CHomeSearchCtrl::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize( nType, cx, cy );
CRect rcClient( 0, 0, cx, cy );
CRect rcItem;
rcClient.DeflateRect( 1, 1 );
rcClient.top += 18;
rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right -
BUTTON_WIDTH - 16, rcClient.top + 256 );
m_wndText.MoveWindow( &rcItem );
rcItem.SetRect( rcClient.right - BUTTON_WIDTH, rcClient.top - 2,
rcClient.right, rcClient.top + 22 );
m_wndSearch.MoveWindow( &rcItem );
rcClient.top += 32;
rcItem.SetRect( rcClient.right - BUTTON_WIDTH - 16 - SCHEMA_WIDTH,
rcClient.top, rcClient.right - BUTTON_WIDTH - 16, rcClient.top +
256 );
rcItem.left = max( rcItem.left, rcClient.left );
m_wndSchema.MoveWindow( &rcItem );
rcItem.SetRect( rcClient.right - BUTTON_WIDTH, rcClient.top,
rcClient.right, rcClient.top + 24 );
m_wndAdvanced.MoveWindow( &rcItem );
}
void CHomeSearchCtrl::OnPaint()
{
CRect rcClient, rcItem;
CPaintDC dc( this );
CString str;
GetClientRect( &rcClient );
rcClient.DeflateRect( 1, 1 );
CFont* pOldFont =
(CFont*)dc.SelectObject( &CoolInterface.m_fntBold );
dc.SetBkMode( OPAQUE );
dc.SetBkColor( m_crWindow );
dc.SetTextColor( 0 );
LoadString( str, IDS_SEARCH_PAD_WORDS );
rcItem.SetRect( rcClient.left, rcClient.top, rcClient.right,
rcClient.top + 16 );
dc.ExtTextOut( rcItem.left + 2, rcItem.top + 2, ETO_CLIPPED|
ETO_OPAQUE, &rcItem, str, NULL );
dc.ExcludeClipRect( &rcItem );
rcClient.top += 18;
rcClient.top += 32;
rcItem.SetRect( rcClient.left, rcClient.top,
rcClient.right - BUTTON_WIDTH - 16 - SCHEMA_WIDTH - 8, rcClient.top
+ 22 );
LoadString( str, IDS_SEARCH_PAD_TYPE );
CSize sz = dc.GetTextExtent( str );
dc.ExtTextOut( rcItem.right - sz.cx, ( rcItem.top + rcItem.bottom ) /
2 - sz.cy / 2,
ETO_CLIPPED|ETO_OPAQUE, &rcItem, str, NULL );
dc.ExcludeClipRect( &rcItem );
dc.SelectObject( pOldFont );
GetClientRect( &rcClient );
dc.FillSolidRect( &rcClient, m_crWindow );
}
void CHomeSearchCtrl::OnCloseUpText()
{
int nSel = m_wndText.GetCurSel();
if ( nSel < 0 ) return;
if ( nSel == m_wndText.GetCount() - 1 )
{
m_wndText.SetWindowText( _T("") );
// Delete all
for ( int i = 0; ; i++ )
{
CString strEntry;
strEntry.Format( _T("Search.%.2i"), i + 1 );
CString strValue( theApp.GetProfileString( _T("Search"),
strEntry ) );
if ( strValue.IsEmpty() )
break;
theApp.WriteProfileString( _T("Search"), strEntry, NULL );
}
m_wndSchema.Select( (CSchemaPtr)NULL );
FillHistory();
}
else
{
m_wndSchema.Select( (CSchemaPtr)m_wndText.GetItemData( nSel ) );
}
}
void CHomeSearchCtrl::OnSelChangeText()
{
OnCloseUpText();
}
void CHomeSearchCtrl::OnSearchStart()
{
Search( true, false );
}
void CHomeSearchCtrl::OnSearchAdvanced()
{
Search( false, false );
}
void CHomeSearchCtrl::Activate()
{
FillHistory();
m_wndText.SetFocus();
}