建立不規則形狀的視窗

debut.cis.nctu.edu.tw
  • No tags were found...

建立不規則形狀的視窗

立 不 狀


– Dialog 例BOOL CTriangleDemo2Dlg::OnInitDialog(){CDialog::OnInitDialog(); InitDialog // 立 狀 HRGN rgn;rgn = CreateEllipticRgn(0,0,200,100); // 立 regionSetWindowRgn(rgn,TRUE); // }return TRUE;void CTriangleDemo2Dlg::OnPaint(){ //CDialog::OnPaint();}


• 練 不 狀 不 Title,, 理


滑 Drag • Mouse Event Handle1. Messagesfunction 2void CTriangleDemo2Dlg::OnLButtonDown(UINT nFlags,CPoint point){// 理 滑 }


行 滑 -- OnLButtonDown// [ 滑 ] 滑 void CTriangleDemo2Dlg::OnLButtonDown(UINT nFlags, CPoint point){if ( !(m_dwFlags & DRAGGING) ){ // 若 不 dragging 狀 m_pntMouse = point;m_dwFlags |= DRAGGING;SetCapture(); // 滑 }}CDialog::OnLButtonDown(nFlags, point);


行 滑 -- OnLButtonUp//[ 滑 ] 滑 void CTriangleDemo2Dlg::OnLButtonUp(UINT nFlags, CPoint point){if ( m_dwFlags & DRAGGING ){ // 若 dragging 狀 m_dwFlags &= ~DRAGGING;ReleaseCapture(); // release 滑 }}CDialog::OnLButtonUp(nFlags, point);


行 滑 -- 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 ); z-order( ignore)}CDialog::OnMouseMove(nFlags, point);


練 • 立 狀 HRGN rgn;INT num[1];POINT points[10];參 num[0]=10;points[0].x = 304; points[0].y = 24;points[1].x = 232; points[1].y = 160;points[2].x = 64; points[2].y = 160;points[3].x = 192; points[3].y = 264;points[4].x = 136; points[4].y = 392;points[5].x = 304; points[5].y = 336;points[6].x = 456; points[6].y = 392;points[7].x = 424; points[7].y = 264;points[8].x = 552; points[8].y = 160;points[9].x = 384; points[9].y = 160;rgn = CreatePolyPolygonRgn( points, num, 1, WINDING );SetWindowRgn(rgn, true);


BITMAP 輪 廓• 讀 mask, Region Mask 來 狀


BITMAP 輪 廓// ==================== 立 狀 =====================// Step 1: instance 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 =====================


CreateRgnFromFile• 量 BMP 識• 參 SOURCE CODE


理 念Device Context• window client area 料 DC (Device Context)(,) 料DCGDI( API)DC


MFC CDC 類 m_hDC: Devicem_AttributeDC: 讀 DC CDC 類 CDCCClientDC CWindowDC CPaintDC CMetaFileDCClient area(Frame control) WM_PaintMessage (OnDraw 來 參 數 )( 量 )


SelectObject function• – Brush – Pen ()– Bitmap– Font– Rgn– Palette (()


立 DC// Step 4: CDC* dc = GetDC(); // client area DCm_dcBkGrnd = CreateCompatibleDC( dc->m_hDC ); // 立 memory DCReleaseDC( dc ); // , release DC// DCSelectObject( m_dcBkGrnd, hBmp );


==================== 立 狀 =====================// 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: CDC* dc = GetDC(); // client area DCm_dcBkGrnd = CreateCompatibleDC( dc->m_hDC ); // 立 memory DCReleaseDC( dc ); // , release DC// DCSelectObject( m_dcBkGrnd, hBmp );// Step 5: 狀SetWindowRgn( hRgn, TRUE );// ==================== End =====================


void CTriangleDemo2Dlg::OnPaint(){// client DCCPaintDC dc(this); // device context for painting}// ,if ( m_dcBkGrnd )BitBlt( dc.m_hDC, 0, 0, m_dwWidth, m_dwHeight,m_dcBkGrnd, 0, 0, SRCCOPY );


• Window Property border•


來 :http://ftp.newave.net.au/~akia/rgn.htm#C%20ExampleAppendix: BCB #include //Is user for SetWindowRgn()#include //Is user for CreatePolygonRgn()void __fastcall FormName::FormCreate(TObject *Sender){HRGN Region;POINT Points[4];//Define the points accross downPoints[0] = Point(100 , 30 );Points[1] = Point(200 , 200 );Points[2] = Point(0 , 200 );Points[3] = Point(105 , 30 );//Define the regionRegion = CreatePolygonRgn(Points, 4, ALTERNATE);//Set the window to have the above defined regionSetWindowRgn(Handle, Region , True);}1. VB example2. Delphi example


參 料• http://visualcpp.net/index.php?qID=31• , P.P.12-4


錄 :• #include “stdafx.h” , – “fatal error C1010: 行 “ .• precompiled Header

More magazines by this user
Similar magazines