Winapi Editbox fehler
-
Hallo

Ich habe ein problem mit dem code (von http://www.win-api.de/tutorials.php?tutid=18&SessID=5ec51edfb6db3ac87cb044ab95eaa75c)ich bekomme immer doe fehler meldung : " invalid conversion 'void to 'car "
und der will irgentwas mit den beiden dinger haben:
buffer = malloc(iFileSize);
buffer = malloc(iLength);wenn ich die aber weg lasse dann schreib der nicht miehr in die test.txt ...

hier der code:
#include <windows.h> #include <stdio.h> #include <stdlib.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASS wc; const char szAppName[] = "Editcontrol Tutorial"; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = szAppName; RegisterClass(&wc); hWnd = CreateWindow( szAppName, "Editcontrol Tutorial", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL ); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hEdit; switch(message) { case WM_CREATE: { FILE *fz; char *buffer = NULL; int iFileSize; fz = fopen("text.txt", "rb"); if(fz != NULL) { fseek(fz, 0, SEEK_END); iFileSize = ftell(fz); buffer = malloc(iFileSize); fseek(fz, 0, SEEK_SET); fread(buffer, 1, iFileSize, fz); fclose(fz); } hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", buffer, // <- das ist der Inhalt der Editfelds WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 0, 0, 0, 0, hWnd, NULL, ((LPCREATESTRUCT) lParam) -> hInstance, NULL); free(buffer); return 0; } case WM_SIZE: { MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); return 0; } case WM_CLOSE: { FILE *fz; char *buffer = NULL; int iLength; iLength = GetWindowTextLength(hEdit); buffer = malloc(iLength); GetWindowText(hEdit, buffer, iLength+1); fz = fopen("text.txt", "wb"); fwrite(buffer, 1, iLength, fz); fclose(fz); free(buffer); DestroyWindow(hWnd); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
-
Hi probiers mal so:
buffer = (char *) malloc(iFileSize); buffer = (char *) malloc(iLength);Malloc liefert einen Zeiger auf void muss, da C++-Compiler das nicht akzeptieren, gecastet (explizite Typenumwandlung) werden.
Wenn du für buffer keinen Speicherplatz reservierst, kann GetWindowText dort nicht den Text reinschreiben.
GetWindowText(hEdit, buffer, iLength+1);Folglich wird in die Datei die leere Variable buffer via
fwrite(buffer, 1, iLength, fz)geschrieben.
MfG WilMen :xmas1:
-
schön , tuts aber es steht nix in der test.txt datei

ich hab alles genau so gemacht wie du wolltes
-
also gut , hier ist der neue code

#include <windows.h> #include <stdio.h> #include <stdlib.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow) { char szName[] = "Fensterklasse"; HBRUSH MyBrush = CreateSolidBrush( RGB( 212, 208, 200 ) ); WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hI; wc.hIcon = LoadIcon (NULL, IDI_WINLOGO); wc.hCursor = 0; wc.hbrBackground = MyBrush; wc.lpszMenuName = NULL; wc.lpszClassName = szName; RegisterClass (&wc); HWND hwnd = CreateWindow (szName, "PPH", WS_OVERLAPPEDWINDOW, 0, 0, 400, 100, NULL, NULL, hI, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); //----------------------------------------------------------------------------------- MSG msg; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; static HWND hwndEdit1, hwndEdit2 ,hwndEdit3; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps); SetTextColor(hdc, RGB(0,0,0) ); SetBkColor(hdc, RGB(212,208,200) ); TextOut (hdc, 20, 10, "Name:", 5); TextOut (hdc, 20, 30, "Icq Adresse:", 12); TextOut (hdc, 20, 50, "Icq Passwort:", 13); EndPaint (hwnd, &ps); return 0; case WM_CREATE : { FILE *fz; char *buffer = NULL; int iFileSize; fz = fopen("text.txt", "rb"); if(fz != NULL) { fseek(fz, 0, SEEK_END); iFileSize = ftell(fz); buffer = (char *) malloc(iFileSize); fseek(fz, 0, SEEK_SET); fread(buffer, 1, iFileSize, fz); fclose(fz); } hwndEdit1 = CreateWindow ( "edit", "", WS_CHILD | WS_VISIBLE , 150, 10, 100, 16, hwnd, (HMENU)2, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); hwndEdit2 = CreateWindow ( "edit", "", WS_CHILD | WS_VISIBLE , 150, 30, 100, 16, hwnd, (HMENU)2, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); hwndEdit3 = CreateWindow ( "edit", "", WS_CHILD | WS_VISIBLE| ES_PASSWORD, 150, 50, 100, 16, hwnd, (HMENU)2, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); free(buffer); return 0; } case WM_COMMAND: switch(LOWORD(wParam)) { case 1: SetWindowText(hwndEdit2,""); SendMessage(hwndEdit2, EM_SETREADONLY, TRUE, 0); break; case 2: SendMessage(hwndEdit2, EM_SETREADONLY, FALSE, 0); break; } return 0; case WM_CLOSE: { FILE *fz; char* buffer = NULL; int iLength; iLength = GetWindowText(hwndEdit1, buffer, iLength+1); iLength = GetWindowText(hwndEdit2, buffer, iLength+2); iLength = GetWindowText(hwndEdit3, buffer, iLength+3); buffer = (char *) malloc(iLength); GetWindowText(hwndEdit1, buffer, iLength+1); fz = fopen("text.txt", "wb"); fwrite(buffer, 1, iLength, fz); fwrite(buffer, 2, iLength, fz); fwrite(buffer, 3, iLength, fz); fclose(fz); free(buffer); DestroyWindow(hwnd); return 0; } case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }
-
habs schon ...