<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem mit Timer]]></title><description><![CDATA[<p>Hallo Leute, ich habe folgendes Programm geschrieben.<br />
Doch leider gibt es ein Problem mit dem Timer.<br />
Immer wenn mann die Maus oder das Fenster bewegt stock die Uhrzeit.<br />
Und nach einer Minute macht das Programm totale Probleme.<br />
Beim ausführen des Programms seht ihr ja was schief läuft.<br />
Hier der Code:</p>
<pre><code>// neu06.cpp : Definiert den Einsprungpunkt für die Anwendung.
// Buch Seite 86-93
//Rot=236 Grün=233 Blau=216 (standart Hellgrau)

#include &quot;stdafx.h&quot;
#include &lt;windows.h&gt;
#include &lt;winbase.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstGlobal;

const UINT TimerSec = 1;

HWND	hButtonRadioButton, hButtonRadioButton2,
		hButtonRadioButton3, hButtonRadioButton4,
		hButtonCheckBox;

SYSTEMTIME st;							//time
			SYSTEMTIME systime;			//time-variable
			char szBuffer[30] = { 0 };	//time-variable

int APIENTRY WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nCmdShow )
{
	hInstGlobal = hInstance;
	WNDCLASS WndClass;
	WndClass.style = 0;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.lpfnWndProc = WndProc;
	WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH)(COLOR_MENU+12);	//+7 ist mitteleres Grau
														//+9 ist dunkles Grau
														//+12 ist helles Grau
	WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
	WndClass.lpszMenuName = 0;
	WndClass.lpszClassName = &quot;WinProg&quot;;

    //GetSystemTime(&amp;st);						//time
    //DWORD hours = st.wHour;					//time
    //DWORD minutes = st.wMinute;				//time
	//DWORD seconds = st.wSecond;				//time

	RegisterClass(&amp;WndClass);
	int x,y;
	x = GetSystemMetrics (SM_CXSCREEN);
	y = GetSystemMetrics (SM_CYSCREEN);

	HWND hWindow;
	hWindow = CreateWindow(&quot;WinProg&quot;,&quot;Shutdown&quot;,
							WS_OVERLAPPED,
							(x/2)-200,(y/2)-150,
							800,300,NULL,NULL,
							hInstance, NULL);
	ShowWindow (hWindow, nCmdShow);
	UpdateWindow (hWindow);
	MSG Message;

	while (GetMessage(&amp;Message, NULL, 0, 0))
	{
		TranslateMessage (&amp;Message);
		DispatchMessage(&amp;Message);
	}
	return (Message.wParam);
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
						  WPARAM wParam,LPARAM lParam)
{
	static RECT rect;
	static BOOL isActive;
	const UINT left = 520;
	const UINT top = 200;
	const UINT right = left+84;
	const UINT bottom = top+16; // static int

	SetTimer(hWnd, TimerSec, 100, NULL);					//TIMER
	isActive = true;

	switch(uiMessage)
	{
		case WM_PAINT:
			HPEN hPen;
			HPEN hPenalt;
			HBRUSH hBrush;
			HBRUSH hBrushalt;
			hBrush = CreateSolidBrush (RGB(255,100,0));
			hPen = CreatePen (PS_SOLID,3,RGB(0,0,255));
			HDC hdc;
			PAINTSTRUCT ps;

			hdc = BeginPaint (hWnd, &amp;ps);							//BEGIN PAINT
			hBrushalt = (HBRUSH) SelectObject (hdc, hBrush);
			hPenalt = (HPEN) SelectObject (hdc, hPen);
			MoveToEx (hdc, 500, 50, NULL);	//Position des Cursors

			hPen = CreatePen (PS_SOLID,3,RGB(255,0,0));	//neue Farbe
			hPenalt = (HPEN) SelectObject (hdc, hPen);

			LineTo (hdc, 600, 100);	//Zeichnet von Cursorposition zu gegebenen Koordinaten eine Linie
		  //BOOL Rectangle( HDC hdc, int nLeftRect, int nTopRect,int nRightRect, int nBottomRect);

			hPen = CreatePen (PS_SOLID,3,RGB(0,0,255));	//neue Farbe
			hPenalt = (HPEN) SelectObject (hdc, hPen);

			Rectangle (hdc, 400,100,500,200);
			//Rectangle (hdc, left, top, right, bottom);	//Bereich des Zeitausgabefenster
			//RoundRect (hdc, 260, 20, 20, 40, 20, 20);

			//SelectObject (hdc, hBrushalt);
			//SelectObject (hdc, hPenalt);

			HFONT hFont;										//textout begin
			hFont = (HFONT) GetStockObject ( SYSTEM_FONT);		//
			//SelectObject (hdc, hFont);						//
			SetTextColor (hdc, RGB(0,0,180));					//
			SetBkColor (hdc, RGB(190,180,200));					//
			//SetTextAlign (hdc, TA_LEFT);						//
			char *string1;										//
			string1 = new char[12];								//
			lstrcpy (string1,&quot;SYSTEM_FONT&quot;);					//belegt string1 mit Text
			TextOut (hdc, 100, 100, string1, lstrlen(string1));	//textout end

			GetLocalTime( &amp;systime );
			//GetSystemTime(&amp;systime);
			wsprintf( szBuffer , &quot;%02d:%02d:%02d:%03d&quot;,systime.wHour,systime.wMinute,systime.wSecond,systime.wMilliseconds);
			string1 = szBuffer;
			SetTextColor (hdc, RGB(0,0,180));
			SetBkColor (hdc, RGB(190,180,200));
			TextOut (hdc, left, top, string1, lstrlen(string1));

//	TextOut (hdc, 100, 100, seconds, lstrlen(seconds));

			EndPaint (hWnd, &amp;ps);
			return 0;

		case WM_SIZE:
		{
			rect.left = left;		//x-links
			rect.top = top;			//y-oben
			rect.right = right;		//x-rechts
			rect.bottom = bottom;	//y-unten	
			return 0;
		}

		case WM_TIMER:
		{
			InvalidateRect(hWnd, &amp;rect, TRUE);	// bewirkt die Aktuallisierung
			return 0;
		}

		case WM_CREATE:
			HWND hButtonShutdown, hButtonExit, hButtonGroupBox, hButtonGroupBox2;

			hButtonShutdown = CreateWindow(&quot;BUTTON&quot;,&quot;Shutdown&quot;,
											WS_CHILD | WS_VISIBLE |
											BS_PUSHBUTTON,
											10,240,80,20,
											hWnd,(HMENU) 1,
											hInstGlobal, NULL);
			hButtonExit = CreateWindow(&quot;BUTTON&quot;,&quot;Exit&quot;,
										WS_CHILD |
										WS_VISIBLE |
										BS_PUSHBUTTON,
										100,240,80,20,
										hWnd,(HMENU) 2,
										hInstGlobal, NULL);
			hButtonGroupBox = CreateWindow(&quot;BUTTON&quot;,&quot;Aktion&quot;,
											WS_CHILD |
											WS_VISIBLE |
											BS_GROUPBOX,
											5,5,380,120,
											hWnd,(HMENU) 3,
											hInstGlobal, NULL);
			hButtonRadioButton = CreateWindow(&quot;BUTTON&quot;,&quot;Herunterfahren&quot;,
											   WS_CHILD |
											   WS_VISIBLE |
											   BS_RADIOBUTTON,
											   10,20,280,20,
											   hWnd,(HMENU) 4,
											   hInstGlobal, NULL);
			hButtonRadioButton2 = CreateWindow(&quot;BUTTON&quot;,&quot;Neustart&quot;,
												WS_CHILD |
												WS_VISIBLE |
												BS_RADIOBUTTON,
												10,40,280,20,
												hWnd,(HMENU) 5,
												hInstGlobal, NULL);
			hButtonRadioButton3 = CreateWindow(	&quot;BUTTON&quot;,&quot;Herunterfahren und Ausschalten&quot;,
												WS_CHILD |
												WS_VISIBLE |
												BS_RADIOBUTTON,
												10,60,280,20,
												hWnd,(HMENU) 6,
												hInstGlobal, NULL);
			hButtonRadioButton4 = CreateWindow(&quot;BUTTON&quot;,&quot;Abmelden&quot;,
												WS_CHILD |
												WS_VISIBLE |
												BS_RADIOBUTTON,
												10,80,280,20,
												hWnd,(HMENU) 7,
												hInstGlobal, NULL);
			hButtonGroupBox2 = CreateWindow(&quot;BUTTON&quot;,&quot;Option&quot;,
											 WS_CHILD |
											 WS_VISIBLE |
											 BS_GROUPBOX,
											 5,140,350,80,
											 hWnd,(HMENU) 8,
											 hInstGlobal, NULL);
			hButtonCheckBox = CreateWindow( &quot;BUTTON&quot;,
											&quot;keine Nachricht an laufende Anwendungen&quot;,
											 WS_CHILD |
											 WS_VISIBLE |
											 BS_CHECKBOX,
											 10,160,340,20,
											 hWnd,(HMENU) 9,
											 hInstGlobal, NULL);
			return 0;

		case WM_COMMAND:
			if (HIWORD(wParam) == BN_CLICKED)
			{
				if (LOWORD(wParam) == 1)
				{
					int Parameter;
					Parameter = 0;
					if (SendMessage (hButtonRadioButton, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_SHUTDOWN;
					}
					if (SendMessage (hButtonRadioButton2, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_REBOOT;
					}
					if (SendMessage (hButtonRadioButton3, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_POWEROFF;
					}
					if (SendMessage (hButtonRadioButton4, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_LOGOFF;
					}
					if (SendMessage (hButtonCheckBox, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = Parameter | EWX_FORCE;
					}
					ExitWindowsEx (Parameter, 0);
				}
				if (LOWORD(wParam) == 2)
				{
					SendMessage (GetParent((HWND)lParam), WM_DESTROY ,0 ,0);
				}
				if (LOWORD(wParam) == 4)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton2, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton3, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton4, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 6)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton2, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton4, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 7)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton3, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton2, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 5)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton3, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton4, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 9)
				{
					if (SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_UNCHECKED, 0);
					}
					else
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
					}
				}
			}
			return 0;
		case WM_DESTROY:
			if (isActive)
				{
					KillTimer(hWnd, TimerSec);
				}
			PostQuitMessage(0);
			return 0;
			default:
			return DefWindowProc (hWnd, uiMessage, wParam, lParam);
	}
}
</code></pre>
<p><strong>Also ich bin für jeden Rat sehr dankbar.</strong></p>
<p>rom4o</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/229957/problem-mit-timer</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 23:26:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/229957.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 18 Dec 2008 16:11:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Timer on Thu, 18 Dec 2008 16:11:15 GMT]]></title><description><![CDATA[<p>Hallo Leute, ich habe folgendes Programm geschrieben.<br />
Doch leider gibt es ein Problem mit dem Timer.<br />
Immer wenn mann die Maus oder das Fenster bewegt stock die Uhrzeit.<br />
Und nach einer Minute macht das Programm totale Probleme.<br />
Beim ausführen des Programms seht ihr ja was schief läuft.<br />
Hier der Code:</p>
<pre><code>// neu06.cpp : Definiert den Einsprungpunkt für die Anwendung.
// Buch Seite 86-93
//Rot=236 Grün=233 Blau=216 (standart Hellgrau)

#include &quot;stdafx.h&quot;
#include &lt;windows.h&gt;
#include &lt;winbase.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstGlobal;

const UINT TimerSec = 1;

HWND	hButtonRadioButton, hButtonRadioButton2,
		hButtonRadioButton3, hButtonRadioButton4,
		hButtonCheckBox;

SYSTEMTIME st;							//time
			SYSTEMTIME systime;			//time-variable
			char szBuffer[30] = { 0 };	//time-variable

int APIENTRY WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nCmdShow )
{
	hInstGlobal = hInstance;
	WNDCLASS WndClass;
	WndClass.style = 0;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.lpfnWndProc = WndProc;
	WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH)(COLOR_MENU+12);	//+7 ist mitteleres Grau
														//+9 ist dunkles Grau
														//+12 ist helles Grau
	WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
	WndClass.lpszMenuName = 0;
	WndClass.lpszClassName = &quot;WinProg&quot;;

    //GetSystemTime(&amp;st);						//time
    //DWORD hours = st.wHour;					//time
    //DWORD minutes = st.wMinute;				//time
	//DWORD seconds = st.wSecond;				//time

	RegisterClass(&amp;WndClass);
	int x,y;
	x = GetSystemMetrics (SM_CXSCREEN);
	y = GetSystemMetrics (SM_CYSCREEN);

	HWND hWindow;
	hWindow = CreateWindow(&quot;WinProg&quot;,&quot;Shutdown&quot;,
							WS_OVERLAPPED,
							(x/2)-200,(y/2)-150,
							800,300,NULL,NULL,
							hInstance, NULL);
	ShowWindow (hWindow, nCmdShow);
	UpdateWindow (hWindow);
	MSG Message;

	while (GetMessage(&amp;Message, NULL, 0, 0))
	{
		TranslateMessage (&amp;Message);
		DispatchMessage(&amp;Message);
	}
	return (Message.wParam);
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
						  WPARAM wParam,LPARAM lParam)
{
	static RECT rect;
	static BOOL isActive;
	const UINT left = 520;
	const UINT top = 200;
	const UINT right = left+84;
	const UINT bottom = top+16; // static int

	SetTimer(hWnd, TimerSec, 100, NULL);					//TIMER
	isActive = true;

	switch(uiMessage)
	{
		case WM_PAINT:
			HPEN hPen;
			HPEN hPenalt;
			HBRUSH hBrush;
			HBRUSH hBrushalt;
			hBrush = CreateSolidBrush (RGB(255,100,0));
			hPen = CreatePen (PS_SOLID,3,RGB(0,0,255));
			HDC hdc;
			PAINTSTRUCT ps;

			hdc = BeginPaint (hWnd, &amp;ps);							//BEGIN PAINT
			hBrushalt = (HBRUSH) SelectObject (hdc, hBrush);
			hPenalt = (HPEN) SelectObject (hdc, hPen);
			MoveToEx (hdc, 500, 50, NULL);	//Position des Cursors

			hPen = CreatePen (PS_SOLID,3,RGB(255,0,0));	//neue Farbe
			hPenalt = (HPEN) SelectObject (hdc, hPen);

			LineTo (hdc, 600, 100);	//Zeichnet von Cursorposition zu gegebenen Koordinaten eine Linie
		  //BOOL Rectangle( HDC hdc, int nLeftRect, int nTopRect,int nRightRect, int nBottomRect);

			hPen = CreatePen (PS_SOLID,3,RGB(0,0,255));	//neue Farbe
			hPenalt = (HPEN) SelectObject (hdc, hPen);

			Rectangle (hdc, 400,100,500,200);
			//Rectangle (hdc, left, top, right, bottom);	//Bereich des Zeitausgabefenster
			//RoundRect (hdc, 260, 20, 20, 40, 20, 20);

			//SelectObject (hdc, hBrushalt);
			//SelectObject (hdc, hPenalt);

			HFONT hFont;										//textout begin
			hFont = (HFONT) GetStockObject ( SYSTEM_FONT);		//
			//SelectObject (hdc, hFont);						//
			SetTextColor (hdc, RGB(0,0,180));					//
			SetBkColor (hdc, RGB(190,180,200));					//
			//SetTextAlign (hdc, TA_LEFT);						//
			char *string1;										//
			string1 = new char[12];								//
			lstrcpy (string1,&quot;SYSTEM_FONT&quot;);					//belegt string1 mit Text
			TextOut (hdc, 100, 100, string1, lstrlen(string1));	//textout end

			GetLocalTime( &amp;systime );
			//GetSystemTime(&amp;systime);
			wsprintf( szBuffer , &quot;%02d:%02d:%02d:%03d&quot;,systime.wHour,systime.wMinute,systime.wSecond,systime.wMilliseconds);
			string1 = szBuffer;
			SetTextColor (hdc, RGB(0,0,180));
			SetBkColor (hdc, RGB(190,180,200));
			TextOut (hdc, left, top, string1, lstrlen(string1));

//	TextOut (hdc, 100, 100, seconds, lstrlen(seconds));

			EndPaint (hWnd, &amp;ps);
			return 0;

		case WM_SIZE:
		{
			rect.left = left;		//x-links
			rect.top = top;			//y-oben
			rect.right = right;		//x-rechts
			rect.bottom = bottom;	//y-unten	
			return 0;
		}

		case WM_TIMER:
		{
			InvalidateRect(hWnd, &amp;rect, TRUE);	// bewirkt die Aktuallisierung
			return 0;
		}

		case WM_CREATE:
			HWND hButtonShutdown, hButtonExit, hButtonGroupBox, hButtonGroupBox2;

			hButtonShutdown = CreateWindow(&quot;BUTTON&quot;,&quot;Shutdown&quot;,
											WS_CHILD | WS_VISIBLE |
											BS_PUSHBUTTON,
											10,240,80,20,
											hWnd,(HMENU) 1,
											hInstGlobal, NULL);
			hButtonExit = CreateWindow(&quot;BUTTON&quot;,&quot;Exit&quot;,
										WS_CHILD |
										WS_VISIBLE |
										BS_PUSHBUTTON,
										100,240,80,20,
										hWnd,(HMENU) 2,
										hInstGlobal, NULL);
			hButtonGroupBox = CreateWindow(&quot;BUTTON&quot;,&quot;Aktion&quot;,
											WS_CHILD |
											WS_VISIBLE |
											BS_GROUPBOX,
											5,5,380,120,
											hWnd,(HMENU) 3,
											hInstGlobal, NULL);
			hButtonRadioButton = CreateWindow(&quot;BUTTON&quot;,&quot;Herunterfahren&quot;,
											   WS_CHILD |
											   WS_VISIBLE |
											   BS_RADIOBUTTON,
											   10,20,280,20,
											   hWnd,(HMENU) 4,
											   hInstGlobal, NULL);
			hButtonRadioButton2 = CreateWindow(&quot;BUTTON&quot;,&quot;Neustart&quot;,
												WS_CHILD |
												WS_VISIBLE |
												BS_RADIOBUTTON,
												10,40,280,20,
												hWnd,(HMENU) 5,
												hInstGlobal, NULL);
			hButtonRadioButton3 = CreateWindow(	&quot;BUTTON&quot;,&quot;Herunterfahren und Ausschalten&quot;,
												WS_CHILD |
												WS_VISIBLE |
												BS_RADIOBUTTON,
												10,60,280,20,
												hWnd,(HMENU) 6,
												hInstGlobal, NULL);
			hButtonRadioButton4 = CreateWindow(&quot;BUTTON&quot;,&quot;Abmelden&quot;,
												WS_CHILD |
												WS_VISIBLE |
												BS_RADIOBUTTON,
												10,80,280,20,
												hWnd,(HMENU) 7,
												hInstGlobal, NULL);
			hButtonGroupBox2 = CreateWindow(&quot;BUTTON&quot;,&quot;Option&quot;,
											 WS_CHILD |
											 WS_VISIBLE |
											 BS_GROUPBOX,
											 5,140,350,80,
											 hWnd,(HMENU) 8,
											 hInstGlobal, NULL);
			hButtonCheckBox = CreateWindow( &quot;BUTTON&quot;,
											&quot;keine Nachricht an laufende Anwendungen&quot;,
											 WS_CHILD |
											 WS_VISIBLE |
											 BS_CHECKBOX,
											 10,160,340,20,
											 hWnd,(HMENU) 9,
											 hInstGlobal, NULL);
			return 0;

		case WM_COMMAND:
			if (HIWORD(wParam) == BN_CLICKED)
			{
				if (LOWORD(wParam) == 1)
				{
					int Parameter;
					Parameter = 0;
					if (SendMessage (hButtonRadioButton, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_SHUTDOWN;
					}
					if (SendMessage (hButtonRadioButton2, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_REBOOT;
					}
					if (SendMessage (hButtonRadioButton3, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_POWEROFF;
					}
					if (SendMessage (hButtonRadioButton4, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = EWX_LOGOFF;
					}
					if (SendMessage (hButtonCheckBox, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						Parameter = Parameter | EWX_FORCE;
					}
					ExitWindowsEx (Parameter, 0);
				}
				if (LOWORD(wParam) == 2)
				{
					SendMessage (GetParent((HWND)lParam), WM_DESTROY ,0 ,0);
				}
				if (LOWORD(wParam) == 4)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton2, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton3, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton4, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 6)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton2, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton4, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 7)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton3, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton2, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 5)
				{
					if (!(SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED))
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
						SendMessage (hButtonRadioButton, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton3, BM_SETCHECK, BST_UNCHECKED, 0);
						SendMessage (hButtonRadioButton4, BM_SETCHECK, BST_UNCHECKED, 0);
					}
				}
				if (LOWORD(wParam) == 9)
				{
					if (SendMessage ((HWND)lParam, BM_GETCHECK, 0, 0) == BST_CHECKED)
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_UNCHECKED, 0);
					}
					else
					{
						SendMessage ((HWND)lParam, BM_SETCHECK, BST_CHECKED, 0);
					}
				}
			}
			return 0;
		case WM_DESTROY:
			if (isActive)
				{
					KillTimer(hWnd, TimerSec);
				}
			PostQuitMessage(0);
			return 0;
			default:
			return DefWindowProc (hWnd, uiMessage, wParam, lParam);
	}
}
</code></pre>
<p><strong>Also ich bin für jeden Rat sehr dankbar.</strong></p>
<p>rom4o</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1632485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1632485</guid><dc:creator><![CDATA[rom4o]]></dc:creator><pubDate>Thu, 18 Dec 2008 16:11:15 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Timer on Thu, 18 Dec 2008 16:21:48 GMT]]></title><description><![CDATA[<p>rom4o schrieb:</p>
<blockquote>
<p><strong>Also ich bin für jeden Rat sehr dankbar.</strong></p>
</blockquote>
<p>Benutz bitte C++-Tags anstatt Code-Tags. Es liest sich so sehr mühsam, zumal es sehr viel Code ist.</p>
<p>Ich hab mir den Source noch nicht genauer angesehen.. aber du sagst nach ner Minute kackt das Programm völlig ab?<br />
Dann könnte irgendwo ein Speicher/Array/wasweißich überlaufen. Schließt du auch alles wieder schön, was du geöffnet hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1632492</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1632492</guid><dc:creator><![CDATA[Machine]]></dc:creator><pubDate>Thu, 18 Dec 2008 16:21:48 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Timer on Thu, 18 Dec 2008 17:09:59 GMT]]></title><description><![CDATA[<p>rom4o schrieb:</p>
<blockquote>
<p>Doch leider gibt es ein Problem mit dem Timer.<br />
Immer wenn mann die Maus oder das Fenster bewegt stock die Uhrzeit.</p>
</blockquote>
<p>Setz mal den Aufruf von SetTimer in die &quot;WinMain&quot; gleich nach CreateWindow und <em>nicht</em> in die &quot;WndProc&quot;.<br />
Es reicht wenn SetTimer nur einmal aufgerufen wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1632511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1632511</guid><dc:creator><![CDATA[zeitloser]]></dc:creator><pubDate>Thu, 18 Dec 2008 17:09:59 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Timer on Thu, 18 Dec 2008 17:45:43 GMT]]></title><description><![CDATA[<p>wie wärs mal mit <strong>DeleteObject</strong>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1632526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1632526</guid><dc:creator><![CDATA[schaafrichter]]></dc:creator><pubDate>Thu, 18 Dec 2008 17:45:43 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Timer on Mon, 29 Dec 2008 23:06:29 GMT]]></title><description><![CDATA[<p>**<br />
Hallo Leute erstmal sorry für das späte Feedback,<br />
bin zur Zeit auf Zypern und hab hier nur sehr selten Internet :-D.</p>
<p>Jetzt hab ich endlich Zeit gefunden mich wieder mit dem Problem zu beschäftigen.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/16372">@Machine</a>, okey das mit den C++-Tags werde ich das nächste mal beachten...danke</p>
<p>@zeitloser, ich habe deinen Rat befolgt und siehe da, es läuft dann sehr gut.</p>
<p>@schaafrichter, was meinst du mit DeleteObject genau?<br />
Muss ich irgendwo zyklisch ein erstelltes Object wieder löschen??<br />
Wenn ja wo?</p>
<p>Ich habe das Programm mal abgespeckt und alle Buttons bis auf Exit herausgenommen.<br />
So wollte ich das Problem finden. Habe aber keinen Erfolg gehabt.</p>
<p>Das Programm welches anfangs wunderbar läuft, stürzt nach ca. 1Minute ab.<br />
Und wenn ich parallel den Windows Task-Manager laufen lasse, sehe ich, dass<br />
die Speicherauslastung für das Programm stätig ansteigt.</p>
<p>Also wie Machine schon vermutet hat muss irgendwo was überlaufen.<br />
Nur ich finde nichts.</p>
<p>Dann habe ich mal die SetTimer-Anweisung in Zeile 50 herausgenommen,<br />
dann läuft der Speicher nur noch voll wenn ich das Fenster oder die Maus bewege.</p>
<p>Hier ist jetzt nochmal der aktuelle Code:<br />
**</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;windows.h&gt;
#include &lt;winbase.h&gt;

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstGlobal;

	const UINT TimerSec = 1;
	SYSTEMTIME systime;			//time-variable
	char szBuffer[30] = { 0 };	//time-variable
	HWND hWindow;				//Hauptfenster, für TIMER2 hier deklariert

int APIENTRY WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nCmdShow )
{
	hInstGlobal = hInstance;
	WNDCLASS WndClass;
	WndClass.style = 0;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.lpfnWndProc = WndProc;
	WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH)(COLOR_MENU+12);	//+7 ist mitteleres Grau
														//+9 ist dunkles Grau
														//+12 ist helles Grau
	WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
	WndClass.lpszMenuName = 0;
	WndClass.lpszClassName = &quot;WinProg&quot;;

	RegisterClass(&amp;WndClass);
	int x,y;
	x = GetSystemMetrics (SM_CXSCREEN);
	y = GetSystemMetrics (SM_CYSCREEN);

//	HWND hWindow;			// wird schon vor der WinMain-Methode deklariert
	hWindow = CreateWindow(&quot;WinProg&quot;,&quot;CountShutdown&quot;,
							WS_OVERLAPPED,
							(x/2)-200,(y/2)-150,
							800,300,NULL,NULL,
							hInstance, NULL);
	ShowWindow (hWindow, nCmdShow);
	UpdateWindow (hWindow);
	MSG Message;

	SetTimer(hWindow, TimerSec, 1, NULL);					//TIMER2 neue Variante

	while (GetMessage(&amp;Message, NULL, 0, 0))
	{
		TranslateMessage (&amp;Message);
		DispatchMessage(&amp;Message);
	}
	return (Message.wParam);
}

LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
{
	static RECT rect;
	static BOOL isActive;
	const UINT left = 520;
	const UINT top = 200;
	const UINT right = left+84;
	const UINT bottom = top+16; // static int
	static char *string1;
	string1 = new char[];

//	SetTimer(hWnd, TimerSec, 100, NULL);					//TIMER1 alte Variante
	isActive = true;										// wenn true, dann ist der Timer initialisiert

	switch(uiMessage)
	{
		case WM_PAINT:
			HDC hdc;
 			PAINTSTRUCT ps;

			hdc = BeginPaint (hWnd, &amp;ps);							//BEGIN PAINT

			GetLocalTime( &amp;systime );
			//GetSystemTime(&amp;systime);
			wsprintf( szBuffer , &quot;%02d:%02d:%02d:%03d&quot;,systime.wHour,systime.wMinute,systime.wSecond,systime.wMilliseconds);
			string1 = szBuffer;
			SetTextColor (hdc, RGB(0,0,180));
			SetBkColor (hdc, RGB(236,233,216));			//Rot=236 Grün=233 Blau=216 (standart Hellgrau)
			TextOut (hdc, left, top, string1, lstrlen(string1));

			EndPaint (hWnd, &amp;ps);									//END PAINT
			return 0;

		case WM_SIZE:
		{
			rect.left = left;		//x-links
			rect.top = top;			//y-oben
			rect.right = right;		//x-rechts
			rect.bottom = bottom;	//y-unten	
			return 0;
		}

		case WM_TIMER:
		{
			InvalidateRect(hWnd, &amp;rect, TRUE);	// bewirkt die Aktuallisierung im Bereich von rect
			return 0;
		}

		case WM_CREATE:
			HWND hButtonExit;
			hButtonExit = CreateWindow(&quot;BUTTON&quot;,&quot;Exit&quot;,
										WS_CHILD |
										WS_VISIBLE |
										BS_PUSHBUTTON,
										100,240,80,20,
										hWnd,(HMENU) 2,
										hInstGlobal, NULL);
			return 0;

		case WM_COMMAND:
			if (HIWORD(wParam) == BN_CLICKED)
			{

				if (LOWORD(wParam) == 2)
				{
					SendMessage (GetParent((HWND)lParam), WM_DESTROY ,0 ,0);
				}

			}
			return 0;

		case WM_DESTROY:
			if (isActive)
				{
					//KillTimer(hWnd, TimerSec);		//TIMER1 alte Variante
					KillTimer(hWindow, TimerSec);		//TIMER2 neue Variante
				}
			PostQuitMessage(0);
			return 0;
			default:
			return DefWindowProc (hWnd, uiMessage, wParam, lParam);
	}
}
</code></pre>
<p>**<br />
Also weierhin vielen Dank für eure Hilfe und die bisherigen Ratschläge.</p>
<p>rom4o**</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1637086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1637086</guid><dc:creator><![CDATA[rom4o]]></dc:creator><pubDate>Mon, 29 Dec 2008 23:06:29 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Timer on Mon, 29 Dec 2008 23:32:48 GMT]]></title><description><![CDATA[<p>zeile 70...</p>
<p>rom40 schrieb:</p>
<blockquote>
<pre><code class="language-cpp">static char *string1; 
string1 = new char[];
</code></pre>
</blockquote>
<p>ähm ja, es wundert mich, das das kompiliert, aber das leckt.</p>
<pre><code class="language-cpp">string1 = szBuffer;
</code></pre>
<p>ist auch sinnlos, du überschreibst ja den angeforderten speicher.<br />
mach doch einfach zu beginn ein<br />
char szBuffer[64]<br />
ob static oder nicht ist egal</p>
<p>btw wofür DeleteObject? ich sehe da kein zu löschendes objekt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1637098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1637098</guid><dc:creator><![CDATA[helferlein]]></dc:creator><pubDate>Mon, 29 Dec 2008 23:32:48 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Timer on Mon, 29 Dec 2008 23:40:53 GMT]]></title><description><![CDATA[<p>dann guck dir mal den code an, auf den sich der kommentar bezog du schmalspuragent, dann siehste gleich dutzende <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1637102</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1637102</guid><dc:creator><![CDATA[smackdowner]]></dc:creator><pubDate>Mon, 29 Dec 2008 23:40:53 GMT</pubDate></item></channel></rss>