SetWindowRgn API - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

SetWindowRgn API

Description:

... DC CPaintDC dc(this); // device context for painting // , if ( m_dcBkGrnd ) BitBlt( dc.m_hDC, 0, 0, m_dwWidth, ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 25
Provided by: edut1184
Category:

less

Transcript and Presenter's Notes

Title: SetWindowRgn API


1
??????????
?????
2
SetWindowRgn API
  • ?? SetWindowRgn ???????????

// ??????????? HRGN rgn rgn
CreateEllipticRgn(0,0,200,100) // ????
region SetWindowRgn(rgn,TRUE)
// ?????????
????,???????
????
3
???? ? Dialog ??
BOOL CTriangleDemo2DlgOnInitDialog() CDialog
OnInitDialog() // ????????? HRGN rgn rgn
CreateEllipticRgn(0,0,200,100) // ????
region SetWindowRgn(rgn,TRUE)
// ????????? return TRUE
? InitDialog ???
void CTriangleDemo2DlgOnPaint() //?????
CDialogOnPaint()
4
  • ??????

5
???? Drag ???
  • Mouse Event Handle

???????function ??
1. ?? Messages
2
void CTriangleDemo2DlgOnLButtonDown(UINT
nFlags, CPoint point) //
???????????
6
???????? -- OnLButtonDown
// ???? ???????? void CTriangleDemo2DlgOnLButt
onDown(UINT nFlags, CPoint point) if (
!(m_dwFlags DRAGGING) )
// ????? dragging
?? m_pntMouse point m_dwFlags DRAGGING
// ????? Drag SetCapture() //
???????? CDialogOnLButtonDown(nFlags,
point)
7
???????? -- OnLButtonUp
//???? ???????? void CTriangleDemo2DlgOnLButto
nUp(UINT nFlags, CPoint point) if (
m_dwFlags DRAGGING )
// ???? dragging
?? m_dwFlags DRAGGING ReleaseCapture()
// release ???? CDialogOnLButtonUp
(nFlags, point)
8
???????? -- OnMouseMove
// ???? ??????, ??????? void CTriangleDemo2Dlg
OnMouseMove(UINT nFlags, CPoint point) if (
m_dwFlags DRAGGING )
// ???? Dragging ??,??????? RECT
rect GetWindowRect( rect ) // ??????
// ???????? rect.left
point.x - m_pntMouse.x rect.top point.y
- m_pntMouse.y SetWindowPos( NULL,
rect.left, rect.top, 0, 0,

SWP_NOZORDER SWP_NOSIZE ) CDialogOnMou
seMove(nFlags, point)
?????
?????????
??????? z-order (?? ignore)
9
??
  • ??????????

HRGN rgn INT num1 POINT points10 num0
10 points0.x 304 points0.y
24 points1.x 232 points1.y
160 points2.x 64 points2.y
160 points3.x 192 points3.y
264 points4.x 136 points4.y
392 points5.x 304 points5.y
336 points6.x 456 points6.y
392 points7.x 424 points7.y
264 points8.x 552 points8.y
160 points9.x 384 points9.y 160 rgn
CreatePolyPolygonRgn( points, num, 1, WINDING
) SetWindowRgn(rgn, true)
?????
10
?BITMAP?????
  • ???????mask, ?? Region ??

?????
Mask ??
?????????
11
?BITMAP?????
// ????
// Step 1 ???? HBITMAP hBmp (HBITMAP)
LoadImage( AfxGetInstanceHandle(),
"Rgn.bmp", IMAGE_BITMAP, 0,
0, LR_LOADFROMFILE ) if ( hBmp NULL
) return TRUE // Step 2???? Region, ???????
(transparent) HRGN hRgn CreateRgnFromFile(
hBmp, RGB(255,0,0) ) // Step 3?????????????
SetWindowPos( NULL, 0, 0, m_dwWidth, m_dwHeight,
SWP_NOZORDER

SWP_NOMOVE ) // Step 4???????
SetWindowRgn( hRgn, TRUE ) //
End
12
CreateRgnFromFile
  • ?????????BMP ??????
  • ????? SOURCE CODE

13
?????????
14
???????? Device Context
  • ????? window client area ??????? ? ???? DC
    (Device Context)

???????
???????? (??,???)???
DC
????
GDI (?????? API)
DC
15
MFC? CDC ??
?? m_hDC ???????? Device m_AttributeDC?? DC
???
CDC ???????
CDC
CClientDC
CWindowDC
CPaintDC
CMetaFileDC
?? WM_Paint Message (? OnDraw ??? ???)
????? Client area
????? ??(Frame ? control)
??????? (??????)
16
SelectObject function
  • ???????????
  • Brush ? ?????
  • Pen ? ????(??)
  • Bitmap
  • Font
  • Rgn
  • Palette (???)

17
??????????????DC
// Step 4 ???? CDC dc GetDC()
// ???? client area ? DC m_dcBkGrnd
CreateCompatibleDC( dc-gtm_hDC ) // ????memory
DC ReleaseDC( dc )
// ????,?? release ? DC // ?????????DC
SelectObject( m_dcBkGrnd, hBmp )
18
// ????
// Step 1 ???? HBITMAP hBmp
(HBITMAP)LoadImage( AfxGetInstanceHandle(),
"Rgn.bmp", IMAGE_BITMAP, 0,
0, LR_LOADFROMFILE ) if ( hBmp NULL
) return TRUE // Step 2???? Region, ???????
(transparent) HRGN hRgn CreateRgnFromFile(
hBmp, RGB(255,0,0) ) // Step 3?????????????
SetWindowPos( NULL, 0, 0, m_dwWidth, m_dwHeight,
SWP_NOZORDER

SWP_NOMOVE ) // Step
5??????? SetWindowRgn( hRgn, TRUE ) //
End
??????????
// Step 4 ???? CDC dc GetDC()
// ???? client area ? DC m_dcBkGrnd
CreateCompatibleDC( dc-gtm_hDC ) // ????memory
DC ReleaseDC( dc )
// ????,?? release ? DC // ?????????DC
SelectObject( m_dcBkGrnd, hBmp )
19
????
void CTriangleDemo2DlgOnPaint() // ??????
client ?? DC CPaintDC dc(this) // device
context for painting // ??????,???? if (
m_dcBkGrnd ) BitBlt( dc.m_hDC, 0, 0, m_dwWidth,
m_dwHeight,
m_dcBkGrnd, 0, 0, SRCCOPY )
20
  • Window Property ?????? border
  • ?????

???????
21
Appendix BCB ???
include ltwinuser.hgt    //Is user for
SetWindowRgn()include ltwingdi.hgt     //Is user
for CreatePolygonRgn() void __fastcall
FormNameFormCreate(TObject Sender)    HRGN
Region    POINT Points4     //Define the
points accross down    Points0 Point(100 ,
30 )    Points1 Point(200 , 200 )   
Points2 Point(0 , 200 )    Points3
Point(105 , 30 )     //Define the region   
Region CreatePolygonRgn(Points, 4,
ALTERNATE)     //Set the window to have the
above defined region    SetWindowRgn(Handle,
Region , True)
  • ????
  • VB example
  • Delphi example

??????????http//ftp.newave.net.au/akia/rgn.htm
C20Example
22
????
  • http//visualcpp.net/index.php?qID31
  • ????????, ??????? P.P.12-4

23
??
  • ???? include stdafx.h ???, ?????
  • fatal error C1010 ???????????????????????
    ?????.
  • ???? precompiled Header ??

24
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com