-
March 9th, 2025, 05:51 PM
#1
Need help with asynchronous timer (UPDATED)
EDIT2: OK, may have it resolved.... Would love to have review of the code. The question I have is why does _endthread cause a crash when it is called in StopTimer?
Code:
void EPIQ_init(const long MyWaitTime)
{
bTimerOn = false;
lWait = MyWaitTime;
return;
}
// Stop the timer from running
void EPIQ_StopTimer()
{
if (bTimerOn)
{
// MessageBox(NULL, L"Made it to stopTimer", L"We made it", NULL);
bTimerOn = false;
WaitForSingleObject(hHwnd, lWait);
// _endthread();
}
return;
}
// Start the timer from running
void EPIQ_StartTimer()
{
if (bTimerOn == false)
{
bTimerOn = true;
EPIQ_ExecuteTimer(NULL);
}
return;
}
//The actual process of the timer
void EPIQ_TimerProc(void* ignored)
{
while (bTimerOn == true)
{
//this window's caption is "Message from webpage", so we search for it's handle using the FindWindow API
WindowHandle = FindWindow(NULL, L"Message from webpage");
SetForegroundWindow(WindowHandle);
//the Button's Caption is "OK" and it is a "Button".
ButtonHandle = FindWindowEx(WindowHandle, 0, L"Button", L"OK");
//send a message to the button that you are "clicking" it.
SendMessage(ButtonHandle, BM_CLICK, 0, 0);
}
return;
}
void EPIQ_ExecuteTimer(void* param)
{
// check to see if we'd overflow result or position
hHwnd = (HANDLE) _beginthread(EPIQ_TimerProc, 0, NULL); // create thread
return;
}
Thanks for the support.
EDIT: Suggestions requested for how to get the TimerProc function, below, to loop without locking out the calling VB application. Any help one can provide would be greatly appreciated.
Code:
void EPIQ_TimerProc(void* ignored)
{
// MessageBox(NULL, L"Made it to TimerProc", L"We made it", NULL);
//this window's caption is "Message from webpage", so we search for it's handle using the FindWindow API
WindowHandle = FindWindow(NULL, L"Message from webpage");
SetForegroundWindow(WindowHandle);
//the Button's Caption is "OK" and it is a "Button".
ButtonHandle = FindWindowEx(WindowHandle, 0, L"Button", L"OK");
//send a message to the button that you are "clicking" it.
SendMessage(ButtonHandle, BM_CLICK, 0, 0);
return;
}
Tried to place a _beginthread in my StartTimer function, but the TimerProc only runs once. I need it to loop until TimerProoc closes a System Dlg that pops up during an HTML.click call. Currently, everything I have tried ties up the VB program and eventually crashes it.
Hi, I'm trying to get a DLL to run a timer that will not freeze the calling application, a timer. I have not been able to find anything that could work and wanted to see if anyone might have something they can share. I have not programmed in C/C++ for over 20 years, so I'm rusty when trying to create a DLL for this function. This is for a work project to automatically process records that no one is able to get to that does not require a person intervention. They just need to be closed.
Here is what I'm tyring to accomplish.
*webpage requires a click to move to the next section. In the process, a System Dlg pops up asking for confirmation.
*HTML.click is called and program freezes until System Dlg is no longer active.
What I need.
I need to activate a timer just before I call HTML.click in order to start code that will wait for the System Dlg to appear and then send messages to it to represent keys pressed so the System Dlg dissapers. I need the DLL to run in the background during the time that the VB program is within the HTML.click function as it is frozen until the Dlg is gone.
Anyone have any code for a DLL like this they can share to help me out?
EDIT: Seems that MFC has gone to the wayside. The AFXthreads were really helpful in the day can they be used in the DLL since I'm somewhat familiar with the functions of MFC?
Last edited by funkmonkey; March 10th, 2025 at 09:34 AM.
-
March 10th, 2025, 03:43 AM
#2
Re: Need help with asynchronous timer
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|