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:
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:
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:
localtime_s on MSVC for safer code if multi-threading.Jump to Post— Ancient Dragon 5,243Step 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
:?:
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 .
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.