fork download
  1. #include <windows.h>
  2.  
  3. HANDLE hFile;
  4. DWORD dwBytes;
  5.  
  6. BITMAPFILEHEADER bmpFileHeader;
  7. BITMAPINFO bmpInfo;
  8.  
  9. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
  10. HDC hdc;
  11. PAINTSTRUCT ps;
  12. int iScan;
  13. static BYTE *bPixelBits;
  14. static int WIDTH = 0;
  15.  
  16. switch (msg) {
  17. case WM_DESTROY:
  18. CloseHandle(hFile);
  19. free(bPixelBits);
  20. PostQuitMessage(0);
  21. return 0;
  22.  
  23. case WM_CREATE:
  24. WIDTH = 4 * ((bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biBitCount + 31) / 32);
  25. bPixelBits = (BYTE *)malloc(WIDTH);
  26. return 0;
  27.  
  28. case WM_PAINT:
  29. hdc = BeginPaint(hwnd, &ps); {
  30. for (iScan = 0; iScan < bmpInfo.bmiHeader.biHeight; iScan++) {
  31. ReadFile(hFile, bPixelBits, WIDTH, &dwBytes, NULL);
  32. Sleep(10);
  33. SetDIBitsToDevice(hdc,
  34. 0, 0, /* 転送先長方形の左上隅 */
  35. bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, /* DIB の幅・高さ */
  36. 0, 0, /* DIB の左隅の論理座標 */
  37. iScan, /* DIB 内の開始走査行 */
  38. 1, /* pPixelBits が示す配列中に含まれている DIB の走査行の数 */
  39. bPixelBits, &bmpInfo, DIB_RGB_COLORS);
  40.  
  41. }
  42. SetFilePointer(hFile,
  43. sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER), NULL, FILE_BEGIN);
  44. } EndPaint(hwnd, &ps);
  45. return 0;
  46.  
  47. }
  48. return DefWindowProc(hwnd, msg, wp, lp);
  49. }
  50.  
  51. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nCmdShow) {
  52. HWND hwnd;
  53. MSG msg;
  54. WNDCLASS winc;
  55. DWORD dwBytes;
  56. hFile = CreateFile(lpCmdLine, GENERIC_READ, 0, NULL,
  57. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  58. if (hFile == INVALID_HANDLE_VALUE) {
  59. MessageBox(NULL, TEXT("failure oppening file"), TEXT("ERROR"), MB_OK);
  60. return -1;
  61. }
  62. ReadFile(hFile, &bmpFileHeader, sizeof(BITMAPFILEHEADER), &dwBytes, NULL);
  63. if (bmpFileHeader.bfType != 0x4d42) {
  64. MessageBox(NULL, TEXT("This file is not bitmap."), TEXT("ERROR"), MB_OK);
  65. return -1;
  66. }
  67. ReadFile(hFile, &bmpInfo, sizeof(BITMAPINFOHEADER), &dwBytes, NULL);
  68.  
  69. winc.style = CS_HREDRAW | CS_VREDRAW;
  70. winc.lpfnWndProc = WndProc;
  71. winc.cbClsExtra = 0;
  72. winc.cbWndExtra = 0;
  73. winc.hInstance = hInstance;
  74. winc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  75. winc.hCursor = LoadCursor(NULL, IDC_ARROW);
  76. winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  77. winc.lpszMenuName = NULL;
  78. winc.lpszClassName = TEXT("KITTY");
  79.  
  80. if (!RegisterClass(&winc)) return -1;
  81.  
  82. hwnd = CreateWindow(TEXT("KITTY"), TEXT("KITTY on your lap"),
  83. WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  84. CW_USEDEFAULT, CW_USEDEFAULT,
  85. CW_USEDEFAULT, CW_USEDEFAULT,
  86. NULL, NULL, hInstance, NULL);
  87.  
  88. if (hwnd == NULL) return 0;
  89.  
  90. while (GetMessage(&msg, NULL, 0, 0)) {
  91. TranslateMessage(&msg);
  92. DispatchMessage(&msg);
  93. }
  94. return msg.wParam;
  95. }
  96. /* end */
  97.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:21: fatal error: windows.h: No such file or directory
 #include <windows.h>
                     ^
compilation terminated.
stdout
Standard output is empty