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.

116 lines
3.1 KiB

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