问题1:
vc多行注释的sample宏如何添加到快捷键,或者工具栏,能快速运行?
Q2:
这个是孙鑫的cpp深入详解capture4::CWindowDC dc(::GetDesktopWindow());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
为何加了::,编译有错误?
: error C2664: 'CWindowDC::CWindowDC' : cannot convert parameter 1 from 'struct HWND__ *' to 'class CWnd *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast没有加::的时候,可以编译,成功运行如下::CWindowDC dc(GetDesktopWindow());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);这个可以运行.
vc多行注释的sample宏如何添加到快捷键,或者工具栏,能快速运行?
Q2:
这个是孙鑫的cpp深入详解capture4::CWindowDC dc(::GetDesktopWindow());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
为何加了::,编译有错误?
: error C2664: 'CWindowDC::CWindowDC' : cannot convert parameter 1 from 'struct HWND__ *' to 'class CWnd *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast没有加::的时候,可以编译,成功运行如下::CWindowDC dc(GetDesktopWindow());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);这个可以运行.
类型不对,CWindowDC构造支持的是CWND类型,你后面没加::表示你用的是this->GetDesktopWindow()返回的是CWND类型~
本人是新手.以前写过几行java谢谢前辈赐教...
LZ别听他瞎忽悠,::是用来表是调用的函数不是本类中的成员函数,而是外部的独立函数.
下面给你看一个示例:int testB()
{
return 20;
}class aaa
{
public:
aaa()
{
}
~aaa()
{
}int testA()
{
int x=testB();//此处testB是调用本类中的成员函数testB(),所以x值为10
int y=x+::testB();//此处testB是调用外部自定义的独立函数testB(),y值为10+20=30
return y;
}int testB()
{
return 10;
}}
CreateSolidCaret(20,100);
ShowCaret();上面这个在MFC的程序中是正确的,可以显示光标.下面这个就不行哦 ::CreateSolidCaret(20,100);
::ShowCaret(要个参数);
有api的参考手册吗?
最好是分类整理过的哦
ShowCaret()是在MFC中的CWnd类中的一个函数.
在CWnd类以及其派生类中调用时不加::就是调用CWnd类中的成员函数,
CWnd类中的成员函数申明原形为BOOL ShowCaret();, 所不用加入参数.
如果加入::就是调用外部的API函数,
外部的API函数申明原形为 BOOL WINAPI ShowCaret(HWND hWnd);所以调用时必须加入参数.
建议你看一下基础的C++书,不要一开始就做MFC程序,不然会让初学者走很多弯路.