C++ウィンドウ表示など

#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#include <chrono>
#include <ctime>
#include <thread>

constexpr int WINDOW_X = 10;
constexpr int WINDOW_Y = 10;

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void DisplayCurrentDateTime(HWND hwnd, int x, int y);
void Waku(HWND hwnd);


int main() {

    // 画面のサイズを取得
    int screenWidth = GetSystemMetrics(SM_CXSCREEN);
    int screenHeight = GetSystemMetrics(SM_CYSCREEN);

    // ウィンドウのサイズ
    int windowWidth = 800;
    int windowHeight = 800;

    // ウィンドウ位置を画面の中央に設定
    int posX = (screenWidth - windowWidth) / 2;
    int posY = (screenHeight - windowHeight) / 2;

    // ウィンドウクラスの登録
    WNDCLASS wc = { 0 };
    wc.lpfnWndProc = WndProc;
    wc.hInstance = GetModuleHandle(NULL);
    wc.lpszClassName = "MyWindowClass";
    RegisterClass(&wc);

    // ウィンドウ作成
    //HWND hwnd = CreateWindow("MyWindowClass", "My Window", WS_OVERLAPPEDWINDOW, WINDOW_X, WINDOW_Y, 400, 300, NULL, NULL, GetModuleHandle(NULL), NULL);
    HWND hwnd = CreateWindow("MyWindowClass", "タイトル", WS_OVERLAPPEDWINDOW, posX, posY, windowWidth, windowHeight, NULL, NULL, GetModuleHandle(NULL), NULL);

    // ウィンドウ表示
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    // ウィンドウの枠を表示
    Waku(hwnd);

    // スレッドを起動して日時を表示
    std::thread dateTimeThread(DisplayCurrentDateTime, hwnd, WINDOW_X, WINDOW_Y);
    //displayThread.detach();

    // メッセージループ
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);

        if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) {     //ESCキーを押すとスレッド終了
            break;
        }
    }

    // スレッドを終了
    dateTimeThread.detach();

    return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch (msg) {
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_KEYDOWN:
        if (wParam == VK_ESCAPE)
            PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

// リアルタイム日時
void DisplayCurrentDateTime(HWND hwnd, int x, int y) {
    while (true) {

        HDC hdc = GetDC(hwnd);
        RECT rect = { x, y, x + 200, y + 100 };

        SetTextColor(hdc, RGB(255, 0, 0));

        time_t now = time(nullptr);
        struct tm* localTime = localtime(&now);
        char timeStr[128];
        strftime(timeStr, sizeof(timeStr), "%Y/%m/%d %H:%M:%S", localTime);

        InvalidateRect(hwnd, NULL, TRUE);
        UpdateWindow(hwnd);


        DrawTextA(hdc, timeStr, -1, &rect, DT_LEFT | DT_TOP | DT_SINGLELINE);   // 日時を描画
        ReleaseDC(hwnd, hdc);

        // 1秒待機
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }
}

// 枠の描画
void Waku(HWND hwnd) {
    HDC hdc = GetDC(hwnd);
    RECT rect;
    GetClientRect(hwnd, &rect);

    Rectangle(hdc, 50, 50, 600, 150);
    Rectangle(hdc, 50, 170, 600, 270);
    Rectangle(hdc, 50, 290, 600, 390);

    // 枠の描画
    FrameRect(hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH));

    ReleaseDC(hwnd, hdc);
}