Advertisement
Guest User

Untitled

a guest
Jul 6th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.54 KB | None | 0 0
  1. /* W2CIF = w2ch.org image format *
  2.  * Credits: w2ch Anon            *
  3.  * File:main.h                   */
  4.  
  5. #ifndef MAIN_H
  6. #define MAIN_H
  7.  
  8. #ifndef WINVER              // Allow use of features specific to Windows 7 or later.
  9. #define WINVER 0x0700       // Change this to the appropriate value to target other versions of Windows.
  10. #endif
  11.  
  12. #ifndef _WIN32_WINNT        // Allow use of features specific to Windows 7 or later.
  13. #define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows.
  14. #endif
  15.  
  16. //#ifndef UNICODE
  17. //#define UNICODE
  18. //#endif
  19.  
  20. #define WIN32_LEAN_AND_MEAN
  21.  
  22. #include <windows.h>
  23. #include <cstdio>
  24.  
  25. #define BITMAP_ID           0x4d42 // BM
  26.  
  27. #endif /* MAIN_H */
  28.  
  29. /* W2CIF = world 2 c image format *
  30.  * Credits: w2ch Anon             *
  31.  * File:main.cpp                  */
  32.  
  33.  
  34. #ifndef MAIN_H
  35. #include "main.h"
  36. #endif
  37.  
  38.  
  39. void Help(char *szExeName);
  40. int  Printf(HANDLE hFileToWriteTo, char *szFormat, ...);
  41. int  WriteW2CIFHead(HANDLE hFileToWriteTo);
  42. int  WriteW2CIFImageCreation(HANDLE hFileToWriteTo, char *szBitmapName, int nBitmapNumber);
  43. int  WriteW2CIFEnd(HANDLE hFileToWriteTo, int nImageSpeed, int NumberOfImages);
  44.  
  45.  
  46. void Help(char *szExeName)
  47. {
  48.     fprintf(stdout, "%s FileToCreate -s Bitmap1 Bitmap2 Bitmap3...\n-s TimeInSecondsToChangeCurrentBitmapToNextBitmap\nNOTE:There is no limit on how many bitmaps you can have\n", szExeName);
  49. }
  50.  
  51.  
  52. int Printf(HANDLE hFileToWriteTo, char *szFormat, ...)
  53. {
  54.     int nReturnValue = 0;
  55.     DWORD nLenghtOfString = 0,
  56.           nNumberOfCharWriten = 0;
  57.  
  58.     char szBuffer[1024];
  59.     va_list pArgList;
  60.     va_start(pArgList, szFormat);
  61.     wvsprintf(szBuffer, szFormat, pArgList);
  62.     va_end(pArgList);
  63.  
  64.  
  65.     for (; szBuffer[nLenghtOfString] != '\0'; ++nLenghtOfString);
  66.  
  67.     nReturnValue = WriteFile(hFileToWriteTo,
  68.         szBuffer, nLenghtOfString, &nNumberOfCharWriten, NULL);
  69.  
  70.     if (nReturnValue) nReturnValue = 0;
  71.     else nReturnValue = GetLastError();
  72.     if (nLenghtOfString != nNumberOfCharWriten) nReturnValue = 1;
  73.  
  74.     return nReturnValue;
  75. }
  76.  
  77.  
  78. int WriteW2CIFHead(HANDLE hFileToWriteTo)
  79. {
  80.     if (Printf(hFileToWriteTo, "/* File:main.h */\r\n\r\n#ifndef MAIN_H\r\n#define MAIN_H\r\n\r\n#ifndef UNICODE\r\n#define UNICODE\r\n#endif\r\n\r\n#define WIN32_LEAN_AND_MEAN\r\n\r\n#include <windows.h>\r\n\r\n#endif /* MAIN_H */\r\n\r\n\r\n")) return 0;
  81.    
  82.     if (Printf(hFileToWriteTo, "/* File: main.c */\r\n\r\n#ifndef MAIN_H\r\n#include \"main.h\"\r\n#endif\r\n\r\n\r\nLRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);\r\nTCHAR szAppName[] = TEXT(\"W2CHimage\");\r\n\r\n\r\n")) return 0;
  83.  
  84.     if(Printf(hFileToWriteTo, "int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)\r\n{\r\n\tHWND hwnd;\r\n\tMSG msg;\r\n\tWNDCLASS wndclass;\r\n\t\r\n\twndclass.style = CS_HREDRAW | CS_VREDRAW;\r\n\twndclass.lpfnWndProc = WndProc;\r\n\twndclass.cbClsExtra = 0;\r\n\twndclass.cbWndExtra = 0;\r\n\twndclass.hInstance = hInstance;\r\n\twndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);\r\n\twndclass.hCursor = LoadCursor(NULL, IDC_ARROW);\r\n\twndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\r\n\twndclass.lpszMenuName = szAppName;\r\n\twndclass.lpszClassName = szAppName;\r\n\t\r\n")) return 0;
  85.     if(Printf(hFileToWriteTo, "\r\n\tif (!RegisterClass(&wndclass))\r\n\t{\r\n\t\tMessageBox(NULL, TEXT(\"This program requires Windows NT!\"),\r\n\t\t\tszAppName, MB_ICONERROR);\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\thwnd = CreateWindow(szAppName, TEXT(\"DIB Section Display\"),\r\n\t\tWS_OVERLAPPEDWINDOW,\r\n\t\tCW_USEDEFAULT, CW_USEDEFAULT,\r\n\t\tCW_USEDEFAULT, CW_USEDEFAULT,\r\n\t\tNULL, NULL, hInstance, NULL);\r\n\t\r\n\tShowWindow(hwnd, iCmdShow);\r\n\tUpdateWindow(hwnd);\r\n\twhile(GetMessage(&msg, NULL, 0, 0))\r\n\t{\r\n\t\tTranslateMessage(&msg);\r\n\t\tDispatchMessage(&msg);\r\n\t}\r\n\t\r\n\treturn msg.wParam;\r\n}\r\n\r\n\r\n")) return 0;
  86.  
  87.     return 1;
  88. }
  89.  
  90.  
  91. int WriteW2CIFImageCreation(HANDLE hFileToWriteTo, char *szBitmapName, int nBitmapNumber)
  92. {
  93.     HANDLE file_handle;             // the file handle to the bitmap to create function to
  94.     int    nReturnValue;
  95.     DWORD  nNumberOfBytesRead;
  96.  
  97.     // 0. Open the file.
  98.     if ((file_handle = CreateFile(szBitmapName, GENERIC_READ, FILE_SHARE_READ/* what if 0? */,
  99.         NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
  100.         return 1;
  101.  
  102.     // 1. Is the file a bitmap?
  103.     BITMAPFILEHEADER bitmapFileHeader;
  104.     nReturnValue = ReadFile(file_handle, &bitmapFileHeader, sizeof(BITMAPFILEHEADER), &nNumberOfBytesRead, NULL);
  105.     if (!nReturnValue || sizeof(BITMAPFILEHEADER) != nNumberOfBytesRead || bitmapFileHeader.bfType != BITMAP_ID)
  106.     {
  107.         CloseHandle(file_handle);
  108.         return 1;
  109.     }
  110.  
  111.     // 2. Read the bitmap infoheader:
  112.     BITMAPINFOHEADER bih;
  113.     nReturnValue = ReadFile(file_handle, &bih, sizeof(BITMAPINFOHEADER), &nNumberOfBytesRead, NULL);
  114.     if (!nReturnValue || sizeof(BITMAPINFOHEADER) != nNumberOfBytesRead)
  115.     {
  116.         CloseHandle(file_handle);
  117.         return 1;
  118.     }
  119.  
  120.     // 3. Load the color palette(if there is one)
  121.     int oldBitCount = bih.biBitCount;
  122.  
  123.     switch (bih.biBitCount)
  124.     {
  125.     default:
  126.     case 0:
  127.         bih.biBitCount = 0;
  128.         break;
  129.  
  130.     case 1:
  131.         bih.biBitCount = 2;
  132.         break;
  133.  
  134.     case 4:
  135.         bih.biBitCount = 16;
  136.         break;
  137.  
  138.     case 8:
  139.         bih.biBitCount = 256;
  140.         break;
  141.     }
  142.  
  143.     /* (1.5) Print The First Things in the Bitmap Function--- */
  144.     if (Printf(hFileToWriteTo, "HBITMAP CreateBitmap%d(void)\r\n{\r\n\tBITMAPINFO * pbmi;\r\n\tBYTE * pBits;\r\n\tHBITMAP hBitmap;\r\n\t\r\n\t// Allocate memory for the BITMAPINFO structure & read it in\r\n\tpbmi = (BITMAPINFO*)new char[sizeof(BITMAPINFOHEADER)+%d * sizeof(RGBQUAD)];\r\n\t\r\n", nBitmapNumber, bih.biBitCount))
  145.     {
  146.         CloseHandle(file_handle);
  147.         return 1;
  148.     }
  149.  
  150.     if (Printf(hFileToWriteTo, "\tpbmi->bmiHeader.biSize          = %d; // size of this header\r\n\tpbmi->bmiHeader.biWidth         = %d; // image width in pixels\r\n\tpbmi->bmiHeader.biHeight        = %d; // image height in pixels\r\n\tpbmi->bmiHeader.biPlanes        = %d; // number of planes (must be set to 1)\r\n\tpbmi->bmiHeader.biBitCount      = %d; // bits per pixel\r\n\tpbmi->bmiHeader.biCompression   = ", bih.biSize, bih.biWidth, bih.biHeight, bih.biPlanes, oldBitCount))
  151.     {
  152.         CloseHandle(file_handle);
  153.         return 1;
  154.     }
  155.    
  156.     switch (bih.biCompression)
  157.     {
  158.         default:
  159.         case BI_RGB:
  160.             if (Printf(hFileToWriteTo, "BI_RGB"))
  161.             {
  162.                 CloseHandle(file_handle);
  163.                 return 1;
  164.             }
  165.             break;
  166.  
  167.         case BI_RLE8:
  168.             if (Printf(hFileToWriteTo, "BI_RLE8"))
  169.             {
  170.                 CloseHandle(file_handle);
  171.                 return 1;
  172.             }
  173.             break;
  174.  
  175.         case BI_RLE4:
  176.             if (Printf(hFileToWriteTo, "BI_RLE4"))
  177.             {
  178.                 CloseHandle(file_handle);
  179.                 return 1;
  180.             }
  181.             break;
  182.            
  183.         case BI_BITFIELDS:
  184.             if (Printf(hFileToWriteTo, "BI_BITFIELDS"))
  185.             {
  186.                 CloseHandle(file_handle);
  187.                 return 1;
  188.             }
  189.             break;
  190.            
  191.         case BI_JPEG:
  192.             if (Printf(hFileToWriteTo, "BI_JPEG"))
  193.             {
  194.                 CloseHandle(file_handle);
  195.                 return 1;
  196.             }
  197.             break;
  198.  
  199.         case BI_PNG:
  200.             if (Printf(hFileToWriteTo, "BI_PNG"))
  201.             {
  202.                 CloseHandle(file_handle);
  203.                 return 1;
  204.             }
  205.             break;
  206.     }
  207.  
  208.     if (Printf(hFileToWriteTo, "; // compression method\r\n\tpbmi->bmiHeader.biSizeImage     = %d; // number of bytes in bitmap\r\n\tpbmi->bmiHeader.biXPelsPerMeter = %d; // horizontal resolution\r\n\tpbmi->bmiHeader.biYPelsPerMeter = %d; // vertical resolution\r\n\tpbmi->bmiHeader.biClrUsed       = %d; // colors used in the image\r\n\tpbmi->bmiHeader.biClrImportant  = %d; // important colors\r\n\r\n", bih.biSizeImage, bih.biXPelsPerMeter, bih.biYPelsPerMeter, bih.biClrUsed, bih.biClrImportant))
  209.     {
  210.         CloseHandle(file_handle);
  211.         return 1;
  212.     }
  213.    
  214.     /* ------------------------------------------------ */
  215.  
  216.     if (bih.biBitCount)
  217.     {
  218.         RGBQUAD *pBitmapColorPalette = (RGBQUAD *)new char[bih.biBitCount * sizeof(RGBQUAD)];
  219.  
  220.         for (int i = 0; i < bih.biBitCount; i++)
  221.         {
  222.             nReturnValue = ReadFile(file_handle, &(pBitmapColorPalette[i]), sizeof(RGBQUAD), &nNumberOfBytesRead, NULL);
  223.             if (!nReturnValue || sizeof(RGBQUAD) != nNumberOfBytesRead)
  224.             {
  225.                 delete[] pBitmapColorPalette;
  226.                 CloseHandle(file_handle);
  227.                 return 1;
  228.             }
  229.         }
  230.  
  231.         // 3.5 Print the color pallet:
  232.         for (int i = 0; i < bih.biBitCount; i++)
  233.         {
  234.             if (Printf(hFileToWriteTo, "\tpbmi->bmiColors[%d].rgbBlue  = %#02x;\r\n\tpbmi->bmiColors[%d].rgbGreen = %#02x;\r\n\tpbmi->bmiColors[%d].rgbRed   = %#02x;\r\n", i, (unsigned char)pBitmapColorPalette[i].rgbBlue, i, (unsigned char)pBitmapColorPalette[i].rgbGreen, i, (unsigned char)pBitmapColorPalette[i].rgbRed))
  235.             {
  236.                 delete[] pBitmapColorPalette;
  237.                 CloseHandle(file_handle);
  238.                 return 1;
  239.             }
  240.         }
  241.  
  242.         if (Printf(hFileToWriteTo, "\r\n\tfor (int n = 0; n < %d; n++) pbmi->bmiColors[n].rgbReserved = 0;\r\n\r\n\t// Create the DIB Section\r\n\thBitmap = CreateDIBSection(NULL, pbmi, ", bih.biBitCount))
  243.         {
  244.             delete[] pBitmapColorPalette;
  245.             CloseHandle(file_handle);
  246.             return 1;
  247.         }
  248.        
  249.         if (oldBitCount > 8 || !bih.biBitCount)
  250.         {
  251.             if (Printf(hFileToWriteTo, "DIB_PAL_COLORS"))
  252.             {
  253.                 delete[] pBitmapColorPalette;
  254.                 CloseHandle(file_handle);
  255.                 return 1;
  256.             }
  257.         }
  258.         else
  259.             if (Printf(hFileToWriteTo, "DIB_RGB_COLORS"))
  260.             {
  261.                 delete[] pBitmapColorPalette;
  262.                 CloseHandle(file_handle);
  263.                 return 1;
  264.             }
  265.            
  266.         delete[] pBitmapColorPalette;
  267.  
  268.         if (Printf(hFileToWriteTo, ", (VOID **)&pBits, NULL, 0);\r\n\t\r\n\tif (hBitmap == NULL)\r\n\t{\r\n\t\tdelete[] pbmi;\r\n\t\treturn NULL;\r\n\t}\r\n\t\r\n\t// Read in the bitmap bits\r\n"))
  269.         {
  270.             CloseHandle(file_handle);
  271.             return 1;
  272.         }
  273.     }
  274.  
  275.     // 4. Get the bitmap data.
  276.     int nBitmapDataSize = bitmapFileHeader.bfSize - bitmapFileHeader.bfOffBits;
  277.     char *pcBitmapData = new CHAR[nBitmapDataSize];
  278.     for (int i = 0; i < nBitmapDataSize; i++)
  279.     {
  280.         nReturnValue = ReadFile(file_handle, &(pcBitmapData[i]), sizeof(CHAR), &nNumberOfBytesRead, NULL);
  281.         if (!nReturnValue || sizeof(CHAR) != nNumberOfBytesRead)
  282.         {
  283.             delete[] pcBitmapData;
  284.             CloseHandle(file_handle);
  285.             return 1;
  286.         }
  287.     }
  288.  
  289.     CloseHandle(file_handle); // No need for the handel any more.
  290.  
  291.     // 4.5 Print the data of the bitmap:
  292.     for (int i = 0; i < nBitmapDataSize; i++)
  293.     {
  294.         if (Printf(hFileToWriteTo, "\tpBits[%d] = %#02x;\r\n", i, (unsigned char)pcBitmapData[i]))
  295.         {
  296.             delete[] pcBitmapData;
  297.             return 1;
  298.         }
  299.     }
  300.  
  301.     delete[] pcBitmapData;
  302.  
  303.     if (Printf(hFileToWriteTo, "\t\r\n\t\r\n\tdelete[] pbmi;\r\n\treturn hBitmap;\r\n}\r\n\r\n")) return 1;
  304.  
  305.     return 0;
  306. }
  307.  
  308.  
  309. int  WriteW2CIFEnd(HANDLE hFileToWriteTo, int nImageSpeed, int NumberOfImages)
  310. {
  311.     if (Printf(hFileToWriteTo, "\r\nLRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\r\n{\r\n\tstatic int nImageToDisplay = 0;\r\n\t\r\n\tstatic int nClientWidth  = 0;\r\n\tstatic int nWindowHeight = 0;\r\n\t\r\n")) return 1;
  312.     for (int i = 0; i < NumberOfImages; ++i)
  313.     {
  314.         if (Printf(hFileToWriteTo, "\tstatic HBITMAP hBitmap%d = NULL;\r\n", i)) return 1;
  315.     }
  316.  
  317.     if (Printf(hFileToWriteTo, "\t\r\n\tswitch(message)\r\n\t{\r\n\t\tcase WM_CREATE:\r\n\t\t\tif (!SetTimer (hwnd, 1, %d, NULL))\r\n\t\t\t{\r\n\t\t\t\tMessageBox (hwnd, TEXT(\"SetTimer failed!\"), TEXT(\"ERROR\"), MB_OK);\r\n\t\t\t\treturn -1;\r\n\t\t\t}\r\n\t\t\t\r\n", nImageSpeed)) return 1;
  318.     for (int i = 0; i < NumberOfImages; ++i)
  319.     {
  320.         if (Printf(hFileToWriteTo, "\t\t\tif (!(hBitmap%d = CreateBitmap%d()))\r\n\t\t\t{\r\n\t\t\t\tMessageBox(NULL, TEXT(\"failed CreateBitmap%d!\"), TEXT(\"ERROR\"), MB_OK);\r\n\t\t\t\treturn -1;\r\n\t\t\t}\r\n", i, i, i)) return 1;
  321.     }
  322.  
  323.     if (Printf(hFileToWriteTo, "\t\t\treturn 0;\r\n\t\t\t\r\n\t\tcase WM_SIZE:\r\n\t\t\tnClientWidth  = LOWORD(lParam);\r\n\t\t\tnWindowHeight = HIWORD(lParam);\r\n\t\t\treturn 0;\r\n\t\t\t\r\n\t\tcase WM_TIMER:\r\n\t\t\tnImageToDisplay = (nImageToDisplay < 2) * (nImageToDisplay + 1);\r\n\t\t\tInvalidateRect(hwnd, NULL, TRUE);\t\t\t// Update the client to show next/new image\r\n\t\t\treturn 0;\r\n\t\t\t\r\n", NumberOfImages)) return 1;
  324.  
  325.     /* !WM_PAINT! */
  326.     if (Printf(hFileToWriteTo, "\t\tcase WM_PAINT:\r\n\t\t\t{\r\n\t\t\t\tHBITMAP hCurrentBitmapToDisplay;\r\n\t\t\t\tHGDIOBJ oldHandelObject;\r\n\t\t\t\tHDC hdc, hdcMem;\r\n\t\t\t\tPAINTSTRUCT ps;\r\n\t\t\t\t\r\n\t\t\t\tswitch(nImageToDisplay)\r\n\t\t\t\t{\r\n\t\t\t\t\tdefault:\r\n")) return 1;
  327.     for (int i = 0; i < NumberOfImages; ++i)
  328.     {
  329.         if (Printf(hFileToWriteTo, "\t\t\t\t\tcase %d:\r\n\t\t\t\t\t\thCurrentBitmapToDisplay = hBitmap%d;\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\r\n", i, i)) return 1;
  330.     }
  331.  
  332.     if (Printf(hFileToWriteTo, "\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\thdc = BeginPaint(hwnd, &ps);\r\n\t\t\t\tif (hCurrentBitmapToDisplay)\r\n\t\t\t\t{\r\n\t\t\t\t\thdcMem = CreateCompatibleDC(hdc);\r\n\t\t\t\t\t/* -------------------------------------- */\r\n\t\t\t\t\tBITMAPINFO bmiTemp;\r\n\t\t\t\t\tZeroMemory(&bmiTemp, sizeof(BITMAPINFO));\r\n\t\t\t\t\tbmiTemp.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);\r\n\t\t\t\t\tif (!GetDIBits(hdc, hCurrentBitmapToDisplay, 0, 0, NULL, &bmiTemp, DIB_RGB_COLORS))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tMessageBox(NULL, TEXT(\"GetDIBits failed!\"), TEXT(\"ERROR\"), MB_OK);\r\n\t\t\t\t\t\tPostMessage(hwnd, WM_DESTROY, 0, 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t\t/* -------------------------------------- */\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n")) return 1;
  333.     if (Printf(hFileToWriteTo, "\t\t\t\t\tif (NULL == (oldHandelObject = SelectObject(hdcMem, hCurrentBitmapToDisplay)))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tMessageBox(NULL, TEXT(\"SelectObject failed!\"), TEXT(\"ERROR\"), MB_OK);\r\n\t\t\t\t\t\t\tPostMessage(hwnd, WM_DESTROY, 0, 0);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tStretchBlt(hdc, 0, 0, nClientWidth, nWindowHeight, hdcMem, 0, 0, bmiTemp.bmiHeader.biWidth, bmiTemp.bmiHeader.biHeight, SRCCOPY);\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\tSelectObject(hdcMem, oldHandelObject);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tDeleteDC(hdcMem);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tEndPaint(hwnd, &ps);\r\n\t\t\t}\r\n\t\t\treturn 0;\r\n\t\t\t\r\n")) return 1;
  334.     /* !WM_PAINT! */
  335.  
  336.     if (Printf(hFileToWriteTo, "\t\tcase WM_DESTROY: \r\n\t\t\tKillTimer(hwnd, 1);\r\n\t\t\t\r\n")) return 1;
  337.  
  338.     for (int i = 0; i < NumberOfImages; ++i)
  339.     {
  340.         if (Printf(hFileToWriteTo, "\t\t\tif (hBitmap%d) DeleteObject(hBitmap%d);\r\n", i, i)) return 1;
  341.     }
  342.  
  343.     if (Printf(hFileToWriteTo, "\t\t\t\r\n\t\t\tPostQuitMessage(0);\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\r\n\treturn DefWindowProc(hwnd, message, wParam, lParam);\r\n}\r\n")) return 1;
  344.    
  345.     return 0;
  346. }
  347.  
  348.  
  349. int main(int argc, char *argv[])
  350. {
  351.     if (argc > 1)
  352.     {
  353.         int nNextImageSpeed = 0;
  354.         int nNumberOfImages = 0;
  355.         HANDLE hNewFile;
  356.        
  357.         //argv[1] "test.txt"
  358.         if ((hNewFile = CreateFile(argv[1], GENERIC_WRITE,
  359.                                   FILE_SHARE_READ/*0*/, NULL, CREATE_NEW,
  360.                                   FILE_ATTRIBUTE_NORMAL, NULL)
  361.                         ) == INVALID_HANDLE_VALUE)
  362.         {
  363.             if (ERROR_FILE_EXISTS == GetLastError()) MessageBox(NULL, "Error CreateFile, file exist that you want to create! Please delete the file to create a new one", "ERROR", MB_OK);
  364.         }
  365.         else
  366.         {
  367.             if (WriteW2CIFHead(hNewFile))
  368.             {
  369.                 int i;
  370.                 for (i = 2; i < argc; ++i)
  371.                 {
  372.                     if (*(argv[i]) == '-')
  373.                         if (*((argv[i]) + 1) == 's')
  374.                             if (*((argv[i]) + 2) == '\0')
  375.                             {
  376.                                 ++i;
  377.                                 for (int n = 0; *((argv[i]) + n) != '\0'; nNextImageSpeed = (nNextImageSpeed * 10) | ((*((argv[i]) + n)) & 0xF), ++n);
  378.                                 continue;
  379.                             }
  380.  
  381.                     if (WriteW2CIFImageCreation(hNewFile, argv[i], nNumberOfImages))
  382.                     {
  383.                         MessageBox(NULL, "WriteW2CIFImageCreation failed!", "ERROR", MB_OK);
  384.                         i = argc + 1;
  385.                     }
  386.                     else ++nNumberOfImages;
  387.                 }
  388.  
  389.                 if (i != argc + 1)
  390.                     if (WriteW2CIFEnd(hNewFile, nNextImageSpeed, nNumberOfImages)) MessageBox(NULL, "WriteW2CIFEnd failed!", "ERROR", MB_OK);
  391.             }
  392.  
  393.             CloseHandle(hNewFile);
  394.         }
  395.     }
  396.     else Help(argv[0]);
  397.  
  398.     return 0;
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement