分类: Win32 SDK 2012-11-10 00:37 3990人阅读 评论(2) 收藏 举报
Win32 填充区 直线 绘图

目录(?)[+]

注:以下内容为学习笔记,多数是从书本、资料中得来,只为加深印象,及日后参考。然而本人表达能力较差,写的不好。因非翻译、非转载,只好选原创,但多数乃摘抄,实为惭愧。但若能帮助一二访客,幸甚!

1.GDI

GDI 的一个主要目的就是支持与设备无关的图形。GDI提供了一种特殊的机制来彻底隔离应用程序和不同输出设备的特性,这样就可以支持与设备无关的图形。

2.设备环境

如果希望在图形输出设备上绘图,必须首先获取设备环境(即DC)的句柄。当Windows把这个句柄交给你的程序,Windows同时也就给予了你使用这个设备的权限。接着,在GDI函数中将这个句柄作为一个参数,告诉Windows在哪个设备上进行绘图。

设备环境中包含许多GDI函数如何工作的属性。

获取设备环境句柄:

1)在处理WM_PAINT消息时使用BeginPaint函数和EndPaint函数:

[cpp] view plain copy print ?
  1. HDC hdc;
  2. hdc = BeginPaint(hwnd, &ps);
  3. // ...
  4. EndPaint(hwnd, &ps);

2)在处理非WM_PAINT消息时由Windows程序获取:

[cpp] view plain copy print ?
  1. HDC hdc;
  2. hdc = GetDC(hwnd);
  3. //....
  4. ReleaseDC(hwnd, hdc);

3)获得用于整个窗口的,而不仅仅是窗口客户区的设备环境句柄:

[cpp] view plain copy print ?
  1. hdc = GetWindowDC(hwnd);
  2. // ...
  3. ReleaseDC(hwnd, hdc);

4)更通用的获取设备环境句柄的函数:

[cpp] view plain copy print ?
  1. hdc = CreateDC(pszDriver, pszDevice, pszOutput, pData);
  2. // ...
  3. DeleteDC(hdc);

获取当前整个屏幕的设备环境句柄:

[cpp] view plain copy print ?
  1. hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);

5)处理位图时,有时可能会用到一个”内存设备环境“:

[cpp] view plain copy print ?
  1. hdcMem = CreateCompatibleDC(hdc);
  2. // ..
  3. DeleteDC(hdcMem);

可以把一个位图选入内存设备环境,并且调用GDI函数绘制这个位图

6)图元文件是以二进制形式编码的GDI函数调用的集合。它可以通过获取一个图元文件的设备环境来创建:

[cpp] view plain copy print ?
  1. hdcMeta = CreateMetaFile(pszFilename);
  2. // ...
  3. hmf = CloseMetaFile(hdcMeta);

3.设备的尺寸

”分辨率“:每度量单位(通常是英寸)中含有的像素数。

常用函数:

GetSystemMetrics、GetDeviceCaps.

4.色彩ABC

获取视频适配器板卡上的内存的组织形式:

1)色彩平面的数目:

[cpp] view plain copy print ?
  1. iPlanes= GetDeviceCaps(hdc, PLANES);

2)每个像素的颜色位数:

[cpp] view plain copy print ?
  1. iBitsPixel = GetDeviceCaps(hdc, BITSPIXEL);

5.点和线的绘制

1)点

[cpp] view plain copy print ?
  1. SetPixel(hdc, x, y, crColor);
  2. crColor = GetPixel(hdc, x, y);

2)直线

[cpp] view plain copy print ?
  1. MoveToEx(hdc, xBeg, yBeg, NULL);
  2. LineTo(hdc, xEnd, yEnd);

数组的点连成线:

[cpp] view plain copy print ?
  1. Polyline(hdc, apt, 5);

用Polyline实现绘制正玄曲线:

