學習windows編程 day5 之 地區裁剪

來源:互聯網
上載者:User

標籤:word   sel   nbsp   裁剪   com   rto   des   color   sage   

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){    HDC hdc;    PAINTSTRUCT ps;    RECT rect;    static int cxClient, cyClient;    HRGN hRgn[6];    static HRGN hTotRgn;    double fAngle, fRadius;    HCURSOR hCursor;    switch (message)    {    case WM_SIZE:        cxClient = LOWORD(lParam);        cyClient = HIWORD(lParam);        hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));        ShowCursor(TRUE);        //建立四個地區        //先左右兩個        hRgn[0]=CreateEllipticRgn(0, cyClient / 3, cxClient / 2, cyClient * 2 / 3);        hRgn[1] = CreateEllipticRgn(cxClient, cyClient / 3, cxClient / 2, cyClient * 2 / 3);        //後上下兩個        hRgn[2] = CreateEllipticRgn(cxClient / 3, 0, cxClient * 2 / 3, cyClient / 2);        hRgn[3] = CreateEllipticRgn(cxClient / 3, cyClient/2, cxClient * 2 / 3, cyClient);        //其餘的先設為一個較小的地區(空)        hRgn[4] = CreateEllipticRgn(0, 0, 1, 1);        hRgn[5] = CreateEllipticRgn(0, 0, 1, 1);        hTotRgn = CreateEllipticRgn(0, 0, 1, 1);        //調用combinRgn後原來這些地區會被銷毀        //先合并左右        CombineRgn(hRgn[4], hRgn[0], hRgn[1], RGN_OR);        CombineRgn(hRgn[5], hRgn[2], hRgn[3], RGN_OR);        //合并為一個總地區控制代碼        CombineRgn(hTotRgn, hRgn[4], hRgn[5], RGN_XOR);        for (int i = 0; i < 6; i++)            DeleteObject(hRgn[i]);        SetCursor(hCursor);        ShowCursor(TRUE);        break;    case WM_PAINT:        hdc = BeginPaint(hwnd, &ps);        GetClientRect(hwnd, &rect);        SetViewportOrgEx(hdc, cxClient / 2, cyClient / 2, NULL);        //選中剪下地區後,會在這個地區作圖        SelectClipRgn(hdc, hTotRgn);        FrameRgn(hdc, hTotRgn, (HBRUSH)GetStockObject(BLACK_BRUSH),1,1);        //內部畫陰影        fRadius = _hypot(cxClient / 2, cyClient / 2);//直角三角形斜邊        for (fAngle = 0.0; fAngle < PI * 2;fAngle += PI*2/360)        {            MoveToEx(hdc, 0, 0, NULL);            LineTo(hdc, (int)(fRadius*cos(fAngle) + 0.5), (int)(-fRadius*sin(fAngle) + 0.5));        }        EndPaint(hwnd, &ps);        break;    case WM_DESTROY:        DeleteObject(hTotRgn);        PostQuitMessage(0);        return 0;    }    return DefWindowProc(hwnd, message, wParam, lParam);}

 

學習windows編程 day5 之 地區裁剪

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.