/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(Scrlzoom)---------------------------------------------------------------- LEAD Functions Used. L_InitBitmap L_CreatePaintPalette L_PaintDC L_FreeBitmap L_FileInfo L_LoadFile We have made the assumption that the user has the knowledge of programing in C and Windows. This is a menu driven demo program with the capability to display, zoom in, and zoom out any image with vertical and horizontal scroll. This program emphasizes the power of the LEADTOOL Function L_PaintDC(). Usage: SCRLZOOM --------------------------------------------------------------------------*/ #include /* Required for all Windows applications. */ #include /* Needed for message crackers. */ #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 "Scrlzoom.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. */ } L_DlgFree(); return (msg.wParam); /* Returns the value from PostQuitMessage. */ } /*---[InitApplication]------------------------------------------------------ Syntax: L_BOOL InitApplication( HANDLE hInstance ) Parameters: hInstance Current instance. Prototype: Scrlzoom.h Notes: Initializes window class structure and registers window class. --------------------------------------------------------------------------*/ L_BOOL InitApplication (HANDLE hInstance) { WNDCLASS wcWindowClass; wcWindowClass.style = CS_HREDRAW | CS_VREDRAW; /* 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 (GRAY_BRUSH); wcWindowClass.lpszMenuName = TEXT("MAIN_MENU"); /* 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: Scrlzoom.h Notes: Creates main window. --------------------------------------------------------------------------*/ L_BOOL InitInstance (HANDLE hInstance, L_INT nCmdShow) { /* Create a main window for this application instance. */ hImageWindow = CreateWindow ( TEXT("LEADWClass"), TEXT("LEADTOOLS Sample Application"), /* Window title */ WS_OVERLAPPEDWINDOW, /* Window style. */ CW_USEDEFAULT, /* Default horizontal position. */ CW_USEDEFAULT, /* Default vertical position. */ 400, /* Window width. */ 400, /* 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 (hImageWindow == NULL) return (FALSE); /* If window could not be created, return "failure". */ hInstApp = hInstance; L_InitBitmap (&Data.Bitmap, sizeof(BITMAPHANDLE), 0, 0, 0); ShowWindow (hImageWindow, nCmdShow); /* Show the window. */ UpdateWindow (hImageWindow); /* 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: Scrlzoom.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_PALETTECHANGED, Window_OnPaletteChanged); HANDLE_MSG (hWnd, WM_QUERYNEWPALETTE, Window_OnQueryNewPalette); HANDLE_MSG (hWnd, WM_PALETTEISCHANGING, Window_OnPaletteChanging); HANDLE_MSG (hWnd, WM_SYSCOLORCHANGE, Window_SysColorChange); HANDLE_MSG (hWnd, WM_ACTIVATE, Window_OnActivate); HANDLE_MSG (hWnd, WM_PAINT, Window_OnPaint); HANDLE_MSG (hWnd, WM_ERASEBKGND, Window_OnEraseBkgnd); HANDLE_MSG (hWnd, WM_SIZE, Window_OnSize); HANDLE_MSG (hWnd, WM_VSCROLL, Window_OnVScroll); HANDLE_MSG (hWnd, WM_HSCROLL, Window_OnHScroll); HANDLE_MSG (hWnd, WM_COMMAND, Window_OnCommand); HANDLE_MSG (hWnd, WM_DESTROY, Window_OnDestroy); } return DefWindowProc (hWnd, Message, wParam, lParam); } /*----[AboutDlgProc]------------------------------------------------------ Syntax: BOOL AboutDlgProc (HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) Parameters: hDlg Handle of the Dialog Box. Msg Message to be processed wParam Windows WORD Parameter. lParam Windows LONG Parameter. Prototype: Scrlzoom.h Notes: This function is responsible for handling the About dialog box messages. --------------------------------------------------------------------------*/ LRESULT CALLBACK L_EXPORT AboutDlgProc (HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { HANDLE_MSG (hDlg, WM_COMMAND, About_OnCommand); } return (FALSE); } /*----[About_OnCommand]-------------------------------------------------- Syntax: VOID About_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: demo.h Notes: This function will translate the WM_COMMAND message. --------------------------------------------------------------------------*/ VOID About_OnCommand (HWND hwnd, L_INT id, HWND hwndCtl, UINT codeNotify) { UNREFERENCED_PARAMETER (hwndCtl); UNREFERENCED_PARAMETER (codeNotify); switch (id) { case IDM_OK: case IDCANCEL: EndDialog (hwnd, 0); break; } 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_ONCOMMAND. --------------------------------------------------------------------------*/ VOID Window_OnActivate(HWND hwnd, UINT state, HWND hwndActDeact, BOOL fMinimized) { if(state!=WA_INACTIVE) Window_OnQueryNewPalette (hwnd); } /*----[Window_OnHScroll]---------------------------------------------------- Syntax: VOID Window_OnHScroll(HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos) Parameters: hWnd Handle to a window. hWndCtl Not used. nCode Amount/Direction to be scrolled. npos The new position of the thumb. Prototype: Scrlzoom.h Notes: This function will scroll the image horizontally. --------------------------------------------------------------------------*/ VOID Window_OnHScroll (HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos) { L_INT nScrollInc; /* Horizontal Increment for scroll */ fInScroll = TRUE; hWndCtl = hWndCtl; switch (nCode) { /* Decrement by current scroll position */ case SB_LEFT: nScrollInc = -Data.nHScrollPos; break; /* Increment by the difference between Max scroll and current scroll position */ case SB_RIGHT: nScrollInc = Data.nHScrollMax - Data.nHScrollPos; break; /* Decrement by one step */ case SB_LINELEFT: nScrollInc = -Data.nHScrollStep; break; /* Increment by one step */ case SB_LINERIGHT: nScrollInc = Data.nHScrollStep; break; /* Decrement by Maximum */ case SB_PAGELEFT: nScrollInc = -max (Data.nHScrollStep, (Data.cxClient - Data.nHScrollStep)); break; /* Increment by Maximum */ case SB_PAGERIGHT: nScrollInc = max (Data.nHScrollStep, (Data.cxClient - Data.nHScrollStep)); break; /* Increment by difference between current scroll position and THUMB position */ case SB_THUMBPOSITION: nScrollInc = nPos - Data.nHScrollPos; break; /* No Increment */ default: nScrollInc = 0; break; } nScrollInc = max (-Data.nHScrollPos, min (nScrollInc, (Data.nHScrollMax - Data.nHScrollPos))); if (nScrollInc) { /* if Scroll increment is greater than nScrollInc, Increment scroll position by nScrollInc */ Data.nHScrollPos += nScrollInc; /* Reposition the picture at (0, -nScrollInc) */ OffsetRect (&Data.rcView, -nScrollInc, 0); /* Scroll left the window by nSrollInc */ ScrollWindow (hWnd, -nScrollInc, 0, NULL, NULL); /* Set new scroll position at current scroll position; */ SetScrollPos (hWnd, SB_HORZ, Data.nHScrollPos, TRUE); /* Update window */ UpdateWindow (hWnd); } fInScroll = FALSE; } /*----[Window_OnVScroll]---------------------------------------------------- Syntax: VOID Window_OnVScroll(HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos) Parameters: hWnd Handle to a window. hWndCtl Not used. nCode Amount/Direction to be scrolled. npos The new position of the thumb. Prototype: Scrlzoom.h Notes: This function will scroll the image vertically. --------------------------------------------------------------------------*/ VOID Window_OnVScroll (HWND hWnd, HWND hWndCtl, UINT nCode, L_INT nPos) { L_INT nScrollInc; /* Vertical Increment for Scroll */ fInScroll = TRUE; UNREFERENCED_PARAMETER (hWndCtl); switch (nCode) { case SB_BOTTOM: /* Increment by Difference between Max scroll and current scroll position */ nScrollInc = Data.nVScrollMax - Data.nVScrollPos; break; case SB_TOP: /* Decrement by current scroll position */ nScrollInc = -Data.nVScrollPos; break; case SB_LINEDOWN: /* Increment by one step */ nScrollInc = Data.nVScrollStep; break; case SB_LINEUP: /* Decrement by one step */ nScrollInc = -Data.nVScrollStep; break; case SB_PAGEDOWN: /* Increment by Maximum */ nScrollInc = max (Data.nVScrollStep, (Data.cyClient - Data.nVScrollStep)); break; case SB_PAGEUP: /* Decrement by Maximum */ nScrollInc = -max (Data.nVScrollStep, (Data.cyClient - Data.nVScrollStep)); break; case SB_THUMBPOSITION: /* Increment by Difference between Current scroll position and THUMB position */ nScrollInc = nPos - Data.nVScrollPos; break; default: /* No increment */ nScrollInc = 0; break; } nScrollInc = max (-Data.nVScrollPos, min (nScrollInc, (Data.nVScrollMax - Data.nVScrollPos))); if (nScrollInc) { /* if Scroll increment is greater than nScrollInc, Increment scroll position by nScrollInc */ Data.nVScrollPos += nScrollInc; /* Reposition the picture at (0, -nScrollInc) */ OffsetRect (&Data.rcView, 0, -nScrollInc); /* Scroll up the window by nSrollInc */ ScrollWindow (hWnd, 0, -nScrollInc, NULL, NULL); /* Set new scroll position at current scroll position */ SetScrollPos (hWnd, SB_VERT, Data.nVScrollPos, TRUE); /* Update window */ UpdateWindow (hWnd); } fInScroll = FALSE; } /*----[Window_OnSize]------------------------------------------------------ Syntax: VOID Window_OnSize (HWND hWnd, UINT nState, L_INT nCx, L_INT nCy) Parameters: hWnd Handle of the window. nState State of the window (iconic?) nCx New width. nCy New height. Prototype: Scrlzoom.h Notes: This function is responsible for handling the WM_SIZE message. --------------------------------------------------------------------------*/ VOID Window_OnSize (HWND hWnd, UINT nState, L_INT nCx, L_INT nCy) { static BOOL fSizeInUse = FALSE; L_INT nWidth, nHeight, nVScroll, nHScroll; DWORD dwStyle; if (!fSizeInUse) { fSizeInUse = TRUE; if (nState != SIZEICONIC) /* If window is normal */ { if (!Data.Bitmap.Flags.Allocated) /* If Flags is not allocated */ { /* set width and height to ZERO */ nWidth = 0; nHeight = 0; } else /* If Flags allocated */ { /* Scale the Bitmap Width to new Width */ nWidth = ScaleDimension (BITMAPWIDTH(&Data.Bitmap), Data.nScalar); /* Scale the Bitmap Height to new Height */ nHeight = ScaleDimension (BITMAPHEIGHT(&Data.Bitmap), Data.nScalar); } /* Set client dimensions to current width and height */ Data.cxClient = nCx; Data.cyClient = nCy; dwStyle = GetWindowLong (hWnd, GWL_STYLE); /* Get Vertical scroll arrow width */ nVScroll = GetSystemMetrics (SM_CXVSCROLL); /* Get Horizontal scroll arrow width */ nHScroll = GetSystemMetrics (SM_CXHSCROLL); /* If Vertical scroll */ if (WS_VSCROLL & dwStyle) Data.cxClient += nVScroll; /* If Horizontal scroll */ if (WS_HSCROLL & dwStyle) Data.cyClient += nHScroll; /* If client width < current width */ if (Data.cxClient < nWidth) { Data.cyClient -= nHScroll; if (Data.cyClient < nHeight) Data.cxClient -= nVScroll; } /* If client height < current height */ else if (Data.cyClient < nHeight) { Data.cxClient -= nVScroll; if (Data.cxClient < nWidth) Data.cyClient -= nHScroll; } /* Set Horizontal scroll step = 1/10 of client width, if > 1 */ Data.nHScrollStep = max (1, Data.cxClient / SCROLL_RATIO); /* Set Vertical scroll step = 1/10 of client height, if > 1 */ Data.nVScrollStep = max (1, Data.cyClient / SCROLL_RATIO); /* Set vetical scroll range */ Data.nVScrollMax = max (0, (nHeight - Data.cyClient /*- 1*/)); /* Set vertical scroll position */ Data.nVScrollPos = max (0, min (Data.nVScrollPos, Data.nVScrollMax)); /* Set horizontal scroll range */ Data.nHScrollMax = max (0, (nWidth - Data.cxClient /*- 1*/)); /* Set horizontal scroll position */ Data.nHScrollPos = max (0, min (Data.nHScrollPos, Data.nHScrollMax)); /* If Flags allocated */ if (Data.Bitmap.Flags.Allocated) { /* Set rcView to new width and new height */ SetRect (&Data.rcView, 0, 0, nWidth, nHeight); /* Set offset by current scroll position */ OffsetRect (&Data.rcView, -Data.nHScrollPos, -Data.nVScrollPos); } /* Set horizontal scroll range = nHScrollMax */ SetScrollRange (hWnd, SB_HORZ, 0, Data.nHScrollMax, FALSE); /* Set horintal scroll position */ SetScrollPos (hWnd, SB_HORZ, Data.nHScrollPos, TRUE); /* Set vertical scroll range = nVScrollMax */ SetScrollRange (hWnd, SB_VERT, 0, Data.nVScrollMax, FALSE); /* Set vertical scroll position */ SetScrollPos (hWnd, SB_VERT, Data.nVScrollPos, TRUE); } else /* If window is iconized */ { /* Retain the x-client and y-client area */ Data.cxClient = nCx; Data.cyClient = nCy; /* set client area */ SetRect (&Data.rcView, 0, 0, Data.cxClient, Data.cyClient); } fSizeInUse = FALSE; } } /*----(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: Scrlzoom.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 (Data.hPalette) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } /* Does this window have a bitmap and a palette? */ if (Data.Bitmap.Flags.Allocated) { hDC = GetDC (hWnd); /* Generate a new logical palette (if needed) for painting. */ Data.hPalette = L_CreatePaintPalette (hDC, &Data.Bitmap); /* 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_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: Scrlzoom.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.Bitmap.Flags.Allocated) { hDC = GetDC (hWnd); /* Generate a new logical palette (if needed) for painting. */ Data.hPalette = L_CreatePaintPalette (hDC, &Data.Bitmap); 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 Handle of the window. Prototype: Scrlzoom.h Notes: This function is responsible for painting the window. --------------------------------------------------------------------------*/ VOID Window_OnPaint (HWND hWnd) { HDC hDC; /* Handle to Device Context */ PAINTSTRUCT ps; /* Paint structure Data */ HPALETTE hOldPal = 0; /* Palette handle */ hDC = BeginPaint (hWnd, &ps);/* Get DC */ if (Data.Bitmap.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. */ /* Paint it */ L_PaintDC (hDC, &Data.Bitmap, NULL, NULL, &Data.rcView, &ps.rcPaint, SRCCOPY); if (Data.hPalette) /* Return old palette if there is one. */ SelectPalette (hDC, hOldPal, TRUE); } EndPaint (hWnd, &ps); return; } /*----[Window_OnEraseBkgnd]------------------------------------------------- Syntax: BOOL Window_OnEraseBkgnd(HWND hWnd, HDC hDC) Parameters: hWnd Handle to the window. hDC Handle to the device context. Prototype: demo.h Notes: This function will erase the background of the window. --------------------------------------------------------------------------*/ BOOL Window_OnEraseBkgnd (HWND hWnd, HDC hDC) { if (!fInScroll) return ((BOOL) FORWARD_WM_ERASEBKGND (hWnd, hDC, DefWindowProc)); return (TRUE); } /*----[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: Scrlzoom.h Notes: This function will translate the WM_COMMAND message. Other command messages that are not part of the main window will be forwarded to the default window proc. --------------------------------------------------------------------------*/ VOID Window_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) { L_TCHAR szFileName[_MAX_PATH]; FARPROC lpfnAboutDlgProc; switch (id) { case IDM_OPEN: if (GetOpenBitmapFile (hWnd, (LPTSTR) szFileName)) { if (!ImageLoad (hWnd, (LPTSTR) szFileName)) InvalidateRect (hWnd, NULL, TRUE); else MessageBox (hWnd, TEXT("ImageLoad Error"), TEXT("ERROR"), MB_OK); } break; case IDM_ZOOMIN2: case IDM_ZOOMIN3: case IDM_ZOOMIN4: case IDM_ZOOMIN5: case IDM_ZOOMIN6: case IDM_ZOOMIN7: case IDM_ZOOMIN8: Scale_Image (hWnd, id - IDM_ZOOMIN2 + 1); break; case IDM_ZOOMOUT2: case IDM_ZOOMOUT3: case IDM_ZOOMOUT4: case IDM_ZOOMOUT5: case IDM_ZOOMOUT6: case IDM_ZOOMOUT7: case IDM_ZOOMOUT8: Scale_Image (hWnd, IDM_ZOOMOUT2 - id - 1); break; case IDM_NORMAL: Scale_Image (hWnd, 0); break; case IDM_ABOUT: /* Display 'About' Dialog box */ lpfnAboutDlgProc = MakeProcInstance ((FARPROC) AboutDlgProc, hInstApp); DialogBox (hInstApp, TEXT("DIALOG_1"), hWnd, (DLGPROC) lpfnAboutDlgProc); FreeProcInstance ((FARPROC) lpfnAboutDlgProc); break; case IDM_EXIT: FORWARD_WM_CLOSE (hWnd, SendMessage); break; default: DefFrameProc (hWnd, hImageWindow, WM_COMMAND, (WPARAM) (int) (id), MAKELPARAM ((UINT) (hwndCtl), (codeNotify))); } } /*----[Window_OnDestroy]------------------------------------------------- Syntax: VOID Window_OnDestroy(HWND hWnd) Parameters: hWnd Handle to the window. Prototype: Scrlzoom.h Notes: This function will do the cleanup for the program, and post WM_QUIT to terminate the application. --------------------------------------------------------------------------*/ VOID Window_OnDestroy (HWND hWnd) { UNREFERENCED_PARAMETER (hWnd); if (Data.Bitmap.Flags.Allocated) /* Do we have an image? */ L_FreeBitmap (&Data.Bitmap); if (Data.hPalette) /* Delete palette if there is one. */ DeleteObject (Data.hPalette); PostQuitMessage (0); } L_VOID CleanOpenDlgParam(LPOPENDLGPARAMS pFOParam) { int i=0; if(pFOParam!=NULL) { if (pFOParam->pFileData!= NULL) { } for(i=0; i < pFOParam->nNumOfFiles; ++i ) { if(pFOParam->pFileData[i].pBitmap != NULL) { if ( pFOParam->pFileData[i].pBitmap->Flags.Allocated ) { L_FreeBitmap(pFOParam->pFileData[i].pBitmap); } GlobalFreePtr(pFOParam->pFileData[i].pBitmap); } if(pFOParam->pFileData[i].pThumbnail != NULL) { if ( pFOParam->pFileData[i].pThumbnail->Flags.Allocated ) { 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; } } /*----[GetOpenBitmapFile]-------------------------------------------------- Syntax: L_BOOL GetOpenBitmapFile(HWND hWnd, LPSTR pFilename) Parameters: hWnd Handle to the window. pFilename Pointer to the filename of the file containing the image to be retrieved. Prototype: Scrlzoom.h Notes: This function will control the retrieval of an image from a file. --------------------------------------------------------------------------*/ L_BOOL GetOpenBitmapFile (HWND hWnd, LPTSTR pFilename) { static OPENDLGPARAMS FOParm; static OPENFILENAME OpenFileName; static L_BOOL fInit = FALSE; L_INT nRet; memset(&FOParm, 0, sizeof(OPENDLGPARAMS)); memset(&OpenFileName, 0, sizeof(OPENFILENAME)); FOParm.uStructSize = sizeof(OPENDLGPARAMS); FOParm.bShowLoadOptions = FALSE ; FOParm.bPreviewEnabled = TRUE; FOParm.uDlgFlags = DLG_OPEN_SHOW_PREVIEW | DLG_OPEN_SHOW_FILEINFO; OpenFileName.lStructSize = sizeof(OPENFILENAME); if (!fInit) { OpenFileName.lpstrInitialDir = Data.szImageDir; fInit = TRUE; } nRet = L_DlgOpen( hWnd, &OpenFileName, &FOParm); if(nRet == SUCCESS_DLG_OK) { Data.FileInfo.uStructSize = sizeof(FILEINFO); nRet = L_FileInfo (FOParm.pFileData[ 0 ].szFileName, &Data.FileInfo, sizeof(FILEINFO), 0, NULL); if (nRet != SUCCESS) MessageBox (hWnd, TEXT("File Error"), TEXT("Open Bitmap File"), MB_ICONEXCLAMATION | MB_OK); else { lstrcpy(pFilename, FOParm.pFileData[ 0 ].szFileName); CleanOpenDlgParam(&FOParm); return (TRUE); } CleanOpenDlgParam(&FOParm); } return (FALSE); } /*----[ImageLoad]----------------------------------------------------------- Syntax: L_BOOL ImageLoad(HWND hWnd, LPSTR lpFilename) Parameters: hWnd Handle to the window. lpFilename Pointer to the filename of the file containing the image to be loaded. Prototype: Scrlzoom.h Notes: This function will load an image from a file. --------------------------------------------------------------------------*/ L_BOOL ImageLoad (HWND hWnd, LPTSTR lpFileName) { HDC hDC; HCURSOR hCursor; L_INT nRet; L_INT nDeviceBits; L_INT nFlags = LOADFILE_ALLOCATE | LOADFILE_STORE; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); /* Compute Device Bits -- Device color mode */ hDC = GetDC (hWnd); nDeviceBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES); /* If Device bits is > 8, set device bits to 24 */ if (nDeviceBits > 8) nDeviceBits = 24; ReleaseDC (hWnd, hDC); /* Free Bitmap and hPalette if already loaded */ if (Data.Bitmap.Flags.Allocated) L_FreeBitmap (&Data.Bitmap); if (Data.hPalette != NULL) { DeleteObject (Data.hPalette); Data.hPalette = NULL; } Scale_Image (hWnd, 0); UpdateWindow (hWnd); /* Get Image file information and load it to FileInfo structure */ Data.FileInfo.uStructSize = sizeof(FILEINFO); if ((nRet = L_FileInfo (lpFileName, &Data.FileInfo, sizeof(FILEINFO), 0, NULL)) != SUCCESS) { SetCursor (hCursor); return (nRet); } /* Initialize Bitmap */ L_InitBitmap (&Data.Bitmap, sizeof(BITMAPHANDLE), Data.FileInfo.Width, Data.FileInfo.Height, nDeviceBits); if (nDeviceBits <= 4) nFlags |= LOADFILE_FIXEDPALETTE; /* Load the file to the bitmap */ nRet = L_LoadFile (lpFileName, &Data.Bitmap, sizeof(BITMAPHANDLE), nDeviceBits, ORDER_BGR, nFlags, NULL, NULL, NULL, &Data.FileInfo); SetCursor (hCursor); if (nRet != SUCCESS) return (nRet); FORWARD_WM_QUERYNEWPALETTE (hWnd, SendMessage); Scale_Image (hWnd, 0); return (0); } /*----[ScaleDimension]------------------------------------------------------ Syntax: VOID ScaleDimension (L_INT nWidth, L_INT nFactor) Parameters: hWidth Width of the image. nFactor Factor to scale by. Prototype: Scrlzoom.h Notes: This function will scale the image by a factor of nFactor. --------------------------------------------------------------------------*/ L_INT ScaleDimension (L_INT nWidth, L_INT nFactor) { if (0 < nFactor) /* Zoom in Condition */ return (nWidth * (nFactor + 1)); else if (0 > nFactor) /* Zoom out Condition */ return (nWidth / (1 - nFactor)); else return nWidth; } /*----[Scale_Image]--------------------------------------------------------- Syntax: L_VOID Scale_Image (HWND hWnd, L_INT nScalar) Parameters: hWnd Handle to the window. nScalar Factor to scale by. Prototype: Scrlzoom.h Notes: This function processes the scaling of the image. --------------------------------------------------------------------------*/ L_VOID Scale_Image (HWND hWnd, L_INT nScalar) { RECT rcClient; /* Set the image scale */ Data.nScalar = nScalar; InvalidateRect (hWnd, NULL, TRUE); GetClientRect (hWnd, &rcClient); /* Call Routine to display the resized image */ Window_OnSize (hWnd, IsIconic (hWnd) ? SIZEICONIC : SIZENORMAL, RECTWIDTH (&rcClient), RECTHEIGHT (&rcClient)); } /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: scrlzoom.c Notes: - This procedure is responsible for extracting the image 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; }