[cpp] view plain copy print ?
  1. /*-------------------------------------------------------------------
  2. SINEWAVE.cpp -- sine wave Using polyline
  3. --------------------------------------------------------------------*/
  4. #include <windows.h>
  5. #include <math.h>
  6. #define NUM     1000
  7. #define TWOPI   (2*3.14159)
  8. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  9. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  10. {
  11. static TCHAR    szAppName[] = TEXT("SineWave");
  12. HWND            hwnd;
  13. MSG             msg;
  14. WNDCLASS        wndclass;
  15. wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  16. wndclass.lpfnWndProc    = WndProc;
  17. wndclass.cbClsExtra     = 0;
  18. wndclass.cbWndExtra     = 0;
  19. wndclass.hInstance      = hInstance;
  20. wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  21. wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  22. wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  23. wndclass.lpszMenuName   = NULL;
  24. wndclass.lpszClassName  = szAppName;
  25. if (!RegisterClass(&wndclass))
  26. {
  27. MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR);
  28. return 0;
  29. }
  30. hwnd = CreateWindow(szAppName, TEXT("Sine Wave Using Polyline"),
  31. WS_OVERLAPPEDWINDOW,
  32. CW_USEDEFAULT, CW_USEDEFAULT,
  33. CW_USEDEFAULT, CW_USEDEFAULT,
  34. NULL, NULL, hInstance, NULL);
  35. ShowWindow(hwnd, iCmdShow);
  36. UpdateWindow(hwnd);
  37. while (GetMessage(&msg, NULL, 0, 0))
  38. {
  39. TranslateMessage(&msg);
  40. DispatchMessage(&msg);
  41. }
  42. return msg.wParam;
  43. }
  44. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  45. {
  46. static int      cxClient, cyClient;
  47. HDC             hdc;
  48. int             i;
  49. PAINTSTRUCT     ps;
  50. POINT           apt[NUM];
  51. switch (message)
  52. {
  53. case WM_SIZE:
  54. cxClient = LOWORD(lParam);
  55. cyClient = HIWORD(lParam);
  56. return 0;
  57. case WM_PAINT:
  58. hdc = BeginPaint(hwnd, &ps);
  59. MoveToEx(hdc, 0, cyClient/2, NULL);
  60. LineTo(hdc, cxClient, cyClient/2);
  61. for (i = 0; i < NUM; i++)
  62. {
  63. apt[i].x = i*cxClient/NUM;
  64. apt[i].y = (int)(cyClient / 2 * (1-sin(TWOPI * i / NUM)));
  65. }
  66. Polyline(hdc, apt, NUM);
  67. EndPaint(hwnd, &ps);
  68. return 0;
  69. case WM_DESTROY:
  70. PostQuitMessage(0);
  71. return 0;
  72. }
  73. return DefWindowProc(hwnd, message, wParam, lParam);
  74. }

6.几个绘图函数:

[cpp] view plain copy print ?
  1. Rectangle(hdc, xLeft, yTop, xRight, yBottom);
  2. Ellipse(hdc, xLeft, yTop, xRight, yBottom);
  3. RoundRect(hdc, xLeft, yTop, xRight, yBottom, xCornerEllipse, yCornerEllipse);
  4. Arc(hdc, xLeft, yTop, xRight, yBottom, xStart, yStart, xEnd, yEnd);
  5. Chord(hdc, xLeft, yTop, xRight, yBottom, xStart, yStart, xEnd, yEnd);
  6. Pie(hdc, xLeft, yTop, xRight, yBottom, xStart, yStart, xEnd, yEnd);

绘图示例:

