void CPropCurtain::OnPaint() { //擦除已画图形 this->Invalidate(true); CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CPropertyPage::OnPaint() /* //CClientDC dc(this); CDC* pDC=GetDC(); CDC* pMemDC=new CDC; CBitmap* pMemBitmap=new CBitmap; CBitmap* pMemBitmapOld; CRect rectTemp; pMemDC->CreateCompatibleDC(NULL); pMemBitmap->CreateCompatibleBitmap(pDC,rectTemp.Width(),rectTemp.Height()); pMemBitmapOld=pMemDC->SelectObject(pMemBitmap); //CBitmap* pBitmapOld=MemDC.SelectObject(&MemBitmap); //MemDC.FillSolidRect(0,0,rectTemp.Width(),rectTemp.Height(),RGB(255,255,255)); CBrush brush2(RGB(0,128,255)); pMemDC->SelectObject(brush2); pMemDC->Rectangle(90,66,90+width,250); pMemDC->Rectangle(290+(200-width),66,490,250); pDC->BitBlt(rectTemp.left,rectTemp.top,rectTemp.Width(),rectTemp.Height(), pMemDC,0,0,SRCCOPY); pMemDC->SelectObject(pMemBitmapOld); pMemBitmap->DeleteObject(); pMemDC->DeleteDC(); */ //窗帘上部 CBrush brush1(RGB(128,0,0)); dc.SelectObject(brush1); HRGN hRgn,hRgn1,hRgn2; hRgn = CreateRectRgn(50, 50, 530, 66); hRgn1 = CreateEllipticRgn(42, 50, 58, 66); hRgn2 = CreateEllipticRgn(522, 50, 538, 66); CombineRgn(hRgn, hRgn, hRgn1, RGN_OR); CombineRgn(hRgn, hRgn, hRgn2, RGN_OR); CRgn* rgn=CRgn::FromHandle(hRgn); dc.FillRgn(rgn, &brush1); DeleteObject(hRgn); DeleteObject(hRgn1); DeleteObject(hRgn2); //窗帘绘制 CPen pen(PS_SOLID,1,RGB(255,0,0)); //CBrush* pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); CBrush brush2(RGB(0,128,255)); dc.SelectObject(brush2); //CClientDC dc(this); dc.SelectObject(&pen); dc.Rectangle(90,66,90+width,250); dc.Rectangle(290+(200-width),66,490,250); }
void CombieCloverRgn(HRGN &hRgnClip, int cxClient, int cyClient) { HRGN hRgnTemp[6] ; int i; HCURSOR hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)) ; ShowCursor (TRUE) ; if (hRgnClip) DeleteObject (hRgnClip) ; hRgnTemp[0] = CreateEllipticRgn (0, cyClient / 3, cxClient / 2, 2 * cyClient / 3) ; hRgnTemp[1] = CreateEllipticRgn (cxClient / 2, cyClient / 3, cxClient, 2 * cyClient / 3) ; hRgnTemp[2] = CreateEllipticRgn (cxClient / 3, 0, 2 * cxClient / 3, cyClient / 2) ; hRgnTemp[3] = CreateEllipticRgn (cxClient / 3, cyClient / 2, 2 * cxClient / 3, cyClient) ; hRgnTemp[4] = CreateRectRgn (0, 0, 1, 1) ; hRgnTemp[5] = CreateRectRgn (0, 0, 1, 1) ; hRgnClip = CreateRectRgn (0, 0, 1, 1) ; CombineRgn (hRgnTemp[4], hRgnTemp[0], hRgnTemp[1], RGN_OR) ; CombineRgn (hRgnTemp[5], hRgnTemp[2], hRgnTemp[3], RGN_OR) ; CombineRgn (hRgnClip, hRgnTemp[4], hRgnTemp[5], RGN_XOR) ; for (i = 0 ; i < 6 ; i++) DeleteObject (hRgnTemp[i]) ; SetCursor (hCursor) ; ShowCursor (FALSE) ; }
QT_BEGIN_NAMESPACE /* In Windows versions before Windows Vista CreateRectRgn - when called in a multi-threaded environment - might return an invalid handle. This function works around this limitation by verifying the handle with a quick GetRegionData() call and re-creates the region if necessary. */ HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom) { const int tries = 10; for (int i = 0; i < tries; ++i) { HRGN region; switch (type) { case QRegion::Rectangle: region = CreateRectRgn(left, top, right, bottom); break; case QRegion::Ellipse: #ifndef Q_OS_WINCE region = CreateEllipticRgn(left, top, right, bottom); #endif break; } if (region) { if (GetRegionData(region, 0, 0)) return region; else DeleteObject(region); } } return 0; }
static PetscErrorCode PetscDrawPoint_Win32(PetscDraw draw,PetscReal x,PetscReal y,int color) { PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data; HBRUSH hbrush; HRGN hrgn; int radius; int x1,yone; HDC hdc; PetscFunctionBegin; TranslateColor_Win32(draw,color); x1 = XTRANS(draw,windraw,x); yone = YTRANS(draw,windraw,y); hbrush = CreateSolidBrush(windraw->currentcolor); if(windraw->node->DoubleBuffered) { hdc = windraw->node->DoubleBuffer; } else { hdc = windraw->node->Buffer; } /* desired size is one logical pixel so just turn it on */ if (windraw->pointdiameter == 1) { SetPixelV(hdc,x1,yone,windraw->currentcolor); } else { /* draw point around position determined */ radius = windraw->pointdiameter/2; /* integer division */ hrgn = CreateEllipticRgn(x1-radius,yone-radius,x1+radius,yone+radius); FillRgn(hdc,hrgn,hbrush); } /* Forces a WM_PAINT and erases background */ InvalidateRect(windraw->hWnd,NULL,TRUE); UpdateWindow(windraw->hWnd); PetscFunctionReturn(0); }
void Init(void) { HRGN TSt; HBITMAP hBmpBack, hBmpCircle; hMenu = CreatePopupMenu(); AppendMenu (hMenu,0,IDM_BACK1, szMenuBack1); AppendMenu (hMenu,0,IDM_BACK2, szMenuBack2); AppendMenu (hMenu,MF_SEPARATOR,0,NULL); AppendMenu (hMenu,0,IDM_CIRCLE1, szMenuCircle1); AppendMenu (hMenu,0,IDM_CIRCLE2, szMenuCircle2); AppendMenu (hMenu,MF_SEPARATOR,0,NULL); AppendMenu (hMenu,0,IDM_EXIT, szMenuExit); CheckMenuRadioItem (hMenu,IDM_BACK1,IDM_BACK2,IDM_BACK1,0); CheckMenuRadioItem (hMenu,IDM_CIRCLE1,IDM_CIRCLE2,IDM_CIRCLE1,0); TSt = CreateEllipticRgn (0,0,CLOCK_SIZE+1,CLOCK_SIZE+1); SetWindowRgn (hWinMain, TSt, TRUE); DeleteObject (TSt); SetWindowPos (hWinMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); dwNowBack = IDB_BACK1; dwNowCircle = IDB_CIRCLE1; CreateBackGround(); CreateClockPic(); SetTimer (hWinMain, ID_TIMER, 1000, NULL); return; }
HRGN getLastEllipticRegion(RECT rect, int stroke, BOOL* flag) { HRGN result = CreateEllipticRgn( rect.left - (stroke / 2) - 1, rect.top - (stroke / 2) - 1, rect.right + (stroke / 2) + 1, rect.bottom + (stroke / 2) + 1); *flag = TRUE; return result; }
long WMSize (HWND hwnd, WPARAM wParam, LPARAM lParam) { HRGN hRgnTemp [6]; HCURSOR hCursor; short i; cxClient = LOWORD (lParam); cyClient = HIWORD (lParam); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); ShowCursor (TRUE); if (hRgnClip != NULL) DeleteObject (hRgnClip); hRgnTemp [0] = CreateEllipticRgn (0, cyClient / 3, cxClient / 2, 2*cyClient / 3); hRgnTemp [1] = CreateEllipticRgn ( cxClient / 2, cyClient / 3, cxClient, 2*cyClient / 3); hRgnTemp [2] = CreateEllipticRgn ( cxClient / 3, 0, 2*cxClient / 3, cyClient / 2); hRgnTemp [3] = CreateEllipticRgn ( cxClient / 3, cyClient / 2, 2*cxClient / 3, cyClient); hRgnTemp [4] = CreateRectRgn (0, 0, 1, 1); hRgnTemp [5] = CreateRectRgn (0, 0, 1, 1); hRgnClip = CreateRectRgn (0, 0, 1, 1); if (CombineRgn (hRgnTemp [4], hRgnTemp [0], hRgnTemp [1], RGN_OR) == ERROR || CombineRgn (hRgnTemp [5], hRgnTemp [2], hRgnTemp [3], RGN_OR) == ERROR || CombineRgn (hRgnClip, hRgnTemp [4], hRgnTemp [5], RGN_XOR) == ERROR) MessageBox (hwnd, "Could not create region, window size too big!", "Clover", MB_ICONEXCLAMATION | MB_OK); for (i = 0; i < 6; i++) DeleteObject (hRgnTemp [i]); SetCursor (hCursor); ShowCursor (FALSE); return 0; }
HWND createMainDialog( HINSTANCE hInstance ) { dcx::dcxWin32DialogTemplate tpl; // Create the dialog tpl.setSizeInDialogUnits( 469, 469 ); tpl.setStyleAsPrompt(); tpl.setStyle( WS_POPUP | WS_CLIPSIBLINGS | WS_SYSMENU | DS_ABSALIGN | DS_NOIDLEMSG | DS_CENTER ); tpl.setTitle( "Evidyon" ); tpl.addEditBoxInDialogUnits( ID_EDITBOX_STATUS, WS_VSCROLL|WS_BORDER|ES_MULTILINE|ES_READONLY|ES_LEFT|ES_AUTOVSCROLL, 10+55, 10 +50, 180, 70, "Contacting update server..." ); tpl.addButtonInDialogUnits( ID_BUTTON_STARTGAME, WS_DISABLED, 10+55, 90+10+5 + 35 , 180, 25, "Play Evidyon" ); tpl.addProgressBarInDialogUnits( ID_PROGRESS, PBS_SMOOTH, 10+55, 90+10+5 +35 + 5 , 180, 15 ); tpl.addButtonInDialogUnits( ID_BUTTON_EXIT, 0, 10+80+30, 90+10+10+15+10+15+5 +50+20+5+15, 70, 20, "Quit" ); tpl.addComboBoxInDialogUnits( ID_COMBO_DISPLAYMODE, WS_DISABLED|CBS_DROPDOWN|CBS_HASSTRINGS|CBS_DROPDOWNLIST| WS_VSCROLL, 10+55, 90+10+10+15+10+15+5 +50+20, 180, 150 ); BYTE buffer[1024]; HWND hWnd = createDialog( hInstance, tpl.compile( buffer, sizeof(buffer) ), NULL ); { // set the window's icon HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon); SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } if( dcx::dcxWin32WindowsVersionIs2000OrXP() ) { // Set this window up as a layered window, which is only supported on 2000/xp systems #define LWA_COLORKEY 0x00000001 #define WS_EX_LAYERED 0x00080000 typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes; HMODULE hUser32 = GetModuleHandle("user32.dll"); SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes"); SetWindowLong( hWnd, GWL_EXSTYLE, GetWindowLong( hWnd, GWL_EXSTYLE) | WS_EX_LAYERED ); SetLayeredWindowAttributes( hWnd, SKIN_TRANSPARENT_COLOR, 0, LWA_COLORKEY ); } else { // Use a region to define this window. This is less efficient on new systems than using the layered approach HRGN hRegion = CreateEllipticRgn( 0, 0, 469, 469 ); SetWindowRgn( hWnd, hRegion, TRUE ); } // Update the window. Get rid of the progress bar for now, since it doesn't do // anything until an update needs to be downloaded. ShowWindow( GetDlgItem( hWnd, ID_PROGRESS ), SW_HIDE ); ShowWindow( GetDlgItem( hWnd, ID_EDITBOX_STATUS ), SW_HIDE ); ShowWindow( GetDlgItem( hWnd, ID_BUTTON_STARTGAME ), SW_HIDE ); ShowWindow( hWnd, SW_SHOW ); // Return the window we just created return hWnd; }
LRESULT _stdcall WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static HDC hDC = GetWindowDC(hWnd); static HRGN hRgn = CreateRectRgn(120, 70, 280, 230); switch(uMsg) { case WM_ERASEBKGND: { DefWindowProc(hWnd, uMsg, wParam, lParam); FillRgn(hDC, hRgn, CreateSolidBrush(RGB(255, 165, 0))); // Orange SelectObject(hDC, hRgn); return 0; } case WM_CREATE: { HRGN hRgn1 = CreateEllipticRgn(0, 0, 400, 300); HRGN hRgn2 = CreateEllipticRgn(150, 100, 250, 200); CombineRgn(hRgn1, hRgn1, hRgn2, RGN_XOR); SetWindowRgn(hWnd, hRgn1, TRUE); DeleteObject(hRgn1); DeleteObject(hRgn2); break; } case WM_LBUTTONDOWN: { SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0); break; } case WM_DESTROY: { DeleteObject(hRgn); ReleaseDC(hWnd, hDC); PostQuitMessage(0); break; } } return DefWindowProc(hWnd, uMsg, wParam, lParam);; }
VOID GameScene::ScenePaint(HDC hdc, HRGN *hRgn , HBITMAP hShipBit, HBITMAP hWeaponBit, HBITMAP hUIBit, HBITMAP hMapBit) { DrawLocalBitmap(hdc, crt.left, crt.top, crt.right, crt.bottom, IMG_UI_BACK01_INDEX, hUIBit); //클리핑 영역 *hRgn = CreateEllipticRgn(GameScreen.left, GameScreen.top, GameScreen.right, GameScreen.bottom); SelectClipRgn(hdc, *hRgn); //월드맵 DrawWorldMap(hdc, hMapBit); MyFleet->FleetPaint(hdc, hShipBit); }
VOID PenBrushDemo(HDC hdc) { HPEN hPen = CreatePen(PS_DASHDOT, 3, myColor); SelectObject(hdc, hPen); MoveToEx(hdc, 100, 100, NULL); LineTo(hdc, 200, 200); Rectangle(hdc, 100, 200, 300, 300); Ellipse(hdc, 100, 200, 300, 300); HRGN hRegion = CreateEllipticRgn(100, 200, 300, 300); HBRUSH hbrush = CreateSolidBrush(RGB(23, 100, 40)); FillRgn(hdc, hRegion, hbrush); Ellipse(hdc, 100, 200, 300, 300); }
static void hugsprim_CreateEllipticRgn_3(HugsStackPtr hugs_root) { HsInt32 arg1; HsInt32 arg2; HsInt32 arg3; HsInt32 arg4; HsPtr res1; arg1 = hugs->getInt32(); arg2 = hugs->getInt32(); arg3 = hugs->getInt32(); arg4 = hugs->getInt32(); res1 = CreateEllipticRgn(arg1, arg2, arg3, arg4); hugs->putPtr(res1); hugs->returnIO(hugs_root,1); }
void fungshuei() { HBITMAP bmp; // Allocating 5000 Bitmaps of size 0xf80 leaving 0x80 space at end of page. for (int k = 0; k < 5000; k++) { //bmp = CreateBitmap(1685, 2, 1, 8, NULL); //800 = 0x8b0 820 = 0x8e0 1730 = 0x1000 1700 = 0xfc0 1670 = 0xf70 bmp = CreateBitmap(1670, 2, 1, 8, NULL); // 1680 = 0xf80 1685 = 0xf90 allocation size 0xfa0 bitmaps[k] = bmp; } HACCEL hAccel, hAccel2; LPACCEL lpAccel; // Initial setup for pool fengshui. lpAccel = (LPACCEL)malloc(sizeof(ACCEL)); SecureZeroMemory(lpAccel, sizeof(ACCEL)); // Allocating 7000 accelerator tables of size 0x40 0x40 *2 = 0x80 filling in the space at end of page. HACCEL *pAccels = (HACCEL *)malloc(sizeof(HACCEL) * 7000); HACCEL *pAccels2 = (HACCEL *)malloc(sizeof(HACCEL) * 7000); for (INT i = 0; i < 7000; i++) { hAccel = CreateAcceleratorTableA(lpAccel, 1); hAccel2 = CreateAcceleratorTableW(lpAccel, 1); pAccels[i] = hAccel; pAccels2[i] = hAccel2; } // Delete the allocated bitmaps to free space at beiginig of pages for (int k = 0; k < 5000; k++) { DeleteObject(bitmaps[k]); } //allocate Gh04 5000 region objects of size 0xbc0 which will reuse the free-ed bitmaps memory. for (int k = 0; k < 5000; k++) { CreateEllipticRgn(0x79, 0x79, 1, 1); //size = 0xbc0 } // Allocate Gh05 5000 bitmaps which would be adjacent to the Gh04 objects previously allocated for (int k = 0; k < 5000; k++) { bmp = CreateBitmap(0x52, 1, 1, 32, NULL); //size = 3c0 bitmaps[k] = bmp; } // Allocate 17500 clipboard objects of size 0x60 to fill any free memory locations of size 0x60 for (int k = 0; k < 1700; k++) { //1500 AllocateClipBoard2(0x30); } // delete 2000 of the allocated accelerator tables to make holes at the end of the page in our spray. for (int k = 2000; k < 4000; k++) { DestroyAcceleratorTable(pAccels[k]); DestroyAcceleratorTable(pAccels2[k]); } }
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch ( msg ) { case WM_SIZE: RECT r; GetWindowRect( hWnd, &r ); SetWindowRgn( hWnd, CreateEllipticRgn( 0, 0, r.right - r.left, r.bottom - r.top ), TRUE ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; default: return DefWindowProc( hWnd, msg, wParam, lParam ); } return 0; }
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int) { HWND hWnd = CreateWindow(_T("EDIT"), NULL, WS_OVERLAPPEDWINDOW, 10, 10, 200, 100, GetDesktopWindow(), NULL, hInst, NULL); ShowWindow(hWnd, SW_SHOW); SetWindowText(hWnd, szRectWin); MyMessageBox(NULL, szRectWin, szProgram, MB_OK); HRGN hRgn = CreateEllipticRgn(0, 0, 200, 100); SetWindowRgn(hWnd, hRgn, TRUE); DeleteObject(hRgn); SetWindowText(hWnd, szEptcWin); MyMessageBox(NULL, szEptcWin, szProgram, MB_OK); DestroyWindow(hWnd); return 0; }
BOOL KDCAttributes::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch ( uMsg ) { case WM_INITDIALOG: m_hWnd = hWnd; { HWND hOK = GetDlgItem(hWnd, IDOK); RECT rect; GetWindowRect(hOK, & rect); HRGN hRgn = CreateEllipticRgn(0, 0, (rect.right - rect.left), (rect.bottom - rect.top)); SetWindowRgn(hOK, hRgn, TRUE); } m_List.FromDlgItem(hWnd, IDC_DCATTRIBUTES); return OnInitDialog(); case WM_COMMAND: switch ( wParam ) { case IDOK: EndDialog(hWnd, TRUE); break; default: return FALSE; } return TRUE; } return FALSE; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { HDC hDC1 = CreateIC(_T("DISPLAY"), NULL, NULL, NULL); HDC hDC2 = CreateDC(_T("DISPLAY"), NULL, NULL, NULL); BOOL r = Rectangle(hDC1, 10, 10, 20, 200); int rs = GetLastError(); r = Rectangle(hDC2, 10, 10, 20, 200); rs = GetLastError(); HWND hWnd = CreateWindow(_T("EDIT"), NULL, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 10, 10, 200, 100, GetDesktopWindow(), NULL, hInstance, NULL); HWND hWnd1 = CreateWindow(_T("EDIT"), NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 5, 5, 20, 20, hWnd, NULL, hInstance, NULL); ShowWindow(hWnd, SW_SHOW); Test(hWnd, _T("Rectangular Window")); HRGN hRgn = CreateEllipticRgn(0, 0, 300, 300); SetWindowRgn(hWnd, hRgn, TRUE); Test(hWnd, _T("Elliptic Window")); DestroyWindow(hWnd); DeleteDC(hDC1); DeleteDC(hDC2); return 0; }
HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom) { const int tries = 10; for (int i = 0; i < tries; ++i) { HRGN region = 0; switch (type) { case QRegion::Rectangle: region = CreateRectRgn(left, top, right, bottom); break; case QRegion::Ellipse: #ifndef Q_OS_WINCE region = CreateEllipticRgn(left, top, right, bottom); #endif break; } if (region) { if (GetRegionData(region, 0, 0)) return region; else DeleteObject(region); } } return 0; }
expect(100,point[2].X); /* buf + 11 */ expect(10, point[2].Y); } expect(0, point[3].X); /* buf + 12 */ todo_wine{ expect(10, point[3].Y); expect_dword(buf + 13, 0x81010100); /* closed */ } } GdipDeleteRegion(region); DeleteObject(hrgn); /* ellipse */ hrgn = CreateEllipticRgn(0, 0, 100, 10); status = GdipCreateRegionHrgn(hrgn, ®ion); todo_wine expect(Ok, status); status = GdipGetRegionDataSize(region, &needed); todo_wine{ expect(Ok, status); expect(216, needed); } status = GdipGetRegionData(region, (BYTE*)buf, sizeof(buf), &needed); todo_wine{ expect(Ok, status); expect(216, needed); expect_dword(buf, 208); expect_magic((DWORD*)(buf + 2)); expect_dword(buf + 3, 0);
// // This is the Window Procedure for handling windows messages // LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient,cyClient; HDC hdc ; PAINTSTRUCT ps ; HRGN hRgn1, hRgn2, hRgn; // region to allow for drawing HGDIOBJ penObject; // so we can release penObject for drawing TCHAR *ButtonName[] = {TEXT("Olives"), TEXT("Peppers"), TEXT("Onions"),TEXT("Havarti"), TEXT("Cheddar"), TEXT("Swiss"), TEXT("WholeWheat"), TEXT("9 Grains"), TEXT("White"), }; static RECT rect ; // region of client window static HMENU hMenu; // handle to menu static INT toppingSelection = 0, breadSelection =0; // current menu selection static int x, y; // mouse position static HWND hButton[9]; // the 3 topping buttons static HWND hButtonToasted; // the "OVEN" Button static COLORREF breadColor=RGB(204,186, 46); SCROLLINFO si; static int iVertPos =0; WNDPROC wpOriginalWndProc; static LPCWSTR instruct= L"SCROLL OVER FOR INSTRUCTIONS!" L"\t\t-->>\t\t\t\t\t\t\tthis way\t\t\t\t-->>" L"\t\t\t\t Step 1. Select a type of bread " L"\t\t\t\t\tStep 2. Choose your toppings " L"\t\t\t\t 3. Check out good luck next time"; switch (message) { case WM_CREATE: GetClientRect(hwnd, &rect); // get dimensions of current window client // so we know where to place the buttons // Create the selection radio pushbuttons for (int i=0;i<=2; i++){ hButton[i] = CreateWindow(TEXT("BUTTON"), ButtonName[i], WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON|WS_GROUP | WS_TABSTOP, 10 + 100*i, rect.bottom-50, 100,20, hwnd, (HMENU)( ID_BASE + i ), ((LPCREATESTRUCT)lParam)->hInstance, NULL); // fill end here } for (int i=3;i<=5; i++){ hButton[i] = CreateWindow(TEXT("BUTTON"), ButtonName[i], WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON, 10 + 100*(i-3), rect.bottom-80, 100,20, hwnd, (HMENU)( ID_BASE + i ), ((LPCREATESTRUCT)lParam)->hInstance, NULL); // fill end here } for (int i=6;i<=8; i++){ hButton[i] = CreateWindow(TEXT("BUTTON"), ButtonName[i], WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON , 10 + 105*(i-6), rect.bottom-110, 105,20, hwnd, (HMENU)( ID_BASE + i ), ((LPCREATESTRUCT)lParam)->hInstance, NULL); } // Initialize menu and button selections. // We have mapped the "base" to "cheese"; See resource.h // fill start here hMenu = GetMenu(hwnd); // handle to menu toppingSelection = ID_BASE; // start with olives breadSelection = ID_BASE +6 ; //start with wholewheat CheckMenuItem(hMenu, toppingSelection, MF_CHECKED); // check menu CheckMenuItem(hMenu, breadSelection, MF_CHECKED); // SendMessage(hwnd, WM_COMMAND, ; // check button //CheckDlgButton(hwnd, ID_TOPPINGS_CHEESE, BST_CHECKED); SendMessage(hButton[toppingSelection-ID_BASE], BM_SETCHECK, BST_CHECKED, 0); SendMessage(hButton[breadSelection - ID_BASE], BM_SETCHECK, BST_CHECKED, 0); // fill end here // Create the "OVEN" push button hButtonToasted = CreateWindow(TEXT("BUTTON"), // button class TEXT("Toaster OFF"), // window name WS_CHILD | WS_VISIBLE | BS_MULTILINE | BS_PUSHBUTTON, // pushbutton style child window rect.right-130, rect.bottom-130, // location bottom right 100,100, hwnd, (HMENU) ID_TOASTED, // fourth unique child window id ((LPCREATESTRUCT)lParam)->hInstance, NULL); // Perform some initializations related to the OVEN button // 1. Display it's initial text // 2. Set keyboard focus to OVEN proc // 3. Subclass the OVEN button window // (Look up msdn "Subclassing a Window" for details) // fill stsart here SetToasted(hButtonToasted,0); // display that OVEN is off default SetFocus(hButtonToasted); // all keyboard action directed to OVEN proc wpOriginalWndProc = (WNDPROC) SetWindowLong(hButtonToasted, GWLP_WNDPROC, (LONG_PTR)NewButtonWndProc); // to take over original wndproc SetClassLongPtr(hwnd, 0, (LONG) wpOriginalWndProc); // fill end here // fill end here cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); si.cbSize = sizeof(si); si.fMask = SIF_ALL; si.nMin = 0; si.nMax = 2000; si.nPos = 0; si.nPage = 30; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); return 0; case WM_HSCROLL: si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_HORZ, &si); iVertPos = si.nPos; switch (LOWORD(wParam)) { case SB_LINELEFT: si.nPos-=50; break; case SB_LINERIGHT: si.nPos+=50; break; case SB_PAGELEFT: si.nPos -= si.nPage; break; case SB_PAGERIGHT: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } hRgn = CreateRectRgn(0, 0, rect.right, (rect.bottom/2)-100); //CombineRgn(hRgn,hRgn, hRgn1, RGN_OR); si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); GetScrollInfo(hwnd, SB_HORZ, &si); if (si.nPos != iVertPos){ // Fill in start InvalidateRgn(hwnd, hRgn, TRUE); // Fill in end } return 0; case WM_LBUTTONDOWN: // When the left-mouse button is pressed, we do all our drawing. x = LOWORD(lParam); // x position of left mouseclick y = HIWORD(lParam); // y position of left mouseclick hdc = GetDC(hwnd); // Limit all drawing to the region of the Pizza base hRgn = CreateEllipticRgn(rect.right/2-400,rect.bottom/2-50,rect.right/2+400,rect.bottom/2+50); hRgn1 = CreateEllipticRgn(rect.right/2-400,rect.bottom/2-100,rect.right/2+400,rect.bottom/2); CombineRgn(hRgn,hRgn, hRgn1, RGN_OR); SelectClipRgn(hdc, hRgn); // Get a pen object, so we can change colors penObject = GetStockObject(DC_BRUSH); SelectObject(hdc, penObject); // fill start here if(toppingSelection == ID_TOPPINGS_OLIVES && !((LPCWSTR)GetWindowLongPtr(hwnd, 0))) { SetDCBrushColor(hdc, RGB(255,255,0)); SelectObject(hdc, penObject); Rectangle(hdc, x-5, y-5, x+10, y+10); } else if(toppingSelection == ID_TOPPINGS_PEPPERS && !((LPCWSTR)GetWindowLongPtr(hwnd, 0))) { SetDCBrushColor(hdc, RGB(255,0,0)); SelectObject(hdc, penObject); Ellipse(hdc, x-20, y-20, x+20, y+20); } else if(toppingSelection == ID_TOPPINGS_ONIONS && !((LPCWSTR)GetWindowLongPtr(hwnd, 0))) { SetDCBrushColor(hdc, RGB(0,122,122)); SelectObject(hdc, penObject); RoundRect(hdc, x-10, y-15, x+10, y+15, 10, 10); } // fill end here // Release pen object and DC DeleteObject(penObject); ReleaseDC(hwnd, hdc); return 0; case WM_COMMAND: // WM_COMMAND is sent from child to parent window when // a menu checkbox is checked (LOWORD(wParam) is menu checkbox ID) // or when a pushbutton is clicked (LOWORD(wParam) is child window ID). // By default, Keyboard focus is also given to the button window that was checked/pushed. // However, we want Keyboard messages sent to OVEN Button. // We want to do all OVEN button related message handling to be done in OVEN subclassed proc. // Therefore, call setFocus() because of previous activity that changed keyboard focus. SetFocus(hButtonToasted); if ( LOWORD(wParam) == ID_TOASTED) { // do nothing; do not process pushbutton clicks for OVEN button here } else if ( !(LPCWSTR)GetWindowLongPtr(hwnd, 0) && !(LOWORD(wParam) == ID_TOASTED) ) // Legally clicked a selection button { // Sychronize menu and radio selections here. // Cancel previous selection, and update menu and buttons with new selection // fill start here hRgn = CreateEllipticRgn(rect.right/2-400,rect.bottom/2-50,rect.right/2+400,rect.bottom/2+50); hRgn1 = CreateEllipticRgn(rect.right/2-400,rect.bottom/2-100,rect.right/2+400,rect.bottom/2); CombineRgn(hRgn,hRgn, hRgn1, RGN_OR); if((LOWORD(wParam))-ID_BASE < 6){ CheckMenuItem(hMenu, toppingSelection, MF_UNCHECKED); SendMessage(hButton[toppingSelection - ID_BASE], BM_SETCHECK, MF_UNCHECKED, 0); //update current selection toppingSelection = LOWORD(wParam); //select menu item CheckMenuItem(hMenu, toppingSelection, MF_CHECKED); //select radio button SendMessage(hButton[toppingSelection -ID_BASE], BM_SETCHECK, MF_CHECKED, 0); }else{ CheckMenuItem(hMenu, breadSelection, MF_UNCHECKED); SendMessage(hButton[breadSelection - ID_BASE], BM_SETCHECK, MF_UNCHECKED, 0); //update current selection breadSelection = LOWORD(wParam); //select menu item CheckMenuItem(hMenu, breadSelection, MF_CHECKED); //select radio button SendMessage(hButton[breadSelection -ID_BASE], BM_SETCHECK, MF_CHECKED, 0); if (breadSelection == ID_BREAD_WHOLEWHEAT && !((LPCWSTR)GetWindowLongPtr(hwnd, 0))) { breadColor = RGB(204,186, 46); InvalidateRgn(hwnd, hRgn, TRUE); }else if(breadSelection == ID_BREAD_9GRAINS && !((LPCWSTR)GetWindowLongPtr(hwnd, 0))) { breadColor =RGB(228 , 213, 183); InvalidateRgn(hwnd, hRgn, TRUE); }else if(breadSelection == ID_BREAD_WHITE && !((LPCWSTR)GetWindowLongPtr(hwnd, 0))) { breadColor =RGB(239,242,179); InvalidateRgn(hwnd, hRgn, TRUE); } } } return 0; case WM_PAINT: // setup hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; SelectObject(hdc, GetStockObject(DC_PEN)); SetDCPenColor(hdc, breadColor); rect.top +=100; rect.left+=400-iVertPos; DrawText( hdc, instruct, -1, &rect, DT_SINGLELINE | DT_NOCLIP |DT_EXPANDTABS) ; // Draw "Pizza Dough". Circle centred in main window. penObject = GetStockObject(DC_BRUSH); rect.top-=100; rect.left-=500; SelectObject(hdc, penObject); SetDCBrushColor(hdc, breadColor); SetViewportOrgEx(hdc,rect.right/2,rect.bottom/2,NULL);//set origin Ellipse(hdc, -400, -50, 400, 50); Ellipse(hdc, -400, -100, 400, 0); //circle // cleanup DeleteObject(penObject); EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
void CTransButton::DrawButton(HDC hDestDC) { CRect rc; GetClientRect(rc); int nWindth=rc.Width(); int nHeight=rc.Height(); HDC hDC=CreateCompatibleDC(hDestDC);//创建兼容DC,采用双缓冲画出 HBITMAP hBitmap=CreateCompatibleBitmap(hDestDC,nWindth,nHeight); HBITMAP hOldBitmap=(HBITMAP)SelectObject(hDC,hBitmap); SetBkMode(hDC,TRANSPARENT); //把父窗口的背景图复制到按钮的DC上,实现视觉透明---------------- CPoint pt(0,0); MapWindowPoints(m_pParentWnd,&pt,1); if(g_pBackDC) { BitBlt(hDC,0,0,nWindth,nHeight,g_pBackDC->GetSafeHdc(), pt.x,pt.y,SRCCOPY); } //------------------------------------------------------------- HDC hMaskDC=CreateCompatibleDC(hDestDC); HBITMAP hMaskBitmap=CreateCompatibleBitmap(hDestDC,nWindth,nHeight); HBITMAP hOldMaskBitmap=(HBITMAP)SelectObject(hMaskDC,hMaskBitmap); int nAlpha=100;//0--255 int nOffset=0; if (m_BkPic.IsEmpty()) { HBRUSH hbr=CreateSolidBrush(m_bkColor); FillRect(hMaskDC,&rc,hbr); DeleteObject(hbr); } else { CDC *pDC = CDC::FromHandle(hMaskDC); CImage img; HRESULT hResult = img.Load(m_BkPic); if(SUCCEEDED(hResult)) { pDC->SetStretchBltMode(STRETCH_HALFTONE); img.Draw(pDC->m_hDC, 0, 0, rc.Width(), rc.Height(), 0, 0, img.GetWidth(), img.GetHeight()); } else { //加载默认按钮背景图片 CDoFile doFile; CString path = doFile.GetExeFullFilePath(); path += _T("\\背景\\按钮背景图片.bmp"); hResult = img.Load(path); if(SUCCEEDED(hResult)) { pDC->SetStretchBltMode(STRETCH_HALFTONE); img.Draw(pDC->m_hDC, 0, 0, rc.Width(), rc.Height(), 0, 0, img.GetWidth(), img.GetHeight()); } else { HBRUSH hbr=CreateSolidBrush(m_bkColor); FillRect(hMaskDC,&rc,hbr); DeleteObject(hbr); } } } if(m_bDisable){ nAlpha=m_nAlpha; }else if(m_bDown){ nAlpha=180; nOffset=1; }else if(m_bOver){ nAlpha=150; }else{ nAlpha=m_nAlpha; } BLENDFUNCTION blend; memset( &blend, 0, sizeof( blend) ); blend.BlendOp= AC_SRC_OVER; blend.SourceConstantAlpha= nAlpha; // 透明度 最大255 HRGN hRgn; switch(m_ButtonType) { case enumRoundRectButton: hRgn=CreateRoundRectRgn(0,0,nWindth,nHeight,5,5); break; case enumRectButton: hRgn=CreateRectRgn(0,0,nWindth,nHeight); break; case enumEllipseButton: hRgn=CreateEllipticRgn(0,0,nWindth,nHeight); break; default: break; } SelectClipRgn (hDC,hRgn); //实现透明 AlphaBlend (hDC,0,0,nWindth,nHeight,hMaskDC,0,0,nWindth,nHeight,blend); ///////////// SelectObject(hMaskDC,hOldMaskBitmap); DeleteObject(hMaskBitmap); DeleteDC(hMaskDC); //////////////显示文字 CString strText; GetWindowText(strText); if(strText!=_T("")) { rc.InflateRect(-2,-2); rc.OffsetRect(nOffset,nOffset); CFont font; font.CreateFontIndirect(&m_lfFont); HFONT hOldFont=(HFONT)SelectObject(hDC,font); ::SetTextColor(hDC,m_textColor); ::DrawText(hDC,strText,-1,&rc,DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_WORD_ELLIPSIS); ::SelectObject(hDC,hOldFont); } SelectClipRgn (hDC,NULL); DeleteObject(hRgn);//释放HRGN //复制到控件的DC上------------------------ BitBlt(hDestDC,0,0,nWindth,nHeight,hDC,0,0,SRCCOPY); //回收资源 SelectObject(hDC,hOldBitmap); DeleteObject(hBitmap); DeleteDC(hDC); }
void CRadar::Update() { HDC dc; if (SUCCEEDED(lpSurface->GetDC(&dc))) { HBRUSH oldbrush; { // Löschen / Auf Farbe setzen PatBlt(dc,0,0,size,size,BLACKNESS); SelectObject(dc,GetStockObject(WHITE_PEN)); const HBRUSH green=CreateSolidBrush(RGB(0,64,0)); oldbrush=(HBRUSH)SelectObject(dc,green); Ellipse(dc,0,0,size,size); SelectObject(dc,oldbrush); DeleteObject(green); } const float sx=parent->pos.x,sy=parent->pos.z; const float mx=size/2.0f,my=size/2.0f; const float InvRation=1.0f/((0.4f)*(256.0f/float(size))); D3DMATRIX m; if (parent->IsType(IDChicken)) D3DUtil_SetRotateYMatrix(m,-parent->ang.y); else D3DUtil_SetRotateYMatrix(m,parent->ang.y); D3DVECTOR v; const HRGN rgn=CreateEllipticRgn(1,1,size-1,size-1); SelectClipRgn(dc,rgn); { // Begrenzung rendern D3DVECTOR b[4]={ D3DVECTOR(world->minx(),0,world->minz())-parent->pos, D3DVECTOR(world->maxx(),0,world->minz())-parent->pos, D3DVECTOR(world->maxx(),0,world->maxz())-parent->pos, D3DVECTOR(world->minx(),0,world->maxz())-parent->pos}; POINT p[4]; for (int i=0;i<4;i++) { D3DMath_VectorMatrixMultiply(b[i],b[i],m); b[i].x=b[i].x*InvRation+mx; b[i].z=-b[i].z*InvRation+my; p[i].x=(int)b[i].x; p[i].y=(int)b[i].z; } SelectObject(dc,GetStockObject(WHITE_PEN)); const HBRUSH green=CreateSolidBrush(RGB(0,128,0)); oldbrush=(HBRUSH)SelectObject(dc,green); Polygon(dc,&p[0],4); SelectObject(dc,oldbrush); DeleteObject(green); } // Grid rendern { D3DVECTOR v2; const HPEN pen1=CreatePen(PS_SOLID,1,RGB(0,192,0)),pen2=CreatePen(PS_SOLID,1,RGB(128,128,0)),pen3=CreatePen(PS_SOLID,1,RGB(0,128,128)),oldpen=(HPEN)SelectObject(dc,pen1); #define Grid 20 int ox=0,oy=0,oz=0,x,z; int num=int((size)/(Grid*InvRation))/2; if (parent->pos.x>0) while (ox<parent->pos.x)ox+=Grid; if (parent->pos.x<0) while (ox>parent->pos.x)ox-=Grid; if (parent->pos.z>0) while (oz<parent->pos.z)oz+=Grid; if (parent->pos.z<0) while (oz>parent->pos.z)oz-=Grid; if (TRUE) { // x/z SelectObject(dc,pen1); for (x=-num-1;x<=num+1;x++) // x-Achse { v.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation); v.y=0; v.z=size*0.5f; v2.x=float(x*(Grid*InvRation))-(parent->pos.x*InvRation)+(ox*InvRation); v2.y=0; v2.z=-int(size)*0.5f; D3DMath_VectorMatrixMultiply(v,v,m); D3DMath_VectorMatrixMultiply(v2,v2,m); MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL); LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z))); } for (z=-num-1;z<=num+1;z++) // z-Achse { v.x=size*0.5f; v.y=0; v.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation); v2.x=-int(size)*0.5f; v2.y=0; v2.z=float(z*(Grid*InvRation))-(parent->pos.z*InvRation)+(oz*InvRation); D3DMath_VectorMatrixMultiply(v,v,m); D3DMath_VectorMatrixMultiply(v2,v2,m); MoveToEx(dc,int(mx+(v.x)),int(my+(-v.z)),NULL); LineTo(dc,int(mx+(v2.x)),int(my+(-v2.z))); } } SelectObject(dc,oldpen); ::DeleteObject(pen1); ::DeleteObject(pen2); ::DeleteObject(pen3); } // --- COLORREF c; float s,x,y; D3DVECTOR p; HBRUSH brush; // Objekte rendern CObject* akt=game->chain->GetFirst(); while (akt) { c=RGB(255,0,0); s=3; switch(GetType(akt->id)) { case IDChicken: if (((CChicken*)akt)->dead!=0.0f)goto weiter; p=((CChicken*)akt)->pos; c=RGB(255,255,255); s=3; break; case IDBauer: if (((CBauer*)akt)->dead!=0.0f)goto weiter; if (((CBauer*)akt)->HasObject(IDDrescher))goto weiter; p=((CBauer*)akt)->pos; c=RGB(192,128,0); s=5; break; case IDStall: p=((CStall*)akt)->pos; c=RGB(214,160,32); s=7; break; case IDTree: p=((CTree*)akt)->pos; c=RGB(0,230,0); s=4; break; case IDGartenkralle: p=((CGartenkralle*)akt)->pos; c=RGB(255,214,0); s=2; break; case IDDrescher: p=((CDrescher*)akt)->pos; c=RGB(255,0,0); s=7; break; case IDGolfer: p=((CGolfer*)akt)->pos; c=RGB(192,192,192); s=2; break; case IDPlasmaCannon: p=((CPlasmaCannon*)akt)->pos; c=RGB(255,255,0); s=3; break; default:goto weiter; } p=p-parent->pos; D3DMath_VectorMatrixMultiply(p,p,m); x=p.x*InvRation; y=-p.z*InvRation; if ((x)*(x)+(y)*(y)<((size*0.5f)*(size*0.5f))-(4.0f*4.0f*4.0f*4.0f)) { x+=mx; y+=my; SelectObject(dc,brush=CreateSolidBrush(c)); SelectObject(dc,GetStockObject(NULL_PEN)); Ellipse(dc,int(x-s),int(y-s),int(x+s),int(y+s)); SelectObject(dc,oldbrush); ::DeleteObject(brush); } weiter: akt=akt->next; } SelectObject(dc,GetStockObject(WHITE_PEN)); Line(dc,size/2,(size*10)/18,size/2,(size*8)/18); Line(dc,(size*10)/18,size/2,(size*8)/18,size/2); SelectClipRgn(dc,NULL); ::DeleteObject(rgn); lpSurface->ReleaseDC(dc); } MakeTransparent(lpSurface,FALSE); }
SOM_Scope void SOMLINK ShapePartAdjustViewTypeShapes(ShapePart *somSelf, Environment *ev, ODFrame* frame) { ShapePartData *somThis = ShapePartGetData(somSelf); ShapePartMethodDebug("ShapePart","ShapePartAdjustViewTypeShapes"); try { // Call parent ShapePart_parent_SimplePart_AdjustViewTypeShapes(somSelf, ev, frame); ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev); // Get facets for frame ODFacet* facet = facets->First(ev); // Assume 1 facet delete facets; ODRect rect; ODTypeToken viewType = frame->GetViewType(ev); // Override SimplePart's behavior only if this is an embedded part displaying as frame. if((viewType == somThis->fSession->Tokenize(ev,kODViewAsFrame)) && (!frame->IsRoot(ev))) { // Set the used and active shape to a circle. int width, height; ODRgnHandle hrgnUsedAndActive; ODRect box; ODCanvas *canvas = facet->GetCanvas(ev); #ifdef _PLATFORM_OS2_ HPS hps; hps = ((ODOS2WindowCanvas*) canvas->GetPlatformCanvas(ev, kODPM))->GetPS(ev); // Obtain a PS #endif //_PLATFORM_OS2_ TempODShape frameShape = frame->AcquireFrameShape(ev, canvas); // Get bounding box frameShape->GetBoundingBox(ev, &box); // of frame width = FixedToInt(box.right)-FixedToInt(box.left); // circle to be height = abs(FixedToInt(box.top)-FixedToInt(box.bottom)); // constructed #ifdef _PLATFORM_OS2_ Point center; center.x = width/2; center.y = height/2; int rad = (width < height) ? center.x : center.y; // get radius GpiBeginPath(hps,1L); // Define GPI path GpiSetCurrentPosition(hps , ¢er); // for circle GpiFullArc(hps,DRO_OUTLINE,MAKEFIXED(rad,0)); GpiEndPath(hps); hrgnUsedAndActive = GpiPathToRegion(hps, 1, FPATH_ALTERNATE); // Convert path to GPI region ((ODOS2WindowCanvas *)canvas->GetPlatformCanvas(ev, kODPM))->ReleasePS(ev); // Release the canvas #elif defined(_PLATFORM_WIN32_) hrgnUsedAndActive = CreateEllipticRgn(0,0,width,height); // region from Ellipse box #endif //_PLATFORM_WIN32_ if(hrgnUsedAndActive) { // Use TempODShape so this object won't have to be released. TempODShape usedAndActiveShape = frame->CreateShape(ev); // create a shape usedAndActiveShape->SetRegion(ev, hrgnUsedAndActive); // assign the region to the shape // Set used and active shapes to the newly defined shape frame->ChangeUsedShape(ev, usedAndActiveShape, kODNULL); if(facet) { facet->ChangeActiveShape(ev, usedAndActiveShape, kODNULL); } } // hrgnUsedAndActive } // viewtype is frame and frame isn't root else { // Reset used and active shapes to frame shape frame->ChangeUsedShape(ev, kODNULL, kODNULL); if(facet) { facet->ChangeActiveShape(ev, kODNULL, kODNULL); } } } catch(...) { } }
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static HRGN hRgnClip ; static int cxClient, cyClient ; double fAngle, fRadius ; HCURSOR hCursor ; HDC hdc ; HRGN hRgnTemp[6] ; // HRGN just like RECT is a self-defined area. int i ; PAINTSTRUCT ps ; switch (iMsg) { // The task of WM_SIZE case is used to create a self-defined region as valid client area. case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)) ; ShowCursor (TRUE) ; if (hRgnClip) DeleteObject (hRgnClip) ; // delete old region before create a new one. // The apis below are used to create RGN just like RECT // other apis including CreateRoundRectRgn & CreatePolygonRgn etc.. // These apis will create region and be ready to be selected, after that the valid client area // will be changed to the region created instead of tranditional rect area. hRgnTemp[0] = CreateEllipticRgn (0, cyClient / 3, cxClient / 2, 2 * cyClient / 3) ; hRgnTemp[1] = CreateEllipticRgn (cxClient / 2, cyClient / 3, cxClient, 2 * cyClient / 3) ; hRgnTemp[2] = CreateEllipticRgn (cxClient / 3, 0, 2 * cxClient / 3, cyClient / 2) ; hRgnTemp[3] = CreateEllipticRgn (cxClient / 3, cyClient / 2, 2 * cxClient / 3, cyClient) ; hRgnTemp[4] = CreateRectRgn (0, 0, 1, 1) ; hRgnTemp[5] = CreateRectRgn (0, 0, 1, 1) ; hRgnClip = CreateRectRgn (0, 0, 1, 1) ; // combie region from the second and the third regions to the first region with the fourth style. // and the first region should be initialized with a small region. // RGN_AND: inter sect // RGN_OR: srcRgn1 || srcRgn2 // RGN_XOR: !RGN_AND // RGN_DIFF: the part belong to srcRgn1 but not belong to srcRgn2 // RGN_COPY: srcRgn1 and ignore srcRgn2 totally. // Return value: NULLREGION; SIMPLEREGION; COMPLEXREGION; ERROR CombineRgn (hRgnTemp[4], hRgnTemp[0], hRgnTemp[1], RGN_OR) ; CombineRgn (hRgnTemp[5], hRgnTemp[2], hRgnTemp[3], RGN_OR) ; CombineRgn (hRgnClip, hRgnTemp[4], hRgnTemp[5], RGN_XOR) ; for (i = 0 ; i < 6 ; i++) DeleteObject (hRgnTemp[i]) ; SetCursor (hCursor) ; ShowCursor (FALSE) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; // draw on region api // FillRgn, FrameRgn, InvertRgn, PaintRgn like FillRect, FrameRect ... etc. HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0)); FillRgn(hdc, hRgnClip, hBrush); DeleteObject(hBrush); // set the center position as the origin. SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ; // select self-defined region as valid client area. // so the painting will only happen in self-defined region. SelectClipRgn (hdc, hRgnClip) ; // equals to SelectObject(hdc, hRgnClip); // Use InvalidateRgn and ValidRgn instead of InvalidRect and ValidRect. fRadius = _hypot (cxClient / 2.0, cyClient / 2.0) ; for (fAngle = 0.0 ; fAngle < TWO_PI ; fAngle += TWO_PI / 360) { MoveToEx (hdc, 0, 0, NULL) ; LineTo (hdc, (int) ( fRadius * cos (fAngle) + 0.5), (int) (-fRadius * sin (fAngle) + 0.5)) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: DeleteObject (hRgnClip) ; // destroy region PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }