Button ist unsichtbar
-
Guten Abend,
ich habe da ein kleines Problemchen mit folgendem Code:
#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <math.h> static RECT rect; static int height = 600; static int width = 600; enum Zustand { ROT = 0, GELB, GRUEN }; char *Farben [3] = { {"ROT"}, {"GELB"}, {"GRUEN"} }; typedef enum Zustand Zustand; struct Ampel { char Name [8]; Zustand Farbe; }; typedef struct Ampel Ampel; Ampel Ampeln [4] = { {"AMPEL01",ROT}, {"AMPEL02",ROT}, {"AMPEL03", ROT}, {"AMPEL04", ROT} }; //************************************************************************* //* LRESULT CALLBACK! * //************************************************************************* LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_ERASEBKGND: { return 1; } break; case WM_SIZE: { rect.top = 0; rect.left = 0; rect.right = LOWORD (lParam); rect.bottom = HIWORD (lParam); } break; case WM_CREATE: { HWND hButton1 = CreateWindowEx (0, "BUTTON", "Beenden", WS_VISIBLE|WS_CHILD, width - 100, height - 50,100,50, hWnd, (HMENU) 1, GetModuleHandle ("Kreuzung"), NULL); HWND hButton2 = CreateWindowEx (0, "BUTTON", "Start", WS_VISIBLE|WS_CHILD, width - 100, 0, 100, 50, hWnd, (HMENU) 2, GetModuleHandle ("Kreuzung"), NULL); } break; case WM_COMMAND: { if (wParam == 1) { DestroyWindow (hWnd); } } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hDC = BeginPaint (hWnd, &ps); HDC hDC2 = CreateCompatibleDC (hDC); HBITMAP hBM = CreateCompatibleBitmap (hDC, rect.right, rect.bottom); SelectObject (hDC2, hBM); { FillRect (hDC2, &rect, (HBRUSH)(COLOR_WINDOW+1)); for (int i = 0; i <= 3; i++) { TextOut (hDC2, 10, 40 + 30*i, Ampeln[i].Name, 9); TextOut (hDC2, 100, 40 + 30*i, Farben [Ampeln[i].Farbe], 3); } } BitBlt (hDC, 0, 0, rect.right, rect.bottom, hDC2, 0, 0, SRCCOPY); DeleteObject (hBM); DeleteDC (hDC2); InvalidateRect (hWnd, &rect, true); EndPaint (hWnd, &ps); } break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, msg, wParam, lParam); } return 0; } //************************************************************************* //* WINAPI WinMain * //************************************************************************* int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; //Step 1: Registering the Window Class wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; 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)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = "WINDOW"; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } // Step 2: Creating the Window hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "WINDOW", "Kreuzung", /*WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU*/ WS_POPUP, 10, 10, width, height, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow (hwnd); // Step 3: The Message Loop while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }
Das Problem ist, das meine Buttons zwar reagieren, aber nicht sichtbar sind.
Kriege ich die also irgendwie in den Vordergrund?
-
Obwohl es wohl schon länger her ist:
vesrsuch mal bei den Flags noch WS_BORDER mitzugeben, sonst sehe ich keinen "Fehler"
mfg -Infected-
-
Danke für die Antwort, aber ich hab einfach die Fläche verschoben, auf die die Bitmap gezeichnet wird. Dann wird halt der Button nicht übermalt.
-
Übermalt wird halt, weil Du auch über die Child Controls zeichnest.
Verwende WS_CLIPCHILDREN