[cpp] view plain copy print ?
  1. /*-------------------------------------------------------------------
  2. lineDemo.cpp -- Line-Drawing Demonstration Program
  3. --------------------------------------------------------------------*/
  4. #include <windows.h>
  5. #include <math.h>
  6. #define NUM     1000
  7. #define TWOPI   (2*3.14159)
  8. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  9. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  10. {
  11. static TCHAR    szAppName[] = TEXT("lineDemo");
  12. HWND            hwnd;
  13. MSG             msg;
  14. WNDCLASS        wndclass;
  15. wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  16. wndclass.lpfnWndProc    = WndProc;
  17. wndclass.cbClsExtra     = 0;
  18. wndclass.cbWndExtra     = 0;
  19. wndclass.hInstance      = hInstance;
  20. wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  21. wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  22. wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  23. wndclass.lpszMenuName   = NULL;
  24. wndclass.lpszClassName  = szAppName;
  25. if (!RegisterClass(&wndclass))
  26. {
  27. MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR);
  28. return 0;
  29. }
  30. hwnd = CreateWindow(szAppName, TEXT("Line Demonstration"),
  31. WS_OVERLAPPEDWINDOW,
  32. CW_USEDEFAULT, CW_USEDEFAULT,
  33. CW_USEDEFAULT, CW_USEDEFAULT,
  34. NULL, NULL, hInstance, NULL);
  35. ShowWindow(hwnd, iCmdShow);
  36. UpdateWindow(hwnd);
  37. while (GetMessage(&msg, NULL, 0, 0))
  38. {
  39. TranslateMessage(&msg);
  40. DispatchMessage(&msg);
  41. }
  42. return msg.wParam;
  43. }
  44. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  45. {
  46. static int      cxClient, cyClient;
  47. HDC             hdc;
  48. PAINTSTRUCT     ps;
  49. switch (message)
  50. {
  51. case WM_SIZE:
  52. cxClient = LOWORD(lParam);
  53. cyClient = HIWORD(lParam);
  54. return 0;
  55. case WM_PAINT:
  56. hdc = BeginPaint(hwnd, &ps);
  57. Rectangle(hdc, cxClient/8, cyClient/8, 7*cxClient/8, 7*cyClient/8);
  58. MoveToEx(hdc, 0, 0, NULL);
  59. LineTo(hdc, cxClient, cyClient);
  60. MoveToEx(hdc, 0, cyClient, NULL);
  61. LineTo(hdc, cxClient, 0);
  62. Ellipse(hdc, cxClient/8, cyClient/8, 7*cxClient/8, 7*cyClient/8);
  63. RoundRect(hdc, cxClient/4, cyClient/4, 3*cxClient/4, 3*cyClient/4, cxClient/4, cyClient/4);
  64. EndPaint(hwnd, &ps);
  65. return 0;
  66. case WM_DESTROY:
  67. PostQuitMessage(0);
  68. return 0;
  69. }
  70. return DefWindowProc(hwnd, message, wParam, lParam);
  71. }

7.贝塞尔样条曲线:

