| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1237 人关注过本帖
标题:一个关于随机显示位图的程序的问题
只看楼主 加入收藏
tcsoftware
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2005-8-6
收藏
 问题点数:0 回复次数:2 
一个关于随机显示位图的程序的问题

我也不知道是怎么回事,希望大家帮帮忙,下面是这一段功能的代码,用途是先产生一个随机数,然后根据随机数显示与之相对应的名称和图片,代码如下,出错提示在代码下面,希望知道的人们能帮下忙啊,谢谢了

void CXingyun52Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_EDIT1=0; //清空EDIT1
stand(time (NULL));
CurrentCommodityIndex=rand()%10;//产生一个0到9的随机数
m_STATIC1.Format("%s",cmmdty[CurrentCommodityIndex]);

UpdateData(FALSE);

if (CurrentCommodityIndex==0)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[0]));

else if (CurrentCommodityIndex==1)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[1]));

else if (CurrentCommodityIndex==2)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[2]));
else if (CurrentCommodityIndex==3)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[3]));
else if (CurrentCommodityIndex==4)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[4]));
else if (CurrentCommodityIndex==5)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[5]));
else if (CurrentCommodityIndex==6)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[6]));
else if (CurrentCommodityIndex==7)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[7]));

else if (CurrentCommodityIndex==8)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[8]));

else if (CurrentCommodityIndex==9)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[9]));

}

出现的错误提示是:
Compiling...
xingyun52Dlg.cpp
\xingyun52\xingyun52Dlg.cpp(218) : error C2065: 'stand' : undeclared identifier
\xingyun52\xingyun52Dlg.cpp(226) : error C2065: 'IDC_PICTURE' : undeclared identifier
\xingyun52\xingyun52Dlg.cpp(226) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(230) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(234) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(237) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(240) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52Dlg.cpp(243) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52Dlg.cpp(246) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(249) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(253) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(257) : error C2227: left of '->SetBitmap' must point to class/struct/union
执行 cl.exe 时出错.

搜索更多相关主题的帖子: 位图 随机 
2006-04-12 22:17
名人
Rank: 1
等 级:新手上路
威 望:1
帖 子:205
专家分:0
注 册:2006-3-3
收藏
得分:0 
以下是引用tcsoftware在2006-4-12 22:17:00的发言:

我也不知道是怎么回事,希望大家帮帮忙,下面是这一段功能的代码,用途是先产生一个随机数,然后根据随机数显示与之相对应的名称和图片,代码如下,出错提示在代码下面,希望知道的人们能帮下忙啊,谢谢了

void CXingyun52Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_EDIT1=0; //清空EDIT1
stand(time (NULL));//应该是srand
CurrentCommodityIndex=rand()%10;//产生一个0到9的随机数
m_STATIC1.Format("%s",cmmdty[CurrentCommodityIndex]);

UpdateData(FALSE);

if (CurrentCommodityIndex==0)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[0]));//看看控件的ID是否正确

else if (CurrentCommodityIndex==1)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[1]));

else if (CurrentCommodityIndex==2)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[2]));
else if (CurrentCommodityIndex==3)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[3]));
else if (CurrentCommodityIndex==4)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[4]));
else if (CurrentCommodityIndex==5)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[5]));
else if (CurrentCommodityIndex==6)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[6]));
else if (CurrentCommodityIndex==7)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[7]));

else if (CurrentCommodityIndex==8)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[8]));

else if (CurrentCommodityIndex==9)

((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[9]));

}

出现的错误提示是:
Compiling...
xingyun52Dlg.cpp
\xingyun52\xingyun52Dlg.cpp(218) : error C2065: 'stand' : undeclared identifier
\xingyun52\xingyun52Dlg.cpp(226) : error C2065: 'IDC_PICTURE' : undeclared identifier
\xingyun52\xingyun52Dlg.cpp(226) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(230) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(234) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(237) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(240) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52Dlg.cpp(243) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52Dlg.cpp(246) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(249) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(253) : error C2227: left of '->SetBitmap' must point to class/struct/union
\xingyun52\xingyun52Dlg.cpp(257) : error C2227: left of '->SetBitmap' must point to class/struct/union
执行 cl.exe 时出错.


未必钱多乐便多,财多累己招烦恼。 清贫乐道真自在,无牵无挂乐逍遥。
2006-04-13 11:08
myajax95
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:30
帖 子:2978
专家分:0
注 册:2006-3-5
收藏
得分:0 
这长长的一大串if...else要是合并成一句((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(Bitmap[CurrentCommodityIndex])); 就好看多了。

http://myajax95./
2006-04-13 15:05
快速回复:一个关于随机显示位图的程序的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054270 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved