/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(RegClass)---------------------------------------------------------------- LEAD Functions Used. L_FileInfo We have made the assumption that the user has the knowledge of programing in C and Windows. This is a demo that demonstrates the full capabilities of the LEAD Registered Class. Most of the LEAD Registered Class window messages are used in this example. We don't have a WndProc procedure associated with the LEAD Registered Class for processing the messages that pass from the user, so a subclass for the LEAD Registered Class window is created and all messages are processed in a new procedure called SubProc(). Note that any message that is not processed by SubProc() must be passed back to the LEAD Registered Class WndProc() using the CallWindowProc() function. Usage: REGCLASS --------------------------------------------------------------------------*/ #include /* Required for all Windows applications. */ #include /* Needed for message crackers. */ #include "tchar.h" #include /* Standard C header files. */ #include #include #include #include #include "..\\..\\..\\include\\l_bitmap.h" /* LEADTOOLS main header file. */ #include "..\\..\\..\\include\\l_error.h" /* LEADTOOLS error definition header file. */ #include "RegClass.h" /* Application specific header file. */ L_BOOL ExtractCommandData ( ) ; /*---[WinMain]--------------------------------------------------------------- Syntax: L_INT L_PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, L_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, L_INT nCmdShow) { MSG msg; /* Message structure, See Windows SDK for more information. */ HWND hWnd; #ifdef WIN32 HICON hIconBig; HICON hIconSmall; #endif /* WIN32 */ UNREFERENCED_PARAMETER (hPrevInstance); UNLOCKSUPPORT (); L_UseBitmapClass (); /* make hInstance a global instance */ hInst = hInstance; ExtractCommandData ( ); /* get procedure instance for SubProc() */ lpfnNewProc = MakeProcInstance ((FARPROC) SubProc, hInst); /* Create a normal overlapped window with scroll bars and automatic window sizing when a bitmap is loaded. */ hWnd = CreateWindow (L_BITMAPCLASS, TEXT("LEAD Registered Class Demo"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL | L_BS_THUMBTRACK, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); #ifdef WIN32 hIconBig = (HICON) LoadImage( hInstance, MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, GetSystemMetrics( SM_CXICON ), GetSystemMetrics( SM_CYICON ), 0 ); hIconSmall = (HICON) LoadImage( hInstance, MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 0 ); /* Set the applilcation small and big icons */ SendMessage( hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall ); SendMessage( hWnd, WM_SETICON, ICON_BIG, (LPARAM) hIconBig ); #endif /* WIN32 */ /* Load and Display Application Menu */ hMenu = LoadMenu (hInstance, TEXT("MY_MENU")); /* Disable All Menuitems except LOAD and QUIT */ ENABLEMENUITEM (hMenu, IDM_SAVE, bMenuFlags); ENABLEMENUITEM (hMenu, IDM_PRINT, bMenuFlags); EnableMenuItem (hMenu, IDM_COPYTOCLIPBOARD, MF_DISABLED | MF_GRAYED); EnableMenuItem (hMenu, IDM_COPYFROMCLIPBOARD, MF_ENABLED); EnableMenuItem (hMenu, IDM_DITHERMETHOD, MF_DISABLED); ENABLEMENUPOS (hMenu, View, bMenuFlags); ENABLEMENUPOS (hMenu, Image, bMenuFlags); ENABLEMENUPOS (hMenu, Color, bMenuFlags); SetMenu (hWnd, hMenu); ShowWindow (hWnd, nCmdShow); /* SubClass the window, and save the old WndProc() address */ lpfnOldProc = (WNDPROC) GetWindowLong (hWnd, GWL_WNDPROC); /* Set the new WndProc() */ SetWindowLong (hWnd, GWL_WNDPROC, (LONG) lpfnNewProc); /* Initialize Structures */ _fmemset (&LoadStruct, 0, sizeof (LoadStruct)); LoadStruct.uStructSize = sizeof (LoadStruct); _fmemset (&SaveStruct, 0, sizeof (SaveStruct)); SaveStruct.uStructSize = sizeof (SaveStruct); _fmemset (&InfoStruct, 0, sizeof (InfoStruct)); InfoStruct.uStructSize = sizeof (InfoStruct); _fmemset (&ColorStruct, 0, sizeof (ColorStruct)); ColorStruct.uStructSize = sizeof (ColorStruct); _fmemset (&ShearStruct, 0, sizeof (ShearStruct)); ShearStruct.uStructSize = sizeof (ShearStruct); _fmemset (&PrintStruct, 0, sizeof (PrintStruct)); PrintStruct.uStructSize = sizeof (PrintStruct); L_DlgInit(DLG_INIT_COLOR); /* Acquire and dispatch messages until a WM_QUIT message is received. In this case, the registered class will post WM_QUIT message. */ while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } L_DlgFree(); return (msg.wParam); /* Returns the value from PostQuitMessage */ } 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; } } /*----(GetOpenBitmapFile)------------------------------------------------- Description: This function will open a file and get image info. from it. Syntax : L_INT GetOpenBitmapFile (HWND hWnd, LPSTR pFilename) Prototype : RegClass.h Parameters : hWnd Handle to the window. pFilename Name of the file to open and get info from. Return Value: SUCCESS Function was Successful. -X Value from L_ERROR.H. 2 No file was selected. --------------------------------------------------------------------------*/ L_INT GetOpenBitmapFile (HWND hWnd, LPTSTR pFilename) { OPENFILENAME OpenFileName; OPENDLGPARAMS FOParm; LOADFILEOPTION LoadFileOption; L_INT nRet = 2; static L_BOOL fInit = FALSE; *pFilename = '\0'; _fmemset (&OpenFileName, 0, sizeof (OPENFILENAME)); _fmemset (&FOParm, 0, sizeof (OPENDLGPARAMS)); FOParm.uStructSize = sizeof(OPENDLGPARAMS); if (!fInit) { OpenFileName.lpstrInitialDir = szImageDir; fInit = TRUE; } OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrFilter = NULL; OpenFileName.lpstrCustomFilter = NULL; OpenFileName.nMaxCustFilter = 0; OpenFileName.nFilterIndex = 0; OpenFileName.lpstrTitle = TEXT("Open a File"); OpenFileName.nFileOffset = 0; OpenFileName.nFileExtension = 0; OpenFileName.lpstrDefExt = NULL; OpenFileName.Flags = 0; FOParm.uDlgFlags = DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_PREVIEW | DLG_OPEN_USEFILESTAMP; nRet = L_DlgOpen( hWnd,&OpenFileName,&FOParm); if (nRet == SUCCESS_DLG_OK) { L_GetDefaultLoadFileOption(&LoadFileOption, sizeof(LOADFILEOPTION)); nRet = L_FileInfo (FOParm.pFileData[0].szFileName,&FileInfo, sizeof(FILEINFO), 0, &LoadFileOption); 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 (SUCCESS); } CleanOpenDlgParam(&FOParm); } return (nRet); } /*----(SaveBitmapFile)----------------------------------------------------- Description: This function will get a file name to save an image to and send the save message to the LEAD Registered Class window. Syntax : L_BOOL SaveBitmapFile (HWND hWnd) Prototype : RegClass.h Parameters : hWnd Handle to the window. Return Value: TRUE Function was Successful. FALSE Function was NOT Successful. --------------------------------------------------------------------------*/ L_BOOL SaveBitmapFile (HWND hWnd) { OPENFILENAME OpenFileName; SAVEFILEOPTION SaveFileOption; SAVEDLGPARAMS FSParm; FILEJ2KOPTIONS FileJ2KOptions; HCURSOR hCursor; L_INT nRet; static L_BOOL fInit = FALSE; _fmemset(&OpenFileName, 0, sizeof(OPENFILENAME)); _fmemset(&FSParm, 0, sizeof(SAVEDLGPARAMS)); _fmemset(&FileJ2KOptions, 0, sizeof(FILEJ2KOPTIONS)); FSParm.uStructSize = sizeof(SAVEDLGPARAMS); FSParm.nQFactor = 2; if (!fInit) { OpenFileName.lpstrInitialDir = szImageDir; fInit = TRUE; } OpenFileName.lStructSize = sizeof(OPENFILENAME); OpenFileName.lpstrInitialDir = NULL; OpenFileName.lpstrTitle = TEXT("Save a File"); OpenFileName.nFileOffset = 0; OpenFileName.Flags = (OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY); FSParm.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR; nRet = L_DlgSave( hWnd,&OpenFileName,&FSParm); if(nRet == SUCCESS_DLG_OK) { hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); lstrcpy ( SaveStruct.Name,FSParm.szFileName); /* Copy file name */ SaveStruct.Format = FSParm.nFormat; SaveStruct.BitsPerPixel = FSParm.nBitsPerPixel; SaveStruct.QFactor = FSParm.nQFactor; 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; } if (!FSParm.bSaveInterlaced) SaveFileOption.Flags &= ~ESO_INTERLACED; else SaveFileOption.Flags |= ESO_INTERLACED; SaveStruct.pOptions = &SaveFileOption; 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); } if ((nRet = (L_INT) SendMessage (hWnd, L_BM_SAVE, 0, (LONG) (LPSTR) & SaveStruct)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SAVE")); 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) return (FALSE); return TRUE; } return (FALSE); } /*----(Window_OnCommand)--------------------------------------------------- Description: This function handles the WM_COMMAND message. Syntax : VOID Window_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) Prototype : RegClass.h Parameters : hWnd Handle to the window. id Control or menu item identifier. hwndCtl Handle of control. codeNotify Notification message. Return Value: None. --------------------------------------------------------------------------*/ VOID Window_OnCommand (HWND hWnd, L_INT id, HWND hwndCtl, UINT codeNotify) { HCURSOR hCursor; RECT rc; L_TCHAR buf[200]; COLORREF crFill = 0; L_INT nGamma = 0; L_INT nRet; UNREFERENCED_PARAMETER (hwndCtl); UNREFERENCED_PARAMETER (codeNotify); switch (id) { case IDM_LOAD: nRet = GetOpenBitmapFile (hWnd, (LPTSTR) LoadStruct.Name); if (nRet == SUCCESS) { /* If Bitmap handle is already loaded, Free bitmap. */ /* If Bitmap handle is NON-NULL, set zoom factor to 100%. */ if (SendMessage (hWnd, L_BM_GETBITMAP, 0, 0) != 0) { SendMessage (hWnd, L_BM_FREE, 0, 0); SendMessage (hWnd, L_BM_SETZOOM, 0, 100); } /* If clipboard object is already pasted, set flag to FALSE. */ if (bClipboardObject) bClipboardObject = FALSE; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); LoadStruct.pOptions = NULL; if (SendMessage (hWnd, L_BM_LOAD, TRUE, (LONG) (LPSTR) & LoadStruct) == SUCCESS) bMenuFlags = TRUE; else { MessageError (hWnd, TEXT("L_BM_LOAD")); bMenuFlags = FALSE; } SetCursor (hCursor); /* Set all menu items */ ENABLEMENUITEM (hMenu, IDM_PRINT, bMenuFlags); ENABLEMENUITEM (hMenu, IDM_SAVE, bMenuFlags); ENABLEMENUITEM (hMenu, IDM_COPYTOCLIPBOARD, bMenuFlags); ENABLEMENUPOS (hMenu, View, bMenuFlags); ENABLEMENUPOS (hMenu, Image, bMenuFlags); ENABLEMENUPOS (hMenu, Color, bMenuFlags); SetMenu (hWnd, hMenu); } else if (nRet < 0) { MessageBox (hWnd, TEXT("Unable to Open File."), TEXT("FILE OPEN ERROR"), MB_OK); } return; case IDM_SAVE: SaveBitmapFile (hWnd); return; case IDM_PRINT: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INFO, InfoStruct.uStructSize, (LONG) (LPSTR) & InfoStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INFO")); PrintStruct.hDC = 0; PrintStruct.nXPos = 100; PrintStruct.nYPos = 100; if (InfoStruct.Width * PRINT_HEIGHT < InfoStruct.Height * PRINT_WIDTH) { PrintStruct.nYSize = PRINT_HEIGHT * 300; /* 300 DPI */ PrintStruct.nXSize = MulDiv (InfoStruct.Width, PRINT_WIDTH * 300, InfoStruct.Height); } else { PrintStruct.nXSize = PRINT_WIDTH * 300; /* 300 DPI */ PrintStruct.nYSize = MulDiv (InfoStruct.Height, PRINT_WIDTH * 300, InfoStruct.Width); } PrintStruct.fEndDoc = TRUE; if ((HDC) SendMessage (hWnd, L_BM_PRINT, FALSE, (LPARAM) (LPSTR) & PrintStruct) == NULL) MessageError (hWnd, TEXT("L_BM_PRINT")); SetCursor (hCursor); return; case IDM_QUIT: FORWARD_WM_CLOSE (hWnd, PostMessage); return; case IDM_COLORRES1: case IDM_COLORRES4: case IDM_COLORRES8: case IDM_COLORRES16: case IDM_COLORRES24: case IDM_COLORRES32: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); ColorStruct.BitsPerPixel = id; ColorStruct.Flags = CRF_BURKESDITHERING; ColorStruct.pPalette = NULL; ColorStruct.Colors = 0; if (ColorStruct.BitsPerPixel > 8) ColorStruct.Flags = CRF_BYTEORDERBGR; else if (ColorStruct.BitsPerPixel > 1) ColorStruct.Flags |= CRF_OPTIMIZEDPALETTE; else ColorStruct.Flags |= CRF_FIXEDPALETTE; if (SendMessage (hWnd, L_BM_COLORRES, TRUE, (LONG) (LPSTR) & ColorStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_COLORRES")); SetCursor (hCursor); return; case IDM_CCWROTATE30: case IDM_CCWROTATE60: case IDM_CCWROTATE90: case IDM_CCWROTATE120: case IDM_CCWROTATE150: case IDM_CCWROTATE180: case IDM_CCWROTATE210: case IDM_CCWROTATE240: case IDM_CCWROTATE270: case IDM_CCWROTATE300: case IDM_CCWROTATE330: case IDM_CCWROTATE360: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_ROTATE, TRUE, MAKELONG (-(id - (L_INT) IDM_CCWROTATE30 + 1) * 30, TRUE)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_ROTATE")); SetCursor (hCursor); return; case IDM_CWROTATE30: case IDM_CWROTATE60: case IDM_CWROTATE90: case IDM_CWROTATE120: case IDM_CWROTATE150: case IDM_CWROTATE180: case IDM_CWROTATE210: case IDM_CWROTATE240: case IDM_CWROTATE270: case IDM_CWROTATE300: case IDM_CWROTATE330: case IDM_CWROTATE360: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_ROTATE, TRUE, MAKELONG ((id - (L_INT) IDM_CWROTATE30 + 1) * 30, TRUE)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_ROTATE")); SetCursor (hCursor); return; case IDM_FLIP: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_FLIP, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_FLIP")); SetCursor (hCursor); return; case IDM_REVERSE: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_REVERSE, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_REVERSE")); SetCursor (hCursor); return; case IDM_DARKEN10: case IDM_DARKEN20: case IDM_DARKEN30: case IDM_DARKEN40: case IDM_DARKEN50: case IDM_DARKEN60: case IDM_DARKEN70: case IDM_DARKEN80: case IDM_DARKEN90: case IDM_DARKEN100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INTENSITY, TRUE, -(((int) id - (L_INT) IDM_DARKEN10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INTENSITY")); SetCursor (hCursor); return; case IDM_BRIGHTEN10: case IDM_BRIGHTEN20: case IDM_BRIGHTEN30: case IDM_BRIGHTEN40: case IDM_BRIGHTEN50: case IDM_BRIGHTEN60: case IDM_BRIGHTEN70: case IDM_BRIGHTEN80: case IDM_BRIGHTEN90: case IDM_BRIGHTEN100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INTENSITY, TRUE, ((id - (L_INT) IDM_BRIGHTEN10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INTENSITY")); SetCursor (hCursor); return; case IDM_MOSAIC2: case IDM_MOSAIC4: case IDM_MOSAIC8: case IDM_MOSAIC16: case IDM_MOSAIC32: case IDM_MOSAIC64: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_MOSAIC, TRUE, 1 << ((int) id - (L_INT) IDM_MOSAIC2 + 1)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_MOSAIC")); SetCursor (hCursor); return; case IDM_POSTERIZE2: case IDM_POSTERIZE4: case IDM_POSTERIZE8: case IDM_POSTERIZE16: case IDM_POSTERIZE32: case IDM_POSTERIZE64: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_POSTERIZE, TRUE, 1 << (id - (L_INT) IDM_POSTERIZE2 + 1)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_POSTERIZE")); SetCursor (hCursor); return; case IDM_RSATURATION10: case IDM_RSATURATION20: case IDM_RSATURATION30: case IDM_RSATURATION40: case IDM_RSATURATION50: case IDM_RSATURATION60: case IDM_RSATURATION70: case IDM_RSATURATION80: case IDM_RSATURATION90: case IDM_RSATURATION100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_SATURATION, TRUE, (((L_INT) IDM_RSATURATION10 - id - 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SATURATION")); SetCursor (hCursor); return; case IDM_ISATURATION10: case IDM_ISATURATION20: case IDM_ISATURATION30: case IDM_ISATURATION40: case IDM_ISATURATION50: case IDM_ISATURATION60: case IDM_ISATURATION70: case IDM_ISATURATION80: case IDM_ISATURATION90: case IDM_ISATURATION100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_SATURATION, TRUE, ((id - (L_INT) IDM_ISATURATION10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SATURATION")); SetCursor (hCursor); return; case IDM_ICONTRAST10: case IDM_ICONTRAST20: case IDM_ICONTRAST30: case IDM_ICONTRAST40: case IDM_ICONTRAST50: case IDM_ICONTRAST60: case IDM_ICONTRAST70: case IDM_ICONTRAST80: case IDM_ICONTRAST90: case IDM_ICONTRAST100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_CONTRAST, TRUE, ((id - (L_INT) IDM_ICONTRAST10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_CONTRAST")); SetCursor (hCursor); return; case IDM_RCONTRAST10: case IDM_RCONTRAST20: case IDM_RCONTRAST30: case IDM_RCONTRAST40: case IDM_RCONTRAST50: case IDM_RCONTRAST60: case IDM_RCONTRAST70: case IDM_RCONTRAST80: case IDM_RCONTRAST90: case IDM_RCONTRAST100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_CONTRAST, TRUE, -(((int) id - (L_INT) IDM_RCONTRAST10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_CONTRAST")); SetCursor (hCursor); return; case IDM_GRAYSCALE: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_GRAYSCALE, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_GRAYSCALE")); SetCursor (hCursor); return; case IDM_HALFTONE: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_HALFTONE, TRUE, HT_VIEW) != SUCCESS) MessageError (hWnd, TEXT("L_BM_HALFTONE")); SetCursor (hCursor); return; case IDM_CHANGEHUE30: case IDM_CHANGEHUE60: case IDM_CHANGEHUE90: case IDM_CHANGEHUE120: case IDM_CHANGEHUE150: case IDM_CHANGEHUE180: case IDM_CHANGEHUE210: case IDM_CHANGEHUE240: case IDM_CHANGEHUE270: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_HUE, TRUE, ((id - (L_INT) IDM_CHANGEHUE30 + 1) * 30)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_HUE")); SetCursor (hCursor); return; case IDM_INVERT: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INVERT, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INVERT")); SetCursor (hCursor); return; case IDM_AVERAGE3: case IDM_AVERAGE5: case IDM_AVERAGE7: case IDM_AVERAGE9: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_AVERAGE, TRUE, 3 + ((id - (L_INT) IDM_AVERAGE3) * 2)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_AVERAGE")); SetCursor (hCursor); return; case IDM_HISTOEQ: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_HISTOEQ, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_HISTOEQ")); SetCursor (hCursor); return; case IDM_MEDIAN3: case IDM_MEDIAN5: case IDM_MEDIAN7: case IDM_MEDIAN9: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_MEDIAN, TRUE, 3 + ((id - (L_INT) IDM_MEDIAN3) * 2)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_MEDIAN")); SetCursor (hCursor); return; case IDM_RSHARPNESS10: case IDM_RSHARPNESS20: case IDM_RSHARPNESS30: case IDM_RSHARPNESS40: case IDM_RSHARPNESS50: case IDM_RSHARPNESS60: case IDM_RSHARPNESS70: case IDM_RSHARPNESS80: case IDM_RSHARPNESS90: case IDM_RSHARPNESS100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_SHARPEN, TRUE, -((id - (L_INT) IDM_RSHARPNESS10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SHARPEN")); SetCursor (hCursor); return; case IDM_ISHARPNESS10: case IDM_ISHARPNESS20: case IDM_ISHARPNESS30: case IDM_ISHARPNESS40: case IDM_ISHARPNESS50: case IDM_ISHARPNESS60: case IDM_ISHARPNESS70: case IDM_ISHARPNESS80: case IDM_ISHARPNESS90: case IDM_ISHARPNESS100: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_SHARPEN, TRUE, ((id - (L_INT) IDM_ISHARPNESS10 + 1) * 100)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SHARPEN")); SetCursor (hCursor); return; case IDM_ZOOMIN2: case IDM_ZOOMIN3: case IDM_ZOOMIN4: case IDM_ZOOMIN5: case IDM_ZOOMIN6: case IDM_ZOOMIN7: case IDM_ZOOMIN8: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); SendMessage (hWnd, L_BM_SETZOOM, TRUE, ((int) id - (L_INT) IDM_ZOOMIN2 + 2) * 100); SetCursor (hCursor); return; case IDM_ZOOMOUT2: case IDM_ZOOMOUT3: case IDM_ZOOMOUT4: case IDM_ZOOMOUT5: case IDM_ZOOMOUT6: case IDM_ZOOMOUT7: case IDM_ZOOMOUT8: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); SendMessage (hWnd, L_BM_SETZOOM, TRUE, 100 / ((int) id - (L_INT) IDM_ZOOMOUT2 + 2)); SetCursor (hCursor); return; case IDM_NORMAL: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); SendMessage (hWnd, L_BM_SETZOOM, TRUE, 100); SetCursor (hCursor); return; case IDM_COPYTOCLIPBOARD: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_COPY, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_COPY")); SetCursor (hCursor); return; case IDM_COPYFROMCLIPBOARD: if (L_ClipboardReady ()) { hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); GetWindowRect (hWnd, &rc); if (SendMessage (hWnd, L_BM_PASTE, TRUE, 0) == SUCCESS) { bMenuFlags = TRUE; bClipboardObject = TRUE; } else { MoveWindow (hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); MessageError (hWnd, TEXT("L_BM_PASTE")); bMenuFlags = FALSE; InvalidateRect (hWnd, NULL, TRUE); } ENABLEMENUITEM (hMenu, IDM_PRINT, bMenuFlags); ENABLEMENUITEM (hMenu, IDM_SAVE, bMenuFlags); ENABLEMENUITEM (hMenu, IDM_COPYTOCLIPBOARD, bMenuFlags); ENABLEMENUPOS (hMenu, View, bMenuFlags); ENABLEMENUPOS (hMenu, Image, bMenuFlags); ENABLEMENUPOS (hMenu, Color, bMenuFlags); SetMenu (hWnd, hMenu); SetCursor (hCursor); } return; case IDM_RESIZEUP2: case IDM_RESIZEUP3: case IDM_RESIZEUP4: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INFO, InfoStruct.uStructSize, (LONG) (LPSTR) & InfoStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INFO")); if (SendMessage (hWnd, L_BM_RESIZE, TRUE, MAKELONG (InfoStruct.Width * (id - (L_INT) IDM_RESIZEUP2 + 2), InfoStruct.Height * (id - (L_INT) IDM_RESIZEUP2 + 2))) != SUCCESS) MessageError (hWnd, TEXT("L_BM_RESIZE")); SetCursor (hCursor); return; case IDM_RESIZEDN2: case IDM_RESIZEDN3: case IDM_RESIZEDN4: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INFO, InfoStruct.uStructSize, (LONG) (LPSTR) & InfoStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INFO")); if (SendMessage (hWnd, L_BM_RESIZE, TRUE, MAKELONG (InfoStruct.Width / (id - (L_INT) IDM_RESIZEDN2 + 2), InfoStruct.Height / (id - (L_INT) IDM_RESIZEDN2 + 2))) != SUCCESS) MessageError (hWnd, TEXT("L_BM_RESIZE")); SetCursor (hCursor); return; case IDM_RESAMPLEUP2: case IDM_RESAMPLEUP3: case IDM_RESAMPLEUP4: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INFO, InfoStruct.uStructSize, (LONG) (LPSTR) & InfoStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INFO")); if (SendMessage (hWnd, L_BM_RESAMPLE, TRUE, MAKELONG (InfoStruct.Width * (id - (L_INT) IDM_RESAMPLEUP2 + 2), InfoStruct.Height * (id - (L_INT) IDM_RESAMPLEUP2 + 2))) != SUCCESS) MessageError (hWnd, TEXT("L_BM_RESAMPLE")); SetCursor (hCursor); return; case IDM_RESAMPLEDN2: case IDM_RESAMPLEDN3: case IDM_RESAMPLEDN4: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INFO, InfoStruct.uStructSize, (LONG) (LPSTR) & InfoStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INFO")); if (SendMessage (hWnd, L_BM_RESAMPLE, TRUE, MAKELONG (InfoStruct.Width / (id - (L_INT) IDM_RESAMPLEDN2 + 2), InfoStruct.Height / (id - (L_INT) IDM_RESAMPLEDN2 + 2))) != SUCCESS) MessageError (hWnd, TEXT("L_BM_RESAMPLE")); SetCursor (hCursor); return; case IDM_SHEAR: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); ShearStruct.nAngle = 3000; ShearStruct.fHorizontal = TRUE; ShearStruct.crFill = RGB (255, 255, 255); if (SendMessage (hWnd, L_BM_SHEAR, TRUE, (LONG) (LPSTR) & ShearStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SHEAR")); SetCursor (hCursor); return; case IDM_DESPECKLE: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_DESPECKLE, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_DESPECKLE")); SetCursor (hCursor); return; case IDM_DESKEW: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_DESKEW, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_DESKEW")); SetCursor (hCursor); return; case IDM_CLEAR: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_CLEAR, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_CLEAR")); SetCursor (hCursor); return; case IDM_NOISE10: case IDM_NOISE20: case IDM_NOISE30: case IDM_NOISE40: case IDM_NOISE50: case IDM_NOISE60: case IDM_NOISE70: case IDM_NOISE80: case IDM_NOISE90: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_ADDNOISE, TRUE, MAKELONG ((id - IDM_NOISE10 + 1) * 100, CHANNEL_MASTER)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_ADDNOISE")); SetCursor (hCursor); return; case IDM_CHANGEGAMMA001: if (!nGamma) nGamma = 1; case IDM_CHANGEGAMMA020: if (!nGamma) nGamma = 20; case IDM_CHANGEGAMMA075: if (!nGamma) nGamma = 75; case IDM_CHANGEGAMMA100: if (!nGamma) nGamma = 100; case IDM_CHANGEGAMMA150: if (!nGamma) nGamma = 150; case IDM_CHANGEGAMMA199: if (!nGamma) nGamma = 199; case IDM_CHANGEGAMMA299: if (!nGamma) nGamma = 299; case IDM_CHANGEGAMMA399: if (!nGamma) nGamma = 399; case IDM_CHANGEGAMMA499: if (!nGamma) nGamma = 499; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_GAMMACORRECT, TRUE, MAKELONG (nGamma, 0L)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_GAMMACORRECT")); SetCursor (hCursor); return; case IDM_INTENSITYDETECT: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_INTENSITYDETECT, TRUE, MAKELONG (100, 180)) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INTENSITYDETECT")); SetCursor (hCursor); return; case IDM_FILLRED: if (!crFill) crFill = RGB (255, 0, 0); case IDM_FILLGREEN: if (!crFill) crFill = RGB (0, 255, 0); case IDM_FILLBLUE: if (!crFill) crFill = RGB (0, 0, 255); case IDM_FILLBLACK: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_FILL, TRUE, crFill) != SUCCESS) MessageError (hWnd, TEXT("L_BM_FILL")); SetCursor (hCursor); return; case IDM_SPATIALFLT: hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (SendMessage (hWnd, L_BM_SPATIALFLT, TRUE, 0) != SUCCESS) MessageError (hWnd, TEXT("L_BM_SPATIALFLT")); SetCursor (hCursor); return; case IDM_INFO: if (SendMessage (hWnd, L_BM_INFO, InfoStruct.uStructSize, (LONG) (LPSTR) & InfoStruct) != SUCCESS) MessageError (hWnd, TEXT("L_BM_INFO")); if (bClipboardObject) wsprintf (buf, TEXT("Name : Clipboard Object\n Format : CLP\n Width : %d\n Height : %d\n BPP : %d"), InfoStruct.Width, InfoStruct.Height, InfoStruct.Pixels); else wsprintf (buf, TEXT("Name : %s\n Format : %d\n Width : %d\n Height : %d\n BPP : %d"), (LPTSTR) FileInfo.Name, FileInfo.Format, InfoStruct.Width, InfoStruct.Height, InfoStruct.Pixels); MessageBox (hWnd, buf, TEXT("Bitmap Information"), MB_OK); return; } } /*---[Window_OnDestroy]---------------------------------------------------- Syntax: VOID Window_OnDestroy( HWND hWnd ); Parameters: hWnd Window handle. Prototype: RegClass.h Notes: This procedure is responsible for handling WM_DESTROY. --------------------------------------------------------------------------*/ VOID Window_OnDestroy (HWND hWnd) { UNREFERENCED_PARAMETER (hWnd); CallWindowProc (lpfnOldProc, hWnd, WM_DESTROY, 0, 0); PostQuitMessage (0); /* Post WM_QUIT, to end the application. */ return; } LRESULT CALLBACK L_EXPORT SubProc (HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { switch (iMessage) { HANDLE_MSG (hWnd, WM_COMMAND, Window_OnCommand); HANDLE_MSG (hWnd, WM_DESTROY, Window_OnDestroy); } /* return all the unprocessed messages to the old WndProc() */ return CallWindowProc (lpfnOldProc, hWnd, iMessage, wParam, lParam); } /* display LEAD message errors */ L_VOID MessageError (HWND hWnd, LPTSTR msg) { L_TCHAR buf[60]; wsprintf (buf, TEXT("LEAD Registered Class Message %s"), (LPTSTR) msg); MessageBox (hWnd, buf, TEXT("ERROR"), MB_OK); } /*---[ExtractCommandData]---------------------------------------------------- Syntax: L_BOOL ExtractCommandData( ); Parameters: None. ProtoType: regclass.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; }