[cpp] view plain copy print ?
  1. /*-------------------------------------------------------------------
  2. bezier.cpp -- Bezier Splines Demo
  3. --------------------------------------------------------------------*/
  4. #include <windows.h>
  5. #include <math.h>
  6. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  7. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  8. {
  9. static TCHAR    szAppName[] = TEXT("Bezier");
  10. HWND            hwnd;
  11. MSG             msg;
  12. WNDCLASS        wndclass;
  13. wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  14. wndclass.lpfnWndProc    = WndProc;
  15. wndclass.cbClsExtra     = 0;
  16. wndclass.cbWndExtra     = 0;
  17. wndclass.hInstance      = hInstance;
  18. wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  19. wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  20. wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  21. wndclass.lpszMenuName   = NULL;
  22. wndclass.lpszClassName  = szAppName;
  23. if (!RegisterClass(&wndclass))
  24. {
  25. MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR);
  26. return 0;
  27. }
  28. hwnd = CreateWindow(szAppName, TEXT("Bezier Splines Demo"),
  29. WS_OVERLAPPEDWINDOW,
  30. CW_USEDEFAULT, CW_USEDEFAULT,
  31. CW_USEDEFAULT, CW_USEDEFAULT,
  32. NULL, NULL, hInstance, NULL);
  33. ShowWindow(hwnd, iCmdShow);
  34. UpdateWindow(hwnd);
  35. while (GetMessage(&msg, NULL, 0, 0))
  36. {
  37. TranslateMessage(&msg);
  38. DispatchMessage(&msg);
  39. }
  40. return msg.wParam;
  41. }
  42. void DrawBezier(HDC hdc, POINT apt[])
  43. {
  44. PolyBezier(hdc, apt, 4);
  45. MoveToEx(hdc, apt[0].x, apt[0].y, NULL);
  46. LineTo(hdc, apt[1].x, apt[1].y);
  47. MoveToEx(hdc, apt[2].x, apt[2].y, NULL);
  48. LineTo(hdc, apt[3].x, apt[3].y);
  49. }
  50. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  51. {
  52. static POINT    apt[4];
  53. int             cxClient, cyClient;
  54. HDC             hdc;
  55. PAINTSTRUCT     ps;
  56. switch (message)
  57. {
  58. case WM_SIZE:
  59. cxClient = LOWORD(lParam);
  60. cyClient = HIWORD(lParam);
  61. apt[0].x = cxClient / 4;
  62. apt[0].y = cyClient / 2;
  63. apt[1].x = cxClient / 2;
  64. apt[1].y = cyClient / 4;
  65. apt[2].x = cxClient / 2;
  66. apt[2].y = 3 * cyClient / 4;
  67. apt[3].x = 3 * cxClient / 4;
  68. apt[3].y = cyClient / 2;
  69. return 0;
  70. case WM_LBUTTONDOWN:
  71. case WM_RBUTTONDOWN:
  72. case WM_MOUSEMOVE:
  73. if (wParam & MK_LBUTTON || wParam & MK_RBUTTON)
  74. {
  75. hdc = GetDC(hwnd);
  76. SelectObject(hdc, GetStockObject(WHITE_PEN));
  77. DrawBezier(hdc, apt);
  78. if (wParam & MK_LBUTTON)
  79. {
  80. apt[1].x = LOWORD(lParam);
  81. apt[1].y = HIWORD(lParam);
  82. }
  83. if (wParam & MK_RBUTTON)
  84. {
  85. apt[2].x = LOWORD(lParam);
  86. apt[2].y = HIWORD(lParam);
  87. }
  88. SelectObject(hdc, GetStockObject(BLACK_PEN));
  89. DrawBezier(hdc, apt);
  90. ReleaseDC(hwnd, hdc);
  91. }
  92. case WM_PAINT:
  93. InvalidateRect(hwnd, NULL, TRUE);
  94. hdc = BeginPaint(hwnd, &ps);
  95. DrawBezier(hdc, apt);
  96. EndPaint(hwnd, &ps);
  97. return 0;
  98. case WM_DESTROY:
  99. PostQuitMessage(0);
  100. return 0;
  101. }
  102. return DefWindowProc(hwnd, message, wParam, lParam);
  103. }

8.填充区域

PeekMessage

在Windows中有很多”空闲时间“,在这期间所有的消息队列都是空的,Windows就在等待键盘或者鼠标的输入。那么能否在空闲期间从某种程度上获取控制,而一旦有消息加载到程序的消息队列,就释放控制呢?这就是PeekMessage的”用武之地“。

PeekMessage的意思,它是”偷看“而不是”获得“。它允许一个程序检查程序队列中的下一个消息,而不是真实地获得并删除它看到的消息。

GetMessage并不把控制权交还给程序,除非它从程序的消息队列中获得了消息。但PeekMessage却总是立即返回,不管消息是否出现。

随机矩形代码:

[cpp] view plain copy print ?
  1. /*-------------------------------------------------------------------
  2. randRect.cpp -- Displays Random Rectangles
  3. --------------------------------------------------------------------*/
  4. #include <windows.h>
  5. #include <stdlib.h>
  6. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  7. void DrawRectangle(HWND);
  8. int cxClient, cyClient;
  9. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  10. {
  11. static TCHAR    szAppName[] = TEXT("RandRect");
  12. HWND            hwnd;
  13. MSG             msg;
  14. WNDCLASS        wndclass;
  15. wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  16. wndclass.lpfnWndProc    = WndProc;
  17. wndclass.cbClsExtra     = 0;
  18. wndclass.cbWndExtra     = 0;
  19. wndclass.hInstance      = hInstance;
  20. wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  21. wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  22. wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  23. wndclass.lpszMenuName   = NULL;
  24. wndclass.lpszClassName  = szAppName;
  25. if (!RegisterClass(&wndclass))
  26. {
  27. MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR);
  28. return 0;
  29. }
  30. hwnd = CreateWindow(szAppName, TEXT("Rand Rectangle"),
  31. WS_OVERLAPPEDWINDOW,
  32. CW_USEDEFAULT, CW_USEDEFAULT,
  33. CW_USEDEFAULT, CW_USEDEFAULT,
  34. NULL, NULL, hInstance, NULL);
  35. ShowWindow(hwnd, iCmdShow);
  36. UpdateWindow(hwnd);
  37. while (TRUE)
  38. {
  39. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  40. {
  41. if (msg.message == WM_QUIT)
  42. break;
  43. TranslateMessage(&msg);
  44. DispatchMessage(&msg);
  45. }
  46. else
  47. {
  48. Sleep(100);
  49. DrawRectangle(hwnd);
  50. }
  51. }
  52. return msg.wParam;
  53. }
  54. void DrawRectangle(HWND hwnd)
  55. {
  56. HBRUSH      hBrush;
  57. HDC         hdc;
  58. RECT        rect;
  59. if (cxClient == 0 || cyClient == 0)
  60. return;
  61. SetRect(&rect, rand() % cxClient, rand() % cyClient, rand() % cxClient, rand() % cyClient);
  62. hBrush = CreateSolidBrush(RGB(rand() % 256, rand() % 256, rand() % 256));
  63. hdc = GetDC(hwnd);
  64. FillRect(hdc, &rect, hBrush);
  65. ReleaseDC(hwnd, hdc);
  66. DeleteObject(hBrush);
  67. }
  68. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  69. {
  70. switch (message)
  71. {
  72. case WM_SIZE:
  73. cxClient = LOWORD(lParam);
  74. cyClient = HIWORD(lParam);
  75. return 0;
  76. case WM_DESTROY:
  77. PostQuitMessage(0);
  78. return 0;
  79. }
  80. return DefWindowProc(hwnd, message, wParam, lParam);
  81. }

9.矩形与区域的裁剪

InvalidRect函数使显示的矩形区域无效,并产生一个WM_PAINT消息。可以用来擦除客户区的内容,并产生一个WM_PAINT消息。

若处理区域而不是矩形可用:

InvalidateRgn(hwnd, hRgn, bErase);

ValidateRgn(hwnd, hRgn);

CLOVER程序:

由四个椭圆形成一个区域,然后把这个区域选入设备环境,接着从窗口的客户区中心发散绘制一系列直线。这些直线仅出现裁剪区内。

