views:

112

answers:

5

Hi, It's 'my' program. How to close windows after 5 seconds?

//...
DeleteObject (hPedzelOkna);

DeleteObject (hBitmapa);

Sleep(5);
PostQuitMessage (0); 

/* The program return-value is 0 - The value that PostQuitMessage() gave */
//...

and

DestroyWindow(hwnd); 

not work

(I using Dev C++)

EDIT People have suggested using SetTimer, however I can't get the following code to work. Could you please a code example showing me how to do this?

 SetTimer(hwnd, DestroyWindow(hwnd), 1000, NULL);
+8  A: 

The Sleep parameter is in milliseconds, so 5 seconds would be 5000, but using Sleep is not the correct approach here (Sleep'ing prevents your window from processing messages)

You should use SetTimer() in WM_CREATE, when the timer fires, call DestroyWindow() on the window

Anders
+1  A: 

First of all, you almost never want to "Sleep" in a windowed program. If I was doing it, I'd set a timer in response to WM_CREATE, and then do the DestroyWindow/PostQuitMessage in response to WM_TIMER.

Jerry Coffin
+1  A: 

You should use a timer. In windows if you do things like Sleep (that by the way accepts as input a number of milliseconds, not seconds) you are not processing events.

6502
A: 
 SetTimer(hwnd, DestroyWindow(hwnd), 1000, NULL);

Not work. Can ypu send me working code?

qwer
A: 

Use SetTimer with a function of NULL. You'll then receive a WM_TIMER message after 1000 milliseconds (ie a second, based on your example).

You then Process the WM_TIMER and send a PostQuitMessage

Goz