Fenster wird nur kurz angezeigt
-
Hier der code:
#include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("HelloWin!"); HWND hwnd; /* This is the handle for our window */ MSG msg; /* Here messages to the application are saved */ WNDCLASS wndclass; /* Data structure for the windowclass */ 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)) { MessageBox (NULL, TEXT ("Dieses Programm setzt ein aktuelles Betriebsystem vorraus!"), szAppName, MB_ICONERROR); return 0; } /* The class is registered, let's create the program*/ hwnd = CreateWindow (szAppName, /* Extended possibilites for variation */ TEXT ("Das erste Windowsprogramm!"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); /* Make the window visible on the screen */ ShowWindow (hwnd, iCmdShow); UpdateWindow(hwnd); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&msg, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&msg); /* Send message to WindowProcedure */ DispatchMessage(&msg); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return msg.wParam; } /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch (message) /* handle the messages */ { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); DrawText (hdc, TEXT ("Hello WinXp!"), -1, &rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER); case WM_DESTROY: PostQuitMessage(0); /* send a WM_QUIT to the message queue */ return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }Mein Problem: Das Fenster bleibt nur ganz kurz da, und ist dann gleich weg.
Ich code mit dem Dev-c++.
Ich hab WinXp drauf und als ich das ding zum ersten mal zum laufen gebracht habe, hatte ich den style windows classic drin. da funktionierte das programm auch nicht. es erstellte einen prozess.
als ich dann den style auf normal umschaltete, passiert es, dass das fenster nur kurz da bleibt.
Bitte helft mir!
-
EndPaint und break vermisse ich in deinem Code.
-
thx, das hab ich übersehen