[cpp] view plain copy print ?
  1. /*-------------------------------------------------------------------
  2. clover.cpp -- Clover Drawing Program Using Regions
  3. --------------------------------------------------------------------*/
  4. #include <windows.h>
  5. #include <math.h>
  6. #define TWO_PI  (2.0 * 3.14159)
  7. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  8. void DrawRectangle(HWND);
  9. int cxClient, cyClient;
  10. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
  11. {
  12. static TCHAR    szAppName[] = TEXT("clover");
  13. HWND            hwnd;
  14. MSG             msg;
  15. WNDCLASS        wndclass;
  16. wndclass.style          = CS_HREDRAW | CS_VREDRAW;
  17. wndclass.lpfnWndProc    = WndProc;
  18. wndclass.cbClsExtra     = 0;
  19. wndclass.cbWndExtra     = 0;
  20. wndclass.hInstance      = hInstance;
  21. wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  22. wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  23. wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  24. wndclass.lpszMenuName   = NULL;
  25. wndclass.lpszClassName  = szAppName;
  26. if (!RegisterClass(&wndclass))
  27. {
  28. MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR);
  29. return 0;
  30. }
  31. hwnd = CreateWindow(szAppName, TEXT("Draw a Clover"),
  32. WS_OVERLAPPEDWINDOW,
  33. CW_USEDEFAULT, CW_USEDEFAULT,
  34. CW_USEDEFAULT, CW_USEDEFAULT,
  35. NULL, NULL, hInstance, NULL);
  36. ShowWindow(hwnd, iCmdShow);
  37. UpdateWindow(hwnd);
  38. while (GetMessage(&msg, NULL, 0, 0))
  39. {
  40. TranslateMessage(&msg);
  41. DispatchMessage(&msg);
  42. }
  43. return msg.wParam;
  44. }
  45. LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  46. {
  47. static HRGN     hRgnClip;
  48. static int      cxClient, cyClient;
  49. double          fAngle, fRadius;
  50. HCURSOR         hCursor;
  51. HDC             hdc;
  52. HRGN            hRgnTemp[6];
  53. int             i;
  54. PAINTSTRUCT     ps;
  55. switch (message)
  56. {
  57. case WM_SIZE:
  58. cxClient = LOWORD(lParam);
  59. cyClient = HIWORD(lParam);
  60. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  61. ShowCursor(TRUE);
  62. if (hRgnClip)
  63. DeleteObject(hRgnClip);
  64. hRgnTemp[0] = CreateEllipticRgn(0,          cyClient/3,     cxClient/2,     2*cyClient/3);
  65. hRgnTemp[1] = CreateEllipticRgn(cxClient/2, cyClient/3,     cxClient,       2*cyClient/3);
  66. hRgnTemp[2] = CreateEllipticRgn(cxClient/3, 0,              2*cxClient/3,   cyClient/2);
  67. hRgnTemp[3] = CreateEllipticRgn(cxClient/3, cyClient/2,     2*cxClient/3,   cyClient);
  68. hRgnTemp[4] = CreateRectRgn(0, 0, 1, 1);
  69. hRgnTemp[5] = CreateRectRgn(0, 0, 1, 1);
  70. hRgnClip = CreateRectRgn(0, 0, 1, 1);
  71. CombineRgn(hRgnTemp[4], hRgnTemp[0], hRgnTemp[1], RGN_OR);
  72. CombineRgn(hRgnTemp[5], hRgnTemp[2], hRgnTemp[3], RGN_OR);
  73. CombineRgn(hRgnClip, hRgnTemp[4], hRgnTemp[5], RGN_XOR);
  74. for (i = 0; i < 6; i++)
  75. DeleteObject(hRgnTemp[i]);
  76. SetCursor(hCursor);
  77. ShowCursor(FALSE);
  78. return 0;
  79. case WM_PAINT:
  80. hdc = BeginPaint(hwnd, &ps);
  81. SetViewportOrgEx(hdc, cxClient/2, cyClient/2, NULL);
  82. SelectClipRgn(hdc, hRgnClip);
  83. // hypot 计算直角三角形斜边的长
  84. fRadius = _hypot(cxClient/2.0, cyClient/2.0);
  85. for (fAngle = 0.0; fAngle < TWO_PI; fAngle += TWO_PI/360)
  86. {
  87. MoveToEx(hdc, 0, 0, NULL);
  88. LineTo(hdc, int(fRadius * cos(fAngle) + 0.5), int(-fRadius * sin(fAngle) + 0.5));
  89. }
  90. EndPaint(hwnd, &ps);
  91. return 0;
  92. case WM_DESTROY:
  93. DeleteObject(hRgnClip);
  94. PostQuitMessage(0);
  95. return 0;
  96. }
  97. return DefWindowProc(hwnd, message, wParam, lParam);
  98. }

版权声明:本文为博主原创文章,未经博主允许不得转载。

