"expected nqualified- id перед строковой константой"
Мне всего 17 лет, поэтому, пожалуйста, поймите, что этот код, вероятно, не будет лучшим, что вы увидите.< /p>
Я пробовал использовать более старую версию RichEdit (Riched20.dll), но выдала ту же ошибку. При просмотре в Интернете другие источники StackOverflow сказали, что это может быть так же просто, как отсутствующая точка с запятой или добавление второго включения. Однако я просматривал это уже целый час и так и не увидел ничего. Любая помощь будет принята с благодарностью! Я также пробовал компилировать в UNICODE, потому что знаю, что строковые литералы иногда могут быть неуместными. Я использую TDM-GCC для компиляции, есть ли вероятность того, что я ввожу неверную команду?
WinMain.cpp
Код: Выделить всё
#define UNICODE
#define _UNICODE
#include
#include
#include
#include
#include
#include
#include
#define ID_FILE_OPEN 1
#define ID_FILE_SAVE 2
#define ID_FILE_EXIT 3
const wchar_t CLASS_NAME[] = L"Win32 Text Editor";
static const wchar_t MSFTEDIT_CLASS[] = L"RICHEDIT20W";
// Function prototypes
void LoadFileContents(const std::wstring& filePath, HWND hRichEdit);
void SaveFileContents(const std::wstring& filePath, HWND hRichEdit);
void OpenFile(HWND hwnd);
void SaveFile(HWND hwnd);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Main entry point
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR, int nCmdShow) {
// Load RichEdit DLL
LoadLibrary(L"Riched20.dll");
InitCommonControls();
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
0, CLASS_NAME, L"Win32 Text Editor", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
nullptr, nullptr, hInstance, nullptr);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg = {};
while (GetMessage(&msg, nullptr, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
// Window Procedure
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static HWND hRichEdit;
switch (uMsg) {
case WM_CREATE:
hRichEdit = CreateWindowEx(
0, MSFTEDIT_CLASS, nullptr, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |
ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER,
0, 0, 800, 600, hwnd, nullptr, ((LPCREATESTRUCT)lParam)->hInstance, nullptr);
break;
case WM_SIZE:
MoveWindow(hRichEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_FILE_OPEN:
OpenFile(hwnd);
break;
case ID_FILE_SAVE:
SaveFile(hwnd);
break;
case ID_FILE_EXIT:
PostQuitMessage(0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
// File handling functions
void OpenFile(HWND hwnd) {
OPENFILENAME ofn = {};
wchar_t szFile[260] = {};
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrTitle = L"Open a file";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)) {
LoadFileContents(ofn.lpstrFile, hwnd);
}
}
void SaveFile(HWND hwnd) {
OPENFILENAME ofn = {};
wchar_t szFile[260] = {};
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = L"Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrTitle = L"Save a file";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
if (GetSaveFileName(&ofn)) {
SaveFileContents(ofn.lpstrFile, hwnd);
}
}
void LoadFileContents(const std::wstring& filePath, HWND hRichEdit) {
std::wifstream file(filePath.c_str());
if (file.is_open()) {
std::wstring content((std::istreambuf_iterator(file)),
(std::istreambuf_iterator()));
SetWindowText(hRichEdit, content.c_str());
}
}
void SaveFileContents(const std::wstring& filePath, HWND hRichEdit) {
std::wstring content;
int length = GetWindowTextLength(hRichEdit);
if (length > 0) {
content.resize(length + 1); // Resize for null terminator
GetWindowText(hRichEdit, &content[0], length + 1);
}
std::wofstream file(filePath.c_str());
if (file.is_open()) {
file
Подробнее здесь: [url]https://stackoverflow.com/questions/79055594/expected-nqualified-id-before-string-constant-in-richedit-program[/url]