最近看了《VC++技术内幕》,做些源代码的简要摘抄(1)
来源:互联网 发布:明星飞机航班软件 编辑:程序博客网 时间:2024/06/05 14:50
看了这本书,感觉真的是深入学习VC++的一本好书,讲的方面很广,也比较深入,但是,如果仔细感觉,可能不是十分细致,但这本书对我来说,已经足够了。如果你没看过,推荐看看哈。
对于我来说,看了这本书,勾起了我高中曾经学习vc++的一些感觉,随便啰嗦几句哈。
第三章:
1:学习最简单的helloworld了,还记得曾经第一次运行出来时的那个高兴啊,好奇啊~~呵呵
void CEx03aView::OnDraw(CDC* pDC)
{
pDC->TextOut(0, 0, "Hello, world!"); // prints in default font
// & size, top left corner
pDC->SelectStockObject(GRAY_BRUSH); // selects a brush for the
// circle interior
pDC->Ellipse(CRect(0, 20, 100, 120)); // draws a gray circle
// 100 units in diameter
}
2:学到的c++类成员终于用到了吧。哈哈
int m_nColor;
CRect m_rectEllipse;//MSDN就是好,看看成员函数。。。挺多的吧
void CEx05aView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse);
}
void CEx05aView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_rectEllipse.PtInRect(point)) {
if (m_nColor == GRAY_BRUSH) {
m_nColor = WHITE_BRUSH;
}
else {
m_nColor = GRAY_BRUSH;
}
InvalidateRect(m_rectEllipse);
}
}
3:换一种方式
void CEx05bView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
OnPrepareDC(&dc);
CRect rectDevice = m_rectEllipse;
dc.LPtoDP(rectDevice);// 这个函数看这里吧http://faq.csdn.net/read/182516.html
if (rectDevice.PtInRect(point)) {
if (m_nColor == GRAY_BRUSH) {
m_nColor = WHITE_BRUSH;
}
else {
m_nColor = GRAY_BRUSH;
}
InvalidateRect(rectDevice);//记得第一次被这函数“高深”的原理,当时那个紧张,激动啊。
}
}
void CEx05bView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
pDC->SetMapMode(MM_HIMETRIC);
CView::OnPrepareDC(pDC, pInfo);
}
4:控制滚动轴
void CEx05cView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar) {
case VK_HOME:
OnVScroll(SB_TOP, 0, NULL);
OnHScroll(SB_LEFT, 0, NULL);
break;
case VK_END:
OnVScroll(SB_BOTTOM, 0, NULL);
OnHScroll(SB_RIGHT, 0, NULL);
break;
case VK_UP:
OnVScroll(SB_LINEUP, 0, NULL);
break;
case VK_DOWN:
OnVScroll(SB_LINEDOWN, 0, NULL);
break;
case VK_PRIOR:
OnVScroll(SB_PAGEUP, 0, NULL);
break;
case VK_NEXT:
OnVScroll(SB_PAGEDOWN, 0, NULL);
break;
case VK_LEFT:
OnHScroll(SB_LINELEFT, 0, NULL);
break;
case VK_RIGHT:
OnHScroll(SB_LINERIGHT, 0, NULL);
break;
default:
break;
}
}
5:字体
void CEx06aView::ShowFont(CDC* pDC, int& nPos, int nPoints)
{
TEXTMETRIC tm;
CFont fontText;
CString strText;
CSize sizeText;
fontText.CreateFont(-nPoints * 20, 0, 0, 0, 400, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS, "Arial");
CFont* pOldFont = (CFont*) pDC->SelectObject(&fontText);
pDC->GetTextMetrics(&tm);
TRACE("points = %d, tmHeight = %d, tmInternalLeading = %d,"
" tmExternalLeading = %d/n", nPoints, tm.tmHeight,
tm.tmInternalLeading, tm.tmExternalLeading);
strText.Format("This is %d-point Arial", nPoints);
sizeText = pDC->GetTextExtent(strText);
TRACE("string width = %d, string height = %d/n", sizeText.cx,
sizeText.cy);
pDC->TextOut(0, nPos, strText);
pDC->SelectObject(pOldFont);
nPos += tm.tmHeight + tm.tmExternalLeading;
}
int nPosition = 0;
for (int i = 6; i <= 24; i += 2) {
ShowFont(pDC, nPosition, i);
}
6:鼠标
::SetCursor(::LoadCursor(NULL, IDC_CROSS));
::ReleaseCapture();
7:CRgn类
http://baike.360.cn/wiki/item/CRgn
8:vfw
http://baike.baidu.com/view/189682.htm
9:Dib文件
http://baike.baidu.com/view/18734.htm
10:serialization
// CEx06eDoc serialization
void CEx06eDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
11:CBitmapButton
CBitmapButton m_editCopy;
CBitmapButton m_editCut;
CBitmapButton m_editPaste;
VERIFY(m_editCopy.AutoLoad(IDC_BUTTON1, this));
VERIFY(m_editCut.AutoLoad(IDC_BUTTON2, this));
VERIFY(m_editPaste.AutoLoad(IDC_BUTTON3, this));
使用方法:
To include a bitmap-button control in a dialog box
Create one to four bitmap images for the button.
Create a dialog template with an owner-draw button positioned where you want the bitmap button. The size of the button in the template does not matter.
Set the button's caption to a value such as "MYIMAGE" and define a symbol for the button such as IDC_MYIMAGE.
In your application's resource script, give each of the images created for the button an ID constructed by appending one of the letters "U," "D," "F," or "X" (for up, down, focused, and disabled) to the string used for the button caption in step 3. For the button caption "MYIMAGE," for example, the IDs would be "MYIMAGEU," "MYIMAGED," "MYIMAGEF," and "MYIMAGEX." You must specify the ID of your bitmaps within double quotes. Otherwise the resource editor will assign an integer to the resource and MFC will fail when loading the image.
In your application's dialog class (derived from CDialog), add a CBitmapButton member object.
In the CDialog object's OnInitDialog routine, call the CBitmapButton object's AutoLoad function, using as parameters the button's control ID and the CDialog object's this pointer
- 最近看了《VC++技术内幕》,做些源代码的简要摘抄(1)
- 最近看了《VC++技术内幕》,做些源代码的简要摘抄(2)
- (摘抄)VC技术内幕笔记
- 记录看vc++技术内幕 学习mfc时遇到的问题
- 看了《spring技术内幕》简单的图解总结下spring一些请求调用流程
- VC++技术内幕(第四版)笔记(1~2章)
- VC++技术内幕(第四版)笔记(1~2章)
- VC技术内幕笔记1-3
- VC技术内幕笔记1-3
- VC++技术内幕(第四版)笔记
- VC++技术内幕(第四版)
- VC技术内幕总结
- VC++技术内幕笔记
- VC++技术内幕
- VC技术内幕笔记
- 《VC++技术内幕》读后感
- vc技术内幕笔记
- VC技术内幕笔记
- 2009的5.12是我的生日
- 值得看看的方法
- 积累人生,沉淀幸福,追逐内心的声音
- 文件编辑器+1.文件节点接口INode
- Oracle白皮书(3)SOA
- 最近看了《VC++技术内幕》,做些源代码的简要摘抄(1)
- 从后现代主义视角看当下的Linux文化
- SAX2 Programming Guide
- practical perforce
- 远程桌面问题,连接后马上断开,并显示“远程计算机已结束连接”
- 最近看了《VC++技术内幕》,做些源代码的简要摘抄(2)
- SRM 440 总结
- Berkeley DB入门篇
- 使用 /proc 文件系统来访问 Linux 内核的内容