2015-02-11 15 views
1

我有一個項目,最初是在Microsoft Visual C++上開發的。 NET,版本7.0.9466,它工作得很好。我嘗試使用MS 2013來運行我的項目,並且當我嘗試構建項目時,出現此錯誤消息:錯誤C1010:查找預編譯頭時出現意外的文件結尾。你忘了添加'#include「stdafx.h」'到你的源?

錯誤C1010:查找預編譯頭時出現意外的文件結尾。你忘了添加'#include「stdafx.h」'到你的源?

,我已經做了一些動作:

  • 我選擇在預編譯頭選項 「使用(/羽)」 在PropertyPages-> C/C++ - >預編譯頭
  • 我設置預編譯頭文件來stdafx.h中
  • 我把#include "stdafx.h"在.cpp文件
  • 我不得不瓚的開始GE #include "stdafx.h"#include "../stdafx.h",因爲我有此錯誤消息:

智能感知:無法打開源文件「stdafx.h中」

這裏是.cpp文件我哪裏有這個消息錯誤

#include "../stdafx.h" 
 
#include "timedmsgbox.h" 
 

 
///////////////////////////////////////////////////////////////////////// 
 
// 
 
// CDlgTimedMessageBox 
 
// 
 
///////////////////////////////////////////////////////////////////////// 
 

 
CMapPtrToPtr \t \t CDlgTimedMessageBox::m_mapTimerIdToClassMe; 
 
CCriticalSection \t CDlgTimedMessageBox::m_sectMap; 
 
extern BOOL AFXAPI AfxIsDescendant(HWND hWndParent, HWND hWndChild); 
 

 
// the static one to call the messagebox with one line 
 
UINT CDlgTimedMessageBox::TimedMessageBox(UINT flags, LPCTSTR ptszMessage, LPCTSTR ptszTitle, 
 
\t \t \t \t \t \t DWORD dwTimeout, UINT dDefaultReturn, 
 
\t \t \t \t \t \t LPCTSTR ptszMessageTimer, HWND hwndParent, BOOL *pbStoppedByUser) 
 
{ 
 
\t CDlgTimedMessageBox \t \t msgBox(flags, ptszMessage, ptszTitle, 
 
\t \t \t \t \t \t \t \t \t dwTimeout, dDefaultReturn, 
 
\t \t \t \t \t \t \t \t \t ptszMessageTimer, hwndParent); 
 

 
\t return msgBox.ShowMessageBox(pbStoppedByUser); 
 
} 
 

 
CDlgTimedMessageBox::CDlgTimedMessageBox(UINT flags, 
 
\t \t \t \t \t \t \t \t LPCTSTR ptszMessage, LPCTSTR ptszTitle, 
 
\t \t \t \t \t \t \t \t DWORD dwTimeout, UINT dDefaultReturn, 
 
\t \t \t \t \t \t \t \t LPCTSTR ptszMessageTimer, 
 
\t \t \t \t \t \t \t \t HWND hwndParent) 
 
{ 
 
\t m_hParent \t \t \t = hwndParent; 
 
\t m_Message \t \t \t = ptszMessage; 
 
\t m_Title \t \t \t \t = ptszTitle; 
 
\t m_flags \t \t \t \t = flags; 
 
\t m_dwTimeout \t \t \t = dwTimeout-1; 
 
\t m_MessageTimer \t \t = ptszMessageTimer; 
 
\t m_DefaultReturn \t \t = dDefaultReturn; 
 
\t 
 
\t m_hMsgBox \t \t \t = NULL; 
 
\t m_hStaticText \t \t = NULL; 
 
\t m_hDefaultButton \t = NULL; 
 
\t m_bRunning \t \t \t = FALSE; 
 
\t m_bStoppedByTimer \t = FALSE; 
 

 
\t if(!m_hParent) 
 
\t { 
 
\t \t CWnd *m_pParent = AfxGetApp()->GetMainWnd(); 
 
\t \t m_hParent = m_pParent->m_hWnd; 
 
\t } 
 
} 
 

 
CDlgTimedMessageBox::~CDlgTimedMessageBox() 
 
{ 
 
} 
 

 
#pragma warning(push) 
 
#pragma warning (disable : 4312) // conversion to type of greater size 
 
UINT CDlgTimedMessageBox::ShowMessageBox(BOOL *pbStoppedByUser) 
 
{ 
 
\t // start timer 
 
\t CDlgTimedMessageBox::m_sectMap.Lock(); 
 
\t { 
 
\t \t m_idTimer = (UINT)::SetTimer(NULL, 0, 1000, (TIMERPROC) CDlgTimedMessageBox::GlobalTimerProc); 
 
\t \t CDlgTimedMessageBox::m_mapTimerIdToClassMe.SetAt((void*)m_idTimer, this); 
 
\t } 
 
\t CDlgTimedMessageBox::m_sectMap.Unlock(); 
 
\t 
 
\t // show MessageBox 
 
\t m_bRunning = TRUE; 
 
\t m_dwStarted = ::GetTickCount(); 
 
\t 
 
\t m_CurrentMessage = m_Message; 
 
\t if(!m_MessageTimer.IsEmpty()) 
 
\t { 
 
\t \t CString \t second; 
 
\t \t second.Format(m_MessageTimer, (m_dwTimeout+1)/1000); 
 
\t \t m_CurrentMessage.Format("%s%s", m_Message, second); 
 
\t } 
 
\t UINT erg = ::MessageBox(m_hParent, m_CurrentMessage, m_Title, m_flags); 
 
\t m_bRunning = FALSE; 
 

 
\t CDlgTimedMessageBox::m_sectMap.Lock(); 
 
\t { 
 
\t \t ::KillTimer(NULL, m_idTimer); 
 
\t \t m_idTimer = 0; 
 
\t \t CDlgTimedMessageBox::m_mapTimerIdToClassMe.RemoveKey((void*)m_idTimer); 
 
\t } 
 
\t CDlgTimedMessageBox::m_sectMap.Unlock(); 
 

 
\t if(pbStoppedByUser) 
 
\t \t *pbStoppedByUser = !m_bStoppedByTimer; 
 
\t 
 
\t return erg; 
 
} 
 
#pragma warning(pop) 
 

 
void CALLBACK CDlgTimedMessageBox::GlobalTimerProc(HWND hwnd, UINT uiMsg, UINT_PTR idEvent, DWORD dwTime) 
 
{ 
 
\t //TRACE("Global timer with id=%u\n", idEvent); 
 
\t 
 
\t CDlgTimedMessageBox \t *pMe = NULL; 
 
\t 
 
\t // Find the corresponding class by the timer-id 
 
\t CDlgTimedMessageBox::m_sectMap.Lock(); 
 
\t { 
 
\t \t CDlgTimedMessageBox::m_mapTimerIdToClassMe.Lookup((void*)idEvent, (void *&) pMe); 
 
\t } \t 
 
\t CDlgTimedMessageBox::m_sectMap.Unlock(); 
 
\t 
 
\t if(pMe!=NULL) 
 
\t \t pMe->LocalTimerProc(); 
 
} 
 

 
void CDlgTimedMessageBox::LocalTimerProc(void) 
 
{ 
 
\t //TRACE("Local timer with id=%u (%s)\n", m_idTimer, m_Title); 
 

 
\t if(!m_bRunning) 
 
\t \t return; 
 

 
\t // lookup the handles 
 
\t GetWindowHandles(); 
 

 

 
\t if(!m_hStaticText || !m_hMsgBox) 
 
\t \t return; 
 

 
\t DWORD now = GetTickCount()-m_dwStarted; 
 
\t 
 
\t if(now >= (m_dwTimeout)) 
 
\t { 
 
\t \t // done with the box 
 
\t \t m_bStoppedByTimer = TRUE; 
 
\t \t ::PostMessage(m_hMsgBox, WM_COMMAND, (WPARAM) m_DefaultReturn, (LPARAM) m_hDefaultButton); 
 
\t } 
 
\t else 
 
\t { 
 
\t \t m_CurrentMessage = m_Message; 
 
\t 
 
\t \t // not done: set text again 
 
\t \t if(!m_MessageTimer.IsEmpty()) 
 
\t \t { 
 
\t \t \t CString \t second; 
 
\t \t \t second.Format(m_MessageTimer, (100+m_dwTimeout-now)/1000); 
 
\t \t \t m_CurrentMessage.Format("%s%s", m_Message, second); 
 
\t \t } 
 
\t \t ::SetWindowText(m_hStaticText, m_CurrentMessage); 
 
\t } \t 
 
} 
 

 
void CDlgTimedMessageBox::GetWindowHandles(void) 
 
