S
Habe meinen vorigen post erweitert.
Ich bekomme einen compile error am Arsch des sources,
wenn ich code unter case WM_SIZE setze.
Mit GetWindow versuche ich, ein handle zum EDIT Control
innerhalb des Hauptfensters zu bekommen.
Also hier der ganze neue code
#include <windows.h>
LPCSTR MainClassName = "Texteditor";
// Zum Empfangen und Auswerten der messages
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
// Generelle Fensterstruktur registrieren
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(0));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(1);
wc.lpszClassName = MainClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(0), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Konnte das Hauptfenster nicht registrieren!", "Fehler!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Fenster erstellen
HWND hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
MainClassName,
"Texteditor",
WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
NULL,
NULL,
hInstance,
NULL
);
// Textbox ins Fenster setzen
HWND hwndEdit = CreateWindowEx(
NULL,
"EDIT",
"Gib was ein",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
3, 3, 400, 300,
hWnd,
NULL,
NULL,
NULL
);
// Fenster anzeigen
ShowWindow(hWnd, iCmdShow);
// Auf Messages reagieren
MSG wmsg;
while( GetMessage(&wmsg, NULL, 0, 0) )
{
TranslateMessage(&wmsg);
DispatchMessage(&wmsg);
}
return wmsg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
char string[255];
switch (iMsg)
{
case WM_SIZE:
HWND hEdit = GetWindow(hWnd, GW_CHILD);
SetWindowPos(
hEdit, hWnd,
0, 0, wParam, wParam,
NULL
);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 11:
LoadString(GetModuleHandle(NULL), 21, string, sizeof(string));
MessageBox(hWnd, string, "Öffnen", MB_ICONINFORMATION);
break;
case 12:
LoadString(GetModuleHandle(NULL), 22, string, sizeof(string));
MessageBox(hWnd, string, "Speichern", MB_ICONINFORMATION);
break;
case 13:
DestroyWindow(hWnd);
break;
}
break;
}
// An Windows weitergeben und dessen Antwort als Rückgabewert zurück
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}
Ohne den code unter case WS_SIZE compiliert es ohne Fehlermeldungen.