/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(CompCB)--------------------------------------------------------------- LEAD Functions Used. L_FileInfo L_InitBitmap L_LoadBitmap L_AccessBitmap L_StartCompressBuffer L_GetBitmapRow L_ReleaseBitmap L_CompressBuffer L_EndCompressBuffer L_ClearBitmap L_FreeBitmap L_CreatePaintPalette L_PaintDC We have made the assumption that the user has the knowledge of programing in C and Windows. This example will: 1. load the image from a file, whose name is sent through the command line, to a bitmap as 24 bits per pixel (L_CompressBuffer requires data to be 24 bit color or 8 bit grayscale), 2. display the image, 3. compress the bitmap to file using the call back feature of LEADTOOLS, 4. clear the bitmap, 5. load the compressed image, 6. display the newly loaded image. Usage: COMPCB --------------------------------------------------------------------------*/ #include /* Needed for message crackers. */ #include /* Required for all Windows applications. */ #include #include #include "TCHAR.h" #include "..\\..\\..\\include\\l_bitmap.h" /* LEADTOOLS main header file. */ #include "..\\..\\..\\include\\l_error.h" /* LEADTOOLS error definition header file. */ #include "CompCB.h" /* Application specific header file. */ #define BUFFER_SIZE 8192 #define NLINES 16 L_BOOL ExtractCommandData ( ) ; /*---[WinMain]--------------------------------------------------------------- Syntax: int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) Parameters: hInstance Current instance. hPrevInstance previous instance. lpCmdLine command line. nCmdShow show-window type. Prototype: Windows.h Notes: Windows main function, calls initialization function and processes message loop. --------------------------------------------------------------------------*/ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; /* Message structure, See Windows SDK for more information. */ UNLOCKSUPPORT(); if (!hPrevInstance) /* Other instances of app running? */ if (!InitApplication (hInstance)) /* Initialize shared things. */ return (FALSE); /* Exits if unable to initialize. */ if (!ExtractCommandData ()) { return FALSE; } if (!InitInstance (hInstance, nCmdShow)) /* Do instance initializations. */ return (FALSE); /* Acquire and dispatch messages until a WM_QUIT message is received. */ while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); /* Translates virtual key codes. */ DispatchMessage (&msg); /* Dispatches message to window. */ } return (msg.wParam); /* Returns the value from PostQuitMessage. */ } /*---[InitApplication]------------------------------------------------------ Syntax: L_BOOL InitApplication( HANDLE hInstance ) Parameters: hInstance Current instance. Prototype: CompCB.h Notes: Initializes window class structure and registers window class. --------------------------------------------------------------------------*/ L_BOOL InitApplication (HANDLE hInstance) { WNDCLASS wcWindowClass; wcWindowClass.style = 0; /* Class style(s). */ wcWindowClass.lpfnWndProc = MainWndProc; /* Function to retrieve messages */ /* for windows of this class. */ wcWindowClass.cbClsExtra = 0;/* No per-class extra data. */ wcWindowClass.cbWndExtra = 0;/* No per-window extra data. */ wcWindowClass.hInstance = hInstance; /* Owner. */ wcWindowClass.hIcon = LoadIcon (hInstance, TEXT("LEAD")); wcWindowClass.hCursor = LoadCursor (NULL, IDC_ARROW); wcWindowClass.hbrBackground = GetStockObject (WHITE_BRUSH); wcWindowClass.lpszMenuName = NULL; /* No menu. */ wcWindowClass.lpszClassName = TEXT("LEADWClass"); /* Name. */ /* Register the window class and return the result code. */ return (RegisterClass (&wcWindowClass)); } /*---[InitInstance]---------------------------------------------------------- Syntax: L_BOOL InitInstance( HANDLE hInstance, L_INT nCmdShow ) Parameters: hInstance Current instance. nCmdShow Param for first ShowWindow() call. Prototype: CompCB.h Notes: Saves instance handle and creates main window. --------------------------------------------------------------------------*/ L_BOOL InitInstance (HANDLE hInstance, L_INT nCmdShow) { HWND hWnd; /* Window handle. */ L_INT nRet; L_TCHAR buf[1024]; hInst = hInstance; /* For use with MakeProcInstance. */ /* Get image information. */ Data.FileInfo.uStructSize = sizeof(FILEINFO); if ((nRet = L_FileInfo (Data.szFilename, &Data.FileInfo, sizeof(FILEINFO), 0, NULL)) != SUCCESS) { wsprintf (buf, TEXT("ERROR %d from L_FileInfo on file %s"), nRet, (LPTSTR) Data.szFilename); MessageBox (NULL, buf, TEXT("ERROR"), MB_OK); return (FALSE); } if (Data.FileInfo.BitsPerPixel != 24) { wsprintf (buf, TEXT("ERROR: Image must be 24-bit")); MessageBox (NULL, buf, TEXT("ERROR"), MB_OK); return (FALSE); } /* Set up RECT for window sizing. */ rWndSize.top = 0; rWndSize.left = 0; rWndSize.bottom = INFOHEIGHT(&Data.FileInfo); rWndSize.right = INFOWIDTH(&Data.FileInfo); /* Create RECT to size of image plus window frame. */ AdjustWindowRect (&rWndSize, WS_OVERLAPPEDWINDOW, FALSE); /* Create a main window for this application instance. */ hWnd = CreateWindow ( TEXT("LEADWClass"), TEXT("LEADTOOLS Sample Application"), /* Window title */ WS_OVERLAPPEDWINDOW, /* Window style. */ CW_USEDEFAULT, /* Default horizontal position. */ CW_USEDEFAULT, /* Default vertical position. */ rWndSize.right - rWndSize.left, /* Window width. */ rWndSize.bottom - rWndSize.top, /* Window height. */ NULL, /* Overlapped windows have no parent. */ NULL, /* Use the window class menu. */ hInstance, /* This instance owns this window. */ NULL /* Pointer not needed. */ ); if (hWnd == NULL) return (FALSE); /* If window could not be created, return "failure". */ ShowWindow (hWnd, nCmdShow); /* Show the window. */ UpdateWindow (hWnd); /* Send WM_PAINT message. */ return (TRUE); } /*---[MainWndProc]----------------------------------------------------------- Syntax: L_INT32 EXT_FUNCTION MainWndProc( HWND hWnd, L_UINT message, WPARAM wParam, LPARAM lParam ) Parameters: hWnd Window handle. message Type of message. wParam Additional information. lParam Additional information. Prototype: CompCB.h Notes: This procedure is responsible for handling window messages. --------------------------------------------------------------------------*/ L_INT32 EXT_FUNCTION MainWndProc (HWND hWnd, L_UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { HANDLE_MSG (hWnd, WM_CREATE, Window_OnCreate); HANDLE_MSG (hWnd, WM_TIMER, Window_OnTimer); HANDLE_MSG (hWnd, WM_COMMAND, Window_OnCommand); HANDLE_MSG (hWnd, WM_PALETTECHANGED, Window_OnPaletteChanged); HANDLE_MSG (hWnd, WM_QUERYNEWPALETTE, Window_OnQueryNewPalette); HANDLE_MSG (hWnd, WM_ACTIVATE, Window_OnActivate); HANDLE_MSG (hWnd, WM_PALETTEISCHANGING, Window_OnPaletteChanging); HANDLE_MSG (hWnd, WM_SYSCOLORCHANGE, Window_SysColorChange); HANDLE_MSG (hWnd, WM_PAINT, Window_OnPaint); HANDLE_MSG (hWnd, WM_DESTROY, Window_OnDestroy); } return DefWindowProc (hWnd, Message, wParam, lParam); } /*---[Window_OnCreate]----------------------------------------------------- Syntax: BOOL Window_OnCreate(HWND hWnd, CREATESTRUCT FAR* lpCreateStruct); Parameters: hWnd Window handle. lpCreateStruct Windows Create Structure. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_CREATE. --------------------------------------------------------------------------*/ BOOL Window_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { L_INT nRet; UNREFERENCED_PARAMETER (lpCreateStruct); /* Initialize some globals. */ bFirst = TRUE; bResetCount = TRUE; nOperation = WM_USER + USER_COMPRESS; /* Load the image to the bitmap. */ nRet = L_LoadBitmap (Data.szFilename, &Data.BitmapHandle, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); if(Data.BitmapHandle.ViewPerspective != TOP_LEFT) L_ChangeBitmapViewPerspective(NULL, &Data.BitmapHandle, sizeof(BITMAPHANDLE), TOP_LEFT); nBytesPerLine = (L_INT32) ((L_UINT) Data.BitmapHandle.Width) * (Data.BitmapHandle.BitsPerPixel / 8); if (nRet != SUCCESS) { L_TCHAR buf[1024]; /* Buffer to hold the error message. */ wsprintf (buf, TEXT("Error %d Loading %s"), nRet, (LPTSTR) Data.szFilename); MessageBox (hWnd, buf, TEXT("Error"), MB_OK); return (FALSE); /* Failure in creation, so return FALSE. */ } FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); return (TRUE); } /*---[Window_OnTimer]------------------------------------------------------- Syntax: VOID Window_OnTimer( HWND hWnd, UINT id ); Parameters: hWnd Window handle. id ID of the Timer. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_TIMER. --------------------------------------------------------------------------*/ VOID Window_OnTimer (HWND hWnd, UINT id) { static HCURSOR hOrigCursor; UNREFERENCED_PARAMETER (id); nCount++; /* Increment the Counter. */ /* Has the image been displayed about 3 seconds? (this is reset in the function Window_OnPaint) */ if (nCount == 1) { hOrigCursor = SetCursor (LoadCursor (NULL, IDC_SIZENS)); return; } else if (nCount == 2) { SetCursor (LoadCursor (NULL, IDC_SIZENESW)); return; } else if (nCount == 3) { /* Kill the timer if nOperation is USER_NONE. */ if (nOperation == WM_USER + USER_RELOAD) KillTimer (hWnd, nTimer); SetCursor (hOrigCursor); /* Let Window_OnPaint reset the counter. */ bResetCount = TRUE; /* nOperation is set in Window_OnCreate and Window_OnCommand. */ FORWARD_WM_COMMAND (hWnd, nOperation, 0, 0, PostMessage); } return; } /*---[Window_OnCommand]----------------------------------------------------- Syntax: VOID Window_OnCommand( HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify ) Parameters: hWnd Window handle. id Menu item or Control ID. hwndCtl 0 if menu item selected, else window handle of the control. codeNotify 1 if accelerator keystroke, else notification code, such as BN_CLICKED. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_ONCOMMAND. --------------------------------------------------------------------------*/ VOID Window_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) { L_INT i, j, nRet; HCURSOR hCursor; HGLOBAL hInBuffer; HGLOBAL hOutBuffer; HANDLE hFile; static L_TCHAR buf[512]; L_UCHAR L_FAR *lpInBuffer; L_UCHAR L_FAR *lpOutBuffer; L_UCHAR L_FAR *lpDataBuffer; UNREFERENCED_PARAMETER (hwndCtl); UNREFERENCED_PARAMETER (codeNotify); switch (id) { case (WM_USER + USER_COMPRESS): /* Set the operation to nothing. If something goes wrong, we don't want to enter this loop again! */ nOperation = WM_USER + USER_NONE; SetWindowText (hWnd, TEXT("Compressing Image...")); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); /* Create the file to store the compress image */ hFile = CreateFile ( Data.szDestFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if(hFile == NULL || hFile == INVALID_HANDLE_VALUE) { MessageBox (hWnd, TEXT("Error opening the output file2222!"), TEXT("Error"), MB_OK); SetWindowText (hWnd, TEXT("Error Opening Output, Example Is Complete")); return; } /* Allocates memory for the incomming compressed data. Note that we are compressing NLINES lines at a time. It is recommended to use multiples of 16 at all times. Also, no padding is to be sent to the compressor. */ hInBuffer = GlobalAlloc (GMEM_MOVEABLE, (L_UINT32) NLINES * nBytesPerLine); if (hInBuffer == NULL) { /* Not enough memory. */ CloseHandle(hFile); MessageBox (hWnd, TEXT("Not enough memory!"), TEXT("Error"), MB_OK); return; } lpInBuffer = (L_UCHAR L_FAR *) GlobalLock (hInBuffer); /* Allocate an output buffer. This is where the compressed data will go. Note that this alocates BUFFER_SIZE byte packets. Depending on your application and compression level, you can determine the buffer size to allocate. We recommend at least 1024 bytes or more for images that have a width of 640 to gain the most speed and performance. */ hOutBuffer = GlobalAlloc (GMEM_MOVEABLE, BUFFER_SIZE); if (hOutBuffer == NULL) { /* Not enough memory. */ GlobalUnlock (hInBuffer); GlobalFree (hInBuffer); CloseHandle(hFile); MessageBox (hWnd, TEXT("Not enough memory!"), TEXT("Error"), MB_OK); return; } lpOutBuffer = (L_UCHAR L_FAR *) GlobalLock (hOutBuffer); L_AccessBitmap (&Data.BitmapHandle); /* Lock down the bitmap. */ /* Initialize the compression engine with all needed parameters. */ nRet = L_StartCompressBuffer (&Data.BitmapHandle, FileWrite, (L_UINT32) NLINES * nBytesPerLine, BUFFER_SIZE, (L_CHAR L_FAR *) lpOutBuffer, LEAD, -1, (L_VOID L_FAR *) &hFile, NULL); if(nRet != SUCCESS) { /* Free all allocated memory. Release the bitmap. Close the file. */ GlobalUnlock (hInBuffer); GlobalFree (hInBuffer); GlobalUnlock (hOutBuffer); GlobalFree (hOutBuffer); L_ReleaseBitmap (&Data.BitmapHandle); CloseHandle(hFile); MessageBox (hWnd, TEXT("Compress Buffer Failure!"), TEXT("Error"), MB_OK); return; } for (i = 0; i < Data.BitmapHandle.Height;) /* i is incremented at the end! */ { lpDataBuffer = lpInBuffer; /* Compression of the NLINE line chunk starts here. */ for (j = 0; (i + j) < Data.BitmapHandle.Height && j < NLINES; j++) { /* Gets the one line at time */ if (L_GetBitmapRow (&Data.BitmapHandle, lpDataBuffer, i + j, (L_UINT32) nBytesPerLine) != (L_INT32) nBytesPerLine) { /* Compression error - Clean up */ GlobalUnlock (hInBuffer); GlobalFree (hInBuffer); GlobalUnlock (hOutBuffer); GlobalFree (hOutBuffer); L_ReleaseBitmap (&Data.BitmapHandle); CloseHandle(hFile); return; } /* Move the pointer to next line. */ lpDataBuffer = lpDataBuffer + nBytesPerLine; } /* This is the main function that will do the actual Compression. */ if ((nRet = L_CompressBuffer (lpInBuffer)) != SUCCESS) { /* Compression error - Clean up */ GlobalUnlock (hInBuffer); GlobalFree (hInBuffer); GlobalUnlock (hOutBuffer); GlobalFree (hOutBuffer); L_ReleaseBitmap (&Data.BitmapHandle); CloseHandle(hFile); return; } /* Do the next NLINE line chunk. */ i += NLINES; } /* Compression is done. Reset The Compression Engine. */ L_EndCompressBuffer (); /* Free all allocated memory. Release the bitmap. Close the file. */ GlobalUnlock (hInBuffer); GlobalFree (hInBuffer); GlobalUnlock (hOutBuffer); GlobalFree (hOutBuffer); L_ReleaseBitmap (&Data.BitmapHandle); CloseHandle(hFile); SetWindowText (hWnd, TEXT("Image Compressed - Clearing Bitmap...")); /* Clear the bitmap. */ L_ClearBitmap (&Data.BitmapHandle); /* Force a repaint. */ FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, TRUE); /* Set nOperation to reload the image. */ nOperation = WM_USER + USER_RELOAD; SetCursor (hCursor); SetWindowText (hWnd, TEXT("Image Compressed - Bitmap Cleared")); bResetCount = TRUE; break; case (WM_USER + USER_RELOAD): /* Set the operation to nothing. If something goes wrong, we don't want to enter this loop again! */ nOperation = WM_USER + USER_NONE; SetWindowText (hWnd, TEXT("Loading Compressed Image...")); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); L_FreeBitmap (&Data.BitmapHandle); /* Reinitialize the bitmap to 24-bits. */ L_InitBitmap (&Data.BitmapHandle, sizeof(BITMAPHANDLE), Data.FileInfo.Width, Data.FileInfo.Height, 24); /* Load the image to the bitmap. */ nRet = L_LoadBitmap (Data.szDestFilename, &Data.BitmapHandle, sizeof(BITMAPHANDLE), 24, ORDER_BGR, NULL, NULL); SetCursor (hCursor); if (nRet != SUCCESS) { wsprintf (buf, TEXT("Error %d Loading %s"), nRet, (LPTSTR) Data.szDestFilename); MessageBox (hWnd, buf, TEXT("Error - Exiting"), MB_OK); /* Failure in load, so kill the application. */ FORWARD_WM_CLOSE (hWnd, PostMessage); } else { /* Force a repaint. */ SetWindowText (hWnd, TEXT("Compressed Image Loaded, Example Is Complete")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, TRUE); } bResetCount = TRUE; break; } } /*----(Window_OnPaletteChanged)-------------------------------------------- Syntax: VOID Window_OnPaletteChanged( HWND hWnd, HWND hWndPaletteChange ) Parameters: hwnd Handle to a window. hWndPaletteChange Handle to a window that has the palette realized. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_PALETTECHANGED. --------------------------------------------------------------------------*/ VOID Window_OnPaletteChanged (HWND hWnd, HWND hWndPaletteChange) { HDC hDC; HPALETTE hPalette; /* If this window initiated the palette change, do nothing. */ if (hWnd == hWndPaletteChange) return; /* Does this window have a bitmap and a palette? */ if (Data.BitmapHandle.Flags.Allocated) { hDC = GetDC (hWnd); /* Generate a new logical palette (if needed) for painting. */ Data.hPalette = L_CreatePaintPalette (hDC, &Data.BitmapHandle); /* Select and Realize the palette. */ hPalette = SelectPalette (hDC, Data.hPalette, TRUE); RealizePalette (hDC); /* Force a repaint. */ InvalidateRect (hWnd, NULL, FALSE); /* Return the old palette. */ SelectPalette (hDC, hPalette, TRUE); ReleaseDC (hWnd, hDC); } return; } /*----(Window_OnQueryNewPalette)-------------------------------------------- Syntax: BOOL Window_OnQueryNewPalette( HWND hWnd ) Parameters: hWnd Handle to a window. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_QUERYNEWPALETTE. --------------------------------------------------------------------------*/ BOOL Window_OnQueryNewPalette (HWND hWnd) { HDC hDC; HPALETTE hPalette; L_INT nNoColors = 0; /* Delete the previous palette, if there is one. */ if (Data.hPalette) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } /* Delete the previous palette, if there is one. */ if (Data.hPalette) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } if (Data.BitmapHandle.Flags.Allocated) { hDC = GetDC (hWnd); /* Generate a new logical palette (if needed) for painting. */ Data.hPalette = L_CreatePaintPalette (hDC, &Data.BitmapHandle); if (Data.hPalette) /* Is a palette needed? */ { hPalette = SelectPalette (hDC, Data.hPalette, FALSE); nNoColors = RealizePalette (hDC); if (nNoColors) /* If the palette changed, force a WM_PAINT */ InvalidateRect (hWnd, NULL, FALSE); /* Restore the old palette. */ SelectPalette (hDC, hPalette, TRUE); } ReleaseDC (hWnd, hDC); } return (nNoColors); } /*---[Window_OnActivate]----------------------------------------------------- Syntax: VOID Window_OnActivate(HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized) Parameters: hWnd Window handle. state WA_ACTIVE | WA_CLICKACTIVE | WA_INACTIVE hwndActDeact the winodw habdle that deactivate fMinimized Window is minimized Prototype: Color.h Notes: This procedure is responsible for handling WM_ACTIVATE. --------------------------------------------------------------------------*/ VOID Window_OnActivate(HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized) { if(state!=WA_INACTIVE) Window_OnQueryNewPalette (hwnd); } /*====(Window_OnPaletteChanging)========================================== Description: Enumerates all child windows and asks them to realize their logical palettes beside the physical palette. Syntax : VOID Window_OnPaletteChanging(HWND hwnd, HWND hWndPaletteChange) Parameters : hwnd Handle to a window. hWndPaletteChange Handle to a window that has the palette realized. Return Value: None. ==========================================================================*/ VOID Window_OnPaletteChanging(HWND hWnd, HWND hWndPaletteChange) { Window_OnPaletteChanged (hWnd, hWndPaletteChange); } /*====(Window_SysColorChange)========================================== Syntax: VOID Window_SysColorChange( HWND hWnd ) Parameters: hWnd Handle to a window. Prototype: Loadsave.h Notes: This procedure is responsible for handling WM_SYSCOLORCHANGE. --------------------------------------------------------------------------*/ VOID Window_SysColorChange(HWND hwnd) { Window_OnQueryNewPalette (hwnd); } /*---[Window_OnPaint]------------------------------------------------------- Syntax: VOID Window_OnPaint( HWND hWnd ); Parameters: hWnd Window handle. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_PAINT. --------------------------------------------------------------------------*/ VOID Window_OnPaint (HWND hWnd) { HDC hdc; RECT rc; PAINTSTRUCT ps; HPALETTE hOldPal = NULL; hdc = BeginPaint (hWnd, &ps);/* Get DC */ if (Data.BitmapHandle.Flags.Allocated) /* Do we have an image? */ { if (Data.hPalette) /* Is there a palette that needs to be selected? */ hOldPal = SelectPalette (hdc, Data.hPalette, TRUE); /* Select it. */ /* Setup the Destination Rectangle. */ SetRect (&rc, 0, 0, BITMAPWIDTH(&Data.BitmapHandle), BITMAPHEIGHT(&Data.BitmapHandle)); /* Paint it */ L_PaintDC (hdc, &Data.BitmapHandle, NULL, NULL, &rc, &ps.rcPaint, SRCCOPY); if (Data.hPalette) /* Return old palette if there is one. */ SelectPalette (hdc, hOldPal, TRUE); if (bResetCount) { bResetCount = FALSE; /* Make sure counter is only reset after image processing has been done in Window_OnTimer. */ nCount = 0; /* Reset the counter for display delay. */ } if (bFirst) { bFirst = FALSE; /* Start a timer to be used for display delay. */ if ((nTimer = SetTimer (hWnd, 1, 1000, 0)) == 0) { MessageBox (hWnd, TEXT("No Timers Are Available!"), TEXT("ERROR - Resources"), MB_OK); /* No timers are available, so quit the application. */ FORWARD_WM_DESTROY (hWnd, PostMessage); } } } EndPaint (hWnd, &ps); /* Return DC */ return; } /*---[Window_OnDestroy]---------------------------------------------------- Syntax: VOID Window_OnDestroy( HWND hWnd ); Parameters: hWnd Window handle. Prototype: CompCB.h Notes: This procedure is responsible for handling WM_DESTROY. --------------------------------------------------------------------------*/ VOID Window_OnDestroy (HWND hWnd) { UNREFERENCED_PARAMETER (hWnd); if (Data.BitmapHandle.Flags.Allocated) /* Do we have an image? */ L_FreeBitmap (&Data.BitmapHandle); if (Data.hPalette) /* Delete palette if there is one. */ DeleteObject (Data.hPalette); PostQuitMessage (0); /* Post WM_QUIT, to end the application. */ return; } /*---[FileWrite]------------------------------------------------------------ Syntax: L_INT FileWrite(pBITMAPHANDLE pBitmap, L_UCHAR L_FAR *pBuffer, L_UINT16 nBytes, L_VOID L_FAR *pParams) Parameters: pBitmap Pointer to the bitmap handle. pBuffer Pointer to a buffer that hold compressed data. nBytes Number of bytes in the compressed buffer. pParams Pointer to a User data, as in this case file handle. Prototype: CompCB.h Notes: If the compression buffer is full or the compression proccess is completed, this function is called. You may change this function to do whatever you may want with the output buffer. In this example, the compressed output buffer will be written to a file. This callback function can be used for purposes like sending the data through the modem, or other operations, depending on your application, rather than just saving the data to disk. --------------------------------------------------------------------------*/ L_INT L_EXPORT L_FAR FileWrite (pBITMAPHANDLE pBitmap, L_UCHAR L_FAR * pBuffer, L_UINT nBytes, L_VOID L_FAR * pParams) { DWORD uNumberOfBytesWritten = 0; UNREFERENCED_PARAMETER (pBitmap); /* Write data to the file. Note: The file handle is passed in as a L_VOID L_FAR pointer as per the LEAD definition and must be cast appropriately to use it as a file handle. */ WriteFile ( *((HANDLE*)pParams), pBuffer, nBytes, &uNumberOfBytesWritten, NULL ); return (SUCCESS); } /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: Compcb.c Notes: - This procedure is responsible for extracting the file names passed through the command line. - You should call this function only in WinMain function. - Consider that between the two images name should be only one space. --------------------------------------------------------------------------*/ L_BOOL ExtractCommandData ( ) { LPTSTR pszFirst = NULL; LPTSTR pszSecond = NULL; LPTSTR pszCmdLine = NULL; LPTSTR psz = NULL; L_INT nFirstPos = 0 ; L_INT nSecondPos = 0 ; L_INT nStringLen = 0 ; pszCmdLine = GetCommandLine(); nStringLen = lstrlen ( pszCmdLine ) ; // To specify that it is command line or not. if(( pszCmdLine[1] == ':' ) || // Shortcut case ( pszCmdLine[2] == ':' )) //VS case { // 1- TRY TO EXPOSE THE EXE NAME FROM THE COMMAND LINE psz = _tcschr ( pszCmdLine, ':' ) ; if ( NULL == psz ) { return FALSE ; } } else { psz = pszCmdLine ; } pszFirst = _tcschr ( psz + 1, ':' ) ; if ( NULL == pszFirst ) { return FALSE ; } // Calc the char number to the image file name. nFirstPos = pszFirst - pszCmdLine - 1 ; if ( 0 > nFirstPos ) { return FALSE ; } // 2- TRY TO EXPOSE THE EXE NAME AND THE FIRST FILE NAME FROM THE COMMAND LINE psz = pszFirst ; pszSecond = _tcschr ( psz + 1, ':' ) ; if ( NULL == pszSecond ) { return FALSE ; } // Calc the char number to the image file name. nSecondPos = pszSecond - pszCmdLine - 1 ; if ( 0 > nSecondPos ) { return FALSE ; } memset (Data.szFilename, 0, sizeof(Data.szFilename)); memset (Data.szDestFilename, 0, sizeof(Data.szDestFilename)); lstrcpyn ( Data.szFilename, pszFirst - 1, abs( ( nStringLen - nFirstPos ) - ( nStringLen - nSecondPos ) ) ) ; lstrcpyn ( Data.szDestFilename, pszSecond - 1, ( nStringLen - ( nStringLen - nSecondPos ) ) ) ; return TRUE; }