Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Rectangle.cpp
Package: TCAD.rar [view]
Upload User: ggmm7909
Upload Date: 2008-11-12
Package Size: 80k
Code Size: 3k
Category:
Graph Drawing
Development Platform:
C/C++
- // Rectangle.cpp: implementation of the CRectangle class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Rectangle.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CRectangle::CRectangle()
- {
- strcpy(m_className,"CRectangle");
- }
- CRectangle::~CRectangle()
- {
- }
- void CRectangle::Draw(HDC hdc)
- {
- HPEN hPen = ::CreatePen( fnPenStyle,nWidth,crColor);
- HPEN hOldPen = (HPEN)::SelectObject(hdc,hPen);
- //不进行填充
- ::SelectObject(hdc,GetStockObject(NULL_BRUSH));
- Rectangle( hdc,
- m_ptFirstPos.x,
- m_ptFirstPos.y,
- m_ptSecondPos.x,
- m_ptSecondPos.y
- );
- ::SelectObject(hdc,hOldPen);
- ::DeleteObject(hPen);
- if(isPick == TRUE)
- {
- //恢复填充
- ::SelectObject(hdc,GetStockObject(WHITE_BRUSH));
- DrawRect(hdc);
- }
- }
- void CRectangle::DrawRect(HDC hdc)
- {
- //Rect为标记圆的半径
- //top left
- Ellipse(hdc,m_ptFirstPos.x - Rect,m_ptFirstPos.y - Rect,
- m_ptFirstPos.x + Rect,m_ptFirstPos.y + Rect);
- //top right
- Ellipse(hdc,m_ptSecondPos.x - Rect,m_ptFirstPos.y - Rect,
- m_ptSecondPos.x + Rect,m_ptFirstPos.y + Rect);
- //top middle
- Ellipse(hdc,mPtx - Rect,m_ptFirstPos.y - Rect,
- mPtx + Rect,m_ptFirstPos.y + Rect);
- //left middle
- Ellipse(hdc,m_ptFirstPos.x - Rect,mPty - Rect,
- m_ptFirstPos.x + Rect,mPty + Rect);
- //right middle
- Ellipse(hdc,m_ptSecondPos.x - Rect,mPty - Rect,
- m_ptSecondPos.x + Rect,mPty + Rect);
- //buttom middle
- Ellipse(hdc,mPtx - Rect,m_ptSecondPos.y - Rect,
- mPtx + Rect,m_ptSecondPos.y + Rect);
- //buttom left
- Ellipse(hdc,m_ptFirstPos.x - Rect,m_ptSecondPos.y - Rect,
- m_ptFirstPos.x + Rect,m_ptSecondPos.y + Rect);
- //buttom right
- Ellipse(hdc,m_ptSecondPos.x - Rect,m_ptSecondPos.y - Rect,
- m_ptSecondPos.x + Rect,m_ptSecondPos.y + Rect);
- }
- BOOL CRectangle::pick(POINT pt)
- {
- //矩形中心坐标
- mPtx = (m_ptSecondPos.x + m_ptFirstPos.x) / 2;
- mPty = (m_ptSecondPos.y + m_ptFirstPos.y) / 2;
- //矩形的长和宽
- int hLength = abs(m_ptSecondPos.x - m_ptFirstPos.x) / 2;
- int hWidth = abs(m_ptSecondPos.y - m_ptFirstPos.y) / 2;
- //拾取的有效范围正负5个象素
- if (pt.x < m_ptFirstPos.x + 5 && pt.x > m_ptFirstPos.x - 5)
- {
- if (pt.y < mPty + hWidth + 5 && pt.y > mPty - hWidth - 5 )
- return TRUE;
- }
- if (pt.x < m_ptSecondPos.x + 5 && pt.x > m_ptSecondPos.x - 5)
- {
- if (pt.y < mPty + hWidth + 5 && pt.y > mPty - hWidth - 5 )
- return TRUE;
- }
- if (pt.y < m_ptFirstPos.y + 5 && pt.y > m_ptFirstPos.y - 5)
- {
- if (pt.x < mPtx + hLength + 5 && pt.x > mPtx - hLength - 5 )
- return TRUE;
- }
- if (pt.y < m_ptSecondPos.y + 5 && pt.y > m_ptSecondPos.y - 5)
- {
- if (pt.x < mPtx + hLength + 5 && pt.x > mPtx - hLength - 5 )
- return TRUE;
- }
- return FALSE;
- }