Can any one tell me when OnTimer event will be fired ? (new to VC++) (sorry for bad formattibg)
谁能告诉我什么时候会被解雇?(new to VC++)(不好意思,formattibg)
enter code here
// iSCSIDlg.h : header file
/ / iSCSIDlg。h:头文件
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);
类CISCSIDlg: public CDialog {public: bool m_testrand;bool m_ack;bool m_testProc;BOOL m_isConnect;BOOL InitSocket();CISCSIDlg(CWnd * pParent = NULL);静态DWORD WINAPI RecvProc(LPVOID lpParameter);静态DWORD WINAPI send_test(LPVOID lpParameter);
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected: afx_msg void OnTimer(UINT nIDEvent); DECLARE_MESSAGE_MAP()
保护: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);
public: CAboutDlg();enum {IDD = IDD_ABOUTBOX};保护:虚拟void DoDataExchange(CDataExchange* pDX);
protected: DECLARE_MESSAGE_MAP() };
保护:DECLARE_MESSAGE_MAP()};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { }
CAboutDlg::CAboutDlg(): CDialog(CAboutDlg::IDD) {}
void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); }
空CAboutDlg::DoDataExchange(CDataExchange* pDX) {CDialog::DoDataExchange(pDX);}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
BEGIN_MESSAGE_MAP(CAboutDlg CDialog)
END_MESSAGE_MAP()
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); }
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); }
空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()
ON_WM_PAINT() ON_WM_PAINT() ON_WM_QUERYDRAGICON() on_bn_click (IDC_BTN_CONNECT, OnBtnConnect) on_bn_click (IDC_BTN_SEND, OnBtnSend) on_bn_click (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; }
BOOL CISCSIDlg:OnInitDialog(){ CDialog:OnInitDialog();CMenu * pSysMenu = GetSystemMenu(假);if (pSysMenu != NULL) {CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);如果(! strAboutMenu.IsEmpty()){ pSysMenu - > AppendMenu(MF_SEPARATOR);pSysMenu - > AppendMenu(MF_STRING、IDM_ABOUTBOX strAboutMenu);} } UpdateData(假);GetDlgItem(IDC_EDIT1)- >显示窗口(SW_HIDE);GetDlgItem(IDC_EDIT2)- >显示窗口(SW_HIDE);返回TRUE;}
void CISCSIDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } }
@ void CISCSIDlg::OnSysCommand(UINT nID, LPARAM LPARAM) {if ((nID & 0xFFF0) == IDM_ABOUTBOX) {CAboutDlg dlgAbout;dlgAbout.DoModal();else {CDialog::OnSysCommand(nID, lParam);} }
void CISCSIDlg::OnPaint() {
空白CISCSIDlg:OnPaint(){
}
}
HCURSOR CISCSIDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }
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;
DWORD WINAPI CISCSIDlg::RecvProc(LPVOID lpParameter) {SOCKET sock=(RECVPARAM*)lpParameter)->sock;HWND HWND =((RECVPARAM *)lpParameter)- > HWND;删除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) {
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() {
空白CISCSIDlg:OnBtnConnect(){
}
}
void CISCSIDlg::OnBtnSend() {
空白CISCSIDlg:OnBtnSend(){
send(m_socket,(char*)msg_header,cmdSize+16,0);//kh 2
}
}
void CISCSIDlg::OnTimer(UINT nIDEvent) {
空白CISCSIDlg::定时(使用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
1
In the Code uploaded, OnTimer will not be called. In order for OnTimer to be called, an initial call to SetTimer must be made.
在上传的代码中,OnTimer不会被调用。要调用OnTimer,必须对SetTimer进行初始调用。
UINT_PTR SetTimer(
UINT_PTR nIDEvent,
UINT nElapse,
void (CALLBACK* lpfnTimer) ( HWND, UINT, UINT_PTR, DWORD )
);
This call can be made in OnInitDialog():
这个调用可以在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:
请参阅MSDN文章,了解更多细节:
http://msdn.microsoft.com/en-us/library/49313fdf(VS.80).aspx
http://msdn.microsoft.com/en-us/library/49313fdf(VS.80). aspx
#1
1
In the Code uploaded, OnTimer will not be called. In order for OnTimer to be called, an initial call to SetTimer must be made.
在上传的代码中,OnTimer不会被调用。要调用OnTimer,必须对SetTimer进行初始调用。
UINT_PTR SetTimer(
UINT_PTR nIDEvent,
UINT nElapse,
void (CALLBACK* lpfnTimer) ( HWND, UINT, UINT_PTR, DWORD )
);
This call can be made in OnInitDialog():
这个调用可以在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:
请参阅MSDN文章,了解更多细节:
http://msdn.microsoft.com/en-us/library/49313fdf(VS.80).aspx
http://msdn.microsoft.com/en-us/library/49313fdf(VS.80). aspx