#include HWND hWnd=NULL; bool bRegioned; LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, \ LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndWc; wndWc.style = CS_OWNDC; wndWc.lpfnWndProc = (WNDPROC) WndProc; wndWc.cbClsExtra = 0; wndWc.cbWndExtra = 0; wndWc.hInstance = GetModuleHandle(NULL); wndWc.hIcon = NULL; wndWc.hCursor = LoadCursor(0, IDC_ARROW); wndWc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndWc.lpszMenuName = NULL; wndWc.lpszClassName = L"w32skin"; if (!RegisterClass(&wndWc)) return false; // get actual screen resolution int iSw = (WORD)GetSystemMetrics(SM_CXSCREEN); // width int iSh = (WORD)GetSystemMetrics(SM_CYSCREEN); // height RECT rc = { (iSw - 320)/2, (iSh - 240)/2, 320, 240 }; hWnd = CreateWindow(L"w32skin", L" w32skin", WS_OVERLAPPEDWINDOW, rc.left,rc.top,rc.right,rc.bottom, NULL, NULL, GetModuleHandle(NULL), NULL); if (hWnd == NULL) { MessageBoxW(NULL, L"Error: create Window", NULL, MB_ICONERROR); return 2; } ShowWindow(hWnd, SW_SHOW); MSG msg; while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } DestroyWindow(hWnd); return 0; } // ------------------------------------------------------------------------ // Build a basic region and set it to the window. // ------------------------------------------------------------------------ void RegionMe() { HRGN hRegion1 = CreateEllipticRgn(20,-20,190,150); SetWindowRgn(hWnd, hRegion1, true); DeleteObject(hRegion1); bRegioned = true; } // ------------------------------------------------------------------------ // Remove the region from the window // ------------------------------------------------------------------------ void UnRegionMe() { SetWindowRgn(hWnd, NULL, true); bRegioned = false; } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch(uMessage) { case WM_KEYDOWN: { // --------------------------------------------------------- // pressing ESC will finish the app. // --------------------------------------------------------- switch (wParam) { case VK_ESCAPE: PostQuitMessage(0); break; case VK_SPACE: if (!bRegioned) RegionMe(); else UnRegionMe(); } break; } case WM_PAINT: { // ------------------------------------------------- // tell user to press SPACE to toggle region. // ------------------------------------------------- PAINTSTRUCT ps; BeginPaint(hWnd,&ps); TextOut(ps.hdc, 115,90, L"Press SPACE", 11); EndPaint(hWnd,&ps); break; } case WM_DESTROY: { PostQuitMessage(0); break; } } return DefWindowProc(hWnd,uMessage,wParam,lParam); }