Solved

TimeProc

Posted on 1998-12-09
5
326 Views
Last Modified: 2008-03-10
Hi.. another multimedia time question... I have a dialog based MFC with a static control that I want to change every time the multimedia timer changes. I had this in the TimeProc

CStatic* staticctrl = (CStatic*) GetDlgItem(IDC_STATIC_TEST);
staticctrl->SetWindowText("Low");  

And I have had grief with the GetDlgItem because of some parameters.
Is there a way to fix this?
Also, If fix it by posting a message in TimeProc with PostMessage, what priority would it have because it is time critical and I want the highest accuracy?
0
Comment
Question by:rose3377
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1179726
Your message will be given high prioroty in the message queue, but that doesn't matter because PostMessage is assynchronous so the message is not likely to be handled very quickly.  

SendMessage would be better, but the prolem is that the program could be waiting for  another sendmessage to return, in which case your sendmessage can't be processed so the message will be ignored.

If you need timely processing, then you had better forget using messages.  What are the problems you are trying to solve?
0
 

Author Comment

by:rose3377
ID: 1179727
I have a program generating a pulse train to my hardware. The pulse has to have an exact period. Timing is critical! How do I achieve this then? I needed the GetDlgItem so that a static control on the dialog box will alternate saying high-low-high-etc.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1179728
NT is far superior to windows 95/98 but it is not a real-time system.  Depending on how critical the timing is you may not be able produce the signal you need.   A more typical solution would be to use NT to control (turn on or off) a hardware signal generator.

You should be able to use GetDlgItem etc you haven't explained what troubles you are having with it.  However, That sort if thing is likley to be slow, how long is your timer event?  Also since the timmer procedure is called asynchronously, you do need to take procautions to syncronize access to shared data, like the dialog item etc.
0
 

Author Comment

by:rose3377
ID: 1179729
The problem with GetDlgItem is that my error says that I am calling a non-static function in a static function, since the callback function of a multimedia timer is static. Is there a way around this problem?
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1179730
Sure.  2 main ways.

I assume what you need is a pointer to the parent window of some control (or just a pointer to that control.  Well you need a pointer to some object, you'll know which)  The easiest way is if there is just one of these objects (i.e. just one parent window in the program--something like that) then you can store a pointer to this object in a global variable and cll the functions you need using this pointer.

However,  if there are more than one of these objects floating around, (i.e if some timer calls will need one pointer and others will need a different one) then you can use dwUser parameter of the timeSetEvent() procedure to pass the pointer you need.  i.e when you call timeSetEvent() to set the timer, pass a pointer to the object to be used.  When your timer procedure is called the dwUser parameter will contain this pointer.  Your timer procedure can convert this pointer to a pointer of the right type and call the appropriate member function.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question