孙鑫MFC学习笔记4:MFC画图

1.画线方法

*1.捕获鼠标按下和弹起消息,获取两个点

*2.消息响应,画线

2.在CMainFrame类中的鼠标左键事件得不到响应的原因是CNameView覆盖了CMainFrame

3.注释宏

孙鑫MFC学习笔记4:MFC画图

4.画线方法

*1.HDC

*2.CDC(MFC封装)

*3.CClientDC(不用显式释放资源)

*4.CWindowDC(可以画到非客户区)

5.画线步骤

*1.获取DC

*2.MoveTo到原点

*3.LineTo到目标点

*4.释放DC

6.CPen

构造函数参数:

线类型PS_SOLID等

宽度

颜色

RGB宏,三个参数:红绿蓝颜色值

7.SelectObject

添加设备到设备描述表,返回旧的设备指针,DC成员函数

8.FillRect

画矩形

9.CBrush

画刷,构造函数参数可以是颜色,位图

10.CBitMap

孙鑫MFC学习笔记4:MFC画图

孙鑫MFC学习笔记4:MFC画图

LoadBitmap:

The LoadBitmap function loads the specified bitmap resource from a module's executable file.

HBITMAP LoadBitmap(

HINSTANCE hInstance,         // handle of application instance

LPCTSTR lpBitmapName      // address of bitmap resource name

);

Parameters

hInstance

Identifies the instance of the module whose executable file contains the bitmap to be loaded.

lpBitmapName

Points to a null-terminated string that contains the name of the bitmap resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MAKEINTRESOURCE macro can be used to create this value.

Return Values

If the function succeeds, the return value is the handle of the specified bitmap.

If the function fails, the return value is NULL.

Remarks

If the bitmap pointed to by the lpBitmapName parameter does not exist or there is insufficient memory to load the bitmap, the function fails.

An application can use the LoadBitmap function to access the predefined bitmaps used by the Win32 API. To do so, the application must set the hInstance parameter to NULL and the lpBitmapName parameter to one of the following values:

OBM_BTNCORNERS       OBM_OLD_RESTORE

OBM_BTSIZE     OBM_OLD_RGARROW

OBM_CHECK     OBM_OLD_UPARROW

OBM_CHECKBOXES       OBM_OLD_ZOOM

OBM_CLOSE      OBM_REDUCE

OBM_COMBO   OBM_REDUCED

OBM_DNARROW           OBM_RESTORE

OBM_DNARROWD         OBM_RESTORED

OBM_DNARROWI          OBM_RGARROW

OBM_LFARROW OBM_RGARROWD

OBM_LFARROWD           OBM_RGARROWI

OBM_LFARROWI            OBM_SIZE

OBM_MNARROW          OBM_UPARROW

OBM_OLD_CLOSE          OBM_UPARROWD

OBM_OLD_DNARROW    OBM_UPARROWI

OBM_OLD_LFARROW     OBM_ZOOM

OBM_OLD_REDUCE        OBM_ZOOMD

Bitmap names that begin with OBM_OLD represent bitmaps used by Windows versions earlier than 3.0.

For an application to use any of the OBM_ constants, the constant OEMRESOURCE must be defined before the WINDOWS.H header file is included.

The application must call the DeleteObject function to delete each bitmap handle returned by the LoadBitmap function.

See Also

CreateBitmap, DeleteObject, LoadCursor, LoadIcon, MAKEINTRESOURCE

11.Rectangle画矩形

12.GetStockObject可以通过NULL_BRUSH获取透明画刷,使矩形不被覆盖

GetStockObject返回画刷句柄,通过CBrush::FromHandle转为CBrush对象指针

13.SetROP2

设置绘画模式

孙鑫MFC学习笔记4:MFC画图 用菊子曰博客,就是爽!
上一篇:js实现快速排序


下一篇:Winform Textbox MultiLine和WordWrap属性的使用