注册 登录
编程论坛 VC++/MFC

VC++常见问题(FAQ)

myajax95 发布于 2006-07-10 01:19, 14338 次点击

在这里我尽量把大家以前提出的问题已经解答的总结一下。如果你有问题需要提问,不妨先看看这里有没有你的答案。否则一个复杂的VC问题几天没有答案也是正常的,毕竟VC比C/C++之类的具体操作复杂的多。

其中大部分问题我都看过,不过肯定有没看仔细的,所以如果回答者的答案不正确,欢迎大家通知回答人或者跟贴更正。如果我漏掉了什么有代表性的问题也欢迎大家指出。同时欢迎其它版主帮忙更新与指正。目前收集了5/10~7/10的问题。

下面是分类索引

第2贴:Visual C++ 基础问题 (Visual C++ basis)
第3贴:MFC控件基础 (MFC control basis)
第4贴:文件/视窗结构 (document/view architechtue)
第5贴:图像处理,GDI
第6贴:数据库
第7贴:进程,线程,模型状态(process,thread,module state)
第8贴:COM,ATL,ActiveX
第9贴:其它问题

[此贴子已经被作者于2006-7-10 4:32:52编辑过]

62 回复
#2
myajax952006-07-10 01:19
Visual C++ 基础问题 (Visual C++ basis)

如何实现窗口全屏幕显示(回答人:云中雾)
鼠标移动到图像编辑控件内如何出现屏幕坐标提示?只是在图像编辑控件内移动鼠标有屏幕坐标提示,怎么办啊?(回答人:C++大粉丝)
截获鼠标的移动事件,如果能在控件里截获更好,如果不能,就在最外面截获,然后判断当前活动窗体是不是这个控件就行了,截获的鼠标移动事件后,其系统的回调函数中有你需要的数据。

GetWindowRect与GetClientRect有什么区别?他们是怎么定义的?(回答人:Bekky)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=77545&page=1" target="_blank">https://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=67990&page=3

鼠标移动到图像编辑控件内如何出现屏幕坐标提示?只是在图像编辑控件内移动鼠标有屏幕坐标提示,怎么办啊?(回答人:C++大粉丝)
截获鼠标的移动事件,如果能在控件里截获更好,如果不能,就在最外面截获,然后判断当前活动窗体是不是这个控件就行了,截获的鼠标移动事件后,其系统的回调函数中有你需要的数据。

GetWindowRect与GetClientRect有什么区别?他们是怎么定义的?(回答人:Bekky)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=77545&page=1


怎样在其他类中访问主对话框类的非静态公有成员变量(回答人:aogun)
AfxGetApp()->m_pMainWnd可以获取主对话框的指针,这样就可以访问该主对话框的公有成员变量和函数了

TextOut(hDCPrint,0,0,buf,8);
我用这个语句想打印一些 CHAR数组(buf里)的内容,如果是数字或者字母没问题,但如果是汉字就是乱码,请哪位大哥指点一下,谢谢先了
(回答人:maoguoqing, aogun)
看一下宏_T你就知道了。有点小问猓琧har buf[8] = _T("我的程序");,"我的程序"占用8个字节,那么中止符'\0'的位置就没了,应该是buf[9]
另外TextOut(hDCPrint,0,0,buf,sizeof(buf));中sizeof只是buf这个数组的长度,并不是其中的文字长度,如果数组大小大于文字长度那么会输出不必要的信息或者乱码,应该用strlen(buf)

[此贴子已经被作者于2006-7-14 0:03:31编辑过]

#3
myajax952006-07-10 01:19
MFC控件基础 (MFC control basis)常见问题

如何实现对对话框的分割?(回答人:myajax95)
回答比较长,参阅以下帖子:怎样增大CListCtrl的行距?(回答人:aogun)
试试插入一列图片,图片的高度设为你想要的高度,这样行高就变高了
[CODE] CImageList imagelist;
ImageList.Create(1, 40, ILC_COLOR, 10, 10);
m_ListCtrl.SetImageList(&ImageList, LVSIL_SMALL);[/CODE]

CListctrl 列表 为 report 型时 点击一行时 全行都被选中了。怎样才能 象excel表一样 单独的修改每个单元格中的内容啊 (回答人:myajax95)
参照下面的帖子:
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=77249&page=1


创建菜单 如何添加响应消息~~
例如利用:menuPopup.InsertMenu(0,MF_BYPOSITION|MF_STRING,ID_MENU_RED,"&Green");(回答人myajax95)

menuPopup.AppendMenu(MF_STRING, resource id, item text);
然后在message map 中加ON_COMMAND或者ON_COMMAND_RANGE管理resource id 对应的事件。

怎么设置VC中的LISTCTRL才可以让类试EXCEL表格框显示出来?(回答人:myajax95)
yourlist.SetExtendedStyle(LVS_EX_GRIDLINES);

如何修改LIST BOX控件里的排列顺序.对LIST BOX控件插入完数据后,它自动按字符顺序排列,如何修该成按每次插入的顺序排列,既取消LIST BOX控件的自动排列功能.(回答人:cathypu0725)
如果是在对话框中,选中此ListBox,点右键设置其属性,在Styles页,uncheck(sorts)即可.

想给对话框加一个背景,结果始终加不上,请问下在VC中给对话框加背景(图片)怎么加?(回答人:柳儿)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=60952&page=22

CStatic控件都能响应鼠标移动或者点击的动作吗?如果能,应该怎么实现呢?(回答人:myajax95)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=77766&page=1" target="_blank">https://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=76928&page=1

怎样增大CListCtrl的行距?(回答人:aogun)
试试插入一列图片,图片的高度设为你想要的高度,这样行高就变高了
[CODE] CImageList imagelist;
ImageList.Create(1, 40, ILC_COLOR, 10, 10);
m_ListCtrl.SetImageList(&ImageList, LVSIL_SMALL);[/CODE]

CListctrl 列表 为 report 型时 点击一行时 全行都被选中了。怎样才能 象excel表一样 单独的修改每个单元格中的内容啊 (回答人:myajax95)
参照下面的帖子:http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=77249&page=1


创建菜单 如何添加响应消息~~
例如利用:menuPopup.InsertMenu(0,MF_BYPOSITION|MF_STRING,ID_MENU_RED,"&Green");(回答人myajax95)

menuPopup.AppendMenu(MF_STRING, resource id, item text);
然后在message map 中加ON_COMMAND或者ON_COMMAND_RANGE管理resource id 对应的事件。

怎么设置VC中的LISTCTRL才可以让类试EXCEL表格框显示出来?(回答人:myajax95)
yourlist.SetExtendedStyle(LVS_EX_GRIDLINES);

如何修改LIST BOX控件里的排列顺序.对LIST BOX控件插入完数据后,它自动按字符顺序排列,如何修该成按每次插入的顺序排列,既取消LIST BOX控件的自动排列功能.(回答人:cathypu0725)
如果是在对话框中,选中此ListBox,点右键设置其属性,在Styles页,uncheck(sorts)即可.

想给对话框加一个背景,结果始终加不上,请问下在VC中给对话框加背景(图片)怎么加?(回答人:柳儿)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=60952&page=22

CStatic控件都能响应鼠标移动或者点击的动作吗?如果能,应该怎么实现呢?(回答人:myajax95)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=77766&page=1

[此贴子已经被作者于2006-7-12 14:37:48编辑过]

#4
myajax952006-07-10 01:19
文件/视窗结构 (document/view architechtue)
我用N多视图类,对应到同一个文档类,如何实现:“在文档内容发生变化后,所有的视图都响应”?(回答人:myajax95)
在你完成doc class的更新之后,用UpdateAllViews。在每个希望得到更新的view class的OnUpdate()里面接收UpdateAllViews()发来的信息。最好是通过UpdateAllViews()的参数来传递信息,实在不行再手动的从view class到doc class里面找信息。

用MFC编程,使用SDI,按退出按钮,退出软件。请问知道SDI中退出调用的函数是哪个?(回答人:myajax95)
PostMessage(WM_CLOSE, 0, 0);

[此贴子已经被作者于2006-7-10 3:46:30编辑过]

#5
myajax952006-07-10 01:19

图像处理,GDI

如何将一个CBitmap拷贝到另一个CBitmap中?目标CBitmap的尺寸比源CBitmap尺寸大。(回答人:aogun)
创建两个CDC类型的对象,用SelectObject载入两个CBitmap类型对象
然后用CDC的BitBlt方法将载入原CBitmap对象的CDC中的内容拷贝到载入目标CBitmap对象的CDC中即可


