Z
hi,..
ich habe ein hauptfenster und ein seperates edit fenster,..
eigentlich soll das edit fenster beim erstellen einen text aus einer file laden und anzeigen,..
zusätzlich soll die hintergrundfarbe und die textfarbe sich ändern, schwarz als background und weiß als textfarbe,..
es passiert folgendes:
das edit fenster lädt den text nicht,..
wenn ich einen text eingebe, danach das hauptfenster anwähle erscheint der text als caption,..
keine farbänderung,...
ich bin neu bzgl. winapi daher bitte ich um hilfe,. hier der source,..
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildEdit(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:
{
hEdit = CreateWindow(
"edit",
"", // <- das ist der Inhalt der Editfelds
WS_VISIBLE | WS_VSCROLL|WS_OVERLAPPEDWINDOW | ES_MULTILINE |
ES_AUTOVSCROLL,
0, 0, 0, 0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
return 0;
}
case WM_SIZE:
{
MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;
}
case WM_CLOSE:
{
DestroyWindow(hWnd);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
LRESULT CALLBACK ChildEdit(HWND hEdit, UINT message, WPARAM wparam, LPARAM lparam)
{
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 = (char*) malloc(iFileSize);
fseek(fz, 0, SEEK_SET);
fread(buffer, 1, iFileSize, fz);
fclose(fz);
}
SendMessage (hEdit, WM_SETTEXT, (WPARAM) FALSE, (LPARAM) buffer);
free(buffer);
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hEdit,&ps);
{
SetTextColor(hdc,RGB(255,255,0));
SetBkColor(hdc,RGB(0,0,0));
}
EndPaint(hEdit,&ps);
return 0;
}
case WM_CLOSE:
{
FILE *fz;
char *buffer = NULL;
int iLength;
iLength = GetWindowTextLength(hEdit);
buffer = (char*)malloc(iLength);
GetWindowText(hEdit, buffer, iLength+1);
fz = fopen("text.txt", "wb");
fwrite(buffer, 1, iLength, fz);
fclose(fz);
free(buffer);
DestroyWindow(hEdit);
return 0;
}
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hEdit,&ps);
{
SetTextColor(hdc,RGB(255,255,0));
SetBkColor(hdc,RGB(0,0,0));
}
EndPaint(hEdit,&ps);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hEdit, message, wparam, lparam);
}
danke für potentielle hilfe