Click here to Skip to main content
15,915,603 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralpThread question in C++ Pin
ChiYung10-Jun-02 11:25
ChiYung10-Jun-02 11:25 
GeneralRe: pThread question in C++ Pin
markkuk10-Jun-02 12:06
markkuk10-Jun-02 12:06 
GeneralRe: pThread question in C++ Pin
10-Jun-02 18:34
suss10-Jun-02 18:34 
GeneralRe: pThread question in C++ Pin
markkuk11-Jun-02 6:18
markkuk11-Jun-02 6:18 
Questioncan CListCtrl show image in the subitems? Pin
rosegame10-Jun-02 8:40
rosegame10-Jun-02 8:40 
AnswerRe: can CListCtrl show image in the subitems? Pin
Gary Kirkham10-Jun-02 11:32
Gary Kirkham10-Jun-02 11:32 
GeneralTimers Pin
arthivjii10-Jun-02 8:30
arthivjii10-Jun-02 8:30 
GeneralRe: Timers Pin
Joaquín M López Muñoz10-Jun-02 9:33
Joaquín M López Muñoz10-Jun-02 9:33 
You've raised a very interesting problem! Apparently, there's no suitable callback parameter one can use to store a pointer to the object responsible of handling a TimerProc-driven timer. A workaround, if a little contrived one, is to have a map from timers IDs to objects. The following sketches the approach (warning: I haven't even compiled it, look for typos)
class MyClass
{
private:
  typedef std::map<UINT,MyClass *> MapFromIdToMyClass
 
  static MapFromIdToMyClass idToMyClass;
protected:
  UINT SetTimer(UINT uElapse)
  {
    UINT id=::SetTimer(NULL,0,uElapse,staticTimerProc);
    if(id){
      idToMyClass[id]=this;
    }
    return id;
  }
 
  BOOL KillTimer(UINT id)
  {
    MapFromIdToMyClass::iterator it=idToMyClass.find(id);
    assert(it!=idToMyClass.end());
    if(!::KillTimer(NULL,id)) return FALSE;
    idToMyClass.erase(it);
    return TRUE;
  }
 
  static VOID CALLBACK staticTimerProc(HWND,UINT,UINT id,DWORD dwTime)
  {
    MapFromIdToMyClass::iterator it=idToMyClass.find(id);
    assert(it!=idToMyClass.end());
    (it->second)->TimerProc(id,dwTime);
  }
 
  void TimerProc(UINT id,DWORD dwTime)
  {
    ... //your stuff here
  }
  ...
);
The idea is to forward all timers to a static TimerProc which uses the map to redirect the call to the associated MyClass object. If you get this to work and find it fit for your needs, please be aware you'll need some kind of concurrency protection (like a CRITICAL_SECTION) to prevent racing problems that can occur if the timer triggers before the id has been mapped to the associated object.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: Timers Pin
Paul M Watt10-Jun-02 21:44
mentorPaul M Watt10-Jun-02 21:44 
Generalthird challange to the masters of vc Pin
SilentWarrior10-Jun-02 7:43
SilentWarrior10-Jun-02 7:43 
GeneralRe: third challange to the masters of vc Pin
Chris Losinger10-Jun-02 8:03
professionalChris Losinger10-Jun-02 8:03 
GeneralRe: third challange to the masters of vc Pin
10-Jun-02 9:30
suss10-Jun-02 9:30 
GeneralRe: third challange to the masters of vc Pin
Chris Losinger10-Jun-02 13:00
professionalChris Losinger10-Jun-02 13:00 
GeneralRe: third challange to the masters of vc Pin
Christian Graus10-Jun-02 13:07
protectorChristian Graus10-Jun-02 13:07 
GeneralRe: third challange to the masters of vc Pin
Christian Graus10-Jun-02 13:04
protectorChristian Graus10-Jun-02 13:04 
Generalsecond challange to all Pin
SilentWarrior10-Jun-02 7:38
SilentWarrior10-Jun-02 7:38 
GeneralRe: second challange to all Pin
Chris Losinger10-Jun-02 8:57
professionalChris Losinger10-Jun-02 8:57 
GeneralRe: second challange to all Pin
Christian Graus10-Jun-02 13:06
protectorChristian Graus10-Jun-02 13:06 
Generalmy first challange to all the masters of vc Pin
SilentWarrior10-Jun-02 7:33
SilentWarrior10-Jun-02 7:33 
GeneralRe: my first challange to all the masters of vc Pin
Chris Losinger10-Jun-02 8:58
professionalChris Losinger10-Jun-02 8:58 
Generalexception handling Pin
Jason Henderson10-Jun-02 7:21
Jason Henderson10-Jun-02 7:21 
GeneralRe: exception handling Pin
Chris Losinger10-Jun-02 7:23
professionalChris Losinger10-Jun-02 7:23 
GeneralRe: exception handling Pin
Le centriste10-Jun-02 8:39
Le centriste10-Jun-02 8:39 
GeneralRe: exception handling Pin
Martin Ziacek10-Jun-02 9:29
Martin Ziacek10-Jun-02 9:29 
GeneralRe: exception handling Pin
Le centriste10-Jun-02 9:49
Le centriste10-Jun-02 9:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.