Implement an MFC menu brush to draw a circle and tick

Source: Internet
Author: User

This is the simplest way to move the client area, the circle will disappear, so the next article I also want to improve.

First create a new MFC single file, under the Resources menu, create a brush, you can pop the red brush, Blue brush and green brush, give Id_red,id_blue,id_green and set the Class Wizard under the Visual class to add the command function, this time, we want to show how these colors , my approach is to define a public integer variable int m_pencolor in the view class, also set three Boolean variables (indicating the hook state, and so on) and then initialize the constructor to 1, (you can choose red by default) in the view class header file Plus

{。。。

Public
BOOL statu2;//Green Brush Hook status
BOOL statu1;//Blue Brush Hook status
BOOL statu;//Red Brush hook status
int m_pencolor;

。。。

}

We choose the red brush by default, when we click on the other color of the pen, to hook in front of the corresponding brush, this time requires an update function, also set up the Class Wizard, select the Visual class Update function

void cxfview::onupdatered (ccmdui* pcmdui)
{
Todo:add your command update UI handler code here
if (m_pencolor=1)

Pcmdui->setcheck (Statu);//Select the menu to set 3 Boolean values

}

void Cxfview::onupdateblue (ccmdui* pcmdui)
{
Todo:add your command update UI handler code here
if (m_pencolor=2)
Pcmdui->setcheck (STATU1);

}

void Cxfview::onupdategreen (ccmdui* pcmdui)
{
Todo:add your command update UI handler code here
if (m_pencolor=3)

Pcmdui->setcheck (STATU2);


}

The command function writes the code:

void Cxfview::onred ()

{//Todo:add your command handler code here

M_pencolor=1;

}

void Cxfview::onblue ()

{//Todo:add your command handler code here

m_pencolor=2;

}

void Cxfview::ongreen ()

{//Todo:add your command handler code here

m_pencolor=3;

}

Then the color is now selectable, so how do we use the mouse to draw a circle?

Right-click the View class and add window message Hanlder

void Cxfview::onlbuttondown (UINT nflags, CPoint Point)
{
Todo:add your message handler code here and/or call default
COLORREF color;
Switch (m_pencolor)//Here is the choice of the sentence to determine what color
{
Case 1:
Color=rgb (255,0,0);//m_pencolor=1 is red
statu=1;//also set the Boolean three variable in the view class to indicate whether the menu bar has a tick,

Here choose the red brush, tick
statu1=0;
statu2=0;
Break
Case 2:
Color=rgb (0,0,255);
statu=0;
Statu1=1;
statu2=0;
Break
Case 3:
Color=rgb (0,255,0);
statu=0;
statu1=0;
Statu2=1;
Break
}
CPen Newpen, *poldpen;
Newpen.createpen (Ps_solid,10,color);//Solid Wire
CCLIENTDC DC (this);
poldpen= DC. SelectObject (&newpen);

dc. Ellipse (point.x-50,point.y-50,point.x+50, point.y+50);//Draw a circle
dc. SelectObject (Poldpen);//This sentence (I do not understand)

Cview::onlbuttondown (nflags, point);
}

This is basically good, here is a temporary write, before tried is can, do not know what will be missing, welcome everyone to criticize correct.

Implement an MFC menu brush to draw a circle and tick

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.