Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
682 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  mise en oeuvre d'un timer

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

mise en oeuvre d'un timer

n°724943
lecoyote
Posté le 13-05-2004 à 17:36:32  profilanswer
 

arrrrrrrrrrgggggggggggggggg !!!!!!!!!!
 
je n'arrive pas à comprendre pourkoi ca ne marche pas !!!!!!!!!!!!!
 
voici mon code :
 

Code :
  1. BOOL MonProg::OnInitDialog()
  2. {
  3.          (..)
  4.          theTime = SetTimer(1000,1000,NULL);
  5.          (...)
  6. }
  7. void MonProg::OnTimer(UINT nIDEvent)
  8. {
  9. if(theTime == nIDEvent)
  10.  AfxMessageBox("Hello",MB_OK);
  11. }


 
et mon prog. ne m'affiche meme pas UNE fois "Hello" !!!
 :cry:  
 
help plz !

mood
Publicité
Posté le 13-05-2004 à 17:36:32  profilanswer
 

n°725436
Taz
bisounours-codeur
Posté le 14-05-2004 à 07:39:59  profilanswer
 

euh, j'y connais rien, mais bon
 
enregister un timer sans donner la fonction de rappel ...
 
SetTimer(1000,1000,NULL);  
 
je vois pas comment tu veux qu'il devine que void MonProg::onTimer(UINT nIDEvent) doit être appeler

n°725451
Ace17
Posté le 14-05-2004 à 08:32:35  profilanswer
 

Effectivement, tu n'y connais rien, mais vu que c'est de la programmation Windows... on peut te comprendre :D
 
OnTimer est appelé automatiquement a la reception d'un message WM_TIMER. Quand tu invoques SetTimer, tu peux éventuellement lui donner une fonction de rappel, mais c'est pas obligé.
 
Essaie plutot ca :
 
SetTimer(MON_TIMER_ID, 1000, NULL);
 
if(nIDEvent == MON_TIMER_ID)
 .......

n°725462
lecoyote
Posté le 14-05-2004 à 08:48:03  profilanswer
 

la fonction OnTimer() est normalement une fonction appelé par défaut lors du lancement du timer...

n°725467
lecoyote
Posté le 14-05-2004 à 08:53:01  profilanswer
 


 
tu n'initialise pas monTimer ?

n°725469
lecoyote
Posté le 14-05-2004 à 08:54:50  profilanswer
 

enfin, de toute manière, même de cette facon, mon OnTimer() n'ai qd meme pas appelé...

n°725470
Ace17
Posté le 14-05-2004 à 08:55:15  profilanswer
 

Tu veux dire MON_TIMER_ID?
C'est une constante, tu lui donnes la valeur que tu veux... et d'ailleurs je vois pas pourquoi tu parles d'initialisation


Message édité par Ace17 le 14-05-2004 à 08:55:48
n°725472
Ace17
Posté le 14-05-2004 à 08:57:17  profilanswer
 

Essaie déja avec ca...

Code :
  1. BOOL MonProg::onInitDialog()
  2. {
  3.        (..)
  4.         SetTimer(0,1000,NULL);
  5.        (...)
  6. }
  7.  
  8. void MonProg::onTimer(UINT nIDEvent)
  9. {
  10.        AfxMessageBox("Hello",MB_OK);
  11. }


Message édité par Ace17 le 14-05-2004 à 08:58:15
n°725474
Ace17
Posté le 14-05-2004 à 08:58:44  profilanswer
 

Au fait ca parait débile mais MonProg ca dérive bien d'un CWnd j'espere?

n°725476
lecoyote
Posté le 14-05-2004 à 09:05:28  profilanswer
 

voila, en fait c'est de ma faute, j'ai oublié de préciser que mon app est une SDI et que ma classe hérite de CDialog ...
 
J'ai bien une OnInitDialog, mais c'est moi qu'il l'ai rajouté à la main, de tel sorte que celle-ci soit lancée automatiquement au lancement de ma boite de dialog (enfin, je vx pas trop rentré ds les détails).
 
et pour reprendre ton Essaie déja avec ca... Ace17, je l'ai déjà essayer plusieurs fois, mais comme ce n'est pas un projet "boite de dialog", ma classe n'hérite pas de CWnd, donc je dois faire avec CDialog...

mood
Publicité
Posté le 14-05-2004 à 09:05:28  profilanswer
 

n°725477
Ace17
Posté le 14-05-2004 à 09:08:54  profilanswer
 

class CDialog : public CWnd
 
Donc un CDialog, c'est un CWnd...
 
Vérifie par un autre moyen que ton OnInitDialog est bien appelée, parce que normalement elle doit l'etre

n°725486
lecoyote
Posté le 14-05-2004 à 09:14:47  profilanswer
 

elle est bien appelé car dans cette fonction, j'ai toute une connexion qui s'établit à une caméra est affiche le flux vidéo de celle-ci à mon écran.
Si cette fonction n'était pas applée, je n'aurais aucune image.
donc, le timer est bien lancer !
mais, à aucun moment ma fonction OnTimer n'est appelé !!!!!!!!!    :cry:

n°725493
Ace17
Posté le 14-05-2004 à 09:17:44  profilanswer
 

Question idiote, encore :

Code :
  1. void MonProg::onTimer(UINT nIDEvent)
  2.   {
  3.      if(theTime == nIDEvent)
  4.         AfxMessageBox("Hello",MB_OK);
  5.   }


 
Ca c'est le code que tu as posté. Ce serait pas plutot OnTimer  ?

n°725495
lecoyote
Posté le 14-05-2004 à 09:18:43  profilanswer
 

Code :
  1. #include "stdafx.h"
  2. #include "VideoProcessing.h"
  3. #include "ClientImage.h"
  4. #include "Video.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. HOSTNAME szHostName;
  11. DWORD dwPort=SERVERIMAGES_TCPPORT;
  12. Video video;
  13. CClientImage::CClientImage(CWnd* pParent /*=NULL*/)
  14. : CDialog(CClientImage::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CClientImage)
  17.  // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. void CClientImage::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(CClientImage)
  24.  DDX_Control(pDX, IDC_NORMAL, m_Normal);
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(CClientImage, CDialog)
  28. //{{AFX_MSG_MAP(CClientImage)
  29. ON_BN_CLICKED(IDC_ARRETER, OnArreter)
  30. ON_BN_CLICKED(IDC_ACQUITTER, OnAcquitter)
  31. ON_WM_DESTROY()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. BOOL CClientImage::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. CDialog::UpdateWindow();
  38. monTimer=500;
  39. SetTimer(monTimer,1000,NULL);
  40. video.pClientImage=this;
  41. StartupWSA();
  42. networkinfosStartup();
  43. codecjpgStartup();
  44. BOOL bError=FALSE;
  45. BUFFER szTemp;
  46. GetPrivateProfileString("VIDEOSTREAM","HOSTNAME","",szHostName,sizeof(szHostName),WANYINFORMATIONFILE);
  47. GetPrivateProfileString("VIDEOSTREAM","PORT","",szTemp,sizeof(szTemp),WANYINFORMATIONFILE);
  48. dwPort=atoi(szTemp);
  49. if(networkinfosEnterHostAddressAndPort(szHostName,&dwPort,SERVERIMAGES_TCPPORT,NULL))
  50. {
  51. if(!video.Connect(szHostName,"","" ))
  52.  {
  53.  BUFFER szBuffer;
  54.  wsprintf(szBuffer,"Connexion à %s impossible ...",szHostName);
  55.  MessageBox(szBuffer,"VideoProcessing",MB_OK|MB_ICONEXCLAMATION);
  56.  bError=TRUE;
  57.  }
  58. }
  59. else
  60. {
  61. bError=TRUE;
  62. }
  63. if(bError) EndDialog(IDCANCEL);
  64. return TRUE;
  65. }
  66. void CClientImage::OnTimer(UINT nIDEvent)
  67. {
  68. if(nIDEvent == monTimer)
  69. // m_Normal.OnSave();
  70. AfxMessageBox("gui" );
  71. CDialog::OnTimer(nIDEvent);
  72. }

n°725498
lecoyote
Posté le 14-05-2004 à 09:21:05  profilanswer
 

Ace17 a écrit :

Question idiote, encore :

Code :
  1. void MonProg::onTimer(UINT nIDEvent)
  2.   {
  3.      if(theTime == nIDEvent)
  4.         AfxMessageBox("Hello",MB_OK);
  5.   }


 
