Here's what I'm trying to do:

I want my program to spawn a Msgbox on the first day of every month with some information for the user. Please walk me throught it EXACTLY, as I'm a beginner :icon_mrgreen:

Dani AI

Generated

Quick summary for : there are two practical, reliable ways to show a message on the 1st of every month — have a small program run at that exact time (Task Scheduler), or let a small program run continuously and detect the date change. was on the right track about checking the date; pointed toward notification-based approaches but beware: system time-change notifications are for manual/time-sync changes and are not a dependable daily trigger.

Example (simple Windows console approach — polls and shows a MessageBox once per month). Compile with Visual Studio; keep this running (or run it at login):

#include <windows.h>
#include <ctime>
#include <thread>
#include <chrono>

int main()
{
    int lastShownYear = -1, lastShownMonth = -1;

    for (;;)
    {
        std::time_t t = std::time(nullptr);
        std::tm tm = *std::localtime(&t); // on MSVC consider localtime_s for thread-safety

        if (tm.tm_mday == 1 && (tm.tm_year != lastShownYear || tm.tm_mon != lastShownMonth))
        {
            MessageBoxA(NULL, "Monthly information here.", "Monthly Notice", MB_OK | MB_ICONINFORMATION);
            lastShownYear = tm.tm_year;
            lastShownMonth = tm.tm_mon;
        }

        std::this_thread::sleep_for(std::chrono::minutes(10));
    }
    return 0;
}

Notes and tips:

  • Recommended: use Windows Task Scheduler to run a tiny EXE at a chosen time on day 1 each month. If you want a visible dialog, set the task to "Run only when user is logged on".
  • If you keep a long-running program, store year+month (not just day) so the dialog appears once each month.
  • Services should not show MessageBox UI; use a scheduled task or a separate GUI app.
  • For testing, temporarily change the condition to your current day or lower the sleep interval to verify behavior. Use localtime_s on MSVC for safer code if multi-threading.

Recommended Answers

All 3 Replies

:?:

Step 1: call function time() to get current time in seconds.

Step 2: call localtime() to convert the integer returned by Step 1 into a struct tm

Step 3: Check if tm_mday is 1

1.U can put an observer which informs u when the system date is changed( u will get notified 12 am everyday).
//please check for the appropeiate api to get the system date change notification in ur sdk .
2.And then do ur task if it is first of the month .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.