Hallo alle miteinander,
ich habe mit der WinAPI ein kleines Schreibprogramm für Windows erstellt, mit der man eben eine Datei erstellen kann und diese dann auch dementsprechend laden/öffnen. So die Theorie, denn es wird jeweils nur der erste Buchstabe des eingegebenen Textes in der Datei gespeichert. Ums öffnen hab ich mich dann erst garnicht gekümmert...
C
#define STRICT
#define NULL 0
#include <Windows.h>
#include <fstream>
using namespace std;
HWND hWndSave;
HWND hWndOpen;
HWND hWndEdit;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
LPWSTR szName = L"Fenterklasse";
WNDCLASS wc;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW; // CS = "class style"
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground= CreateSolidBrush(RGB(240, 240, 240));
wc.lpszMenuName = NULL;
wc.lpszClassName= szName;
RegisterClass(&wc);
HWND hWnd = CreateWindow(szName, L"Schreibprogramm", WS_SYSMENU | WS_MINIMIZEBOX, 30, 30, 1024, 768, 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)
{
HDC hdc; // Handle Device Context
PAINTSTRUCT ps;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TextOut(hdc, 20, 10, L"Editbox und Button:", 19);
EndPaint(hWnd, &ps);
return 0;
case WM_CREATE:
hWndSave = CreateWindow(L"Button", L"Dokument speichern", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
20, 20, 482, 30, hWnd, (HMENU)1, GetModuleHandle(0), 0);
hWndOpen = CreateWindow(L"Button", L"Dokument öffnen", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
516, 20, 482, 30, hWnd, (HMENU)2, GetModuleHandle(0), 0);
hWndEdit = CreateWindow(L"Edit", L"", WS_VISIBLE | WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL, // ES = "edit style"
20, 70, 978, 650, hWnd, (HMENU)3, GetModuleHandle(0), 0);
return 0;
case WM_COMMAND:
switch(wParam)
{
case 1:
int len = SendMessage(hWndEdit, WM_GETTEXTLENGTH, 0, 0); // Länge des Textes
char *buf = new char[len + 1];
SendMessage(hWndEdit, WM_GETTEXT, len + 1, (LPARAM)buf);
ofstream file("MeinText.txt", ios::out|ios::binary);
if(file << buf)
MessageBox(hWnd, L"Der Text wurde erfolgreich gespeichert!", L"Gespeichert", MB_OK | MB_ICONINFORMATION);
file.close();
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Alles anzeigen
Ideen woran das liegen könnte?
Grüße
tomate22