Einer meiner Button wird nicht angezeigt...
-
hi
ich suche schon länger den Fehler in meinem Code, welcher bewirkt das einer der drei Buttons nicht angezeigt wird. Der Compiler gibt aber keinen Fehler aus.
Wahrscheinlich habe ich was übersehen. Vielleicht kann mir ja jemand helfen...Erstmal der Code...
(durch die vielen Schnipsel, die ich aus der Not/Verzweifelung hinein kopiert habe, wirkt das ein oder andere vielleicht ein bisschen komisch oder überflüssig)#include <windows.h> /* Declare Windows procedure */ #define i 1 #define j 2 #define k 3 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */ char szAppName[ ] = "CodeBlocksWindowsApp"; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; /* Register the window class, and if it fails quit the program */ if (!RegisterClass (&wndclass)) { // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit MessageBox (NULL, TEXT ("Programm arbeitet mit Unicode und setzt Windows NT voraus!"), szAppName, MB_ICONERROR) ; return 0 ; } /* The class is registered, let's create the program*/ hwnd = CreateWindow (szAppName, TEXT ("Varianten von Kontrollelementen"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; /* Make the window visible on the screen */ ShowWindow (hwnd, iCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HWND hwndButton; static HWND hwndbutton; static HWND hwndbuttonen; static RECT rect; static int cxChar, cyChar ; HDC hdc ; PAINTSTRUCT ps ; switch (message) /* handle the messages */ { case WM_CREATE: cxChar = LOWORD (GetDialogBaseUnits ()) ; cyChar = HIWORD (GetDialogBaseUnits ()) ; //der folgende ist der Problembutton, der nicht angezeigt wird hwndButton = CreateWindow (TEXT("button1"), "Butoon1", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, cxChar, cyChar * (1 + 2* k), 21 * cxChar, 8 * cyChar / 3,hwnd,(HMENU) k, ((LPCREATESTRUCT) lParam)->hInstance, NULL); //der folgende wird angezeigt hwndbutton = CreateWindow ( TEXT("button"), "DEFPUSHBUTTON1", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, cxChar, cyChar * (1 + 2 * i), 20 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) i, ((LPCREATESTRUCT) lParam)->hInstance, NULL) ; //der folgende wird angezeigt hwndbuttonen = CreateWindow ( TEXT("button"), "DEFPUSHBUTTON2", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, cxChar, cyChar * (1 + 2 * j), 20 * cxChar, 7 * cyChar / 4, hwnd, (HMENU) j, ((LPCREATESTRUCT) lParam)->hInstance, NULL) ; return 0; case WM_SIZE : //rect.left = 24 * cxChar ; //rect.top = 2 * cyChar ; //rect.right = LOWORD (lParam) ; //rect.bottom = HIWORD (lParam) ; return 0 ; case WM_PAINT : InvalidateRect (hwnd, &rect, TRUE) ; hdc = BeginPaint (hwnd, &ps) ; //Paint EndPaint (hwnd, &ps) ; return 0 ; case WM_DRAWITEM : case WM_COMMAND : hdc = GetDC (hwnd) ; ReleaseDC (hwnd, hdc) ; InvalidateRect (hwnd, &rect, TRUE) ; break ; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }Vielleicht kann mir ja jemand helfen...
und vielleicht hat ja auch jemand VerbesserungsvorschlägeDanke an alle, die zu einer Lösung beitragen...

-
Beim Problembutton hast du dich verschrieben.
hwndButton = CreateWindow (TEXT("button1"), "BUTTON", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, cxChar, cyChar * (1 + 2* k), 21 * cxChar, 8 * cyChar / 3,hwnd,(HMENU) k, ((LPCREATESTRUCT) lParam)->hInstance, NULL);Es muss BUTTON heißen und nicht Butoon.
MFG Thorben
-
danke für deine antwort
aber es lag nicht an dem "Butoon1", weil es nur die Beschriftung des Buttons darstellt.
Der Fehler war das es (TEXT("button") heißen muss und nicht (TEXT("button1")
Aber trotzdem danke, weil mich deine Antwort darauf aufmerksam gemacht hat und ich ohne die Antwort wahrscheinlich noch Jahre gesucht hätte
