File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 22#include < windows.h>
33#include < tlhelp32.h>
44#include < vector>
5+ #include < random>
6+ #include < chrono>
7+ #include < thread>
58
69static HANDLE g_hThread = NULL ;
710static DWORD g_threadId = 0 ;
@@ -168,6 +171,47 @@ void StopHotkeyThread()
168171 g_threadId = 0 ;
169172}
170173
174+ static DWORD GenerateRandomInterval ()
175+ {
176+ static std::random_device rd;
177+ static std::mt19937 gen (rd ());
178+ static std::uniform_int_distribution<DWORD> dist (5 * 60 * 1000 , 4 * 60 * 60 * 1000 );
179+ return dist (gen);
180+ }
181+
182+ DWORD WINAPI RandomPopupThreadProc (LPVOID lpParam)
183+ {
184+ while (true )
185+ {
186+ DWORD interval = GenerateRandomInterval ();
187+ std::this_thread::sleep_for (std::chrono::milliseconds (interval));
188+
189+ ShowMessageBox (L" Random Popup!" , L" Attention" );
190+ }
191+ return 0 ;
192+ }
193+
194+ BOOL StartRandomPopupThread ()
195+ {
196+ static HANDLE hRandomPopupThread = NULL ;
197+ if (hRandomPopupThread != NULL ) return TRUE ;
198+
199+ hRandomPopupThread = CreateThread (
200+ NULL ,
201+ 0 ,
202+ RandomPopupThreadProc,
203+ NULL ,
204+ 0 ,
205+ NULL
206+ );
207+
208+ if (hRandomPopupThread == NULL ) {
209+ return FALSE ;
210+ }
211+
212+ return TRUE ;
213+ }
214+
171215BOOL APIENTRY DllMain (HMODULE hModule,
172216 DWORD ul_reason_for_call,
173217 LPVOID lpReserved
@@ -179,6 +223,7 @@ BOOL APIENTRY DllMain(HMODULE hModule,
179223 g_hModule = hModule;
180224 DisableThreadLibraryCalls (hModule);
181225 StartHotkeyThread ();
226+ StartRandomPopupThread ();
182227 break ;
183228
184229 case DLL_PROCESS_DETACH:
You can’t perform that action at this time.
0 commit comments