MultiThread2Dlg.cpp代码:
// MultiThread2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "MultiThread2.h"
#include "MultiThread2Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
...................省略了自动生成的代码!
void ThreadProc()
{
CTime time;
CString m_time;
for(;;)
{
time=CTime::GetCurrentTime();
m_time=time.Format("%H:%M:%S");
::SetDlgItemText(AfxGetMainWnd()->m_hWnd,IDC_TIME,m_time);
Sleep(1000);
}
}
void CMultiThread2Dlg::OnBnClickedStart()
{
// TODO: 在此添加控件通知处理程序代码
hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,NULL,0,&ThreadID);
}
void CMultiThread2Dlg::OnBnClickedStop()
{
// TODO: 在此添加控件通知处理程序代码
TerminateThread(hThread,1);
}
MultiThread2Dlg.h代码:
// MultiThread2Dlg.h : header file
//
#pragma once
DWORD ThreadID;
HANDLE hThread;
// CMultiThread2Dlg dialog
class CMultiThread2Dlg : public CDialog
{
// Construction
public:
CMultiThread2Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MULTITHREAD2_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedStart();
public:
afx_msg void OnBnClickedStop();
};
错误输出:1>------ 已启动生成: 项目: MultiThread2, 配置: Debug Win32 ------
1>正在链接...
1>MultiThread2Dlg.obj : error LNK2005: "unsigned long ThreadID" (?ThreadID@@3KA) 已经在 MultiThread2.obj 中定义
1>MultiThread2Dlg.obj : error LNK2005: "void * hThread" (?hThread@@3PAXA) 已经在 MultiThread2.obj 中定义
1>C:\Users\noPassword\Documents\Visual Studio 2005\Projects\MultiThread2\Debug\MultiThread2.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
1>生成日志保存在“file://c:\Users\noPassword\Documents\Visual Studio 2005\Projects\MultiThread2\MultiThread2\Debug\BuildLog.htm”
1>MultiThread2 - 3 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
--------------------next---------------------
阅读(1050) | 评论(0) | 转发(0) |