`szFileName' was not declared in this scope
-
Hallo,
immer wenn ich mein Programm kompilliere, kommt diese Fehlermeldung. Ich habe die windows.h und die commctrl.h eingebunden, aber immer noch wird diese Fehlermeldung angezeigt.
#include <windows.h> #include <commctrl.h> BOOL LoadText(HWND hEdit, LPCTSTR pszFileName) { HANDLE hFile; BOOL bSuccess = FALSE; hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwFileSize; dwFileSize = GetFileSize(hFile, NULL); if(dwFileSize != 0xFFFFFFFF) { LPSTR pszFileText; pszFileText=(char *)GlobalAlloc(GPTR, dwFileSize + 1); if(pszFileText != NULL) { DWORD dwRead; if(ReadFile( hFile, pszFileText, dwFileSize, &dwRead, NULL ) ) { pszFileText[dwFileSize] = '\0'; if(SetWindowText(hEdit, pszFileText)) bSuccess = TRUE; } GlobalFree(pszFileText); } } CloseHandle(hFile); } return bSuccess; } void OpenFileBox(HWND hwnd) { OPENFILENAME ofn; //char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Datei (*.txt)\0*.txt\0" "MS Word (*.doc)\0*.doc\0" "Alle Dateien (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_EDIT); if(LoadText(hEdit, szFileName)) { SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Geöffnet..."); SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName); } } }Ich habe die Dialogboxen in eine externe Datei gepackt, bei der main.cpp wird auch diese Fehlermeldung angezeigt. Muss ich ausser der Gdi32.lib noch eine Datei hinzufügen?
-
Das hat nix mit Headern oder Libs zu tun. In deiner Funktion OpenFileBox gibt es einfach keine Variable mit dem Namen szFileName. Die musst du schon selbst erzeugen...
-
Hallo,
jetzt habe ich folgendes Problem:
Ich habe einen selbst geschriebenen Editor. Nun kann ich Dateien im DOC Format speichern, aber wenn ich das Dokument mit MS Word öffnen will, kommt nur:
"Das angegbene Feature ist nicht installiert. Möchten Sie es installieren?"
Wenn ich auf Abbrechen gehe, dann zeigt er mir aber nur ein leeres Blatt an. Wie kann ich das ändern?
-
Auch bei Text-Dateien wird dann nur ein leeres Feld angezeigt.
-
Hier ist der Code:
main.cpp#include <windows.h> #include <string.h> #include <commctrl.h> #include "resource.h" #include "dialogs.h" LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); //Deklaration der Windows-Nachrichten-Prozedur HINSTANCE hlnst; int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow) { char szName[] = "Fensterklasse"; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; // CS = "class style" wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hI; wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH); wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); wc.lpszClassName = szName; RegisterClass (&wc); HWND hwnd = CreateWindow (szName, "Editor", WS_OVERLAPPEDWINDOW, -4, -2, 1030, 775, NULL, NULL, hI, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); // Nachrichten-Schleife MSG msg; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } // Windows-Nachrichten-Prozedur LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; char string[255]; static HWND hEdit; switch (message) { case WM_CREATE: hEdit = CreateWindow("edit","",WS_CHILD|WS_VISIBLE|WS_HSCROLL| WS_VSCROLL|ES_LEFT|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL, 0,0,1024,768,hwnd, (HMENU)2,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); return 0; case WM_SETFOCUS: SetFocus ( hEdit ); return 0; case WM_SIZE: MoveWindow(hEdit,0,0,LOWORD(lParam),HIWORD(lParam),TRUE); return 0; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_FILE_NEW: SetDlgItemText(hwnd, IDC_EDIT, ""); SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Neue Datei..."); SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)"Unbenannt"); return 0; case ID_FILE_OPEN: OpenFileBox(hwnd); return 0; case ID_FILE_SAVE: SaveFileBox(hwnd); return 0; case ID_FILE_EXIT: DestroyWindow(hwnd); break; case ID_FILE_FONT: FontChooseFont(hEdit); FontSetFont(hEdit); return 0; } break; case WM_CLOSE: DestroyWindow(hwnd); case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }dialogs.h
#ifndef DIALOGS_H_INCLUDED #define DIALOGS_H_INCLUDED #include <windows.h> #include <commctrl.h> #include "resource.h" #define SCHWARZ RGB(0,0,0) static LOGFONT logfont; static HFONT hfont; void SetupChooseColor(CHOOSECOLOR *cc,COLORREF *customclrs, HWND hwnd, COLORREF init) { int ca; for(ca = 0; ca < 16; ca++) *(customclrs+ca) = SCHWARZ; cc->lStructSize = sizeof(CHOOSECOLOR); cc->hwndOwner = hwnd; cc->rgbResult = init; cc->lpCustColors = customclrs; cc->Flags = CC_ANYCOLOR|/*CC_FULLOPEN|*/CC_RGBINIT; } BOOL FontChooseFont (HWND hwnd) { CHOOSEFONT cf ; ZeroMemory(&cf, sizeof(cf)); cf.lStructSize = sizeof (CHOOSEFONT) ; cf.hwndOwner = hwnd ; cf.lpLogFont = &logfont ; cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS ; //Dialogbox:Schriftart auswählen return ChooseFont (&cf) ; } void FontInitialize (HWND hwndEdit) { GetObject (GetStockObject (SYSTEM_FONT), sizeof (LOGFONT), (PTSTR) &logfont) ; hfont = CreateFontIndirect (&logfont) ; SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hfont, 0) ; } void FontSetFont (HWND hwndEdit) { HFONT hFontNew ; RECT rect ; hFontNew = CreateFontIndirect (&logfont) ; SendMessage (hwndEdit, WM_SETFONT, (WPARAM) hFontNew, 0) ; DeleteObject (hfont) ; hfont = hFontNew ; GetClientRect (hwndEdit, &rect) ; InvalidateRect (hwndEdit, &rect, TRUE) ; } BOOL LoadText(HWND hEdit, LPCTSTR pszFileName) { HANDLE hFile; BOOL bSuccess = FALSE; hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwFileSize; dwFileSize = GetFileSize(hFile, NULL); if(dwFileSize != 0xFFFFFFFF) { LPSTR pszFileText; pszFileText=(char *)GlobalAlloc(GPTR, dwFileSize + 1); if(pszFileText != NULL) { DWORD dwRead; if(ReadFile( hFile, pszFileText, dwFileSize, &dwRead, NULL ) ) { pszFileText[dwFileSize] = '\0'; if(SetWindowText(hEdit, pszFileText)) bSuccess = TRUE; } GlobalFree(pszFileText); } } CloseHandle(hFile); } return bSuccess; } void OpenFileBox(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Datei (*.txt)\0*.txt\0" "MS Word (*.doc)\0*.doc\0" "Alle Dateien (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_EDIT); if(LoadText(hEdit, szFileName)) { SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Geöffnet..."); SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName); } } } BOOL SaveText(HWND hEdit, LPCTSTR pszFileName) { HANDLE hFile; BOOL bSuccess = FALSE; hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwTextLength; dwTextLength = GetWindowTextLength(hEdit); if(dwTextLength > 0) { LPSTR pszText; DWORD dwBufferSize = dwTextLength + 1; pszText =(char *)GlobalAlloc(GPTR, dwBufferSize); if(pszText != NULL) { if(GetWindowText(hEdit, pszText, dwBufferSize)) { DWORD dwWritten; if(WriteFile(hFile,pszText,dwTextLength, &dwWritten, NULL ) ) bSuccess = TRUE; } GlobalFree(pszText); } } CloseHandle(hFile); } return bSuccess; } void SaveFileBox(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Datei (*.txt)\0*.txt\0" /**"MS Word (*.doc)\0*.doc\0"**/ "Alle Dateien (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.lpstrDefExt = "txt"; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if(GetSaveFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_EDIT); if(SaveText(hEdit, szFileName)) { SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Gespeichert..."); SendDlgItemMessage(hwnd, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName); } } } #endif // DIALOGS_H_INCLUDED
-
Ich schreibe auch einen Editor

Du musst einfach Zeile 42 in deinem ersten Post einkommentieren.Hast du dir mal die erstellte Datei mit zum Beispiel Notepad angesehen? Ist es eine anständige doc-Datei oder eine falsche oder ist sie leer?
-
Du bist einfach nur zu blöde Microsoftsachen zu programmieren! Lass es doch sein, hat eh keinen Wert.
http://www.c-plusplus.net/forum/viewtopic-var-p-is-1814284-and-highlight-is-.html#1814284