C++ Stylish Analog Clock App | Modern GUI Clock Using GDI+ (With Source Code)
Demo :
Click Video πππ
Code :
#include <windows.h>
#include <ctime>
#include <string>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch(msg) {
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
SYSTEMTIME st;
GetLocalTime(&st);
char buffer[100];
sprintf(buffer, "Time: %02d:%02d:%02d Date: %02d-%02d-%04d",
st.wHour, st.wMinute, st.wSecond, st.wDay, st.wMonth, st.wYear);
SetBkColor(hdc, RGB(0, 0, 0));
SetTextColor(hdc, RGB(0, 255, 0));
TextOut(hdc, 60, 100, buffer, strlen(buffer));
EndPaint(hwnd, &ps);
break;
}
case WM_TIMER:
InvalidateRect(hwnd, NULL, TRUE);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, msg, wp, lp);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR args, int ncmdshow) {
WNDCLASSW wc = {0};
wc.lpszClassName = L"ClockWin";
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpfnWndProc = WndProc;
RegisterClassW(&wc);
HWND hwnd = CreateWindowW(L"ClockWin", L"C++ Digital Clock", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
200, 200, 400, 200, NULL, NULL, NULL, NULL);
SetTimer(hwnd, 1, 1000, NULL);
MSG msg = {0};
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Comments
Post a Comment