GDI+如何判断一个点是否在区域内
2016-10-24 12:20
459 查看
https://msdn.microsoft.com/en-us/library/windows/desktop/ms533826(v=vs.85).aspx
The purpose of hit testing is to determine whether the cursor is over a given object, such as an icon or a button. The following example creates a plus-shaped region by forming the union of two rectangular regions. Assume that the variable point holds the location of the most recent click. The code checks to see whether point is in the plus-shaped region. If point is in the region (a hit), the region is filled with an opaque red brush. Otherwise, the region is filled with a semitransparent red brush. |
Point point(60, 10); // Assume that the variable "point" contains the location // of the most recent click. // To simulate a hit, assign (60, 10) to point. // To simulate a miss, assign (0, 0) to point. SolidBrush solidBrush(Color()); Region region1(Rect(50, 0, 50, 150)); Region region2(Rect(0, 50, 150, 50)); // Create a plus-shaped region by forming the union of region1 and region2. // The union replaces region1. region1.Union(®ion2); if(region1.IsVisible(point, &graphics)) { // The point is in the region. Use an opaque brush. solidBrush.SetColor(Color(255, 255, 0, 0)); } else { // The point is not in the region. Use a semitransparent brush. solidBrush.SetColor(Color(64, 255, 0, 0)); } graphics.FillRegion(&solidBrush, ®ion1);
LRESULT CMovableWinView::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { curPos.X = GET_X_LPARAM(lParam); curPos.Y = GET_Y_LPARAM(lParam); if (wParam & MK_LBUTTON) { ; } Gdiplus::Graphics g(m_hWnd); Gdiplus::Point point(curPos.X, curPos.Y); Gdiplus::Rect rect(100, 100, 300, 300); Gdiplus::Pen pen(penColor); g.DrawRectangle(&pen, rect); Gdiplus::Region region(rect); Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 255, 255, 255)); if (region.IsVisible(point, &g)) { solidBrush.SetColor(Gdiplus::Color(255, 255, 0, 0)); } else { solidBrush.SetColor(Gdiplus::Color(255, 255, 255, 255)); } rect.X += 1; rect.Y += 1; rect.Width -= 1; rect.Height -= 1; g.FillRectangle(&solidBrush, rect); return TRUE; }
相关文章推荐
- GDI+如何判断一个点是否在区域内
- GDI+如何判断一个点是否在区域内
- 如何判断一个指定的经纬度点是否落在一个多边形区域内?
- 在Android里如何判断一个指定的经纬度点是否落在一个多边形区域内
- Matlab如何判断一个点是否落在一个不规则的封闭区域中
- 如何判断一个指定的经纬度点是否落在一个多边形区域内?
- 如何判断一个Div是否可视区域,判断div是否可见
- 如何判断一个点是否在一个闭合区域内(无凹进的顶点)
- 如何判断一个机器的MSSQL是否启动
- C#实现如何判断一个字符串是否为整数和浮点
- JavaScript 里如何判断一个字符串里是否存在某个字符串?(支持中文)
- VBS中如何判断一个引用对象是否存在?
- .net C# 如何判断一个对象是否具有某个方法
- 如何判断一个字符串是否为正确的IP地址
- 如何判断一个点是否在三角形内部
- 如何判断一个文件是否是win32可执行文件
- 如何判断一个已知的表中是否存在某个字段,如果不存在就创建它.
- 如何用创建命名对象来判断应用程序是否已有一个实例在运行?
- 如何判断一个整数是否为奇数
- 如何判断一个单向链表是否有环路