Using gdiplus-in VC6

Source: Internet
Author: User

Below use VC6 to write a GdiPlus of the Demo project

STEP1: Create a new MFC AppWizard (EXE) project named Demo_gdiplus

Operation Steps:
(1) Main Menu file->new ..., select the Projects tab;
(2) In the Project type list, select MFC AppWizard (EXE);
(3) Project name fills in the Demo_gdiplus, press OK to go to the next page;
(4) Select the single document type of program framework and complete the project creation work by finish.


STEP2: Add header File Declaration

Add the following code in StdAfx.h:

{{Afx_insert_location}}
Microsoft Visual C + + would insert additional declarations immediately before the previous line.
typedef unsigned long ulong_ptr, *pulong_ptr;
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "GdiPlus.lib")

STEP3: Add member Variable M_gdiplustoken in Cdemo_gdiplusapp and initialize in constructor

Class Cdemo_gdiplusapp:public CWINAPP
{
Private
ULONG_PTR M_gdiplustoken;
...... ......
};

Cdemo_gdiplusapp::cdemo_gdiplusapp ()
{
Todo:add Construction code here,
Place all significant initialization in InitInstance
M_gdiplustoken = NULL;
}

STEP4: Add code to install and uninstall GdiPlus
Adding member functions to Cdemo_gdiplusapp by ClassWizard

declarations in. h
Virtual BOOL InitInstance ();
virtual int exitinstance ();

Implementations in the. cpp
BOOL cdemo_gdiplusapp::initinstance ()
{
Load GdiPlus
Gdiplus::gdiplusstartupinput Gdiplusstartupinput;
Gdiplus::gdiplusstartup (&m_gdiplustoken, &gdiplusstartupinput, NULL);
...... ......
}


int Cdemo_gdiplusapp::exitinstance ()
{
Todo:add your specialized code here and/or call the base class
Uninstalling GdiPlus
if (M_gdiplustoken)
Gdiplus::gdiplusshutdown (M_gdiplustoken);
return CWinApp::ExitInstance ();
}

STEP5: Find the Cdemo_gdiplusview::ondraw () function and add a GdiPlus drawing code inside

void Cdemo_gdiplusview::ondraw (cdc* pDC)
{
cdemo_gdiplusdoc* PDoc = GetDocument ();
Assert_valid (PDOC);
Todo:add draw code for native data here

Graphics Graphics (PDC-&GT;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 < n; x + = 5)
{
Graphics. DrawLine (&blue, 0, y, x, 0);
Graphics. DrawLine (&red, n, x, y, 256);
Y-= 5;
}
}


Compile and run, Demo program completed. Keep this Demo program, we will use it for more in-depth GdiPlus learning in the future.

Using gdiplus-in VC6

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.