/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(Info)---------------------------------------------------------------- LEAD Functions Used. L_FileInfo L_VersionInfo We have made the assumption that the user has the knowledge of programing in C and Windows. This example will: 1. display vital image information from a file whose name is sent through the command line, and version information about the LEAD DLL in use. Usage: INFO --------------------------------------------------------------------------*/ #include /* required for all Windows applications. */ #include /* Windows header for message cracker. */ #include "tchar.h" #include #include #include "..\\..\\..\\include\\l_bitmap.h" /* LEADTOOLS main header file. */ #include "..\\..\\..\\include\\l_error.h" /* LEADTOOLS error definition header file. */ #include "Info.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; /* Windows' Message variable for holding messages */ 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); /* 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: Bitmap.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: Bitmap.h Notes: Creates main window. --------------------------------------------------------------------------*/ L_BOOL InitInstance (HANDLE hInstance, L_INT nCmdShow) { HWND hWnd; /* Window handle. */ 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, /* Window width. */ CW_USEDEFAULT, /* 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); /* Sends 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: Bitmap.h Notes: This procedure is responsible for dispatching 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); } 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: Bitmap.h Notes: This procedure is responsible for handling WM_CREATE. --------------------------------------------------------------------------*/ BOOL Window_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { L_INT nRet; FILEINFO FileInfo; /* LEAD File Information structure. */ VERSIONINFO VersionInfo; /* LEAD Version Information structure. */ L_TCHAR Buf[1024]; /* Buffer to hold information for display. */ UNREFERENCED_PARAMETER (lpCreateStruct); FileInfo.uStructSize = sizeof(FILEINFO); nRet = L_FileInfo ((L_TCHAR L_FAR *) szFilename, &FileInfo, sizeof(FILEINFO), 0, NULL); if (nRet == SUCCESS) { wsprintf (Buf, TEXT("Filename: %s\n\n") TEXT("Format: %c\n\n") TEXT("Width: %d\n\n") TEXT("Height: %d\n\n") TEXT("BitsPerPixel: %d\n\n") TEXT("ViewPerspective: %d\n\n") TEXT("Size On Disk: %ld\n\n") TEXT("Size In Memory: %ld\n\n") TEXT("Compression: %s"), (LPTSTR) szFilename, FileInfo.Format + '0', FileInfo.Width, FileInfo.Height, FileInfo.BitsPerPixel, FileInfo.ViewPerspective, FileInfo.SizeDisk, FileInfo.SizeMem, (LPSTR) FileInfo.Compression); MessageBox (hWnd, Buf, TEXT("File Information"), MB_OK); } else { wsprintf (Buf, TEXT("Error %d obtaining information on the file %s"), nRet, (LPTSTR) szFilename); MessageBox (hWnd, Buf, TEXT("ERROR"), MB_OK); } { // VERSIONINFO L_CHAR VersionInfoBuf[1024]; VersionInfo.uStructSize = sizeof(VersionInfo); L_VersionInfo (&VersionInfo, sizeof(VersionInfo)); sprintf (VersionInfoBuf, "LEAD Product: %s, %s\n\n" "Version %d.%d\n\n" "Date: %s\n\n" "Time: %s", (LPSTR) VersionInfo.Product, (LPSTR) (VersionInfo.Level == TOOLKIT_LEVEL_DOCUMENT ? "Express Edition": VersionInfo.Level == TOOLKIT_LEVEL_MEDICAL ? "Medical Express Edition": "Professional Edition"), VersionInfo.MajorNumber, VersionInfo.MinorNumber, (LPSTR) VersionInfo.Date, (LPSTR) VersionInfo.Time); MessageBoxA (hWnd, VersionInfoBuf, "DLL Version Information", MB_OK); } // VERSIONINFO return (FALSE); } /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: Info.c Notes: - This procedure is responsible for extracting the file 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 ( szFilename, 0, sizeof ( szFilename ) ); lstrcpyn ( szFilename, pszFirst - 1, ( nStringLen - nFirstPos ) ) ; return TRUE; }