zoukankan      html  css  js  c++  java
  • GDI+如何判断一个点是否在区域内

    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(&region2);
    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, &region1);
    

    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;
    }


    Keep it simple!
    作者:N3verL4nd
    知识共享,欢迎转载。
  • 相关阅读:
    VMdomainXml
    C 本地文件夸网文件Cp操作
    C++ auto 与 register、static keyword 浅析
    机器学习笔记——SVM
    NYOJ 298-点的变换(经典矩阵解决点平移、缩放、翻转和旋转)
    HDU 5407 CRB and Candies(LCM +最大素因子求逆元)
    Java总结之网络
    五月份小结
    算法——字符串匹配之BM算法
    javaweb_page指令
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616339.html
Copyright © 2011-2022 走看看