Win32 绘图基础 -- 绘制直线、边框、贝塞尔曲线、填充、裁剪相关推荐

  1. WPF绘制光滑连续贝塞尔曲线

    原文:WPF绘制光滑连续贝塞尔曲线 1.需求 WPF本身没有直接把点集合绘制成曲线的函数.可以通过贝塞尔曲线函数来绘制. 贝塞尔曲线类是:BezierSegment,三次贝塞尔曲线,通过两个控制点来控 ...

  2. 绘制二次贝塞尔曲线的几种方式

    1.通过turf.js插件绘制 import * as turf from "@turf/turf";//P1,p2为起终点 export default function two ...

  3. Python+Matplotlib绘制三次贝塞尔曲线

    开学第一课:一定不要这样问老师Python问题 中国大学MOOC"Python程序设计基础"第6次开课时间 董付国老师Python系列教材推荐与选用参考 ============= ...

  4. Python绘制三次贝塞尔曲线

    对于贝塞尔曲线而言,其特点在于第一个控制点恰好是曲线的起点,最后一个控制点是曲线的终点,其他控制点并不在曲线上,而是起到控制曲线形状的作用.另外,曲线的起点处与前两个控制点构成的线段相切,而曲线的终点 ...

  5. 绘制二次贝塞尔曲线(二次贝兹曲线)等距线:让 IE 支持 canvas接口 isPointInPath

    一.背景: 在使用 canvas 做知识图谱的时,实体关系使用线宽为 1px 的线绘制, 用户必须点在线上, 才能正常拾取到点击的边. 边关系,有些是直线边,有些是二次贝塞尔曲线.产品提议,线不能加粗 ...

  6. 用C语言绘制任意阶贝塞尔曲线(Bézier curve)

    计算机图形学中贝塞尔曲线的绘制.使用的开发软件及版本为VS2015,以及 EasyX库.实现动态演示贝塞尔曲线实现的过程,且阶次不限! 源代码获取方式:1.添加微信(微信号:my_12581)获取.2 ...

  7. MFC鼠标绘制直线段并使用编码裁剪算法

    聪明的你通过本文可以学会在MFC中 初始化时绘制自定义矩形框 使用鼠标来实时绘制你想要的直线段 实现编码裁剪算法裁去直线段在自定义矩形框以外的部分 完成效果如下 进入运行界面 鼠标绘制直线 编码算法裁 ...

  8. Path绘制动态的贝塞尔曲线、PathMeasure来绘制path动画

    上一篇的波浪曲线是左右重复平移,这次是每一帧绘制一条线,组成上下浮动的曲线,下面是效果图 public WaveView(Context context, @Nullable AttributeSet ...

  9. Qt:QPainter重写mainwindows绘图事件绘制直线,弧线、设置画笔画刷

    //光标定位到QPainter类名上,然后按下键盘上的F1按键,这时会自动跳转到该类的帮助页面 1.新建Qt Gui应用,名为MainWindow,基类为QMainWindow. 2.修改mainwi ...

最新文章

  1. mysql之子查询作业
  2. 51nod-正整数分组问题(基础方程DP-01背包)
  3. 接软件开发项目,你需要知道这些!
  4. spike 序列matlab,SPKtool1.0.1 神经信号spike 分类及处理 工具包 matlab 238万源代码下载- www.pudn.com...
  5. SpringBoot-核心功能
  6. python文件中写中文_解决python中csv文件中文写入问题
  7. 抓取html文件swf,如何把网页上的flash动画保存为swf格式文件(缓存提取)
  8. 详解GAMIT/GLOBK软件使用
  9. iOS开发各种证书详解
  10. python123第九周_我的python学习之路-基础3
  11. (转)国内外优秀的Web前端工程师
  12. Windows 编程基础(四)
  13. PS学习笔记------运用脚本及自动化批量处理
  14. 世界读书日送你畅销好书!前所未有4折购书福利
  15. 中美程序员不完全对比
  16. Postgresql杂谈 04—Postgresql中的五种常规索引
  17. 怎么处理微信web页面字体自动变大
  18. 乳腺癌诊断和药物技术行业调研报告 - 市场现状分析与发展前景预测
  19. Ubuntu 安装出现 error vmlinuz has invalid signature 【或者】 mmx64.efi not found
  20. 90 后高管:“下不手开除 70、80 后,公司死了谁负责?”

热门文章

  1. python解析十六进制字符串
  2. 高位缩量,暴跌还是洗盘?
  3. 苹果或在 WWDC20 期间发布自研 ARM 芯片的Mac:5nm+12核
  4. Mac简单的上手指南
  5. Bootstrap 附加导航(Affix)插件
  6. matlab画加速度响应频域曲线,车辆振动加速度响应分析的速度—频域方法
  7. libsvm java 实例_LibSvm流程及java代码测试
  8. spring security调用过程;及自定义改造
  9. XP正版序列号|XP好用的正版序列号
  10. 【ICLR 2018录用结果出炉】23篇oral干货,强化学习、对抗网络、可解释性最受关注...