资源描述:
《在vc6中使用gdiplus》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、在VC6中使用GdiPlus(五)下面用VC6来写一个GdiPlus的Demo工程 Step1:新建一个名为Demo_GdiPlus的MFCAppWizard(exe)工程操作步骤:(1)主菜单File->New...,选择Projects选项卡;(2)在工程类型列表中选中MFCAppWizard(exe);(3)Projectname填入Demo_GdiPlus,按OK进入下一页;(4)选择单文档(Singledocument)类型的程序框架,按Finish完成工程创建工作。Step2:添加头文件声明在StdAfx
2、.h中添加以下代码://{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.typedef unsigned long ULONG_PTR, *PULONG_PTR;#include using namespace Gdiplus;#pragma comment (lib, "GdiPlus.lib") Ste
3、p3:在CDemo_GdiPlusApp中增加成员变量m_gdiplusToken,并在构造函数中进行初始化class CDemo_GdiPlusApp : public CWinApp{private: ULONG_PTR m_gdiplusToken; // …… ……};CDemo_GdiPlusApp::CDemo_GdiPlusApp(){ // TODO: add construction code here, // Place all significant initialization in Init
4、Instance m_gdiplusToken = NULL;} Step4:添加安装和卸载GdiPlus的代码通过ClassWizard在CDemo_GdiPlusApp中增加成员函数// .h 中的声明virtual BOOL InitInstance();virtual int ExitInstance();// .cpp 中的实现BOOL CDemo_GdiPlusApp::InitInstance(){ // 加载 GdiPlus Gdiplus::GdiplusStartupInput gdiplusSt
5、artupInput; Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); // …… ……} int CDemo_GdiPlusApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class // 卸载 GdiPlus if (m_gdiplusToken) Gdiplus::GdiplusShutdown(m_g
6、diplusToken); return CWinApp::ExitInstance();} Step5:找到CDemo_GdiPlusView::OnDraw()函数,在里面添加一段GdiPlus的绘图代码void CDemo_GdiPlusView::OnDraw(CDC* pDC){ CDemo_GdiPlusDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here Graphics
7、 graphics(pDC->GetSafeHdc()); // Pen can also be constructed using a brush or another pen. There is a second parameter - a width which defaults to 1.0f Pen blue (Color(255, 0, 0, 255)); Pen red (Color(255, 255, 0, 0)); int y = 256; for (int x = 0; x < 256;
8、x += 5) { graphics.DrawLine(&blue, 0, y, x, 0); graphics.DrawLine(&red, 256, x, y, 256); y -= 5; } }编译运行,Demo程序完成。留住这个Demo程序,今后我们会利用它进行更加深入的GdiPlus学习。