Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3313700
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:08:45+00:00 2026-05-17T22:08:45+00:00

I have been looking at this code and I am having trouble understanding the

  • 0

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.

Can any one tell me when OnTimer event will be fired ? I have pasted my code below for review.

(new to VC++)
(sorry for bad formatting)

iSCSIDlg.h : header file

#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()->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->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }
    UpdateData(FALSE);
    GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);
    GetDlgItem(IDC_EDIT2)->ShowWindow(SW_HIDE);
    return TRUE;
}

void CISCSIDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 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)->sock;
    HWND hwnd=((RECVPARAM*)lpParameter)->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 && m_testProc)
    {
        
        SetDlgItemText(IDC_ERR,temp);
    }
    else
        if(msg[12]==0 && 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<0)
        {
            KillTimer(1);
            flag_test_ready=0;
            AfxMessageBox("xxx");
        }
        
    }
    
    if(nIDEvent==2)
    {
        unsigned char testBuf[100];
        int testSize=16;
        memset(testBuf,0,sizeof(testBuf));
        
        testBuf[0]=0xa5;

        
        if(m_testrand  &&  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("rand:%2d:%2d:%2d  cmd(%2x):--",time.GetHour(),time.GetMinute(),time.GetSecond(),testBuf[0]);
                for( i=0;i<testSize+16;i++)
                {
                    temp.Format(" %2x",msg_header[i]);  
                    toShow+=temp;
                    if(i%8==7)
                    {
                        ((CListBox*)GetDlgItem(IDC_LIST_MSG))->InsertString(0,toShow);
                        toShow.Empty();
                        toShow.Format("rand:%2d:%2d:%2d  cmd(%2x):--",time.GetHour(),time.GetMinute(),time.GetSecond(),testBuf[0]);
                    }
                }
                if(i%8!=0)
                    ((CListBox*)GetDlgItem(IDC_LIST_MSG))->InsertString(0,toShow);
            }
        }
    }

    CDialog::OnTimer(nIDEvent);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:08:45+00:00Added an answer on May 17, 2026 at 10:08 pm

    In the Code uploaded, OnTimer will not be called. In order for OnTimer to be called, an initial call to SetTimer must be made.

    UINT_PTR SetTimer(
       UINT_PTR nIDEvent,
       UINT nElapse,
       void (CALLBACK* lpfnTimer) ( HWND, UINT, UINT_PTR, DWORD ) 
    );
    

    This call can be made in OnInitDialog():

    ...
    //TODO: Add extra initialization here
    //         +---------------- Some unique identifier, to differentiate timers
    //         |      +--------- The timeout value,
    //         |      |    +---- A callback - NULL in this case because of WM_TIMER
    //         |      |    |
    //         V      V    V
    SetTimer( 9001, 2000, NULL );
    ...
    

    See the MSDN article for more detail:

    http://msdn.microsoft.com/en-us/library/49313fdf(VS.80).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be too opinionated a question, but looking for help! I have been
I have been looking at the new database server we are setting up for
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been looking into IKVMing Apache's FOP project to use with our .NET
We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance
I have been looking at metrics for coupling and also look at DSM .
I have been looking for documentation related to interacting with MSPaint from the command
I have been looking at jQUery thickbox for showing modal dialogs with images, it
I have been looking at various dependency injection frameworks for .NET as I feel
I have been looking in to doing some test driven development for one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.