VC 实现视图区背景颜色渐变填充
睿丰德科技 专注RFID识别技术和条码识别技术与管理软件的集成项目。质量追溯系统、MES系统、金蝶与条码系统对接、用友与条码系统对接
[cpp] view plaincopy
- void CSTest1View::OnDraw(CDC* pDC)
- {
- CSTest1Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- CRect rcClient;
- GetClientRect(&rcClient);
- rcClient.DeflateRect(5,5,5,5);
- if(m_nMode==0)
- {
- TRIVERTEX vert[2] ;
- GRADIENT_RECT gRect;
- vert [0] .x = rcClient.left;
- vert [0] .y = rcClient.top;
- vert [0] .Red = 0x8000;
- vert [0] .Green = 0xc000;
- vert [0] .Blue = 0xff00;
- vert [0] .Alpha = 0x0000;
- vert [1] .x = rcClient.right;
- vert [1] .y = rcClient.bottom;
- vert [1] .Red = 0xff00;
- vert [1] .Green = 0xc000;
- vert [1] .Blue = 0x8000;
- vert [1] .Alpha = 0x0000;
- gRect.UpperLeft = 1;
- gRect.LowerRight = 0;
- GradientFill(pDC->GetSafeHdc(),vert,2,&gRect,1,GRADIENT_FILL_RECT_V);
- }
- if(m_nMode==1)
- {
- TRIVERTEX vert [4] ;
- GRADIENT_TRIANGLE gTri[2];
- vert [0] .x = rcClient.left;
- vert [0] .y = rcClient.top;
- vert [0] .Red = 0xff00;
- vert [0] .Green = 0xc000;
- vert [0] .Blue = 0x8000;
- vert [0] .Alpha = 0x0000;
- vert [1] .x = rcClient.Width();
- vert [1] .y = rcClient.top;
- vert [1] .Red = 0x8000;
- vert [1] .Green = 0xff00;
- vert [1] .Blue = 0x8000;
- vert [1] .Alpha = 0x0000;
- vert [2] .x = rcClient.CenterPoint().x;
- vert [2] .y = rcClient.bottom;
- vert [2] .Red = 0x8000;
- vert [2] .Green = 0xc000;
- vert [2] .Blue = 0xff00;
- vert [2] .Alpha = 0x0000;
- vert [3] .x = rcClient.CenterPoint().x;
- vert [3] .y = rcClient.CenterPoint().y;
- vert [3] .Red = 0xff00;
- vert [3] .Green = 0x0000;
- vert [3] .Blue = 0x0000;
- vert [3] .Alpha = 0x0000;
- gTri[0].Vertex1 = 0;
- gTri[0].Vertex2 = 1;
- gTri[0].Vertex3 = 2;
- gTri[1].Vertex1 = 0;
- gTri[1].Vertex2 = 0;
- gTri[1].Vertex3 = 0;
- GradientFill(pDC->GetSafeHdc(),vert,4,&gTri,1,GRADIENT_FILL_TRIANGLE);
- }
- }