Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" _
(ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, _
ByVal hBrush As Long) As Long
Private Declare Function CreateRectRgn Lib "gdi32" _
(ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GetClipBox Lib "gdi32" (ByVal hdc As Long, _
lpRect As RECT) As Long
Private Declare Function SelectClipRgn Lib "gdi32" _
(ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Sub cmdGetClipBox_Click()
Dim nRgn As Long
Dim nhDC As Long
Dim nRect As RECT
Const BLACK_BRUSH = 4
Const RGN_COPY = 5
Picture1.Cls
'/ DC 생성
nhDC = GetDC(Picture1.hwnd)
nRgn = CreateRectRgn(10, 10, 100, 100)
'/주어진 영역을 클리핑영역으로 선택한다.
SelectClipRgn nhDC, nRgn
'/클리핑박스를 구하고 테두리를 그린다.
GetClipBox nhDC, nRect
'/사각형의 테두리를 그린다.
FrameRect nhDC, nRect, GetStockObject(BLACK_BRUSH)
'/생성된 영역을 삭제한다.
DeleteObject nRgn
'/ DC 해제
ReleaseDC Picture1.hwnd, nhDC
End Sub
Private Sub Form_Load()
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
End Sub