Wiso funktioniert das nicht?!
-
#include <windows.h> typedef struct BUTTON_{ HWND hwnd; int cx, cy; POINT pos; } BUTTON; typedef struct EDIT_{ HWND hwnd; int cx, cy; POINT pos; } EDIT; typedef struct GROUPBOX_{ HWND hwnd; int cx, cy; POINT pos; } GROUPBOX; LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); BUTTON CreateButton(HWND, int, char *); VOID MoveButton(BUTTON *, int, int); EDIT CreateEdit(HWND, int, int); VOID MoveEdit(EDIT *, int, int); GROUPBOX CreateGroupbox(HWND, int, char *); char szClassName[ ] = "Edit"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ szClassName, /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); ShowWindow (hwnd, nFunsterStil); UpdateWindow(hwnd); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient, cxChar, cyChar; static BUTTON button[2]; static EDIT edit[2]; static GROUPBOX groupbox; HDC hdc; PAINTSTRUCT ps; char szBuffer[128]; static int iLen; int i; switch (message) { case WM_DESTROY: PostQuitMessage (0); break; case WM_CREATE: cxChar = LOWORD(GetDialogBaseUnits()); cyChar = HIWORD(GetDialogBaseUnits()); groupbox = CreateGroupbox(hwnd, 10, "Control"); for(i = 0; i < 2; i++){ edit[i] = CreateEdit(hwnd, (20 + i), 10); iLen = wsprintf(szBuffer, "Button %d", i); button[i] = CreateButton(hwnd, (30 + i), szBuffer); } break; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); // MoveButton(&button[1], cxClient/2, cyClient/2); MoveEdit(&edit[0], cxClient/2, cyClient/2); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; case WM_COMMAND: break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } BUTTON CreateButton(HWND hwndParent, int id, char * szCaption) { BUTTON button; HINSTANCE hInstance; hInstance = (HINSTANCE) GetWindowLong(hwndParent, GWL_HINSTANCE); button.hwnd = CreateWindowEx( 0, "button", szCaption, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 0, 0, hwndParent, (HMENU) id, hInstance, NULL); button.cx = LOWORD(GetDialogBaseUnits()) * (strlen(szCaption) + 2); button.cy = HIWORD(GetDialogBaseUnits())/4 * 7; button.pos.x = 0; button.pos.y = 0; return(button); } VOID MoveButton(BUTTON * button, int x, int y) { RECT rect; rect.left = button->pos.x - 10; rect.top = button->pos.y - 10; rect.right = rect.left + button->cx + 20; rect.bottom = rect.top + button->cy + 20; button->pos.x = x; button->pos.y = y; MoveWindow(button->hwnd, x, y, button->cx, button->cy, TRUE); InvalidateRect(GetParent(button->hwnd), &rect, TRUE); } EDIT CreateEdit(HWND hwndParent, int id, int cChars) { EDIT edit; HINSTANCE hInstance; hInstance = (HINSTANCE) GetWindowLong(hwndParent, GWL_HINSTANCE); edit.hwnd = CreateWindowEx( 0, "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOHSCROLL, 0, 0, 0, 0, hwndParent, (HMENU) id, hInstance, NULL); edit.cx = LOWORD(GetDialogBaseUnits()) * cChars; edit.cy = HIWORD(GetDialogBaseUnits())/3 * 4; edit.pos.x = 0; edit.pos.y = 0; return(edit); } VOID MoveEdit(EDIT * edit, int x, int y) { RECT rect; rect.left = edit->pos.x - 10; rect.top = edit->pos.y - 10; rect.right = rect.left + edit->cx + 20; rect.bottom = rect.top + edit->cy + 20; edit->pos.x = x; edit->pos.y = y; MoveWindow(edit->hwnd, x, y, edit->cx, edit->cy, TRUE); InvalidateRect(GetParent(edit->hwnd), &rect, TRUE); } GROUPBOX CreateGroupbox(HWND hwndParent, int id, char * szCaption) { GROUPBOX groupbox; HINSTANCE hInstance; hInstance = (HINSTANCE) GetWindowLong(hwndParent, GWL_HINSTANCE); groupbox.hwnd = CreateWindowEx( 0, "button", szCaption, WS_VISIBLE | WS_CHILD | BS_GROUPBOX, 0, 0, 0, 0, hwndParent, (HMENU) id, hInstance, NULL); groupbox.cx = 0; groupbox.cy = 0; groupbox.pos.x = 0; groupbox.pos.y = 0; return(groupbox); }Hi Leute,
erst mal tut mir Leid, das ich so viel code hier reinpacke.
Ich weis einfach nicht, wo ich den Fehler suchen soll. Nach einigen Tests stelle ich fest, dass es probleme mit CreateEdit() zu geben scheint:
Das Problem:
Wenn ich das Programm starte, kommt kein fenster, und das Bild fängt an zu flackern
Wenn ich die Operationen mit dem Edit rauskomentiere, dann funktioniert alles.
Aber wo ist nun der Fehler?Für Eure Antwort wäre ich sehr dankbar

gruss

-
Schlechter Beitrag. Bitte vernünftige Beiträge erstellen.
-
Tipp schrieb:
Schlechter Beitrag. Bitte vernünftige Beiträge erstellen.
Ja sorry, ist mir schon aufgefallen. Tut mir leid kommt nicht mehr wider vor

-
So ich hab nun endlich den Fehler gefunden:
Ich hatte die Fensterklasse (meines Haubtfensters) "edit" genannt. So heist aber bereits die Klasse das Edits. Das hat zu Fehlern geführt.
Vielen Dank an alle, die sich dennoch bemüht haben

gruss