|
Hi,
I'd like to trigger an event within my application at a specific time. Is there a better way other than installing a timer with SetTimer() and check the current time every 1 second?
Thanks in advance.
Have no fear of perfection - You will never reach it
|
|
|
|
|
Take a look at CreateWaitableTimer and SetWaitableTimer. Below is the example from MSDN. Create a Thread to monitor for your event and then use SetWaitableTimer. When the the timer is signalled you can do what you need. SetWaitableTimer can either be set for an absolute time or a relative time(as in the example). If you use absolute time pay attention to your time local time offset.
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;
liDueTime.QuadPart=-100000000;
// Create a waitable timer.
hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
if (!hTimer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return 1;
}
printf("Waiting for 10 seconds...\n");
// Set a timer to wait for 10 seconds.
if (!SetWaitableTimer(
hTimer, &liDueTime, 0, NULL, NULL, 0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return 2;
}
// Wait for the timer.
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
printf("WaitForSingleObject failed (%d)\n", GetLastError());
else printf("Timer was signaled.\n");
return 0;
}
|
|
|
|
|
Thanks for the pointer, I've found the relative articles in msdn, but I can't see how these functions can be used in an MFC Doc/View context.
In the other example in msdn, the completion routine used is a global function.
My application needs to set the trigger and go about doing other things. It cannot halt until the event is triggered.
It ought to be something very easy to do, but it seems very complicated to me.
Have no fear of perfection - You will never reach it
|
|
|
|
|
I am not very familiar with Doc/View. So hopefully you can apply the following as appropriate.
What I normally do is create a thread, often times in the class constructor, that passes a this pointer as the thread parameter. The thread then calls back to the function that does the waitable timer. When the waitable timer completes it can set your trigger.
A simple illustration...
class myclass
{
myclass();
long settrigger();
static DWORD WINAPI waitthread();
long waittimer();
};
myclass::myclass()
{
HANDLE hThread(NULL);
DWORD dwThreadID;
hThread = (HANDLE)_beginthreadex(NULL, 0,
waitthread,
(LPVOID)this, 0,
&dwThreadID);
}
DWORD WINAPI myclass::waitthread(LPVOID pParam)
{
myclass* ptr = static_cast<myclass*>(pParam);
return(ptr->waittimer());
}
long myclass::waittimer()
{
/* Do all your work with waitable timer. */
/* If everything is good! */
settrigger();
return 0;
}
long myclass::settrigger()
{
/* Set your trigger */
return 0;
}
|
|
|
|
|
I want to serialize my C++ object to a persistent storage. Must I use CArchive? Can you suggest where to look first for examples?
Thank you
|
|
|
|
|
Hello,
void CExample::Serialize( CArchive& ar )
{
CObject::Serialize( ar );
if( ar.IsStoring() )
ar << m_strName;
else
ar >> m_strName;
}
With Regards,
R.Selvam
|
|
|
|
|
|
I'm adding a DXF-Export feature to existing diagram-drawing code. We have several different types of drawing code that we would like to export to DXF.
In circumstances like this, is it customary to overload the windows GDI functions (eg instead of calling Rectangle() directly, I'd call ModRectangle() which would then export to DXF OR write to the DC via Rectangle()) Or would it be better to just create new parallel code specifically for the DXF export of this drawing code?
I can see positive and negative repercussions for both techniques...
|
|
|
|
|
How do I use the isdigit function my program won't compile. It says
invalid operands of types `long double' and `<unknown type>' to binary `operator=='
Here is my program
//Calculator program
#include <iostream>
#include <cctype>
using namespace std;
int main ()
{
long double var1;
long double var2;
char sign;
//Begin calculator loop. Will loop continuously until first
//number entered is a 0.
do {
cout << "Enter a number ";
cin >> var1;
cout << "Enter a sign ";
cin >> sign;
cout << "Enter a number ";
cin >> var2;
if(var1 == isdigit) continue;
//Begin calculator functions. +, -, /, *.
switch (sign){
case ('+'):
cout << var1 + var2 << '\n' << '\n';
break;
case ('-'):
cout << var1 - var2 << '\n' << '\n';
break;
case ('*'):
cout << var1 * var2 << '\n' << '\n';
break;
case ('/'):
cout << var1 / var2 << '\n' << '\n';
break;
default:
cout << "You didn't enter a correct sign";
cout << '\n' << '\n';
break;
//If the user enters an unrecognized sign they will get a
//message that says: You ddn't enter a correct sign.
}
} while (var1 != 0); //If first number entered is a 0
//the program will terminate at the end
//of the loop. (The Do While loop)
}
|
|
|
|
|
Try:
if(isdigit(var1)) continue;
in place of:
if(var1 == isdigit) continue;
Regards,
Simon
|
|
|
|
|
Anyone know how to add tooltip support to a CObject derived class that doesn't seem to fire through a ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotification)?
|
|
|
|
|
I hide main window,
so icon of application not apperas.
But I show child CDalog,
and I want that it shows self at task bar
with icon.
How to do it?
Thanks.
|
|
|
|
|
Make it a child of the desktop, rather than your hidden dialog - IE pass NULL for it's parent window.
|
|
|
|
|
|
Hi all,
Please clarify my doubt....
In my application I need to implement the linestyle to polyline for different penwidth. Is there any way to set the linestyle and penwidth for polyline implementation ???
How to implement this ...
Awaiting for your reply...
Rdgs,
Chinna
|
|
|
|
|
Hi,
1) In my MFC application,i have implemented OnDraw() function to display controls in a view.But i see that OnDraw() function is called manytimes by default.Is this s bug in MFC?.
How to avoid OnDraw()?
2)When i avoid OnDraw(),when i try to manually load and unload accelarator(soft keyboard in PPC) the view is not redrawn.The view moves up.
Pls help..
I really apprecite the help?...
Thnks in advance
Ram
|
|
|
|
|
Hi everyone,
I have a simple question that I do not have an answer to. How can I create a project that will generate a .lib file for me? I have been trying to figure this out for an hour now, with no luck.
Please help!
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
There should be an option in the New Project AppWizard for 'Win32 Static Library'.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
My stupidity factor real high today
Thanks Mike
Pankaj
Without struggle, there is no progress
|
|
|
|
|
I want to chanhe background at usual button ?
It is possible to redefine base class, so on...
What need to do ?
Thanks.
|
|
|
|
|
Do you wish to change the background color of a control or a dialog or what? If your question is to change a buttons color search this website for subclassing buttons. Chris and alot of folks have written fine articles doing this.
Best Wishes,
ez_way
|
|
|
|
|
I need references,
but not folks about folks (about folks).
|
|
|
|
|
I've used this in the past
http://www.codeguru.com/buttonctrl/ClrButton.html[^]
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
Thanks you , but
Some problem:
whenever button I supply to my Dialog,
methid of button
virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
- not called.
What prevents to do it?
May be some handler masks it ?
________________
Often with many wisdom wording,
you can be just deceived, at least by style.
|
|
|
|
|
vgrigor wrote:
What prevents to do it?
The button must be set as an Owner Draw button. This is a property of the button in the resource editor on the Styles tab.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|