如何将一幅图像作为对话框背景显示。(回答人:python)
图片并没有在编程时加入到资源中,如何通过文件框选项找到某一任意.bmp,然后如何显示在.view界面上。(回答人:沐海思潮)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=72956&page=9" target="_blank">https://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=28725&page=6

图片并没有在编程时加入到资源中,如何通过文件框选项找到某一任意.bmp,然后如何显示在.view界面上。(回答人:沐海思潮)
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=55&ID=72956&page=9

[此贴子已经被作者于2006-7-10 3:51:17编辑过]

#6
myajax952006-07-10 01:20
数据库
#7
myajax952006-07-10 01:20

进程,线程,模型状态(process,thread,module state)

[此贴子已经被作者于2006-7-10 2:18:36编辑过]

#8
myajax952006-07-10 01:20
COM,ATL,ActiveX

[此贴子已经被作者于2006-7-10 2:17:52编辑过]


#9
myajax952006-07-10 02:17
其它问题
#10
funcity2006-07-21 12:22

Hi,

May I ask a very stupid question?

I am a complete beginner on C++ and I tried to install the eVC4 and wrote a very simple Helloworld program. But error messages kept coming up. I think it is because the "iostream.h" file could not be found in my computer. Just wondering if someone could kindly post the file "iostream.h" as I could not find it anywhere over the internet

Thank you very much for your help

#11
myajax952006-07-24 14:01
以下是引用funcity在2006-7-21 12:22:17的发言:

Hi,

May I ask a very stupid question?

I am a complete beginner on C++ and I tried to install the eVC4 and wrote a very simple Helloworld program. But error messages kept coming up. I think it is because the "iostream.h" file could not be found in my computer. Just wondering if someone could kindly post the file "iostream.h" as I could not find it anywhere over the internet

Thank you very much for your help

I'm not exactly sure what is eVC4, but looks like the installation is not compete, so "iostream.h" can not be found. If this is the case, I suggest you to reinstall the software instead of looking for a file and copy it to your system. Since it is very likely to happen that after patching this header file in, you will find some other compilation error about some other files.

#12
wfpb2006-07-26 09:56
I also think the question is coming from the uncompletely installation.
If you don't want to install again ,but just want to solve the question now quickly,there is anther way to solve this question you can choose.
You can get "iostream" to instead of "iostream.h", "iostream" is the I/O for the newest standard C++,but when you do this you must write "using namaspace std;" for using that head file since something is in the space.
So,insteading of "iostream.h",you just need write :
#include <iostream>
using namespace std;
#13
funcity2006-07-26 15:58

Dear myajax95 and wfpb,

Thank you very much for your relpies.

I tried to write the simple code with #include <iostream>
using namespace std;
However, I still encounter the same error "fatal error C1083: Cannot open include file: 'iostream': No such file or directory".
I wonder how I should solve this problem. Thank you very much.

My simple coding is as follows:

#include <iostream>
using namespace std;

int main(void)
{
cout << "Hello!"
<< endl
<< "Welcome to Visual C++"
<< endl << endl;
return 0;
}


p.s., eVC4 stands for "Microsoft Embedded Visual C++ 4.0.

#14
wfpb2006-07-26 16:22
My QQ number is 460809865.If you want,I can send these files which you need.
#15
funcity2006-07-26 16:25

Dear wfpb,

I haven't got QQ but my email address is lcnz@hotmail.com.

Thanks for your help and thanks for sharing the files!!

#16
wfpb2006-07-26 16:51
I 'll send to you at once,but last time.
If the problem also can't be solved,I suggest you'd better download a VC again ,because we can't keep in touch with each other in time which will makes some trouble.
#17
wfpb2006-07-26 16:58
It's OK now.
#18
jallen0072006-07-27 21:30

大概是说编译不通过,因为缺少iostrean.h头文件吗???
我外语不太好
wfpb
能也发那个文件给我不
我的email是jallen007@126.com

#19
jacky8422006-07-28 21:04
trouble relly comes...bz...
#20
大水牛2006-08-09 23:08
我是能看不能写啊,哈哈
#21
z1089799792006-08-27 22:56
#22
bingeyi2006-09-03 22:42
F:\vc\Ex_MCI\Ex_MCIView.cpp(24) : error C2065: 'OnNotifySize' : undeclared identifier
F:\vc\Ex_MCI\Ex_MCIView.cpp(24) : error C2440: 'type cast' : cannot convert from 'int *' to 'long (__thiscall CWnd::*)(unsigned int,long)'
There is no context in which this conversion is possible
F:\vc\Ex_MCI\Ex_MCIView.cpp(112) : error C2065: 'm_hMCIWnd' : undeclared identifier
Error executing cl.exe.
你们 能告诉我 这调试后的结果是什么意思吗
#23
Bekky2006-09-22 13:32
I 服了 you,竟然用E文。
#24
好学天才猪头2006-10-19 01:02
hello everybody
i have also some question
when i complie my vc++ program
he turns out to some informations about ::

says end of couldn't find
maybe it couldn't complie the head papers .
please would you help me :?
thank you
#25
xl_1983_102006-11-07 21:29
谢谢  我邮箱是xl_1983_10@
#26
modern_roc2006-11-13 22:08

顶!!!!!!

#27
pinevspine2006-11-15 22:10
我今天安装VC++ 但是怎么也安装不上啊 ! 安常规装的! 得先安装安装向导!
#28
王崇2006-11-25 11:29

都是狠人啊

#29
xiaoxiangzi2006-11-27 18:57
请问你的这些问题是基于那个平台调试的?
是vc6.0 vs2003 vs2005
我这按照书敲了些代码怎么也调试不起来帮我看看好么?
#include<iostream>
using std::cout;
using std::endl;
struct person
{
char * name;
int age;

};
int main()
{
person * p;
p=new person;
p->name=new char[20];
p->name="Smart";
p->age=23;
cout<<"\n"<<p->name<<" "<<p->age;
delete p;

}

我用的是vs2005
#30
潮爆2006-12-11 16:21
, 十分好,方便大家要找解决办法…
#31
小人物一个2006-12-11 21:24
是得多学点外语啊
#32
jxl1203122006-12-13 23:04
好贴
可惜没数据库的相关内容.
我现在在做个数据库
有一大堆问题都不知道怎么解决.
#33
beysbc2007-01-07 21:21
很多都是无法找到该页

建议重新编辑!
#34
wosuiniqunba2007-01-13 16:33
对不起,我想请问一下,为什么以下的程序总是显示m是redefinition?
#include <iostream >
using namespace std;
long fun1 (int);
long add (long,long);
int main()
{
int n,s1,s2, m;
cout <<"please input a number "<<endl;
cin >>n;
s1=fun1(n);
n=n+2;
s2=fun1(n+2);
if((s1!=-1)&&(s2!=-1))
{
cin>>s1>>s2;
m=add(s1,s2);

cout <<"m="<<m<<endl;}
return 0;
}
long fun1(int n)
{
long f;
if(n<0)
{
cout <<"the data is error"<<endl;
return -1;
}
else if(n==0||n==1)f=1;
else f=n*fun1(n-1);
return f;
}
long add(int s1,int s2)
{ int m,
m=s1+s2;
return m;
}
谢谢你的帮助
#35
wyzn122007-01-24 15:41
以下是引用wosuiniqunba在2007-1-13 16:33:28的发言:
对不起,我想请问一下,为什么以下的程序总是显示m是redefinition?
#include <iostream >
using namespace std;
long fun1 (int);
long add (long,long);
int main()
{
int n,s1,s2, m;
cout <<"please input a number "<<endl;
cin >>n;
s1=fun1(n);
n=n+2;
s2=fun1(n+2);
if((s1!=-1)&&(s2!=-1))
{
cin>>s1>>s2;
m=add(s1,s2);

cout <<"m="<<m<<endl;}
return 0;
}
long fun1(int n)
{
long f;
if(n<0)
{
cout <<"the data is error"<<endl;
return -1;
}
else if(n==0||n==1)f=1;
else f=n*fun1(n-1);
return f;
}
long add(int s1,int s2)
{ int m,
m=s1+s2;
return m;
}
谢谢你的帮助

m重定义了啊,main()和add()函数里你都定义了m,把其中一个改了就可以了

#36
flyqq2007-03-11 17:29
good ,your english are both good
expect you1
#37
zfeidy2007-03-26 19:17

我的妈妈哟!
我还没过4级!
把这看完真费了我好大的劲!

#38
zfeidy2007-03-26 19:42

我要快点学英语了哦
不然4级就挂了哦

[此贴子已经被作者于2007-3-26 19:56:59编辑过]

