SetTimer() question

I'm using the timer function 'SetTimer()' and 'KillTimer()' function to
start and stop the animation. The problem is, the animation pauses during
the call to the Sleep() function or call to a function that takes a long
time to complete processing. What can I do so that the animation does not
pause.

Thank you


0
horvathr (32)
9/2/2005 7:31:58 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
598 Views

Similar Articles

[PageSpeed] 1

Put the long process in a seperate thread. Or Pump messages in between your
long process.
You can also change your sleep to do something like this

void CMyApp::Wait(DWORD HowLong)
{
MSG Msg;

   DWORD Start = GetTickCount();

   while (Start + HowLong > GetTickCount())
   {
      if (PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
      {
         if (!PreTranslateMessage(&Msg))
         {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
         }
      }
   }
}

and instead of calling sleep call

((CMyApp *)AfxGetApp())->Wait(2000);

this can be used to pump message in between your long process also
for (int i = 0; i < 1000000000;i++)
{
    ((CMyApp *)AfxGetApp())->Wait(100);
    DoSomething....
    ((CMyApp *)AfxGetApp())->Wait(100);
    DoSomeMore..
    ((CMyApp *)AfxGetApp())->Wait(100);
    And more
}

AliR.

"Ririko Horvath" <horvathr@securemethods.com> wrote in message
news:Ofb99T$rFHA.2008@TK2MSFTNGP10.phx.gbl...
> I'm using the timer function 'SetTimer()' and 'KillTimer()' function to
> start and stop the animation. The problem is, the animation pauses during
> the call to the Sleep() function or call to a function that takes a long
> time to complete processing. What can I do so that the animation does not
> pause.
>
> Thank you
>
>


0
AliR3470 (3235)
9/2/2005 8:23:02 PM
AliR,

  That's a good suggestion, except you've made a very common and
sometimes very pernicious mistake in your use of GetTickCount()...
you've forgotten about rollover.  For instance, imagine the value of
GetTickCount() assigned to start is 0xFFFFFF00 and "HowLong" is passed
in as 0x100.  The first comparison will yield:
  (Start + HowLong) = (0xFFFFFF00 + 0x100) = (1 > GetTickCount())

  This means that if GetTickCount() hasn't rolled over before the next
call to it, the function will kick out regardless of the time elapsed.
The far WORSE case, however, would be if GetTickCount DID roll over,
but your comparison didn't.  For instance, if HowLong was 0xFF, the
comparison would shake out to be:

  while(0xFFFFFFFF > GetTickCount())

  You can see that if one of your calls to GetTickCount doesn't line up
EXACTLY when it's at 0xFFFFFFFF that you're going to hang for (on most
systems) about 40 days.  The safe way to do things is:

  while (GetTickCount() - Start < HowLong)

  Imagining the same scenario, you can see that even when
GetTickCount() rolls over, the comparison will be correct and you'll
get the desired elapsed time.

0
9/3/2005 1:54:45 AM
It's a shame that in Linux, programmers don't hesitate to compare 'jiffies' 
(10 ms tick count) against a "target time'. Of course, jiffies roll over 
after 470 days, but it's no good anyway.

"Jay Daniel" <Phaze426SPAMBOX@gmail.com> wrote in message 
news:1125712485.915608.4090@g43g2000cwa.googlegroups.com...
> AliR,
>
>  That's a good suggestion, except you've made a very common and
> sometimes very pernicious mistake in your use of GetTickCount()...
> you've forgotten about rollover.  For instance, imagine the value of
> GetTickCount() assigned to start is 0xFFFFFF00 and "HowLong" is passed
> in as 0x100.  The first comparison will yield:
>  (Start + HowLong) = (0xFFFFFF00 + 0x100) = (1 > GetTickCount())
>
>  This means that if GetTickCount() hasn't rolled over before the next
> call to it, the function will kick out regardless of the time elapsed.
> The far WORSE case, however, would be if GetTickCount DID roll over,
> but your comparison didn't.  For instance, if HowLong was 0xFF, the
> comparison would shake out to be:
>
>  while(0xFFFFFFFF > GetTickCount())
>
>  You can see that if one of your calls to GetTickCount doesn't line up
> EXACTLY when it's at 0xFFFFFFFF that you're going to hang for (on most
> systems) about 40 days.  The safe way to do things is:
>
>  while (GetTickCount() - Start < HowLong)
>
>  Imagining the same scenario, you can see that even when
> GetTickCount() rolls over, the comparison will be correct and you'll
> get the desired elapsed time.
> 


0
alegr (1131)
9/3/2005 4:57:19 AM
Reply:

Similar Artilces:

REQ: Can Someone Help Me With This Outlook XP Question?
Hello All: I use Word to edit my e-mail msgs in Outlook XP. I had to reinstall Office the other day and now whenever I want to start a new e-mail or reply to an e-mail I get a warning that comes up: "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this? If this is unexpected it may be a virus and you should choose 'No'" There is a box that asks for the amount of time to allow the access: 1 to 10 minutes. Do I have to have specific settings for my Outlook address book? I use the Contact area in Outlook for addresses. I have ...

noob questions
sorry, to bother u with a noob question, but for selfstudy purposes i have come across a thing that i would like to figure out on how it works. how does it work ? (i don t even know what it is called, so i best describe what i mean.... if you have a few rows and you want to make them dissappear with a "plus sign in front! so you can open and close this range of coloumns ... how do you do that ... i mean how do you make this kind of view? (or at least what is this feature called, so i can find out in the office help feature... that would already be a superb help! thankx y´all ...

Three questions about fields in worksheets
Hello! I have a workbook that tracks patients (mothers) and contacts (mom's family members). The mother worksheet is named MAT_INF and the contacts one is named CONTACTS. 1. In MAT_INF, I have a field named CASE_NUMBER. How can I tell this field to automatically start out with a value like "2009-"? An example case number would look like 2009-001 or 2010-099. 2. Once CASE_NUMBER, LAST_NAME_MOM and FIRST_NAME_MOM have been populated by the user in MAT_INF, how can I automate adding those values to the CONTACT sheet, where the corresponding fields are named CASE_N...

Access question
Our Help Desk is trying to give access to the following menu, but can't seem to find the correct setting: <transactions><financial><financial deferral>. Can someone help point me in the right direction so we can get it accomplished? Thanks Merle: They'll find the deferral items in Advanced Security here - Set the View to: By Dictionary Look for Revenue Expense Deferrals The deferral windows are listed there. Frank Hamelly MCP-GP, MCT, MVP East Coast Dynamics www.eastcoast-dynamics.com ...

problem with SetTimer()
Hi All, I've a problem with SetTimer function. I've wrote this code: class myClass { void CALLBACK TimerProc( HWND hWnd, // handle of CWnd that called SetTimer UINT nMsg, // WM_TIMER UINT nIDEvent // timer identification DWORD dwTime // system time ){ //some code.... } myClass() { SetTimer (1, 1000, (TIMERPROC) TimerProc); } } the compiler returns a conversion error for 3th parameter of SetTimer (TimerProc) help me, what's wrong ?? System info: - Visual Studio 7.0 - Windows XP SP2 Make TimerProc() static. class myClass { static...

Accessing all questions I have asked in the Office forums
Is there a way I can call up all questions and answers I have ever asked via my login to Microsoft Discussion groups? I sure appreciate your help, John In news:FB996750-8ACF-4806-BDF8-7E66057A0DBB@microsoft.com, John <John@discussions.microsoft.com> typed: > Is there a way I can call up all questions and answers I > have ever asked via my login to Microsoft Discussion groups? > > I sure appreciate your help, John Use Google; look up your own name; finesse from there if you get too many hits. HTH, Twayne` ...

Sync Center question
Hi, How do I use sync folders on my PC (using Sync Center or any other program) with a USB drive? Currently "Setup sync partnerships" does not show anything. Visa Home Prem SP1 Thank you for your help. you can sync external devices like flash drive and flash cards to the hard drive (and vice versa) with microsoft's sync toy. it is free and can be found via microsoft.com -- db���`�...�><)))�> DatabaseBen, Retired Professional - Systems Analyst - Database Developer - Accountancy - Veteran of the Armed Forces - @Hotmail.com - nntp Post...

SetTimer ?
In my VC6 MFC app, I establish a timer by using a call to SetTimer(...) for an elapsed time of 5 second intervals. All working fine in this manner, but... I need to reset this timer to start counting at zero if a certain unrelated event occurs. Can this be done in this rather primitive arrangement? I'm wondering if I could call KillTimer and immediately call SetTimer each time I need to reset this timer? Is there a better way? Essentially, I am recognizing when a mouse cursor enters a window and at that moment, I need to set the timer to trigger a message 5 seconds later. Any...

2 Questions
1. Using 1.3 on XPP on two networked PC's. Database connects fine. After starting SO POS on front computer w/dongle, I use start up SO Manager and I receive "warning 941, the copyright..." My firewalls are set (I believe) correctly. What do I need to do to allow back office to recognize dongle on the front PC. 2. While I am able to open SO POS just fine, when I sign in with name/password I receive "ACCESS DENIED." However, I click "okay," and it seems that everything works okay. I checked my cashier's security settings, all are in place....w...

Payroll Question
Could somebody that's a little more into payroll than I am help me out here. At the end of the year, does the previous payroll year have to be closed and the W-2's printed before checks for the next year can be cut? -- Japheth Nolt Microsoft SBF Specialist Landis Computer www.landiscomputer.com 8/22/2007 10:26:03 AM You do not have to print W2s before you process payroll runs in the new year. You do have to run the routine to create the year end file before you process W2s or do transactions in the new year. The year end processing articles have a lot of details on steps. -- Ch...

Drop Down Question
At one point, I think I read dynamic drop down would be possible with crm 3.0. Is this true? If so, can you link me to some documentation or sample code in how I can do this? Let me describe what I’m trying to accomplish. I’m looking to propagate a referrals drop down based on the challenges records in a custom entity I created. So, the parent drop down would provide a list of the distinct challenges. When one is selected, it would fill the referral drop down with all the referrals available with a challenge type of the parent drop down. Possible? Thanks for your help! ...

Some generic questions about UDFs
I have a small collection of UDFs some kindly provided by members of this newsgroup. I've searched the net but I can't seem to find answers to the following questions: 1st Ques: Ideally I would like the 2nd half of the UDF's [function argument] box to provide additional information, like Excel's integral functions. I definitely do not want to incorporate a help file. Is it possible to add additional code to the UDF so a small description is displayed? They are for my own use so I don't want to go to the palaver of learning how to do add-ins or produce help files. 2nd Que...

Excel guru question..
I have a table, 4w x 10h. I input data into A1-A10 and B1-B10. The data is converted into values in C1-C10 and D1-10. I need the data in the following format: C1,D1 C2,D2 C3,D3 C4,D4 C5,D5 C6,D6 C7,D7 C8,D8 C9,D9 C10,D10 ....all in one cell and with the commas included. I know there's a way to do this, but damn if I can remember it. Anyone? -- Bryan S. Slick, onyx_hokie at yahoo dot com "Violence is the last refuge of the incompetent." (Salvor Hardin in 'Foundation', Isaac Asimov) You could do it manually, but a macro is much quicker. Sub ConCat_Cells() Di...

Mail Routing Question.
I have an Exchange 2003 Server. My client would like for all mail to be sent to the internet, no internal x400 mail. He wants this because he is away from the office quuite a bit and syncs his phone with the ISP, receives all external email, but none from his office. He does not have a compatible phone yet for Exchange Activesync. How would I set it up on the server to have all mail go through the Internet. Thank you. Keith Your question is a little confusing please clarify. SMTP is native to Exchange 2003 and while the X400 protocol is available by default it is not used. If you set...

question #2
how to format x - axis scale , minor and major ...

Morbid Categories Question
How have others who have lost loved ones categorized their final expenses (casket, funeral, plot, monument, etc.)? TIA. Never done it. I'm thinking Miscellaneous:Other. Seems like I wouldn't want to spend much more time thinking about it. "Brent" <HarvestThis@Spammers.Net> wrote in message news:ONbDcEZeHHA.596@TK2MSFTNGP06.phx.gbl... > How have others who have lost loved ones categorized their final expenses > (casket, funeral, plot, monument, etc.)? In microsoft.public.money, Dick Watson wrote: >Never done it. I'm thinking Miscellaneous:Other...

Division and formatting excel question
I am doing a spread sheet right now and I am not having good luck with a certain function I need to do. What it is, I need a number, say 55,104 divided by 1,440 which equals 38.266666 . I would like it to only display 38.26 in the cell. I did a format cell and show 2 decimal places but it doesnt do it. Then I need to add up the results of 5 cells of the same kind as previously mentioned. When I try to add them up now it just shows 0.00 using the sum function? I dont get what I need to do different. What it is, is a production sheet, we produced 55104 gallons of product i...

Iffunction questions pulling values from other sheets +return value from partial data
I have been struggling with the IF Function for a while, what I a trying to accomplish is this: Let's say the data in cell A1 depends on part of the data in cell B1. need the function to bring up a value in A1 (for this example we'll us Nelson Rains) ONLY IF the first two letters in Cell B1 are NR. So basically if I enter "NR430" in cell "B1" then cell A1 will displa "Nelson Rains". Can this be Done? +--------------------------------------------------+ Another matter (albeit less pressing) I would like help on is whethe or not an IF Function can pull...

Validation question in 2007
If I click on Col B I and select DATA/ Validation I get the message:The selection contains more than one type of validation. Erase current and continue?" My question is: How can I find out what data validation are currently in use. Thanks Hi, You can use Goto Special cells . CTRL+G displays dialog Special... Check Data validation. You can then select all cells with data validation or this with the same data validation as the activecell. Cheers Andy pcor wrote: > If I click on Col B I and select DATA/ Validation I get the message:The > selection contains more than one type...

A Question about CTreeCntrl
I'm writing an application from an example that uses a CTreeCtrl. I'm don't understand the usage of the InsertItem methods and its parameters. HTREEITEM InsertItem( LPTVINSERTSTRUCT lpInsertStruct ); HTREEITEM InsertItem( UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter ); HTREEITEM InsertItem( LPCTSTR lpszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST ); HTREEITEM InsertItem( LPCTSTR lpszItem, int nImage, int nS...

Question on "Monthly Income and Expenses" report
I decided I wanted to generate a quarterly report by category showing monthly income and expenses. I was able to get it to work, but try as I might, I can not find a way to show transfers from my checking account to my savings account. I know that I do not want to show transfers to the credit card account. But the choices on the show transfers does not result in the transfers to savings or the purchase of CD's as showing up in the report. I am running Money Plus Delux. Without chasing the specifics just yet, understand that "Income and Expenses" are everything Transfe...

Question about WM_SIZEPARENT
I have a CWnd derived class which is in control of some tabbed CView objects. The first view which is AFX_IDW_PANE_FIRST controls sizing of the views when it receives the WM_SIZEPARENT message. The problem is that it doesn't always get the message. I've traced into CWnd::RepositionBars(...) and found the following code: for (HWND hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL; hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT)) { UINT nIDC = _AfxGetDlgCtrlID(hWndChild); CWnd* pWnd = CWnd::FromHandlePermanent(hWndChild); if (nIDC == nIDLeftOver) hWndLeftOver = hWnd...

2 more questions
First of all thanks to all of you who helped me with my workbook. I have 2 more questions to ask: 1. cell F2 has a SUM formula. I would like the formula to go automatically to F3 but this ONLY if A3 is not empty and to F4 if A4 is not empty and so on. Is it possible? 2. at the end of the day all data inserted in Sheet 1 go automatically to a hidden sheet and is deleted from sheet 1. is it possible to create a macro or whatever which can restore the SUM formula in F2 etc (as above)? Thanks again for your help Try this in F2: =IF(A2<>0,SUM(A2:E2),"") And drag down to...

CRM3.0 Question on Activity
Hello, I am using CRM3.0. I have the following case. 1. Create Campaign 2. Add contact to campaign list 3. Create Campaign activity - Phone call 4. Distribute activity 5. CRM User will make phone call 6. When contact is interest, CRM user will make a "Free Trail" for contact. I am having troble in step 6. So far as I know, I have two choices for "Free Trail". A) Service Activity If I choose to create a service activity, then I can not link up the service activity with the campaign or phone call. B) Appointment If I choose appointment, I can set "regarding"...

Moving mailbox question
I am moving mailboxes between exchange 5.5 to Exchange 2003. I've noticed after the move, in Exchange 5.5, the mailbox still exist. Shouldn't the mailbox be deleted or removed from exchange 5.5? Thanks how, exactly, are you moving them? -- Susan Conkey [MVP] "sean" <nosean@noemail.gmail.com> wrote in message news:Orrizb8FHHA.5000@TK2MSFTNGP03.phx.gbl... >I am moving mailboxes between exchange 5.5 to Exchange 2003. I've noticed >after the move, in Exchange 5.5, the mailbox still exist. Shouldn't the >mailbox be deleted or removed from e...