/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(DIBDDB)--------------------------------------------------------------- LEAD Functions Used. L_CreatePaintPalette L_PaintDC L_FreeBitmap L_FileInfo L_InitBitmap L_LoadBitmap L_ColorResBitmap L_ConvertToDDB L_ConvertToDIB L_ConvertFromDDB L_ConvertFromDIB We have made the assumption that the user has the knowledge of programing in C and Windows. This example is a menu driven program that can be used to demonstrate the DIB-LEAD-DDB Cycle. Usage: DIBDDB --------------------------------------------------------------------------*/ #include /* Needed for message crackers. */ #include /* Required for all Windows applications. */ #include #include #include #include #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 "dibddb.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; HMENU hMainMenu; WNDCLASS wndClass; UNREFERENCED_PARAMETER (lpCmdLine); UNLOCKSUPPORT(); if (!hPrevInstance) { wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon (hInstance, TEXT("LEAD")); wndClass.hCursor = LoadCursor (NULL, IDC_ARROW); wndClass.hbrBackground = GetStockObject (BLACK_BRUSH); wndClass.lpszMenuName = TEXT("MAIN_MENU"); wndClass.lpszClassName = TEXT("LEADDLL Class"); RegisterClass (&wndClass); } hMainWnd = CreateWindow (TEXT("LEADDLL Class"), TEXT("LEAD-DIB-DDB Cycle Demo"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, hInstance, NULL); hMainMenu = GetMenu (hMainWnd); SetImageType(TYPE_NONE); ExtractCommandData ( ) ; ShowWindow (hMainWnd, nCmdShow); UpdateWindow (hMainWnd); while (GetMessage (&Msg, NULL, 0, 0)) { TranslateMessage (&Msg); DispatchMessage (&Msg); } return Msg.wParam; } /*---[WndProc]-------------------------------------------------------------- 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: DIBDDB.h Notes: This procedure is responsible for handling window messages. --------------------------------------------------------------------------*/ L_INT32 EXT_FUNCTION WndProc (HWND hWnd, L_UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { HANDLE_MSG (hWnd, WM_CREATE, Window_OnCreate); 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_COMMAND, Window_OnCommand); 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 Handle to the window. lpCreateStruct Pointer to CREATESTRUCT Prototype: DIBDDB.h Notes: This function handles the WM_CREATE message. --------------------------------------------------------------------------*/ BOOL Window_OnCreate (HWND hWnd, CREATESTRUCT FAR * lpCreateStruct) { UNREFERENCED_PARAMETER (lpCreateStruct); UNREFERENCED_PARAMETER (hWnd); nImageType = TYPE_NONE; nOpenTypeIdx = 1; /* Default file type index */ hDDB = 0; hDIB = 0; return (TRUE); } /*----[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: DIBDDB.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; /* Delete the previous palette, if there is one. */ if (hPaintPalette) { DeleteObject (hPaintPalette); hPaintPalette = NULL; } /* Does this window have a bitmap and a palette? */ if ((Bitmap.Flags.Allocated || hDIB || hDDB)) { hDC = GetDC (hWnd); /* Generate a new logical palette (if needed) for painting. */ hPaintPalette = L_CreatePaintPalette (hDC, &Bitmap); /* Select and Realize the palette. */ hPalette = SelectPalette (hDC, hPaintPalette, 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: DIBDDB.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 (hPaintPalette) { DeleteObject (hPaintPalette); hPaintPalette = NULL; } hDC = GetDC (hWnd); if (Bitmap.Flags.Allocated) { /* Generate a new logical palette (if needed) for painting. */ hPaintPalette = L_CreatePaintPalette (hDC, &Bitmap); } if (hPaintPalette) /* Is a palette needed? */ { hPalette = SelectPalette (hDC, hPaintPalette, 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); } #ifndef WIN32 L_CHAR pszErrorString[] = "Enhanced Metafiles are not supported in 16 bit"; #define PlayEnhMetaFile(hdc, hWMF, lprc) TextOut(hdc, 20, 20, pszErrorString, sizeof(pszErrorString)-1) #define DeleteEnhMetaFile(hEMF) #else #define SetViewportOrg(hdc, x, y) SetViewportOrgEx(hdc, x, y, NULL) #define SetViewportExt(hdc, x, y) SetViewportExtEx(hdc, x, y, NULL) #endif /*---[Window_OnPaint]------------------------------------------------------- Syntax: VOID Window_OnPaint( HWND hWnd ); Parameters: hWnd Window handle. Prototype: DIBDDB.h Notes: This procedure is responsible for handling WM_PAINT. --------------------------------------------------------------------------*/ VOID Window_OnPaint (HWND hWnd) { HDC hdc; HDC hMemDC; RECT rc; PAINTSTRUCT ps; HPALETTE hOldPal = NULL; LPSTR lpstBitmap; LPBITMAPINFO lpBitInfo; L_INT Width; L_INT Height; L_INT nColorData; hdc = BeginPaint (hWnd, &ps);/* Get DC */ if (hPaintPalette) /* Is there a palette that needs to be selected? */ hOldPal = SelectPalette (hdc, hPaintPalette, TRUE); /* Select it. */ switch (nImageType) { case TYPE_WMF: SetMapMode(hdc, MM_ANISOTROPIC); SetViewportExt(hdc, nWMFWidth, nWMFHeight); SetViewportOrg(hdc, 0, 0); PlayMetaFile(hdc, hWMF); break; #ifdef WIN32 case TYPE_EMF: SetMapMode(hdc, MM_ANISOTROPIC); PlayEnhMetaFile(hdc, hEMF, &rcEMF); break; #endif case TYPE_DDB: hMemDC = CreateCompatibleDC (hdc); SelectObject (hMemDC, hDDB); StretchBlt (hdc, 0, 0, nDDBWidth, nDDBHeight, hMemDC, 0, 0, nDDBWidth, nDDBHeight, SRCCOPY); DeleteDC (hMemDC); break; case TYPE_DIB: lpBitInfo = (LPBITMAPINFO) GlobalLock (hDIB); /* Determine the # colors in the image */ if (lpBitInfo->bmiHeader.biBitCount <= 8) nColorData = 1 << lpBitInfo->bmiHeader.biBitCount; else nColorData = 0; lpstBitmap = (LPSTR) lpBitInfo + (WORD) sizeof (BITMAPINFOHEADER) + (nColorData * sizeof (RGBQUAD)); Width = (L_INT) lpBitInfo->bmiHeader.biWidth; Height = (L_INT) lpBitInfo->bmiHeader.biHeight; StretchDIBits (hdc, 0, 0, Width, Height, 0, 0, Width, Height, lpstBitmap, lpBitInfo, DIB_RGB_COLORS, SRCCOPY); GlobalUnlock (hDIB); break; case TYPE_LEAD: /* Setup the Destination Rectangle. */ SetRect (&rc, 0, 0, BITMAPWIDTH(&Bitmap), BITMAPHEIGHT(&Bitmap)); /* Paint it */ L_PaintDC (hdc, &Bitmap, NULL, NULL, &rc, &ps.rcPaint, SRCCOPY); break; } if (hPaintPalette) /* Return old palette if there is one. */ SelectPalette (hdc, hOldPal, TRUE); EndPaint (hWnd, &ps); /* Return DC */ return; } /*----[Window_OnCommand]--------------------------------------------------- Syntax: VOID Window_OnCommand( HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify ) Parameters: hWnd Handle to the window. id Control or menu item identifier. hwndCtl Handle of control. codeNotify Notification message. Prototype: DIBDDB.h Notes: This function handles the WM_COMMAND message. --------------------------------------------------------------------------*/ VOID Window_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) { L_TCHAR szFileName[MAXFILENAME]; switch (id) { case IDM_OPEN: if (GetOpenBitmapFile (hWnd, szFileName)) { if (!ImageLoad (hWnd, (LPTSTR) szFileName)) FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); else MessageBox (hWnd, TEXT("ImageLoad Error"), TEXT("ERROR"), MB_OK); } break; case IDM_TO_DDB: SetWindowText (hWnd, TEXT("Creating a DDB...")); Create_DDB (hWnd, &Bitmap); break; case IDM_TO_DIB: SetWindowText (hWnd, TEXT("Creating a DIB...")); Create_DIB (hWnd, &Bitmap); break; case IDM_FROM_DDB: SetWindowText (hWnd, TEXT("Converting a DDB to LEAD Bitmap...")); ConvertFromDDB (hWnd, &Bitmap); break; case IDM_FROM_DIB: SetWindowText (hWnd, TEXT("Converting a DIB to LEAD Bitmap...")); ConvertFromDIB (hWnd, &Bitmap); break; case IDM_TO_WMF: SetWindowText (hWnd, TEXT("Creating a WMF...")); Create_WMF (hWnd, &Bitmap); break; case IDM_FROM_WMF: SetWindowText (hWnd, TEXT("Converting a WMF to LEAD Bitmap...")); ConvertFromWMF (hWnd, &Bitmap); break; #ifdef WIN32 case IDM_TO_EMF: SetWindowText (hWnd, TEXT("Creating a EMF...")); Create_EMF (hWnd, &Bitmap); break; case IDM_FROM_EMF: SetWindowText (hWnd, TEXT("Converting a EMF to LEAD Bitmap...")); ConvertFromEMF (hWnd, &Bitmap); break; #endif case IDM_EXIT: FORWARD_WM_CLOSE (hWnd, SendMessage); break; default: DefFrameProc (hWnd, hMainWnd, WM_COMMAND, (WPARAM) id, MAKELPARAM ((UINT) (hwndCtl), (codeNotify))); } return; } /*----[Window_OnDestroy]--------------------------------------------------- Syntax: VOID Window_OnDestroy( HWND hWnd ) Parameters: hWnd Handle to the window. Prototype: DIBDDB.h Notes: This function handles the WM_DESTROY message. --------------------------------------------------------------------------*/ VOID Window_OnDestroy (HWND hWnd) { UNREFERENCED_PARAMETER (hWnd); switch (nImageType) { case TYPE_WMF: DeleteMetaFile(hWMF); break; #ifdef WIN32 case TYPE_EMF: DeleteEnhMetaFile(hEMF); break; #endif case TYPE_DDB: DeleteObject (hDDB); break; case TYPE_DIB: GlobalUnlock (hDIB); GlobalFree (hDIB); break; case TYPE_LEAD: if (Bitmap.Flags.Allocated) L_FreeBitmap (&Bitmap); break; } if (hPaintPalette) { DeleteObject (hPaintPalette); hPaintPalette = NULL; } PostQuitMessage (0); return; } /*----[GetOpenBitmapFile]------------------------------------------------- Syntax: L_BOOL GetOpenBitmapFile (HWND hWnd, LPSTR pFilename) Prototype: DIBDDB.h Parameters: hWnd Handle to the window. pFilename Name of the file to open and get info from. Notes: This function will open a file and get image information from it. --------------------------------------------------------------------------*/ L_BOOL GetOpenBitmapFile (HWND hWnd, LPTSTR pFilename) { OPENFILENAME ofn; FILEINFO FileInfo; L_TCHAR szFileTitle[256]; L_TCHAR szFilter[1024]; L_INT nRet; L_INT i; static L_BOOL fInit = FALSE; *pFilename = '\0'; /* Image File Formats */ lstrcpy (szFilter, TEXT("ALL|*.*|") TEXT("LEAD|*.cmp|") TEXT("JPEG JFIF|*.JPG|") TEXT("JPEG JTIF|*.jtf|") TEXT("TGA|*.tga|") TEXT("TIF|*.tif|") TEXT("CALS 1|*.cal|Macintosh 1|*.mac|GEM image 1|*.img|MS Paint 1|*.msp|") TEXT("WordPerfect|*.wpg|") TEXT("SUN Raster|*.ras|") TEXT("Mac PICT 1|*.PCT|") TEXT("Windows BMP|*.bmp|") TEXT("OS/2 BMP|*.bmp|") TEXT("PCX|*.pcx|") TEXT("GIF|*.gif|") TEXT("WMF|*.wmf|") TEXT("EPS|*.eps|")); for (i = 0; szFilter[i] != '\0'; i++) { if (szFilter[i] == '|') szFilter[i] = '\0'; } _fmemset (&ofn, 0, sizeof (OPENFILENAME)); ofn.lStructSize = sizeof (OPENFILENAME); ofn.hwndOwner = hWnd; ofn.lpstrFilter = szFilter; ofn.nFilterIndex = nOpenTypeIdx; ofn.lpstrFile = pFilename; ofn.nMaxFile = MAXFILENAME; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof (szFileTitle)/sizeof(L_TCHAR); if (!fInit) { ofn.lpstrInitialDir = szImageDir; fInit = TRUE; } ofn.lpstrTitle = TEXT("Open Bitmap File"); ofn.Flags = (OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY); if (GetOpenFileName (&ofn)) { nOpenTypeIdx = (L_INT) ofn.nFilterIndex; FileInfo.uStructSize = sizeof(FILEINFO); nRet = L_FileInfo (pFilename, &FileInfo, sizeof(FILEINFO), 0, NULL); if (nRet != SUCCESS) MessageBox (hWnd, TEXT("File Error"), TEXT("Open Bitmap File"), MB_ICONEXCLAMATION | MB_OK); else return (TRUE); } return (FALSE); } /*----[ImageLoad]----------------------------------------------------------- Syntax: L_BOOL ImageLoad( HWND hWnd, LPSTR pFileName ) Parameters: hWnd Handle to the window. pFileName Name of the file to open and get info from. Prototype: DIBDDB.h Notes: This function will load the image from a file. --------------------------------------------------------------------------*/ L_BOOL ImageLoad (HWND hWnd, LPTSTR lpFileName) { HDC hDC; HCURSOR hCursor; RECT rcClient, rcWindow; FILEINFO FileInfo; L_INT nRet; L_INT nDeviceBits; /* Get fileinfo of the file */ FileInfo.uStructSize = sizeof(FILEINFO); if (L_FileInfo (lpFileName, &FileInfo, sizeof(FILEINFO), 0, NULL) != SUCCESS) { MessageBox (hWnd, TEXT("Error Reading Input File"), TEXT("Error"), MB_OK); return (FALSE); } switch (nImageType) { case TYPE_WMF: DeleteMetaFile(hWMF); hWMF = NULL; break; #ifdef WIN32 case TYPE_EMF: DeleteEnhMetaFile(hEMF); hEMF = NULL; break; #endif case TYPE_DDB: DeleteObject (hDDB); hDDB = NULL; break; case TYPE_DIB: GlobalUnlock (hDIB); GlobalFree (hDIB); hDIB = NULL; break; case TYPE_LEAD: if (Bitmap.Flags.Allocated) L_FreeBitmap (&Bitmap); break; } if (hPaintPalette) { DeleteObject (hPaintPalette); hPaintPalette = NULL; } /* Snap the window to image */ ShowWindow (hWnd, SW_NORMAL); GetClientRect (hWnd, &rcClient); GetWindowRect (hWnd, &rcWindow); MoveWindow (hWnd, rcWindow.left, rcWindow.top, RECTWIDTH (&rcWindow) + INFOWIDTH(&FileInfo) - RECTWIDTH (&rcClient), RECTHEIGHT (&rcWindow) + INFOHEIGHT(&FileInfo) - RECTHEIGHT (&rcClient), TRUE); /* do it again, in case the image is small and the menu bar was resized */ // GetClientRect (hWnd, &rcClient); // GetWindowRect (hWnd, &rcWindow); // MoveWindow (hWnd, rcWindow.left, rcWindow.top, // RECTWIDTH (&rcWindow) + INFOWIDTH(&FileInfo) - RECTWIDTH (&rcClient), // RECTHEIGHT (&rcWindow) + INFOHEIGHT(&FileInfo) - RECTHEIGHT (&rcClient), // TRUE); hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); /* Change to WAIT */ hDC = GetDC (hWnd); nDeviceBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES); ReleaseDC (hWnd, hDC); /* If Device bits is > 8, set device bits to 24 */ if (nDeviceBits > 8) nDeviceBits = 24; /* Initialize the bitmap */ L_InitBitmap (&Bitmap, sizeof(BITMAPHANDLE), 0, 0, 0); /* Load the bitmap */ if ((FileInfo.BitsPerPixel > nDeviceBits) && (nDeviceBits <= 8)) { if (nDeviceBits <= 4) { nRet = L_LoadBitmap (lpFileName, &Bitmap, sizeof(BITMAPHANDLE), FileInfo.BitsPerPixel, ORDER_BGR, NULL, NULL); if (nRet == SUCCESS) nRet = L_ColorResBitmap (&Bitmap, &Bitmap, sizeof(BITMAPHANDLE), 4, CRF_FIXEDPALETTE | CRF_FLOYDSTEINDITHERING, NULL, NULL, 0, NULL, NULL); } else nRet = L_LoadBitmap (lpFileName, &Bitmap, sizeof(BITMAPHANDLE), nDeviceBits, ORDER_RGB, NULL, NULL); } else /* if the device is 32K or more color order, must be BGR */ nRet = L_LoadBitmap (lpFileName, &Bitmap, sizeof(BITMAPHANDLE), FileInfo.BitsPerPixel, ORDER_BGR, NULL, NULL); if (nRet == SUCCESS) { SetImageType(TYPE_LEAD); nRet = FALSE; SetWindowText (hWnd, TEXT("Displaying a LEAD Bitmap")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, TRUE); } hCursor = SetCursor (hCursor); /* Change to original. */ return (nRet); } /*----[SetImageType]----------------------------------------------------------- Syntax: L_INT SetImageType(L_INT nType) Parameters: type Image type. (TYPE_NONE, TYPE_LEAD, TYPE_DIB, TYPE_DDB, TYPE_WMF or TYPE_EMF) Prototype: DIBDDB.h Notes: This function sets the image type and enables the menu items for the operations that can be performed at one time. --------------------------------------------------------------------------*/ L_VOID SetImageType(L_INT nType) { HMENU hMainMenu = GetMenu (hMainWnd); nImageType = nType; EnableMenuItem (hMainMenu, IDM_TO_DIB, MF_BYCOMMAND | (nType == TYPE_LEAD ? MF_ENABLED : MF_GRAYED)); EnableMenuItem (hMainMenu, IDM_TO_DDB, MF_BYCOMMAND | (nType == TYPE_LEAD ? MF_ENABLED : MF_GRAYED)); EnableMenuItem (hMainMenu, IDM_FROM_DIB, MF_BYCOMMAND | (nType == TYPE_DIB ? MF_ENABLED : MF_GRAYED)); EnableMenuItem (hMainMenu, IDM_FROM_DDB, MF_BYCOMMAND | (nType == TYPE_DDB ? MF_ENABLED : MF_GRAYED)); #ifdef WIN32 EnableMenuItem (hMainMenu, IDM_TO_EMF, MF_BYCOMMAND | (nType == TYPE_LEAD ? MF_ENABLED : MF_GRAYED)); EnableMenuItem (hMainMenu, IDM_FROM_EMF, MF_BYCOMMAND | (nType == TYPE_EMF ? MF_ENABLED : MF_GRAYED)); #else // EMF is not enabled in 16 bit EnableMenuItem (hMainMenu, IDM_TO_EMF, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem (hMainMenu, IDM_FROM_EMF, MF_BYCOMMAND | MF_GRAYED); #endif EnableMenuItem (hMainMenu, IDM_TO_WMF, MF_BYCOMMAND | (nType == TYPE_LEAD ? MF_ENABLED : MF_GRAYED)); EnableMenuItem (hMainMenu, IDM_FROM_WMF, MF_BYCOMMAND | (nType == TYPE_WMF ? MF_ENABLED : MF_GRAYED)); DrawMenuBar (hMainWnd); } /*----[Create_DDB]----------------------------------------------------------- Syntax: L_INT Create_DDB( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will convert a LEAD Bitmap to a DDB. --------------------------------------------------------------------------*/ L_INT Create_DDB (HWND hWnd, pBITMAPHANDLE pBitmap) { HDC hDC; L_INT nRet = TRUE; hDC = GetDC (hWnd); hDDB = L_ConvertToDDB (hDC, pBitmap); ReleaseDC (hWnd, hDC); if (hDDB) { SetImageType(TYPE_DDB); nDDBWidth=BITMAPWIDTH(pBitmap); nDDBHeight=BITMAPHEIGHT(pBitmap); L_FreeBitmap (pBitmap); SetWindowText (hWnd, TEXT("Displaying a DDB")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, FALSE); } else { MessageBox (hWnd, TEXT("Failure to convert to DDB."), TEXT("Error!"), MB_OK); nRet = FALSE; } return (nRet); } /*----[Create_DIB]----------------------------------------------------------- Syntax: L_INT Create_DIB( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will convert a LEAD Bitmap to DIB. --------------------------------------------------------------------------*/ L_INT Create_DIB (HWND hWnd, pBITMAPHANDLE pBitmap) { L_INT nRet = FALSE; hDIB = L_ConvertToDIB (pBitmap, DIB_BITMAPINFOHEADER); if (hDIB) { SetImageType(TYPE_DIB); L_FreeBitmap (pBitmap); SetWindowText (hWnd, TEXT("Displaying a DIB")); InvalidateRect (hWnd, NULL, FALSE); nRet = TRUE; } return (nRet); } /*----[ConvertFromDDB]----------------------------------------------------------- Syntax: L_INT ConvertFromDDB( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will convert a DDB to LEAD Bitmap. --------------------------------------------------------------------------*/ L_INT ConvertFromDDB (HWND hWnd, pBITMAPHANDLE pBitmap) { HDC hDC; L_INT nRet ; HPALETTE hOldPal = NULL; if (hDDB) { hDC = GetDC (hWnd); L_InitBitmap (pBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); nRet = L_ConvertFromDDB(hDC, pBitmap, sizeof(BITMAPHANDLE), hDDB, L_DupPalette(hPaintPalette)); ReleaseDC (hWnd, hDC); if ( nRet != SUCCESS) { MessageBox (hWnd, TEXT("Failure to Convert DDB to LEAD Bitmap."), TEXT("Error!"), MB_OK); return (FALSE); } SetImageType(TYPE_LEAD); DeleteObject (hDDB); hDDB = NULL; SetWindowText (hWnd, TEXT("Displaying a LEAD Bitmap")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, FALSE); } return (TRUE); } /*----[ConvertFromDIB]----------------------------------------------------------- Syntax: L_INT ConvertFromDIB( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will change a DIB to LEAD Bitmap. --------------------------------------------------------------------------*/ L_INT ConvertFromDIB (HWND hWnd, pBITMAPHANDLE pBitmap) { LPBITMAPINFO lpBitInfo; L_UCHAR L_FAR *lpstBitmap; L_UINT32 nColorData; if (hDIB) { L_InitBitmap (pBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); lpBitInfo = (LPBITMAPINFO) GlobalLock (hDIB); if (lpBitInfo->bmiHeader.biBitCount <= 8) { nColorData = 1 << lpBitInfo->bmiHeader.biBitCount; if(lpBitInfo->bmiHeader.biClrUsed) nColorData = lpBitInfo->bmiHeader.biClrUsed; } else nColorData = 0; lpstBitmap = (L_UCHAR L_FAR *) lpBitInfo + sizeof (BITMAPINFOHEADER) + (nColorData * sizeof (RGBQUAD)); if (L_ConvertFromDIB (pBitmap, sizeof(BITMAPHANDLE), lpBitInfo, lpstBitmap) != SUCCESS) { MessageBox (hWnd, TEXT("Failure to convert DIB to LEAD Bitmap."), TEXT("Error!"), MB_OK); return (FALSE); } SetImageType(TYPE_LEAD); GlobalUnlock (hDIB); GlobalFree (hDIB); hDIB = NULL; SetWindowText (hWnd, TEXT("Displaying a LEAD Bitmap")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, FALSE); } return (TRUE); } /*----[Create_WMF]----------------------------------------------------------- Syntax: L_INT Create_WMF( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will convert a LEAD Bitmap to a WMF. --------------------------------------------------------------------------*/ L_INT Create_WMF (HWND hWnd, pBITMAPHANDLE pBitmap) { HDC hDC; L_INT nRet = TRUE; hDC = GetDC (hWnd); hWMF = L_ConvertToWMF (pBitmap); if (hWMF) { SetImageType(TYPE_WMF); nWMFWidth = pBitmap->Width; nWMFHeight = pBitmap->Height; L_FreeBitmap (pBitmap); SetWindowText (hWnd, TEXT("Displaying a WMF")); InvalidateRect (hWnd, NULL, FALSE); } else { MessageBox (hWnd, TEXT("Failure to convert to WMF."), TEXT("Error!"), MB_OK); nRet = FALSE; } ReleaseDC (hWnd, hDC); return (nRet); } #ifdef WIN32 /*----[Create_EMF]----------------------------------------------------------- Syntax: L_INT Create_EMF( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will convert a LEAD Bitmap to EMF. --------------------------------------------------------------------------*/ L_INT Create_EMF (HWND hWnd, pBITMAPHANDLE pBitmap) { L_INT nRet = FALSE; hEMF = L_ConvertToEMF (pBitmap); if (hEMF) { SetImageType(TYPE_EMF); SetRect(&rcEMF, 0, 0, pBitmap->Width, pBitmap->Height); L_FreeBitmap (pBitmap); SetWindowText (hWnd, TEXT("Displaying a EMF")); InvalidateRect (hWnd, NULL, FALSE); nRet = TRUE; } return (nRet); } #endif /*----[ConvertFromWMF]----------------------------------------------------------- Syntax: L_INT ConvertFromWMF( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will convert a WMF to LEAD Bitmap. --------------------------------------------------------------------------*/ L_INT ConvertFromWMF (HWND hWnd, pBITMAPHANDLE pBitmap) { if (hWMF) { L_InitBitmap (pBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); if (L_ConvertFromWMF (pBitmap, sizeof(BITMAPHANDLE), hWMF, 0, 0) != SUCCESS) { MessageBox (hWnd, TEXT("Failure to Convert WMF to LEAD Bitmap."), TEXT("Error!"), MB_OK); return (FALSE); } SetImageType(TYPE_LEAD); DeleteMetaFile (hWMF); hWMF = NULL; SetWindowText (hWnd, TEXT("Displaying a LEAD Bitmap")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, FALSE); } return (TRUE); } #ifdef WIN32 /*----[ConvertFromEMF]----------------------------------------------------------- Syntax: L_INT ConvertFromEMF( HWND hWnd, pBITMAPHANDLE pBitmap ) Parameters: hWnd Handle to the window. pBitmap Pointer to LEAD Bitmap Handle Prototype: DIBDDB.h Notes: This function will change a EMF to LEAD Bitmap. --------------------------------------------------------------------------*/ L_INT ConvertFromEMF (HWND hWnd, pBITMAPHANDLE pBitmap) { if (hEMF) { L_InitBitmap (pBitmap, sizeof(BITMAPHANDLE), 0, 0, 0); if (L_ConvertFromEMF (pBitmap, sizeof(BITMAPHANDLE), hEMF, 0, 0) != SUCCESS) { MessageBox (hWnd, TEXT("Failure to convert EMF to LEAD Bitmap."), TEXT("Error!"), MB_OK); return (FALSE); } SetImageType(TYPE_LEAD); DeleteEnhMetaFile (hEMF); hEMF = NULL; SetWindowText (hWnd, TEXT("Displaying a LEAD Bitmap")); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); InvalidateRect (hWnd, NULL, FALSE); } return (TRUE); } #endif /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: Dibddb.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 (szImageDir, 0, sizeof(szImageDir)); lstrcpyn ( szImageDir, pszFirst - 1, ( nStringLen - nFirstPos ) ) ; return TRUE; }