/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(LoadSave)------------------------------------------------------------ LEAD Functions Used. L_SetDisplayMode L_CreatePaintPalette L_PaintDC L_FreeBitmap L_FileInfo L_LoadFile L_SaveFile We have made the assumption that the user has the knowledge of programing in C and Windows. This example will: 1. load an image from a file, selfected using Windows' common dialog box for opening a file, to a bitmap, 2. display the image in a window. 3. get a filename, format, and bits per pixel to save to, using Windows' common dialog box, 4. save the image. This is a menu driven example for loading and saving images. Usage: LOADSAVE --------------------------------------------------------------------------*/ #include /* Required for all Windows applications. */ #include /* Needed for message crackers. */ #include "tchar.h" #include /* Windows' header for common dialog box. */ #include /* Standard C header files. */ #include #include "..\\..\\..\\include\\l_bitmap.h" /* LEADTOOLS main header file. */ #include "..\\..\\..\\include\\l_error.h" /* LEADTOOLS error definition header file. */ #include "LoadSave.h" /* Application specific header file. */ 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. */ ExtractCommandData ( ); if (!InitInstance (hInstance, nCmdShow)) /* Do instance initializations. */ return (FALSE); L_DlgInit(DLG_INIT_COLOR); /* 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: Loadsave.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 = TEXT("MENU_MAIN"); /* Menu Name. */ wcWindowClass.lpszClassName = TEXT("LEADWClass"); /* Class 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: Loadsave.h Notes: Saves instance handle and creates main window. --------------------------------------------------------------------------*/ L_BOOL InitInstance (HANDLE hInstance, L_INT nCmdShow) { HWND hWnd; /* Window handle. */ /* 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. */ CW_USEDEFAULT, /* Default width. */ CW_USEDEFAULT, /* Default 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: Loadsave.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_COMMAND, Window_OnCommand); HANDLE_MSG (hWnd, WM_PALETTECHANGED, Window_OnPaletteChanged); HANDLE_MSG (hWnd, WM_QUERYNEWPALETTE, Window_OnQueryNewPalette); HANDLE_MSG (hWnd, WM_PAINT, Window_OnPaint); HANDLE_MSG (hWnd, WM_DESTROY, Window_OnDestroy); HANDLE_MSG (hWnd, WM_ACTIVATE, Window_OnActivate); HANDLE_MSG (hWnd, WM_PALETTEISCHANGING, Window_OnPaletteChanging); HANDLE_MSG (hWnd, WM_SYSCOLORCHANGE, Window_SysColorChange); } 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: Loadsave.h Notes: This procedure is responsible for handling WM_CREATE. --------------------------------------------------------------------------*/ BOOL Window_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { HMENU hMenu; UNREFERENCED_PARAMETER (hWnd); UNREFERENCED_PARAMETER (lpCreateStruct); hMenu = GetMenu (hWnd); ENABLEMENUITEM (hMenu, IDM_SAVE, Data.BitmapHandle.Flags.Allocated); Data.hPalette = NULL; /* Set Ordered Dithering for the Display */ L_SetDisplayMode (DISPLAYMODE_ORDEREDDITHER, DISPLAYMODE_ORDEREDDITHER); return (TRUE); } /*---[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: Color.h Notes: This procedure is responsible for handling WM_ONCOMMAND. --------------------------------------------------------------------------*/ VOID Window_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) { L_INT nRet; L_TCHAR buf[1024]; /* Buffer to hold the error message. */ UNREFERENCED_PARAMETER (hwndCtl); UNREFERENCED_PARAMETER (codeNotify); switch (id) { case IDM_OPEN: nRet = Get_OpenFile (hWnd); if (nRet == 2) ; /* No file was selected for opening, so do nothing. */ else if (nRet == SUCCESS) FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); else { wsprintf (buf, TEXT("Error %d Loading %s"), nRet, (LPTSTR) Data.szFilename); MessageBox (hWnd, buf, TEXT("Error"), MB_OK); } break; case IDM_SAVE: nRet = SaveBitmapFile (hWnd, &Data.BitmapHandle); if (nRet < SUCCESS) { wsprintf (buf, TEXT("Error %d Saving %s"), nRet, (LPTSTR) Data.szFilename); MessageBox (hWnd, buf, TEXT("Error"), MB_OK); } break; case IDM_EXIT: DestroyWindow (hWnd); break; } return; } /*----(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: Loadsave.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); /* 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_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_OnQueryNewPalette)-------------------------------------------- Syntax: BOOL Window_OnQueryNewPalette( HWND hWnd ) Parameters: hWnd Handle to a window. Prototype: Loadsave.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; } 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_OnPaint]------------------------------------------------------- Syntax: VOID Window_OnPaint( HWND hWnd ); Parameters: hWnd Window handle. Prototype: Loadsave.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); } EndPaint (hWnd, &ps); /* Return DC */ return; } /*---[Window_OnDestroy]---------------------------------------------------- Syntax: VOID Window_OnDestroy( HWND hWnd ); Parameters: hWnd Window handle. Prototype: Loadsave.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); L_DlgFree(); PostQuitMessage (0); /* Post WM_QUIT, to end the application. */ return; } L_VOID CleanOpenDlgParam(LPOPENDLGPARAMS pFOParam) { int i=0; if(pFOParam!=NULL && pFOParam->pFileData!= NULL ) { for(i=0; i < pFOParam->nNumOfFiles; ++i ) { if(pFOParam->pFileData[i].pBitmap != NULL) { L_FreeBitmap(pFOParam->pFileData[i].pBitmap); GlobalFreePtr(pFOParam->pFileData[i].pBitmap); } if(pFOParam->pFileData[i].pThumbnail != NULL) { L_FreeBitmap(pFOParam->pFileData[i].pThumbnail); GlobalFreePtr(pFOParam->pFileData[i].pThumbnail); } if(pFOParam->pFileData[i].pFileInfo != NULL) { GlobalFreePtr(pFOParam->pFileData[i].pFileInfo); } } GlobalFreePtr(pFOParam->pFileData); pFOParam->pFileData =NULL; pFOParam->nNumOfFiles = 0; } } L_INT Get_OpenFile (HWND hWnd) { static OPENDLGPARAMS FOParm; static OPENFILENAME OpenFileName; static LOADFILEOPTION LoadFileOption; HMENU hMenu; HCURSOR hCursor; L_INT nRet; _fmemset(&FOParm, 0, sizeof(OPENDLGPARAMS)); _fmemset(&OpenFileName, 0, sizeof(OPENFILENAME)); FOParm.uStructSize = sizeof(OPENDLGPARAMS); FOParm.bShowLoadOptions = FALSE ; FOParm.bPreviewEnabled = TRUE; FOParm.uDlgFlags = DLG_OPEN_LOADBITMAP | DLG_OPEN_SHOW_PREVIEW | DLG_OPEN_SHOW_FILEINFO; OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.hwndOwner = hWnd; OpenFileName.lpstrFilter = NULL; OpenFileName.lpstrCustomFilter = NULL; OpenFileName.nMaxCustFilter = 0; OpenFileName.nFilterIndex = 1; OpenFileName.lpstrInitialDir = Data.szImageDir; OpenFileName.lpstrTitle = TEXT("Open File"); OpenFileName.lpstrDefExt = NULL; OpenFileName.Flags = 0; L_GetDefaultLoadFileOption(&LoadFileOption, sizeof(LOADFILEOPTION)); LoadFileOption.Flags |= ELO_ROTATED; nRet = L_DlgOpen( hWnd, &OpenFileName, &FOParm); if(nRet == SUCCESS_DLG_OK) { nRet=FAILURE; if ( ( FOParm.pFileData != NULL ) && ( FOParm.nNumOfFiles > 0 ) ) { lstrcpy (Data.szFilename, FOParm.pFileData[ 0 ].szFileName); if ( FOParm.pFileData[ 0 ].pBitmap != NULL ) { if ( FOParm.pFileData[ 0 ].pBitmap->Flags.Allocated ) { hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); Data.FileInfo.uStructSize = sizeof(FILEINFO); nRet = L_FileInfo (Data.szFilename, &Data.FileInfo, sizeof(FILEINFO), 0, &LoadFileOption); if ( nRet == SUCCESS ) { /* If there is a bitmap, free it. */ if (Data.BitmapHandle.Flags.Allocated) L_FreeBitmap (&Data.BitmapHandle); nRet = L_LoadBitmap (Data.szFilename, &Data.BitmapHandle, sizeof(BITMAPHANDLE), Data.FileInfo.BitsPerPixel, ORDER_BGR, &LoadFileOption, &Data.FileInfo); } SetCursor (hCursor); } } } CleanOpenDlgParam(&FOParm); } if (nRet == SUCCESS) { FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, TRUE); hMenu = GetMenu (hWnd); ENABLEMENUITEM (hMenu, IDM_SAVE, Data.BitmapHandle.Flags.Allocated); DrawMenuBar (hWnd); return nRet; } return 2; } /*----(SaveBitmapFile)----------------------------------------------------- Syntax: L_INT SaveBitmapFile( HWND hWnd, pBITMAPHANDLE pBitmapHandle ) Prototype: Loadsave.h Parameters: hWnd Handle of the window owner. pBitmapHandle Pointer to the bitmap handle of the image to be saved. Notes: This function will control the saving of an image to a file. --------------------------------------------------------------------------*/ L_INT SaveBitmapFile (HWND hWnd, pBITMAPHANDLE pBitmapHandle) { OPENFILENAME SaveFileName; SAVEDLGPARAMS FSParm; SAVEFILEOPTION SaveFileOption; FILEJ2KOPTIONS FileJ2KOptions; L_UINT uFlags=0; L_TCHAR buf[1024]; HCURSOR hCursor; L_INT nRet; memset(&SaveFileName, 0, sizeof(OPENFILENAME)); memset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); memset(&FileJ2KOptions,0,sizeof(FileJ2KOptions)); FSParm.uStructSize = sizeof(SAVEDLGPARAMS); FSParm.nQFactor = 2; FSParm.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE| DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE| DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR| DLG_SAVE_SHOW_FILEOPTIONS_STAMP| DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS| DLG_SAVE_ENABLESIZING; SaveFileName.lStructSize = sizeof(OPENFILENAME); SaveFileName.lpstrInitialDir = NULL; SaveFileName.lpstrTitle = TEXT("Save As"); SaveFileName.nFileOffset = 0; SaveFileName.Flags = 0; nRet = L_DlgSave( hWnd, &SaveFileName, &FSParm ); if(nRet == SUCCESS_DLG_OK) { L_GetDefaultSaveFileOption(&SaveFileOption, sizeof(SAVEFILEOPTION)); SaveFileOption.Flags &= ~(ESO_REPLACEPAGE|ESO_INSERTPAGE); switch(FSParm.uSaveMulti) { case MULTIPAGE_OPERATION_OVERWRITE: SaveFileOption.PageNumber = 1; break; case MULTIPAGE_OPERATION_APPEND: SaveFileOption.PageNumber = 2; break; case MULTIPAGE_OPERATION_REPLACE: SaveFileOption.PageNumber = FSParm.nPageNumber; SaveFileOption.Flags |= ESO_REPLACEPAGE; break; case MULTIPAGE_OPERATION_INSERT: SaveFileOption.PageNumber = FSParm.nPageNumber; SaveFileOption.Flags |= ESO_INSERTPAGE; break; } SaveFileOption.Passes = FSParm.nPasses; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (FSParm.nBitsPerPixel <= 4 && pBitmapHandle->BitsPerPixel != FSParm.nBitsPerPixel) uFlags = SAVEFILE_FIXEDPALETTE; else uFlags = SAVEFILE_OPTIMIZEDPALETTE; if((FSParm.nFormat == FILE_J2K)|| (FSParm.nFormat == FILE_JP2)|| (FSParm.nFormat == FILE_CMW)|| (FSParm.nFormat == FILE_TIF_J2K)|| (FSParm.nFormat == FILE_TIF_CMW)) { /*Restore the old J2K Options*/ L_GetJ2KOptions(&FileJ2KOptions,sizeof(FILEJ2KOPTIONS)); L_SetJ2KOptions(&FSParm.FileJ2KOptions); } nRet = L_SaveFile(FSParm.szFileName , pBitmapHandle, FSParm.nFormat, FSParm.nBitsPerPixel, FSParm.nQFactor, uFlags, NULL, NULL, &SaveFileOption ); SetCursor (hCursor); if((FSParm.nFormat == FILE_J2K)|| (FSParm.nFormat == FILE_JP2)|| (FSParm.nFormat == FILE_CMW)|| (FSParm.nFormat == FILE_TIF_J2K)|| (FSParm.nFormat == FILE_TIF_CMW)) { /*Restore the old J2K Options*/ L_SetJ2KOptions(&FileJ2KOptions); } if (nRet != SUCCESS) { wsprintf (buf, TEXT("ERROR %d saving the file %s."), nRet, (LPSTR) FSParm.szFileName); MessageBox (hWnd, buf, TEXT("ERROR"), MB_OK); } else return (TRUE); } return (2); } /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: loadsave.c Notes: - This procedure is responsible for extracting the dir name passed through the command line. - You should call this function only in WinMain function. --------------------------------------------------------------------------*/ L_BOOL ExtractCommandData ( ) { LPTSTR pszFirst = NULL; LPTSTR pszCmdLine = NULL; LPTSTR psz = NULL; L_INT nFirstPos = 0 ; L_INT nStringLen = 0 ; pszCmdLine = GetCommandLine(); nStringLen = lstrlen ( pszCmdLine ) + 1 ; // 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 ; } memset ( Data.szImageDir , 0, sizeof ( Data.szImageDir ) ); lstrcpyn ( Data.szImageDir, pszFirst - 1, ( nStringLen - nFirstPos ) ) ; return TRUE; }