發信人: heibow.bbs@bbs.mgt.ncu.edu.tw (速度金屬) 日期: 25 Jan 2000 20:06:46 GMT 標題: Re: 問一下SetWindowRgn() 信群: tw.bbs.comp.language 看板: Program 來源: <3YZQiN$Sz7@bbs.mgt.ncu.edu.tw>:24706, bbs.mgt.ncu.edu.tw 組織: 中大資管龍貓資訊天地 ==> KingArthur.bbs@bbs.et.ntust.edu.tw (Sephiroth) 提到: : SetWindowRgn()是不是只能用一次啊? : 用了第二次以後程式就變得怪怪的了, : 萬一只能用一次,那我要如何改變Region呢? 可以用好幾次啊, 請看如下的範例, 按 F1, F2 有不同的功能 F1 是放大, F2 是縮小 用 SDK 寫的 相信您也是吧... #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "HelloWin" ; HWND hwnd ; MSG msg ; WNDCLASSEX wndclass ; wndclass.cbSize = sizeof (wndclass) ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ; RegisterClassEx (&wndclass) ; hwnd = CreateWindow (szAppName, // window class name "The Hello Program", // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; HRGN RoundRgn; HRGN h2; static int Width=100,Height=100; switch (iMsg) { case WM_KEYDOWN: switch(wParam) { case VK_F1: Width+=10; Height+=10; break; case VK_F2: Width-=10; Height-=10; break; } h2=CreateRectRgn(0,0,Width,Height); SetWindowRgn(hwnd,h2,true); break; case WM_CREATE : return 0 ; case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, "Hello, Windows 95!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY : PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; } -- ◎龍貓資訊天地(bbs.mgt.ncu.edu.tw) ◎[heibow]來自: g4324b.dorm.ccu.edu.tw .