#39
zfeidy2007-03-26 19:55
回复:(wosuiniqunba)对不起,我想请问一下,为什么...
对不起,我想请问一下,为什么以下的程序总是显示m是redefinition?
#include <iostream >
using namespace std;
long fun1 (int);
long add (long,long);
int main()
{
int n,s1,s2, m;
cout <<"please input a number "<<endl;
cin >>n;
s1=fun1(n);
n=n+2;
s2=fun1(n+2);
if((s1!=-1)&&(s2!=-1))
{
cin>>s1>>s2;
m=add(s1,s2);

cout <<"m="<<m<<endl;}
return 0;
}
long fun1(int n)
{
long f;
if(n<0)
{
cout <<"the data is error"<<endl;
return -1;
}
else if(n==0||n==1)f=1;
else f=n*fun1(n-1);
return f;
}
long add(int s1,int s2)
{ int m,
m=s1+s2;
return m;
}
谢谢你的帮助


你的程序有几个问题:
1:你声明的add(long,long)型,而定义的是add(int,int)型;
2:我不知道你的这句话做什么用的cin>>s1>>s2;这个是输入数字的,可你前面已经计算出来这两个值了,要是再输入,也就没什么意义了,所以这句话要删出。
3:你的此段函数

long add(int s1,int s2)
{ int m,
m=s1+s2;
return m;
}

的m后面的逗号改成分号就好了,其实m并没有重复定义。所以35楼的回答错了。
4:你的程序可以改成这样的:
#include <iostream >
using namespace std;
long fun1 (int);
long add (long,long);
int main()
{
int n,s1,s2, m;
cout <<"please input a number "<<endl;
cin >>n;
s1=fun1(n);
s2=fun1(n+2); //要是求n+2,这样就好了
if((s1!=-1)&&(s2!=-1))
{
m=add(s1,s2);
cout <<"m="<<m<<endl;
}
return 0;
}
long fun1(int n)
{
long f;
if(n<0)
{
cout <<"the data is error"<<endl;
return -1;
}
else if(n==0||n==1)f=1;
else f=n*fun1(n-1);
return f;
}

long add(long s1,long s2)
{
return(s1+s2);
}

[此贴子已经被作者于2007-3-26 20:04:34编辑过]

#40
帅得不敢出门2007-03-27 21:41
这里面的E文高手真多
#41
TJ8402292007-03-28 15:56

小弟VC新手,想请教一个问题,谁知道VC编程里,歌词的时间类型,应该用什么变量好???
急~

#42
wyb81332007-03-31 16:09
回复:(myajax95)VC++常见问题(FAQ)
f:\编程\net\dgsend\dgsend.cpp(5) : fatal error C1853: 'Debug/DGSEND.pch' is not a precompiled header file created with this compiler
执行 cl.exe 时出错.

问题指向 #include "stdafx.h"

这是什么问题?怎么解决?

[此贴子已经被作者于2007-3-31 16:18:02编辑过]

#43
mycatboys2007-04-15 18:54
My QQ number is 460809865










哈哈,我终于换工作了,做<a href=http://www.118cy.net>域名申请</a>的,在外面经历了多年风吹雨打,做过保险、做过销售、但终归还是做技术!每天的<a href=http://www.118cy.net/host>虚拟主机</a>工作虽然枯燥点,但内心安稳很多,呵呵。
#44
19860815abc2007-05-03 17:44
是不是学计算机的人都会很流利的打五笔?????????????????
#45
slowboy2007-05-07 22:00

求救1!!
为什么我的 VC有时候运行的时候,在连接阶段出错?
而且有时候根本就卡在LINKING阶段 搞的我得重启VC??

#46
lgm91282007-05-11 22:31
it's should be #include &lt;iostream.h&gt;.
#47
jaychang2007-05-15 12:32

咋都整英语了噢.我还以为走错地方了呢!

#48
财鸟2007-05-20 17:09
中国人说英语是不是自我感觉很自毫呀!!!!!!!!!!!!!!
有本事去外企和老外说去!!!!!!!!!!!!
IBM/微软什么的!!!!!!!!!!!!!!!
#49
berry22002007-06-04 20:43
我同意用E,这是基础,没有基础如何学VC?
#50
革命接班人2007-06-10 18:00
E文是计算机的基础`````不会E文怎么看MSDN啊``兄弟``
#51
xujyule2007-06-11 23:57
现在正式开始学习   到时候不懂就跑来这里找解答方法   呵呵
12