Ca c'est le code que tu as posté. Ce serait pas plutot OnTimer  ?


 
lorsque tu poste du codage, il te transforme un OnTimer en onTimer ...

n°725500
Ace17
Posté le 14-05-2004 à 09:23:02  profilanswer
 

Montre comment est déclaré OnTimer dans la classe MonProg

n°725502
lecoyote
Posté le 14-05-2004 à 09:26:36  profilanswer
 

:ange: heu.... je l'ai déclaré en void .... c'est plutot du type CDialog ?  :??:

n°725505
Ace17
Posté le 14-05-2004 à 09:28:32  profilanswer
 

Code :
  1. afx_msg void OnTimer( UINT nIDEvent );


 
Sinon le compilo comprendra pas que t'es en train de redéfinir la fonction virtuelle


Message édité par Ace17 le 14-05-2004 à 09:28:49
n°725508
lecoyote
Posté le 14-05-2004 à 09:33:06  profilanswer
 

voila fait, cependant, ma fonction n'est toujours pas appelé par SetTimer()... !

n°725547
Ace17
Posté le 14-05-2004 à 10:03:23  profilanswer
 

Bon, balance tout ton code

n°725575
lecoyote
Posté le 14-05-2004 à 10:27:00  profilanswer
 

le .h :
 

Code :
  1. #if !defined(AFX_CLIENTIMAGE_H__F7F7C5FB_63B8_4161_8676_7EDCA035F974__INCLUDED_)
  2. #define AFX_CLIENTIMAGE_H__F7F7C5FB_63B8_4161_8676_7EDCA035F974__INCLUDED_
  3. #include "ImageNormal.h"
  4. #if _MSC_VER > 1000
  5. #pragma once
  6. #endif // _MSC_VER > 1000
  7. // ClientImage.h : header file
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CClientImage dialog
  11. class CClientImage : public CDialog
  12. {
  13. // Construction
  14. public:
  15. UINT monTimer;
  16. CClientImage(CWnd* pParent = NULL);   // standard constructor
  17. // Dialog Data
  18. //{{AFX_DATA(CClientImage)
  19. enum { IDD = IDD_AFFICHAGE };
  20. CImageNormal m_Normal;
  21. afx_msg void OnArreter();
  22. afx_msg void OnAcquitter();
  23. afx_msg void OnTimer(UINT nIDEvent);
  24.  // NOTE: the ClassWizard will add data members here
  25. //}}AFX_DATA
  26. // Overrides
  27. // ClassWizard generated virtual function overrides
  28. //{{AFX_VIRTUAL(CClientImage)
  29. protected:
  30. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31. //}}AFX_VIRTUAL
  32. // Implementation
  33. protected:
  34. //{{AFX_MSG(CClientImage)
  35.  virtual BOOL OnInitDialog();
  36.  afx_msg void OnDestroy();
  37. //}}AFX_MSG
  38. DECLARE_MESSAGE_MAP()
  39. };
  40. //{{AFX_INSERT_LOCATION}}
  41. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  42. #endif // !defined(AFX_CLIENTIMAGE_H__F7F7C5FB_63B8_4161_8676_7EDCA035F974__INCLUDED_)


 
 
 
 
 
le .cpp :
 

