1
我在ATL dll文件中創建了一個對話框,並添加了一個類來操縱它的性能。我好不容易最初使它編譯,但現在(因爲扭捏包括可能)我收到在編譯的奇怪的消息:創建對話框時沒有類或名稱空間框
CTestDlg:無類或命名空間
我舉頭和源代碼下面CPP文件:
#pragma once
#include "resource.h" // Hauptsymbole
#include <atlhost.h>
class CTestDlg : public CAxDialogImpl<CTestDlg>
{
private:
bool m_cancel;
public:
CTestDlg()
{
m_cancel = true;
}
~CTestDlg()
{
}
enum { IDD = IDD_TESTDLG };
BEGIN_MSG_MAP(CTestDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
COMMAND_HANDLER(IDC_EDIT1, EN_CHANGE, OnEnChangeEdit1)
CHAIN_MSG_MAP(CAxDialogImpl<CTestDlg>)
END_MSG_MAP()
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CAxDialogImpl<CTestDlg>::OnInitDialog(uMsg, wParam, lParam, bHandled);
bHandled = TRUE;
//CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
//pEdit->SetWindowTextW(L"Hello");
CWindow textBox(GetDlgItem(IDC_EDIT1));
textBox.SetWindowTextW(L"hello");
//textBox.SendMessageW(WM_SETTEXT, 0, (LPARAM)L"test!!!");
return 1; // Das System kann den Fokus festlegen
}
LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
m_cancel = false;
return 0;
}
LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
LRESULT OnEnChangeEdit1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
bool IsCancelled() const { return m_cancel; }
bool saveFile();
};
//.cpp文件
#include "CTestDlg.h"
#include "stdafx.h"
LRESULT CTestDlg::OnEnChangeEdit1(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
return 0;
}
bool CTestDlg::saveFile()
{
OPENFILENAME ofn;
WCHAR szFileName[MAX_PATH] = L"";
ZeroMemory(&ofn , sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFilter = (LPCWSTR)L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = (LPWSTR)szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = (LPCWSTR)L"txt";
if(GetSaveFileNameW(&ofn))
{
HANDLE hFile = CreateFile(ofn.lpstrFile,
GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL);
DWORD dwBytesWritten = 0;
char str[] = "Example text testing WriteFile";
WriteFile(hFile, str, strlen(str), &dwBytesWritten, NULL);
CloseHandle(hFile);
return true;
}
else
return false;
}
什麼似乎是錯誤的代碼的任何指示?
我們需要完整的錯誤信息。 – orlp 2012-07-17 08:06:28
你在哪裏使用這門課?在哪個文件中? – flamingo 2012-07-17 08:08:53
錯誤C2653:CTestDlg:沒有類或名稱空間。對不起,我提供的最初錯誤並不完全正確。我編輯了這個問題。 – arjacsoh 2012-07-17 08:09:03