title: When OnTimer event will be fired?
body: <p>I have been looking at this code and I am having trouble understanding the functionality of the OnTimer function. I am quite new to VC++ so all of this is new knowledge for me.</p>
  <p>Can any one tell me when OnTimer event will be fired ? I have pasted my code below for review.</p>
  <p>(new to VC++)
  (sorry for bad formatting)</p>
  <p><strong>iSCSIDlg.h : header file</strong></p>
  <pre class="lang-c# prettyprint-override"><code>#define WM_RECVDATA     WM_USER+1
  
  class CISCSIDlg : public CDialog
  {
  public:
      bool m_testrand;
      bool m_ack;
      bool m_testProc;
      BOOL m_isConnect;
      BOOL InitSocket();
      CISCSIDlg(CWnd* pParent = NULL);
      static DWORD WINAPI RecvProc(LPVOID lpParameter);   
      static DWORD WINAPI send_test(LPVOID lpParameter);  
      
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);
  
  protected:
      afx_msg void OnTimer(UINT nIDEvent);
      DECLARE_MESSAGE_MAP()
  
  };
  
  class CAboutDlg : public CDialog
  {
  public:
      CAboutDlg();
      enum { IDD = IDD_ABOUTBOX };
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);
  
  protected:
      DECLARE_MESSAGE_MAP()
  };
  
  CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  {
  }
  
  void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  {
      CDialog::DoDataExchange(pDX);
  }
  
  BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
      
  END_MESSAGE_MAP()
  
  
  
  CISCSIDlg::CISCSIDlg(CWnd* pParent)
      : CDialog(CISCSIDlg::IDD, pParent)
  {
      m_srvPort = 0;
      m_cmd = -1;
      m_param1 = 0;
      m_hIcon = AfxGetApp()-&gt;LoadIcon(IDR_MAINFRAME);
  }
  
  void CISCSIDlg::DoDataExchange(CDataExchange* pDX)
  {
      CDialog::DoDataExchange(pDX);
      DDX_Control(pDX, IDC_BTN_CONNECT, m_btnConnect);
      DDX_Control(pDX, IDC_BTN_SEND, m_btnSend);
      DDX_Text(pDX, IDC_EDIT_PORT, m_srvPort);
      DDX_Radio(pDX, IDC_RADIO0, m_cmd);
      DDX_Text(pDX, IDC_EDIT1, m_param1);
  }
  
  BEGIN_MESSAGE_MAP(CISCSIDlg, CDialog)
      ON_WM_SYSCOMMAND()
      ON_WM_PAINT()
      ON_WM_QUERYDRAGICON()
      ON_BN_CLICKED(IDC_BTN_CONNECT, OnBtnConnect)
      ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
      ON_BN_CLICKED(IDC_RADIO0, OnRadio)
      ON_WM_TIMER()
      ON_MESSAGE(WM_RECVDATA,OnRecvData)
  END_MESSAGE_MAP()
  
  BOOL CISCSIDlg::OnInitDialog()
  {
      CDialog::OnInitDialog();
      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
          CString strAboutMenu;
          strAboutMenu.LoadString(IDS_ABOUTBOX);
          if (!strAboutMenu.IsEmpty())
          {
              pSysMenu-&gt;AppendMenu(MF_SEPARATOR);
              pSysMenu-&gt;AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
          }
      }
      UpdateData(FALSE);
      GetDlgItem(IDC_EDIT1)-&gt;ShowWindow(SW_HIDE);
      GetDlgItem(IDC_EDIT2)-&gt;ShowWindow(SW_HIDE);
      return TRUE;
  }
  
  void CISCSIDlg::OnSysCommand(UINT nID, LPARAM lParam)
  {
      if ((nID &amp; 0xFFF0) == IDM_ABOUTBOX)
      {
          CAboutDlg dlgAbout;
          dlgAbout.DoModal();
      }
      else
      {
          CDialog::OnSysCommand(nID, lParam);
      }
  }
  
  void CISCSIDlg::OnPaint() 
  {
  
  }
  
  HCURSOR CISCSIDlg::OnQueryDragIcon()
  {
      return (HCURSOR) m_hIcon;
  }
  
  DWORD WINAPI CISCSIDlg::RecvProc(LPVOID lpParameter)
  {
      SOCKET sock=((RECVPARAM*)lpParameter)-&gt;sock;
      HWND hwnd=((RECVPARAM*)lpParameter)-&gt;hwnd;
      delete lpParameter; 
      
      unsigned char recvBuf[1500];
      unsigned char tempBuf[1500];
      int retval;
      while(TRUE)
      {
          memset(recvBuf,0,sizeof(recvBuf));
          retval=recv(sock,(char *)recvBuf,1500,0);
          memcpy(tempBuf,recvBuf,1500);
          ::PostMessage(hwnd,WM_RECVDATA,0,(LPARAM)tempBuf);
      }
      return 0;
  }
  
  
  void CISCSIDlg::OnRecvData(WPARAM wParam,LPARAM lParam)
  {
  
      CTime time=CTime::GetCurrentTime();
      
      if(msg[12]==0)
      {
  
      }
      else
      {
          
          send(m_socket,(char*)tmp_buf,32,0);
      }
  
      if(msg[12]==0 &amp;&amp; m_testProc)
      {
          
          SetDlgItemText(IDC_ERR,temp);
      }
      else
          if(msg[12]==0 &amp;&amp; m_testrand)
          {
  
          }
          else
              if(m_testProc || m_testrand)
                  m_ack=true;
  
  }
  
  void CISCSIDlg::OnBtnConnect() 
  {
  
  
  }
  
  
  void CISCSIDlg::OnBtnSend() 
  {
  
      send(m_socket,(char*)msg_header,cmdSize+16,0);//kh 2
  
  }
  
  void CISCSIDlg::OnTimer(UINT nIDEvent) 
  {
  
      if(nIDEvent==1)
      {
          timeout--;
          if(timeout&lt;0)
          {
              KillTimer(1);
              flag_test_ready=0;
              AfxMessageBox(&quot;xxx&quot;);
          }
          
      }
      
      if(nIDEvent==2)
      {
          unsigned char testBuf[100];
          int testSize=16;
          memset(testBuf,0,sizeof(testBuf));
          
          testBuf[0]=0xa5;
  
          
          if(m_testrand  &amp;&amp;  m_isConnect )
          {
              if(m_ack)
              {
                  m_ack=false;
      
                  unsigned char msg_header[16+100];
                  
  
  
                  send(m_socket,(char*)msg_header,16+testSize,0);
                  
                  CString toShow,temp;
                  CTime time=CTime::GetCurrentTime();
                  
                  toShow.Format(&quot;rand:%2d:%2d:%2d  cmd(%2x):--&quot;,time.GetHour(),time.GetMinute(),time.GetSecond(),testBuf[0]);
                  for( i=0;i&lt;testSize+16;i++)
                  {
                      temp.Format(&quot; %2x&quot;,msg_header[i]);  
                      toShow+=temp;
                      if(i%8==7)
                      {
                          ((CListBox*)GetDlgItem(IDC_LIST_MSG))-&gt;InsertString(0,toShow);
                          toShow.Empty();
                          toShow.Format(&quot;rand:%2d:%2d:%2d  cmd(%2x):--&quot;,time.GetHour(),time.GetMinute(),time.GetSecond(),testBuf[0]);
                      }
                  }
                  if(i%8!=0)
                      ((CListBox*)GetDlgItem(IDC_LIST_MSG))-&gt;InsertString(0,toShow);
              }
          }
      }
  
      CDialog::OnTimer(nIDEvent);
  }
  </code></pre>