{ 
 
\t HWND \t \t hWnd; 
 
\t CWnd \t \t *pWnd; 
 
\t CString \t \t title; 
 
\t CPtrList \t allButtons; 
 

 
\t // 
 
\t // Handle of the messageBox 
 
\t // 
 
\t if(!m_hMsgBox) 
 
\t { 
 
\t \t hWnd = ::GetWindow(::GetDesktopWindow(), GW_CHILD); 
 
\t \t while((hWnd!=NULL) && (m_hMsgBox==NULL)) 
 
\t \t { 
 
\t \t \t pWnd = CWnd::FromHandle(hWnd); 
 
\t \t \t pWnd->GetWindowText(title); 
 

 
\t \t \t if(AfxIsDescendant(m_hParent, hWnd) && ::IsWindowVisible(hWnd) && (m_Title.CompareNoCase(title)==0)) 
 
\t \t \t { 
 
\t \t \t \t m_hMsgBox = hWnd; 
 
\t \t \t \t break; 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); 
 
\t \t } 
 
\t } 
 

 
\t // 
 
\t // Handle of the static text 
 
\t // TODO only if text-replace is needed 
 
\t // 
 
\t if(m_hMsgBox && !m_hStaticText) 
 
\t { 
 
\t \t // not sure if this will work always 
 
\t \t // under Win2000 it did 
 
\t \t //m_hStaticText = ::GetDlgItem(m_hMsgBox, 0xFFFF); 
 

 
\t \t // not sure, so lets find it dynamically! 
 

 
\t \t char \t \t className[_MAX_PATH]; 
 
\t \t CString \t \t classNameOk("STATIC"); 
 
\t \t LONG \t \t id; 
 

 
\t \t hWnd = ::GetWindow(m_hMsgBox, GW_CHILD); 
 
\t \t while((hWnd!=NULL) && (m_hStaticText==NULL)) 
 
\t \t { 
 
\t \t \t id = ::GetWindowLong(hWnd, GWL_ID); 
 
\t \t \t 
 
\t \t \t // small ids only for buttons 
 
\t \t \t if(id > IDHELP) 
 
\t \t \t { 
 
\t \t \t \t if(::GetClassName(hWnd, className, _MAX_PATH)) 
 
\t \t \t \t { 
 

 
\t \t \t \t \t // looking only for a static 
 
\t \t \t \t \t if(classNameOk.CompareNoCase(className) == 0) 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t // not check the text 
 
\t \t \t \t \t \t pWnd = CWnd::FromHandle(hWnd); 
 
\t \t \t \t \t \t pWnd->GetWindowText(title); 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t if(m_CurrentMessage.CompareNoCase(title) == 0) 
 
\t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t m_hStaticText = hWnd; 
 
\t \t \t \t \t \t \t break; 
 
\t \t \t \t \t \t } 
 

 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t \t else 
 
\t \t \t { 
 
\t \t \t \t allButtons.AddTail(hWnd); 
 
\t \t \t } 
 

 
\t \t \t hWnd = ::GetWindow(hWnd, GW_HWNDNEXT); 
 
\t \t } 
 

 
\t } 
 

 
\t // 
 
\t // Handle of the default button 
 
\t // 
 
\t if(m_hMsgBox && !m_hDefaultButton) 
 
\t { 
 
\t \t m_hDefaultButton = ::GetDlgItem(m_hMsgBox, m_DefaultReturn); 
 
\t \t 
 
\t \t // Problem: 
 
\t \t // if generated with MB_OK the button has NOT IDOK, but IDCANCEL !! 
 
\t \t // then lets take the first button we find ! 
 
\t \t // (with and IDCANCEL this works, because it is the only button 
 
\t \t // if this problem encounters also with 2 buttons, I have no chance 
 
\t \t // to find out which one is the better one!) 
 
\t \t while(allButtons.GetCount()>0 && !m_hDefaultButton) 
 
\t \t { 
 
\t \t \t m_hDefaultButton = (HWND) allButtons.GetHead(); 
 
\t \t \t allButtons.RemoveHead(); 
 
\t \t \t 
 
\t \t \t if(m_hDefaultButton) 
 
\t \t \t \t m_DefaultReturn = ::GetWindowLong(m_hDefaultButton, GWL_ID); 
 
\t \t } 
 
\t } 
 
}

這裏是StdAfx.h文件

// stdafx.h : include file for standard system include files, 
 
// or project specific include files that are used frequently, 
 
// but are changed infrequently 
 

 
#pragma once 
 

 
#ifndef VC_EXTRALEAN 
 
#define VC_EXTRALEAN \t \t // Exclude rarely-used stuff from Windows headers 
 
#endif 
 

 
// Modify the following defines if you have to target a platform prior to the ones specified below. 
 
// Refer to MSDN for the latest info on corresponding values for different platforms. 
 
#ifndef WINVER \t \t \t \t // Allow use of features specific to Windows 95 and Windows NT 4 or later. 
 
//#define WINVER 0x0400 \t \t // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. 
 
#define WINVER 0x0602  // SMS2014XXXX alteração para funcionar windows 8 
 
#endif 
 

 
#ifndef _WIN32_WINNT \t \t // Allow use of features specific to Windows NT 4 or later. 
 
//#define _WIN32_WINNT 0x0400 \t \t // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. 
 
#define _WIN32_WINNT 0x0602  // SMS2014XXXX alteração para funcionar windows 8 
 
#endif \t \t \t \t \t \t 
 

 
#ifndef _WIN32_WINDOWS \t \t // Allow use of features specific to Windows 98 or later. 
 
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. 
 
#endif 
 

 
#ifndef _WIN32_IE \t \t \t // Allow use of features specific to IE 4.0 or later. 
 
#define _WIN32_IE 0x0400 \t // Change this to the appropriate value to target IE 5.0 or later. 
 
#endif 
 

 
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS \t // some CString constructors will be explicit 
 

 
// turns off MFC's hiding of some common and often safely ignored warning messages 
 
#define _AFX_ALL_WARNINGS 
 

 
#include <afxwin.h>   // MFC core and standard components 
 
#include <afxext.h>   // MFC extensions 
 
#include <afxdisp.h>  // MFC Automation classes 
 
#include <afxdtctl.h> \t \t // MFC support for Internet Explorer 4 Common Controls 
 

 
#ifndef _AFX_NO_AFXCMN_SUPPORT 
 
#include <afxcmn.h> \t \t \t // MFC support for Windows Common Controls 
 
#endif // _AFX_NO_AFXCMN_SUPPORT 
 

 
#include <afxdhtml.h>

我在Visual Studio中新我沒有IDEIA什麼是錯了這一切。有人可以幫助我嗎?

+0

您必須在每個文件上更改/ Yc和/ Yu編譯選項。這是不實際的,只需使用普通的「stdafx.h」,這樣編譯選項就很好。然後移動.h文件或使用編譯器的「附加包含目錄」設置。 – 2015-02-11 17:05:01

回答

4

這是intellisense和編譯器之間的混淆。

您應該能夠通過添加$(ProjectDir)Additional Include Directories選項的申請,並"StdAfx.h"更換"..\StdAfx.h"智能感知現在應該開始回升的路徑來解決它。

相關問題