mfc基础问题

在头文件中我已经定义了这个函数啊UINT ThreadFunc(LPVOID lpParam);
BOOL CTexttextDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

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);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_ctrlprocess.SetRange(0,99);
m_second=10;
UpdateData(false);
UINT ThreadFunc(LPVOID lpParam)
{
threadinfo *pinfo=(threadinfo *)lpParam;
for(int i=0;i<100;i++)
{
int nTemp=pinfo->second;
pinfo->progress->SetPos(i);
Sleep(nTemp);
}
}
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
此行有一个“{”没有匹配项
“ThreadFunc”: 本地函数定义是非法的
报这两个错误

第1个回答  2011-05-25
UINT ThreadFunc(LPVOID lpParam)
{
threadinfo *pinfo=(threadinfo *)lpParam;
for(int i=0;i<100;i++)
{
int nTemp=pinfo->second;
pinfo->progress->SetPos(i);
Sleep(nTemp);
}
}
那你这一段代码是什么意思呢?
在一个函数里定义另一个函数?
如果你是要在这个函数中使用ThreadFunc这个函数的话也应该是在外面定义好
直接在里面调用ThreadFunc()才可以.
也不能直接在函数内部写上一个UINT ThreadFunc(LPVOID lpParam)这样一个完整的函数定义啊
第2个回答  2011-05-25
UINT ThreadFunc(LPVOID lpParam)
{
threadinfo *pinfo=(threadinfo *)lpParam;
for(int i=0;i<100;i++)
{
int nTemp=pinfo->second;
pinfo->progress->SetPos(i);
Sleep(nTemp);
}
}

BOOL CTexttextDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

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);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_ctrlprocess.SetRange(0,99);
m_second=10;
UpdateData(false);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
第3个回答  2011-05-25
UINT ThreadFunc(LPVOID lpParam)
{
threadinfo *pinfo=(threadinfo *)lpParam;
for(int i=0;i<100;i++)
{
int nTemp=pinfo->second;
pinfo->progress->SetPos(i);
Sleep(nTemp);
}
}
你怎么在函数里面定义函数,弄到那个函数外面
第4个回答  2011-05-25
需要 先在 dlg类中添加 线程函数

然后才可以调用本回答被提问者采纳
相似回答