1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| class CPwet
{
public :
void Init()
{
UINT_PTR Id = SetTimer(NULL, NULL, 2000, &CPwet::GlobalTimerProc);
if (Id)
{
// On associe l'identificateur du timer à l'instance de Pwet correspondante
Pwets[Id] = this;
}
else
{
// Erreur lors de la création du timer...
}
}
private :
void TimerProc()
{
// Là tu es dans une fonction membre, tu fais ce que tu veux
}
static void CALLBACK GlobalTimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
// On cherche l'instance de Pwet correspondant à l'identificateur
std::map<UINT_PTR, CPwet*>::const_iterator It = Pwets.find(idEvent);
if (It != Pwets.end())
{
// Trouvé : on peut utiliser l'instance de Pwet
CPwet* ThePwet = It->second;
ThePwet->TimerProc();
}
else
{
// Problème... identificateur non enregistré
}
}
static std::map<UINT_PTR, CPwet*> Pwets;
}; |