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. 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. SetDIBitsToDevice(hdc,
  33. 0, 0, /* 転送先長方形の左上隅 */
  34. bmpInfo.bmiHeader.biWidth, bmpInfo.bmiHeader.biHeight, /* DIB の幅・高さ */
  35. 0, 0, /* DIB の左隅の論理座標 */
  36. iScan, /* DIB 内の開始走査行 */
  37. 1, /* pPixelBits が示す配列中に含まれている DIB の走査行の数 */
  38. bPixelBits, &bmpInfo, DIB_RGB_COLORS);
  39.  
  40. SetFilePointer(hFile,
  41. sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + WIDTH * (iScan + 1),
  42. NULL, FILE_BEGIN);
  43. }
  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. HANDLE hFile;
  56. DWORD dwBytes;
  57. hFile = CreateFile(lpCmdLine, GENERIC_READ, 0, NULL,
  58. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  59. if (hFile == INVALID_HANDLE_VALUE) {
  60. MessageBox(NULL, TEXT("failure oppening file"), TEXT("ERROR"), MB_OK);
  61. return -1;
  62. }
  63. ReadFile(hFile, &bmpFileHeader, sizeof(BITMAPFILEHEADER), &dwBytes, NULL);
  64. if (bmpFileHeader.bfType != 0x4d42) {
  65. MessageBox(NULL, TEXT("This file is not bitmap."), TEXT("ERROR"), MB_OK);
  66. return -1;
  67. }
  68. ReadFile(hFile, &bmpInfo, sizeof(BITMAPINFOHEADER), &dwBytes, NULL);
  69.  
  70. winc.style = CS_HREDRAW | CS_VREDRAW;
  71. winc.lpfnWndProc = WndProc;
  72. winc.cbClsExtra = 0;
  73. winc.cbWndExtra = 0;
  74. winc.hInstance = hInstance;
  75. winc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  76. winc.hCursor = LoadCursor(NULL, IDC_ARROW);
  77. winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  78. winc.lpszMenuName = NULL;
  79. winc.lpszClassName = TEXT("KITTY");
  80.  
  81. if (!RegisterClass(&winc)) return -1;
  82.  
  83. hwnd = CreateWindow(TEXT("KITTY"), TEXT("KITTY on your lap"),
  84. WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  85. CW_USEDEFAULT, CW_USEDEFAULT,
  86. CW_USEDEFAULT, CW_USEDEFAULT,
  87. NULL, NULL, hInstance, NULL);
  88.  
  89. if (hwnd == NULL) return 0;
  90.  
  91. while (GetMessage(&msg, NULL, 0, 0)) {
  92. TranslateMessage(&msg);
  93. DispatchMessage(&msg);
  94. }
  95. return msg.wParam;
  96. }
  97. /* end */
  98.  
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