You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.1 KiB

5 years ago
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include "Raster.h"
  4. LRESULT CALLBACK windowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  5. {
  6. switch(msg)
  7. {
  8. case WM_SIZE:
  9. break;
  10. case WM_CLOSE:
  11. case WM_DESTROY:
  12. PostQuitMessage(0);
  13. break;
  14. default:
  15. break;
  16. }
  17. return DefWindowProc( hWnd, msg, wParam, lParam );
  18. }
  19. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
  20. {
  21. // 1 ע�ᴰ����
  22. ::WNDCLASSEXA winClass;
  23. winClass.lpszClassName = "Raster";
  24. winClass.cbSize = sizeof(::WNDCLASSEX);
  25. winClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
  26. winClass.lpfnWndProc = windowProc;
  27. winClass.hInstance = hInstance;
  28. winClass.hIcon = 0;
  29. winClass.hIconSm = 0;
  30. winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  31. winClass.hbrBackground = (HBRUSH)(BLACK_BRUSH);
  32. winClass.lpszMenuName = NULL;
  33. winClass.cbClsExtra = 0;
  34. winClass.cbWndExtra = 0;
  35. RegisterClassExA(&winClass);
  36. // 2 ��������
  37. HWND hWnd = CreateWindowExA(
  38. NULL,
  39. "Raster",
  40. "Raster",
  41. WS_POPUPWINDOW,
  42. 0,
  43. 0,
  44. 256,
  45. 256,
  46. 0,
  47. 0,
  48. hInstance,
  49. 0
  50. );
  51. UpdateWindow( hWnd );
  52. ShowWindow(hWnd,SW_SHOW);
  53. RECT rt = {0};
  54. GetClientRect(hWnd,&rt);
  55. int width = rt.right - rt.left;
  56. int height = rt.bottom - rt.top;
  57. void* buffer = 0;
  58. HDC hDC = GetDC(hWnd);
  59. HDC hMem = ::CreateCompatibleDC(hDC);
  60. BITMAPINFO bmpInfor;
  61. bmpInfor.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  62. bmpInfor.bmiHeader.biWidth = width;
  63. bmpInfor.bmiHeader.biHeight = height;
  64. bmpInfor.bmiHeader.biPlanes = 1;
  65. bmpInfor.bmiHeader.biBitCount = 32;
  66. bmpInfor.bmiHeader.biCompression = BI_RGB;
  67. bmpInfor.bmiHeader.biSizeImage = 0;
  68. bmpInfor.bmiHeader.biXPelsPerMeter = 0;
  69. bmpInfor.bmiHeader.biYPelsPerMeter = 0;
  70. bmpInfor.bmiHeader.biClrUsed = 0;
  71. bmpInfor.bmiHeader.biClrImportant = 0;
  72. HBITMAP hBmp = CreateDIBSection(hDC,&bmpInfor,DIB_RGB_COLORS,(void**)&buffer,0,0);
  73. SelectObject(hMem,hBmp);
  74. CELL::Raster raster(width,height,buffer);
  75. MSG msg = {0};
  76. while(true)
  77. {
  78. if (msg.message == WM_DESTROY
  79. ||msg.message == WM_CLOSE
  80. ||msg.message == WM_QUIT)
  81. {
  82. break;
  83. }
  84. if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  85. {
  86. TranslateMessage( &msg );
  87. DispatchMessage( &msg );
  88. }
  89. raster.clear();
  90. for (int i = 0 ;i < 100 ; ++ i)
  91. {
  92. raster.drawPoint(rand()%256,rand()%256,CELL::Rgba(255,0,0),2);
  93. }
  94. memcpy(buffer,raster._buffer,raster._width * raster._height * sizeof(CELL::Rgba));
  95. BitBlt(hDC,0,0,width,height,hMem,0,0,SRCCOPY);
  96. }
  97. return 0;
  98. }