Code :
  1. #include "stdafx.h"
  2. #include "VideoProcessing.h"
  3. #include "ClientImage.h"
  4. #include "Video.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. HOSTNAME szHostName;
  11. DWORD dwPort=SERVERIMAGES_TCPPORT;
  12. Video video;
  13. CClientImage::CClientImage(CWnd* pParent /*=NULL*/)
  14. : CDialog(CClientImage::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CClientImage)
  17.  // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. void CClientImage::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(CClientImage)
  24.  DDX_Control(pDX, IDC_NORMAL, m_Normal);
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(CClientImage, CDialog)
  28. //{{AFX_MSG_MAP(CClientImage)
  29. ON_BN_CLICKED(IDC_ARRETER, OnArreter)
  30. ON_BN_CLICKED(IDC_ACQUITTER, OnAcquitter)
  31. ON_WM_DESTROY()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CClientImage message handlers
  36. BOOL CClientImage::OnInitDialog()
  37. {
  38. CDialog::OnInitDialog();
  39. CDialog::UpdateWindow();
  40. monTimer=5000;
  41. CDialog::SetTimer(monTimer,1000,NULL);
  42. video.pClientImage=this;
  43. StartupWSA();
  44. networkinfosStartup();
  45. codecjpgStartup();
  46. BOOL bError=FALSE;
  47. BUFFER szTemp;
  48. GetPrivateProfileString("VIDEOSTREAM","HOSTNAME","",szHostName,sizeof(szHostName),WANYINFORMATIONFILE);
  49. GetPrivateProfileString("VIDEOSTREAM","PORT","",szTemp,sizeof(szTemp),WANYINFORMATIONFILE);
  50. dwPort=atoi(szTemp);
  51. if(networkinfosEnterHostAddressAndPort(szHostName,&dwPort,SERVERIMAGES_TCPPORT,NULL))
  52. {
  53. if(!video.Connect(szHostName,"","" ))
  54.  {
  55.  BUFFER szBuffer;
  56.  wsprintf(szBuffer,"Connexion à %s impossible ...",szHostName);
  57.  MessageBox(szBuffer,"VideoProcessing",MB_OK|MB_ICONEXCLAMATION);
  58.  bError=TRUE;
  59.  }
  60. }
  61. else
  62. {
  63. bError=TRUE;
  64. }
  65. if(bError) EndDialog(IDCANCEL);
  66. return TRUE;
  67. }
  68. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  69. // Timer
  70. void CClientImage::OnTimer(UINT nIDEvent)
  71. {
  72. if(nIDEvent == monTimer)
  73.  AfxMessageBox("Hello",MB_OK);
  74. CDialog::OnTimer(nIDEvent);
  75. }
  76. void CClientImage::OnDestroy()
  77. {
  78. BUFFER szBuffer;
  79. codecjpgStop();
  80. networkinfosStop();
  81. WritePrivateProfileString ("VIDEOSTREAM","HOSTNAME",szHostName,WANYINFORMATIONFILE);
  82. wsprintf(szBuffer,"%lu",dwPort);
  83. WritePrivateProfileString ("VIDEOSTREAM","PORT",szBuffer,WANYINFORMATIONFILE);
  84. CDialog::OnDestroy();
  85. }
  86. void CClientImage::OnArreter()
  87. {
  88. video.Disconnect();
  89. }
  90. void CClientImage::OnAcquitter()
  91. {
  92. video.Disconnect();
  93. CDialog::OnOK();
  94. }

n°725595
Ace17
Posté le 14-05-2004 à 10:35:48  profilanswer
 

Code :
  1. BEGIN_MESSAGE_MAP(CClientImage, CDialog)
  2.    //{{AFX_MSG_MAP(CClientImage)
  3.      ON_BN_CLICKED(IDC_ARRETER, OnArreter)
  4.      ON_BN_CLICKED(IDC_ACQUITTER, OnAcquitter)
  5.      ON_WM_DESTROY()
  6.      ON_WM_TIMER() // tu l'as oublié
  7.    //}}AFX_MSG_MAP
  8.   END_MESSAGE_MAP()


 
T'utilises Visual? Parce que si oui tu ferais mieux de laisser faire ca au ClassWizard


Message édité par Ace17 le 14-05-2004 à 10:36:58
n°725610
lecoyote
Posté le 14-05-2004 à 10:42:36  profilanswer
 

lol, oui c'était ca... j'aime bien comprendre ce que je fais, alors je me tappe tout à la main, et j'avais complètement oublié de le rajouter à la main !
 
en tout cas je te remercies, ca m'enlève une bonne épine du pied ;)
:hello:

mood
Publicité
Posté le   profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  mise en oeuvre d'un timer

 

Sujets relatifs
mise à jour automatique de champsMise à jour automatique d'un champ d'un formulaire
Impression/configuration/mise en page[CSS] mise en page et largeur dynamique
mise en forme résultat d'une requete SQLMFC appeler un "event" pour simuler 1 timer
Timerattacher un timer à une fonction
[CSS] Probleme de mise en forme...[Dreamweaer Mx] : Pb d'espaces entre 'tableau de mise en forme'
Plus de sujets relatifs à : mise en oeuvre d'un timer


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR