读书人

哪位高手能帮小弟我看看这个有关问题

发布时间: 2012-01-19 00:22:27 作者: rapoo

谁能帮我看看这个问题
我从网上下了一个程序,编译时提示
C:\Documents and Settings\Administrator\桌面\openfiledlg\StatLink.cpp(179) : error C2065: 'GetSystemWindowsDirectory' : undeclared identifier
执行 cl.exe 时出错.
可我找StatLink.cpp 179行没发现'GetSystemWindowsDirectory' 这个函数,请教一下该怎么改?
StatLink.cpp文件如下:
////////////////////////////////////////////////////////////////
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0 for Windows XP and probably Windows 2000 too.
//
#include "StdAfx.h"
#include "MyDlg.h"
#include "FileDlgHelper.h"
#include "Resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// IDs of controls in Explorer-style dialog, from Spy
#define ID_FILESOFTYPE0x0441
#define ID_FILENAME0x0442
#define ID_LOOKIN0x0443

IMPLEMENT_DYNAMIC(CMyOpenDlg, CFileDialog)
BEGIN_MESSAGE_MAP(CMyOpenDlg, CFileDialog)
ON_COMMAND(ID_SELECT_ALL,OnSelectAll)
ON_UPDATE_COMMAND_UI(ID_SELECT_ALL,OnUpdateSelectAll)
ON_WM_SIZE()
END_MESSAGE_MAP()

//////////////////
// does path ends in ".txt" ?
//
static BOOL IsTextFileName(CString fn)
{
fn.MakeLower();
return fn.Right(4)==".txt";
}

////////////////
// Constructor
//
CMyOpenDlg::CMyOpenDlg() : CFileDialog(TRUE,
NULL, // no default extension
NULL, // ..or file name
OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,
_T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"))
{
m_ofn.lpstrTitle = _T("请选择文件或文件夹");
}

//////////////////
// Initialize dialog.
// For Explorer, this is actually a child of the main dialog.
//
BOOL CMyOpenDlg::OnInitDialog()
{
// subclass controls...
m_edit1.SubclassDlgItem(IDC_MYDLGINFO1, this);
m_edit2.SubclassDlgItem(IDC_MYDLGINFO2, this);

// initialize helper
m_dlghelper.Init(this);

return CFileDialog::OnInitDialog();
}

//////////////////
// Select all text files. This won't work if user has checked "Hide
// extensions for known file types" because then the item name in the list
// box doesn't end in .txt !!
//
void CMyOpenDlg::OnSelectAll()
{
CFileDlgHelper& fdh = m_dlghelper;
CListCtrl* plc = fdh.GetListCtrl();
for (int i=0; i<plc->GetItemCount(); i++) {
CString fn = fdh.GetItemName(i);
if (IsTextFileName(fn)) {
plc->SetItemState(i,LVIS_SELECTED,LVIS_SELECTED);
}
}
plc->SetFocus();
}

//////////////////
// Update "Select All" button: disable if no .txt files. This won't work if
// user has checked "Hide extensions for known file types" because then the
// item name in the list box doesn't end in .txt !!
//
void CMyOpenDlg::OnUpdateSelectAll(CCmdUI* pCmdUI)
{
CFileDlgHelper& fdh = m_dlghelper;
CListCtrl* plc = fdh.GetListCtrl();
for (int i=0; i<plc->GetItemCount(); i++) {
CString fn = fdh.GetItemName(i);
if (IsTextFileName(fn)) {
pCmdUI->Enable(TRUE);
return;
}
}
pCmdUI->Enable(FALSE);
}

//////////////////
// DoModal override: use my template
//
int CMyOpenDlg::DoModal()
{
// Add my custom dialog to bottom
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_MYOPENDLG);
m_ofn.Flags |= OFN_ENABLETEMPLATE;
return CFileDialog::DoModal();
}

//////////////////
// User selected new file (CDN_SELCHANGE)
//
void CMyOpenDlg::OnFileNameChange()
{
ShowFileInfo();
}

//////////////////
// User selected new folder (CDN_SELCHANGE)
//
void CMyOpenDlg::OnFolderChange()


{
ShowFileInfo();
}

//////////////////
// User selected new file type (from drop-down)
//
void CMyOpenDlg::OnTypeChange()
{
ShowFileInfo();
}

////////////////// CDM_GETFILEPATH
// Common helper: show information in the preview and debug panes
//
void CMyOpenDlg::ShowFileInfo()
{
CFileDlgHelper& fdh = m_dlghelper;
CString path = GetPathName();
CString fldr = GetFolderPath();

// Create debug message
//
CString s;
s.Format("GetPathName=%s\nGetFolderPath=%s\n",
(LPCTSTR)path, (LPCTSTR)fldr);

int nSelected = 0;
s += "选中:\n";
CListCtrl* plc = fdh.GetListCtrl();
POSITION pos = plc->GetFirstSelectedItemPosition();
while (pos) {
int i = plc->GetNextSelectedItem(pos);
CString name = fdh.GetItemName(i);
CString type;
if (fdh.IsItemFolder(i))
type = "(此为文件夹)";
CString s2;
s2.Format(" %s %s\n", (LPCTSTR)name, (LPCTSTR)type);
s += s2;
nSelected++;
}
AddText(m_edit2, s, TRUE);

// Create preview text
//
s.Empty();
if (nSelected==1 && IsTextFileName(path)) {
s = GetTextPreview(path);
} else if (nSelected>1) {
s = "[选中多个文件]";
} else if (nSelected==0) {
s = "[没有选择]";
}                     //179行
AddText(m_edit1,s,TRUE);
}

//////////////////
// Preview: Read first 256 characters of text file
//
CString CMyOpenDlg::GetTextPreview(LPCTSTR pszPath)
{
CString buf;
CFile f;
if (f.Open(pszPath,CFile::modeRead)) {
int len = f.Read(buf.GetBuffer(256),256);
buf.ReleaseBuffer();
if (len==256)
buf += "...";
}
return buf;
}

//////////////////
// Helper adds text to an edit control that I've added to the open dialog
//
void CMyOpenDlg::AddText(CEdit& wndEdit, LPCTSTR lpText, BOOL bClear)
{
if (wndEdit) {
// Convert \n to \n\r for Windows brain-damaged edit control !&#%!
// It's 2001, and I'm still writing code like this!
//
LPCTSTR src = lpText;

TCHAR buf[1024];
TCHAR* dst = buf;
TCHAR* endbuf = buf + sizeof(buf) - 1;

while (*src && dst < endbuf) {
if (*src == '\n')
*dst++ = '\r';
*dst++ = *src++;
}
*dst = 0;

wndEdit.SetSel(bClear ? 0 : -1, -1); // end of edit text
wndEdit.ReplaceSel(buf);// append string..
wndEdit.SendMessage(EM_SCROLLCARET);// ..and show caret
}
}

//////////////////
// Dialog was sized: reposition my controls. Zzzzz.
//
void CMyOpenDlg::OnSize(UINT nType, int cx, int cy)
{
CWnd* pDlg = GetParent();
CRect rcDlg;
pDlg->GetWindowRect(&rcDlg);

CWnd* pCancel = pDlg->GetDlgItem(IDCANCEL);
ASSERT(pCancel);
CRect rcCancel;
pCancel->GetWindowRect(&rcCancel);

int cxRightMargin = rcDlg.right-rcCancel.right;

CWnd* pSelAll = GetDlgItem(ID_SELECT_ALL);
ASSERT(pSelAll);
CRect rc;
pSelAll->GetWindowRect(&rc);
rc.left = rcDlg.right - cxRightMargin - rcCancel.Width();
rc.right = rc.left + rcCancel.Width();
rc.bottom= rc.top + rcCancel.Height();
ScreenToClient(&rc);
pSelAll->SetWindowPos(NULL,rc.left,rc.top,rc.Width(),rc.Height(),0);

for (int i = IDC_MYDLGINFO1; i<= IDC_MYDLGINFO2; i++) {
CWnd* pInfoWnd = GetDlgItem(i);
ASSERT(pInfoWnd);
pInfoWnd->GetWindowRect(&rc);
rc.right = rcDlg.right - cxRightMargin;
ScreenToClient(&rc);
pInfoWnd->SetWindowPos(NULL,rc.left,rc.top,rc.Width(),rc.Height(),0);
}
}




------解决方案--------------------


加个头文件

#include "Windows.h"
[解决办法]
我们看到的是不是你编译的代码啊
试一试将179行之前加入错误代码,比如

C/C++ code
int d,e;d-e = 199; 

读书人网 >VC/MFC

热点推荐