Wakey-Wakey Alarm : Visual C++

  Do you need to set a reminder, or something to wake you up from your nap (after long hours of coding)? Are you feeling too lazy (or simply don’t have the time) to get up from your desk and set the alarm in a clock or your phone? Then the Wakey-Wakey Alarm is what you need.


This alarm clock (created in Visual C++ for the Win32 platform) will let you set an alarm for waking you up at the right time. The most wonderful thing about it is that you can customise it (in code, of course). You can set the time after which the alarm starts ringing, the number of times it rings and the interval between two subsequent rings.

Here’s the source code for this program :


 /* Source Code for Wakey-Wakey Alarm */

#include <windows.h>

#define ID_TIMER 1

int ActivateAlarm (HWND, int, int);

int playafter = 10;            /* This variable sets the time (in seconds) after which the timer event will occur and the alarm will start */
int success;
int repeat = 30;            /* This variable sets how many times the alarm will beep */
int sleep = 200;            /* This variable sets the interval (in milliseconds) between two subsequent beeps while the alarm is ringing */

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
static TCHAR szAppName[] = TEXT(“Alarm”);
HWND hwnd;
MSG msg;
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;
if (!RegisterClass(&wndclass))
MessageBox(NULL, TEXT(“This application is incompatible with this version of Windows !!!”),
return 0;
hwnd = CreateWindow(szAppName, TEXT(“Alarm”), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);

MessageBox(hwnd, L”The Alarm will play when the specified time has elapsed”,L”Alarm”,NULL);

while (GetMessage(&msg, NULL, 0, 0))
return msg.wParam;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
HDC hdc;

switch (message)
SetTimer(hwnd, ID_TIMER, playafter*1000, NULL);
return 0;
case WM_TIMER:
success = ActivateAlarm(hwnd, repeat, sleep);
if (success == 0)
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
KillTimer(hwnd, ID_TIMER);
return 0;
return DefWindowProc(hwnd, message, wParam, lParam);

int ActivateAlarm(HWND hWnd, int repeat, int sleep)
KillTimer(hWnd, ID_TIMER);
for (int i = 0; i < repeat; i++)
return 0;


Click here to download the Wakey-Wakey Alarm project.

Click here to download the Wakey-Wakey Alarm executable only.

Here are similar projects you may find interesting :

WCB Clock
Digital Clock
Amazing Clock

Did you like this project? Tell us in your comments below.

(Visited 379 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *