VC++实现不规则窗口说明

最近做一贴图程序,使用到一些API,因第一次弄,所以把它说明写出来,以备将来使用。

CreateRectRgn

原型:BOOL CreateRectRgn(int x1,int y1,int x2,int y2);

说明:创建一矩形区域存储在CRgn对象中

x1指定区域左上角X坐标,y1指定区域左上角y坐标,x2指定区域右下角X坐标,y2指定区域右下角y坐标

示例:CRgn   rgn;

BOOL bSucceeded = rgn.CreateRectRgn( 50, 20, 150, 120 );

CombineRgn

原型:int CombineRgn(CRgn* pRgn1,CRgn* pRgn2,int nCombineMode);
说明:将两个存在的区域合并成一个新的区域
pRgn1第一个存在区域的指针,pRgn2第二个存在区域的指针,nCombineMode合并模式(RGN_AND最后的区域是pRgn1和pRgn2的重叠部分;RGN_COPY最后的区域是pRgn1的拷贝;RGN_DIFF最后的区域是pRgn1中不包含pRgn2的部分;RGN_OR最后的区域同时包含pRgn1和pRgn2;RGN_XOR最后的区域同时包含pRgn1和pRgn2,但不包含pRng1和pRng2重叠的部分。)

示例:CRgn   rgnA, rgnB, rgnC;

VERIFY(rgnA.CreateRectRgn( 50, 50, 150, 150 ));
VERIFY(rgnB.CreateRectRgn( 100, 100, 200, 200 ));
VERIFY(rgnC.CreateRectRgn( 0, 0, 50, 50 ));

int nCombineResult = rgnC.CombineRgn( &rgnA, &rgnB, RGN_OR );

GetPixel

原型:COLORREF GetPixel(int x,int y) const;
说明:取得指定坐标点的RGB颜色值
x指定点的X坐标,y指定点的y坐标
示例:CPaintDC dc(this);
COLORREF col = dc.GetPixel(1, 1);
SetWindowRgn
原型:int SetWindowRgn(HRGN hRgn,BOOL bRedraw = FALSE) throw();
说明:设置窗体形状
hRgn是一个CRgn类的句柄;bRedraw如果被设置成TRUE,那么,在窗口次序发生变化时,系统会发送WM_WINDOWPOSCHANGING和WM_WINDOWPOSCHANGED消息给窗口。
示例:CRgn rgn;
rgn.CreateRectRgn(0, 0, 100, 100);
int iResult = SetWindowRgn(rgn, TRUE);
CreateRectRgnIndirect
原型:BOOL CreateRectRgnIndirect(LPCRECT lpRect);
说明:创建一个矩形区域
lpRect指定所创建的矩形区域在窗口用户区中的left(左)、top(上)、right(右)、bottom(下)坐标。
示例:CRgn MyRgn;
RECT m_rect;
m_rect.left=0; m_rect.top=0; m_rect.right=500; m_rect.bottom=300;
MyRgn.CreateRectRgnIndirect( &m_rect );
CreateEllipticRgnIndirect
原型:BOOL CreateEllipticRgnIndirect(LPCRECT lpRect);
说明:创建一个椭圆形区域
lpRect指定所创建的椭圆形区域在窗口用户区中的left(左)、top(上)、right(右)、bottom(下)坐标,如果指定right坐标与left坐标之差等于bottom坐标与top坐标之差,则创建的区域是一个圆
示例:CRgn MyRgn;
RECT m_rect;
m_rect.left=0; m_rect.top=0; m_rect.right=500; m_rect.bottom=300;
MyRgn.CreateEllitpticRgnIndirect( &m_rect );
CreatePolygonRgn
原型:BOOL CreatePolygonRgn(LPPOINT lpPoints,int nCount,int nMode);
说明:创建一个多边形区域
lpPoints指向一个POINT结构数组,在POINT结构数组中每个POINT结构项,用来确定多边形顶点在窗口用户区中的坐标;nCount说明POINT结构数组中POINT结构项的数目,也就是多边形的顶点数;nMode指定多边形的填充方式,一般使用ALTERNATE方式。
示例:CRgn MyRgn;
POINT Points[3];
Points[0].x=Points[0].y=0; Points[1].x=10; Points[1].y=30; Points[2].x=5; Points[2].y=60;
MyRgn.CreatePolygonRgn(Points, 3, ALTERNATE);
CreateCompatibleDC
原型:BOOL CreateCompatibleDC(CDC* pDC);
说明:创建一个和pDC指定设备上下文一致的内存设备上下文
pDC一设备上下文指针,如果为NULL,这个函数创建一个和系统显示一致的内存设备上下文。
示例:CPaintDC dc(this);
CDC dcMemory;
dcMemory.CreateCompatibleDC(&dc);
 
CreateCompatibleBitmap
 
原型:BOOL CreateCompatibleBitmap(CDC* pDC,int nWidth,int nHeight );
说明:创建一个和pDC指定设备一致的位图
pDC设备上下文指针,nWidth为位图的宽度,nHeight为位图的高度
示例:HDC hDC,                  // Handle to the display device context 
      hDCMem;               // Handle to the memory device context
  HBITMAP hBitmap;          // Handle to the new bitmap
  int iWidth, iHeight;      // Width and height of the bitmap
  // Retrieve the handle to a display device context for the client 
  // area of the window.
  hDC = GetDC (hwnd);
  // Create a memory device context compatible with the device. 
  hDCMem = CreateCompatibleDC (hDC);
  // Retrieve the width and height of window display elements.
  iWidth = GetSystemMetrics (SM_CXSCREEN) / 10;
  iHeight = GetSystemMetrics (SM_CYSCREEN) / 10;
  // Create a bitmap compatible with the device associated with the 
  // device context.
  hBitmap = CreateCompatibleBitmap (hDC, iWidth, iHeight);
SelectObject
原型:CPen* SelectObject(CPen* pPen);
CBrush* SelectObject(CBrush* pBrush);
virtual CFont* SelectObject(CFont* pFont);
CBitmap* SelectObject(CBitmap* pBitmap);
int SelectObject(CRgn* pRgn);
CGdiObject* SelectObject(CGdiObject* pObject);
说明:选择一对象插入到设备上下文
pPeng一个CPen对象指针
pBrush一个CBrush对象指针
pFont一个CFont对象指针
pBitmap一个CBitmap对象指针
pRgn一个CRgn对象指针
pObject一个CGdiObject对象指针
示例:CClientDC dc(this);
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 2, RGB(0,0,0));
CPen* pOldPen = dc.SelectObject(&penBlack);
CClientDC dc(this);
CBrush brush1;
brush1.CreateSolidBrush(RGB(0,0,255));
CBrush* pTempBrush = (CBrush*)dc.SelectObject(&brush1);
CFont font;
VERIFY(font.CreateFont(
   12,                        // nHeight
   0,                         // nWidth
   0,                         // nEscapement
   0,                         // nOrientation
   FW_NORMAL,                 // nWeight
   FALSE,                     // bItalic
   FALSE,                     // bUnderline
   0,                         // cStrikeOut
   ANSI_CHARSET,              // nCharSet
   OUT_DEFAULT_PRECIS,        // nOutPrecision
   CLIP_DEFAULT_PRECIS,       // nClipPrecision
   DEFAULT_QUALITY,           // nQuality
   DEFAULT_PITCH | FF_SWISS,  // nPitchAndFamily
   "Arial"));                 // lpszFacename
CClientDC dc(this); 
CFont* def_font = dc.SelectObject(&font);
CClientDC dc(this);
CBitmap btScreen;
btScreen.CreateCompatibleBitmap(&dc, 100, 100);
CBitmap* newBmp = dc.SelectObject(&btScreen);
CClientDC dc(this);
CRgn   rgn;
BOOL bSucceeded = rgn.CreateRectRgn( 50, 20, 150, 120 );
int iResult = dc.SelectObject(&rgn);
BitBlt
原型:BOOL BitBlt(int x,int y,int nWidth,int nHeight,CDC* pSrcDC,int xSrc,int ySrc,DWORD dwRop);
说明:从源设备上下文复制位图到当前设备上下文
x目标区域的左上角x坐标,y目标区域的左上角y坐标,nWidth目标区域和位图的宽度,nHeight目标区域和位图的高度,pSrcDC将复制的位图所在的源设备上下文(如果dwRop指定不包含源,那么pSrcDC必须为NULL),xSrc源位图的左上角x坐标,ySrc源位图的左上角y坐标,dwRop指定光栅操作的执行方式
示例:CClientDC dc(this);
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
dc.BitBlt(0, 0, 100, 100, &MemDC, 0, 0, SRCCOPY);
 
 


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值