孙鑫《vc ++深入详解》第十章绘图控制

原创 2007年09月19日 22:32:00

1.绘制点

COLORREF SetPixel( POINT point, COLORREF crColor );
2.绘制矩形:
bool rectangle(LPCRECT  lpRect);
crect类重载了LPCRECT 操作符,其作用是将CRect转换为LPCRECT类型
operator LPCRECT( ) const;

//

Converts a CRect to an LPCRECT. When you use this function, you don't need the address-of (&) operator. This operator will be automatically used when you pass a CRect object to a function that expects an LPCRECT.

Example

void CYourView::OnInitialUpdate()
{
   // CWnd::GetWindowRect() takes a LPRECT, but we can
   // simply pass our CRect object because of the LPRECT
   // cast operator in the CRect class.

   CRect rect;
   GetWindowRect(rect);

   // Similarly, CWnd::MoveWindow() takes a LPCRECT but
   // the LPCRECT cast operator is used implicitly:

   MoveWindow(rect, FALSE);

   // ... more code here ...
}
 
当我传递的参数数值类型和所需要的类型不匹配,但编译和运行都正确的时候:可能是这些类型之间本来就可以互相转换,例如short
和int。但是如果参数类型是对象类型的话,就要考虑:它选择的是对象的构造方法进行的隐式转换还是有其他重载的操作。]
 

3.GetStockObject

The GetStockObject function retrieves a handle to one of the stock pens, brushes, fonts, or palettes.

HGDIOBJ GetStockObject(
  int fnObject   // stock object type
);

Parameters

fnObject
[in] Specifies the type of stock object. This parameter can be one of the following values.
Value Meaning
BLACK_BRUSH Black brush.
DKGRAY_BRUSH Dark gray brush.
DC_BRUSH Windows 2000/XP: Solid color brush. The default color is white. The color can be changed by using the SetDCBrushColor function. For more information, see the Remarks section.
GRAY_BRUSH Gray brush.
HOLLOW_BRUSH Hollow brush (equivalent to NULL_BRUSH).
LTGRAY_BRUSH Light gray brush.
NULL_BRUSH Null brush (equivalent to HOLLOW_BRUSH).
WHITE_BRUSH White brush.
BLACK_PEN Black pen.
DC_PEN Windows 2000/XP: Solid pen color. The default color is white. The color can be changed by using the SetDCPenColor function. For more information, see the Remarks section.
WHITE_PEN White pen.
ANSI_FIXED_FONT Windows fixed-pitch (monospace) system font.
ANSI_VAR_FONT Windows variable-pitch (proportional space) system font.
DEVICE_DEFAULT_FONT Windows NT/2000/XP: Device-dependent font.
DEFAULT_GUI_FONT Default font for user interface objects such as menus and dialog boxes. This is MS Sans Serif. Compare this with SYSTEM_FONT.
OEM_FIXED_FONT Original equipment manufacturer (OEM) dependent fixed-pitch (monospace) font.
SYSTEM_FONT System font. By default, the system uses the system font to draw menus, dialog box controls, and text.

Windows 95/98 and Windows NT: The system font is MS Sans Serif.

Windows 2000/XP: The system font is Tahoma

SYSTEM_FIXED_FONT Fixed-pitch (monospace) system font. This stock object is provided only for compatibility with 16-bit Windows versions earlier than 3.0.
DEFAULT_PALETTE Default palette. This palette consists of the static colors in the system palette.

Return Values

If the function succeeds, the return value is a handle to the requested logical object.

If the function fails, the return value is NULL.

4.CBrush::FromHandle

static CBrush* PASCAL FromHandle( HBRUSH hBrush );

Remarks

Returns a pointer to a CBrush object when given a handle to a Windows HBRUSH object. If a CBrush object is not already attached to the handle, a temporary CBrush object is created and attached. This temporary CBrush object is valid only until the next time the application has idle time in its event loop. At this time, all temporary graphic objects are deleted. In other words, the temporary object is valid only during the processing of one window message.

5.颜色对话框

CColorDialog( COLORREF clrInit = 0, DWORD dwFlags = 0, CWnd* pParentWnd = NULL );

保存用户所选择的颜色:CHOOSECOLOR结构体类型的成员变量:m_cc.

typedef struct { 
  DWORD        lStructSize; 
  HWND         hwndOwner; 
  HWND         hInstance; 
  COLORREF     rgbResult; 
  COLORREF   * lpCustColors; 
  DWORD        Flags; 
  LPARAM       lCustData; 
  LPCCHOOKPROC lpfnHook; 
  LPCTSTR      lpTemplateName; 
} CHOOSECOLOR, *LPCHOOSECOLOR; 
注意书中出现的调试错误。
6.字体对话框

CFontDialog( LPLOGFONT lplfInitial = NULL, DWORD

dwFlags = CF_EFFECTS | CF_SCREENFONTS, CDC* pdcPrinter = NULL,

CWnd* pParentWnd = NULL );

同样也有一个CHOOSEFONT的结构体类型的数据成员:m_cf来保存用户选择

 

typedef struct { DWORD lStructSize; HWND hwndOwner; HDC hDC; LPLOGFONT lpLogFont; INT iPointSize; DWORD Flags; COLORREF rgbColors; LPARAM lCustData; LPCFHOOKPROC lpfnHook; LPCTSTR lpTemplateName; HINSTANCE hInstance; LPTSTR lpszStyle; WORD nFontType; WORD ___MISSING_ALIGNMENT__; INT nSizeMin; INT nSizeMax; } CHOOSEFONT, *LPCHOOSEFONT;

cfont类的CreateFontIndirect成员函数来根据指定特征的逻辑字体来初始化这个字体对象。

BOOL CreateFontIndirect(const LOGFONT* lpLogFont );

利用参数lplogfont指向的LOGFont结构中的一些特征来初始化对象

7.窗口无效

void Invalidate( BOOL bErase = TRUE );

书中程序出现的错误。

释放资源:CGdiObject类的DeleteObject函数来实现]

判断对象是否与某个资源相关联:利用CGdiObjectde 的数据成员m_ hObject来判断

(A HANDLE containing the HBITMAP, HRGN, HBRUSH, HPEN, HPALETTE, or HFONT attached to this object.),该变量保存了与CGdiObject

对象相关连的 Windows GDI 资源的句柄。DeleteObject可以释放这个资源。

8.selectobject

CPen* SelectObject( CPen* pPen );

CBrush* SelectObject( CBrush* pBrush );

virtual CFont* SelectObject( CFont* pFont );

CBitmap* SelectObject( CBitmap* pBitmap );

int SelectObject( CRgn* pRgn );

Return Value

A pointer to the object being replaced. This is a pointer to an object of one of the classes derived from CGdiObject, such as CPen, depending on which version of the function is used. The return value is NULL if there is an error. This function may return a pointer to a temporary object. This temporary object is only valid during the processing of one Windows message. For more information, see CGdiObject::FromHandle.

 

 

相关文章推荐

孙鑫《VC++深入详解》完整版PDF 下载

非常不错的书,结合孙鑫视频看,效果很好。 下载地址: http://www.kuaipan.cn/file/id_63659674548831553.html...
  • gneveek
  • gneveek
  • 2012年08月22日 16:07
  • 46790

《VC++深入详解》学习笔记 第十章 绘图控制

1.简单绘图 (1)画点:CDC类的成员函数SetPixel      函数原型:COLORREF SetPixel(POINT point,COLORREF crColor); (2)画直线:...

孙鑫VC++深入详解(9):绘图控制

1、CColorDialog为颜色对话框,

孙鑫VC++深入详解(3):简单绘图

1、MFC消息映射机制 在每个能接受和处理消息的类中定义一个消息和消息处理函数对照表,即消息映射表。在消息映射表中,消息与对应的消息处理函数是成对出现的。当有消息要处理时,程序即在消息映射表中搜索是...

VC++深入详解 第十章 绘图控制 用CButtonST类改变按钮控件的背景色及文本颜色 自己实现

在学习孙鑫老师的vc++深入详解一书第十章 10.6.4  改变按钮控件的背景色及文本颜色 一节中讲到用CButtonST类来实现的方法,书中用到CButtonST类的子函数m_btnST.SetAc...

孙鑫VC++第10章绘图控制

十、绘图控制   1.        简单绘图          CClientDC dc(this);          CPen pen(PS_SOLID,1,RGB(255,0,0)...

VC++深入详解(孙鑫)

  • 2017年11月07日 21:01
  • 70.28MB
  • 下载

孙鑫VC++深入详解:Lesson9 Part6---在状态栏中添加进度条

最直接的办法就是: //------ 在OnPaint中创建....且窗口改变是重绘进度条.  void CMainFrame::OnPaint()  { CPaintDC dc(this); // ...
  • sergery
  • sergery
  • 2013年07月13日 14:29
  • 1379

孙鑫VC++深入详解之第一个简单win32窗体程序

#include #include #include LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to win...
  • earbao
  • earbao
  • 2013年10月31日 22:12
  • 2709

孙鑫VC++深入详解:Lesson6 Part4 ---CMenu 类的应用:添加子菜单项AppendMenu,插入子菜单项InsertMenu,删除菜单DeleteMenu

CMenu 类的应用 添加子菜单项AppendMenu,插入子菜单项InsertMenu,删除菜单DeleteMenu // //------ 追加菜单,在已菜单后面追加一个子菜单 用函数CMenu:...
  • sergery
  • sergery
  • 2013年07月05日 17:44
  • 11169
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:孙鑫《vc ++深入详解》第十章绘图控制
举报原因:
原因补充:

(最多只允许输入30个字)