/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 13 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2001 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #define STRICT #include #include #include #include #include #include #include #include #include #include #include "../../../include/l_bitmap.h" #include "../../../include/l_error.h" #include "demo.h" static LOADINFOCALLBACK pfnOldLoadInfo; static LOADINFOCALLBACK pfnLoadInfo; static L_BOOL fGetImageParm = FALSE; static IMAGEPARM ImageParm = { 0, // nType; 2560, // nWidth; 3500, // nHeight; 300, // nHorz; 300, // nVert; 0, // nOffset; TRUE, // fBlackOnWhite; TRUE, // fMSB; TOP_LEFT, // nViewPerspective; ORDER_BGR, // nOrder; 24, // nBitsPerPixel; 0, // nPalette; TRUE // fPadding; }; /* static variables used by the IDD_BITMAPCOLORS dialog box */ static WNDPROC pfnDefaultButtonProc; /* message handler for the color array button */ static L_INT nIndex; /* the index of the current selected color */ static COLORLAYOUT colorlayout; static LPCOLORPARM pParm; typedef struct _CHILDLIST { L_INT nCount; HWND ahWnd[1]; } CHILDLIST, L_FAR *LPCHILDLIST; typedef struct _RANGEPARM { L_TCHAR szTitle[32]; L_TCHAR szLabel[32]; L_INT nValue; L_INT nMin; L_INT nMax; L_INT nStep; L_INT nPage; } RANGEPARM, FAR * LPRANGEPARM; typedef struct _LISTPARM { L_TCHAR szTitle[32]; L_TCHAR szLabel[32]; L_INT nValue; L_TCHAR* pList; } LISTPARM, FAR * LPLISTPARM; L_BOOL ChangeColor(HWND hWnd, L_INT nIndex); L_BOOL CALLBACK L_EXPORT AddChildThumbnailsCB(HWND hWnd, LPARAM lParam) { if(GetParent(hWnd)==hWndClient) FORWARD_WM_USER(hWnd,(WPARAM)lParam,0,SendMessage); return(TRUE); } L_VOID AddChildThumbnails(L_BOOL bAddThumbnails) { EnumChildWindows(hWndClient, AddChildThumbnailsCB, (LPARAM)bAddThumbnails); } L_BOOL ShowHorizontal ( HWND hList ) { L_TCHAR szItemText [ L_MAXPATH ]; SIZE sTextsize ; L_INT nLargestTextSize = 0 ; HDC hDC = NULL ; L_INT nIndex = 0 ; L_INT nListCount = 0 ; L_INT nStringLen = 0 ; L_INT nHorizontalExtent = 0 ; memset ( szItemText, 0, sizeof ( L_TCHAR ) * L_MAXPATH ) ; hDC = GetDC ( hList ) ; nListCount = ListBox_GetCount ( hList ) ; // Find the longest string in the list box. for ( nIndex = 0 ; nIndex < nListCount ; nIndex++ ) { ListBox_GetText ( hList, nIndex, szItemText ) ; nStringLen = lstrlen ( szItemText ) ; GetTextExtentPoint32 ( hDC, szItemText, nStringLen, &sTextsize ) ; if ( sTextsize.cx > nLargestTextSize ) { nLargestTextSize = sTextsize.cx ; } } ReleaseDC ( hList, hDC ) ; ListBox_GetHorizontalExtent ( hList ) ; ListBox_SetHorizontalExtent ( hList, nLargestTextSize ) ; if ( ListBox_GetHorizontalExtent ( hList ) == nLargestTextSize ) { return FALSE ; } return TRUE ; } /*====(RangeDlgProc)====================================================== Description: Processes Range dialog box messages. Syntax : L_BOOL CALLBACK L_EXPORT RangeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Handle of the dialog box. message Message to be processed. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE/FALSE Depends on the message. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT RangeDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPRANGEPARM pParm; L_INT n; L_BOOL fTranslated; switch (message) { case WM_INITDIALOG: pParm = (LPRANGEPARM) lParam; SetWindowText (hDlg, pParm->szTitle); SetDlgItemText (hDlg, IDC_RANGELABEL, pParm->szLabel); SetScrollRange (GetDlgItem (hDlg, IDC_RANGESCROLL), SB_CTL, pParm->nMin, pParm->nMax, FALSE); SetScrollPos (GetDlgItem (hDlg, IDC_RANGESCROLL), SB_CTL, pParm->nValue, TRUE); SetDlgItemInt (hDlg, IDC_RANGEEDIT, pParm->nValue, TRUE); return (TRUE); case WM_HSCROLL: n = GetDlgItemInt (hDlg, IDC_RANGEEDIT, &fTranslated, TRUE); if (!(!fTranslated || n < pParm->nMin || n > pParm->nMax)) pParm->nValue = n; switch (SCROLLCODE(wParam, lParam)) { case SB_LEFT: pParm->nValue = pParm->nMin; break; case SB_RIGHT: pParm->nValue = pParm->nMax; break; case SB_THUMBPOSITION: case SB_THUMBTRACK: pParm->nValue = SCROLLPOS(wParam, lParam); break; case SB_LINELEFT: pParm->nValue = max (pParm->nValue - pParm->nStep, pParm->nMin); break; case SB_LINERIGHT: pParm->nValue = min (pParm->nValue + pParm->nStep, pParm->nMax); break; case SB_PAGELEFT: pParm->nValue = max (pParm->nValue - pParm->nPage, pParm->nMin); break; case SB_PAGERIGHT: pParm->nValue = min (pParm->nValue + pParm->nPage, pParm->nMax); break; } SetDlgItemInt (hDlg, IDC_RANGEEDIT, pParm->nValue, TRUE); SetScrollPos (GetDlgItem (hDlg, IDC_RANGESCROLL), SB_CTL, pParm->nValue, TRUE); return (TRUE); case WM_COMMAND: switch (CTLID(wParam, lParam)) { case IDC_RANGEEDIT: switch (NOTIFYCODE(wParam, lParam)) { case EN_CHANGE: n = GetDlgItemInt (hDlg, IDC_RANGEEDIT, &fTranslated, TRUE); if (!(!fTranslated || n < pParm->nMin || n > pParm->nMax)) { pParm->nValue = n; SetScrollPos (GetDlgItem (hDlg, IDC_RANGESCROLL), SB_CTL, pParm->nValue, TRUE); } break; } return (TRUE); case IDOK: n = GetDlgItemInt (hDlg, IDC_RANGEEDIT, &fTranslated, TRUE); if (!fTranslated || n < pParm->nMin || n > pParm->nMax) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_RANGEEDIT)); SendDlgItemMessage(hDlg, IDC_RANGEEDIT, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); } else { pParm->nValue = n; EndDialog (hDlg, IDOK); } return (TRUE); case IDCANCEL: EndDialog (hDlg, IDCANCEL); return (TRUE); } } return (FALSE); } /*====(LoadInfoCallback)=================================================== Description: Obtains info to load headerless fax format files. Syntax : L_INT L_FAR L_EXPORT LoadInfoCallback(L_INT fd, pLOADINFO pInfo) Parameters : fd File handle to obtain info about. pInfo Structure to load with info. pData UserData Return Value: SUCCESS Function was successful. ERROR_FILE_FORMAT User has indicated that the file is not a headerless fax format. ==========================================================================*/ L_INT L_FAR L_EXPORT LoadInfoCallback(L_INT fd, pLOADINFO pInfo, L_VOID L_FAR* pUserData) { static L_UINT32 aViewPerspective[8] = { LOADINFO_TOPLEFT, LOADINFO_REVERSE, LOADINFO_BOTTOMLEFT180, LOADINFO_TOPLEFT180, LOADINFO_TOPLEFT90, LOADINFO_TOPLEFT270, LOADINFO_BOTTOMLEFT90, LOADINFO_BOTTOMLEFT270 }; static L_UINT32 aFormat[6] = {FILE_RAW, FILE_FAX_G3_1D_NOEOL, FILE_FAX_G3_1D, FILE_FAX_G3_2D, FILE_FAX_G4, FILE_ABIC}; UNREFERENCED_PARAMETER(fd); UNREFERENCED_PARAMETER(pUserData); if(fGetImageParm) { fGetImageParm = FALSE; if(!GetImageParm(hWndFrame, &ImageParm)) { fGetImageParm = TRUE; return(ERROR_FILE_FORMAT); } } pInfo->Format = aFormat[ImageParm.nType]; pInfo->Flags = 0; pInfo->Flags |= aViewPerspective[ImageParm.nViewPerspective]; pInfo->Flags |= (ImageParm.nOrder == 2 ? LOADINFO_ORDERGRAY : ImageParm.nOrder == 0 ? LOADINFO_ORDERRGB : 0); pInfo->Flags |= (ImageParm.fBlackOnWhite ? 0 : LOADINFO_WHITEONBLACK); pInfo->Flags |= (ImageParm.fMSB ? 0 : LOADINFO_LSB); pInfo->Flags |= (ImageParm.fPadding ? LOADINFO_PAD4 : 0); pInfo->Width = ImageParm.nWidth; pInfo->Height = ImageParm.nHeight; pInfo->BitsPerPixel = ImageParm.nBitsPerPixel; pInfo->XResolution = ImageParm.nHorz; pInfo->YResolution = ImageParm.nVert; pInfo->Offset = ImageParm.nOffset; if ( ( (pInfo->BitsPerPixel <= 8) && (aFormat[ImageParm.nType] == FILE_RAW) ) || ( (pInfo->BitsPerPixel <= 8) && (aFormat[ImageParm.nType] == FILE_ABIC)) ) { pInfo->Flags |= LOADINFO_PALETTE; switch (ImageParm.nPalette) { case 0: //create a grayscale palette { L_INT nColors, i; nColors = 1 << pInfo->BitsPerPixel; pInfo->Flags |= LOADINFO_PALETTE; for (i=0; irgbQuad[i].rgbBlue = (i * 256) / nColors; pInfo->rgbQuad[i].rgbGreen = (i * 256) / nColors; pInfo->rgbQuad[i].rgbRed = (i * 256) / nColors; pInfo->rgbQuad[i].rgbReserved = 0; } } break; case 1: //LEAD fixed L_GetFixedPalette(pInfo->rgbQuad, pInfo->BitsPerPixel); break; } } return(SUCCESS); } /*====(EnableLoadInfo)=================================================== Description: Enables/Disables the load info hook Syntax : L_BOOL EnableLoadInfo(L_BOOL fEnable) Parameters : fEnable TRUE to enable Return Value: Previous state ==========================================================================*/ L_BOOL EnableLoadInfo(L_BOOL fEnable) { L_BOOL fRet; if(fEnable) { if(!pfnLoadInfo) { if(fLoadRawFax) { pfnLoadInfo = LoadInfoCallback; pfnOldLoadInfo = L_SetLoadInfoCallback(pfnLoadInfo,NULL); fRet = FALSE; } else { fRet = TRUE; pfnLoadInfo = NULL; } } else { fRet = TRUE; } fGetImageParm = TRUE; } else { if(pfnLoadInfo) { L_SetLoadInfoCallback(pfnOldLoadInfo,NULL); pfnLoadInfo = NULL; fRet = TRUE; } else { fRet = FALSE; } } return(fRet); } L_VOID EnableRawDlgItems(HWND hDlg, L_BOOL bEnable, L_BOOL bOrder) { L_INT nBPP; L_BOOL bEnablePalette; EnableWindow(GetDlgItem(hDlg, IDC_STATIC_COLOR), !bEnable); EnableWindow(GetDlgItem(hDlg, IDC_IMAGEBONW), !bEnable); EnableWindow(GetDlgItem(hDlg, IDC_IMAGEWONB), !bEnable); EnableWindow(GetDlgItem(hDlg, IDC_IMAGEMSB), bOrder); EnableWindow(GetDlgItem(hDlg, IDC_IMAGELSB), bOrder); EnableWindow(GetDlgItem(hDlg, IDC_STATIC_FILL), bOrder); EnableWindow(GetDlgItem(hDlg, IDC_STATIC_BPP), bEnable); EnableWindow(GetDlgItem(hDlg, IDC_EDIT_BPP), bEnable); EnableWindow(GetDlgItem(hDlg, IDC_CHECK_PADDING), bEnable); //EnableWindow(GetDlgItem(hDlg, IDC_STATIC_VIEW_PERSPECTIVE), bEnable); //EnableWindow(GetDlgItem(hDlg, IDC_COMBO_VIEWPERSPECTIVE), bEnable); EnableWindow(GetDlgItem(hDlg, IDC_STATIC_COLOR_ORDER), bEnable & bOrder); EnableWindow(GetDlgItem(hDlg, IDC_COMBO_ORDER), bEnable & bOrder); nBPP = GetDlgItemInt(hDlg, IDC_EDIT_BPP, NULL, FALSE); bEnablePalette = (nBPP <= 8) && (bEnable); EnableWindow(GetDlgItem(hDlg, IDC_STATIC_PALETTE), bEnablePalette); EnableWindow(GetDlgItem(hDlg, IDC_COMBO_PALETTE), bEnablePalette); } /*====(ImageDlgProc)====================================================== Description: Processes Headerless Fax dialog box messages. Syntax : L_BOOL CALLBACK L_EXPORT ImageDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Handle of the dialog box. message Message to be processed. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE/FALSE Depends on the message. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT ImageDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPIMAGEPARM pParm; L_INT n; L_BOOL fTranslated; L_TCHAR szText[16]; L_INT nItem; switch (message) { case WM_INITDIALOG: pParm = (LPIMAGEPARM) lParam; SetDlgItemInt(hDlg, IDC_IMAGEWIDTH, pParm->nWidth, FALSE); SetDlgItemInt(hDlg, IDC_IMAGEHEIGHT, pParm->nHeight, FALSE); SetDlgItemInt(hDlg, IDC_IMAGEHORZ, pParm->nHorz, FALSE); SetDlgItemInt(hDlg, IDC_IMAGEVERT, pParm->nVert, FALSE); strprintf(szText, TEXT("%lu"), pParm->nOffset); SetDlgItemText(hDlg, IDC_IMAGEOFFSET, szText); CheckDlgButton(hDlg, pParm->fBlackOnWhite ? IDC_IMAGEBONW : IDC_IMAGEWONB, TRUE); CheckDlgButton(hDlg, pParm->fMSB ? IDC_IMAGEMSB : IDC_IMAGELSB, TRUE); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_ADDSTRING, 0, (LPARAM) TEXT("RAW")); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_ADDSTRING, 0, (LPARAM) TEXT("Group 3-1D (No EOL) Fax")); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_ADDSTRING, 0, (LPARAM) TEXT("Group 3-1D Fax")); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_ADDSTRING, 0, (LPARAM) TEXT("Group 3-2D Fax")); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_ADDSTRING, 0, (LPARAM) TEXT("Group 4 Fax")); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_ADDSTRING, 0, (LPARAM) TEXT("ABIC Raw")); SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_SETCURSEL, pParm->nType, 0); //View Perspective SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Top Left")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Bottom Left")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Top Right (Bottom Left 180)")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Bottom Right (Top Left 180)")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Right Top (Top Left 90)")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Left Bottom (Top Left 270)")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Left Top (Bottom Left 90)")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_ADDSTRING, 0, (LPARAM) TEXT("Right Bottom (Bottom Left 270)")); SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_SETCURSEL, pParm->nViewPerspective, 0); //Order SendDlgItemMessage(hDlg, IDC_COMBO_ORDER, CB_ADDSTRING, 0, (LPARAM) TEXT("Order RGB")); SendDlgItemMessage(hDlg, IDC_COMBO_ORDER, CB_ADDSTRING, 0, (LPARAM) TEXT("Order BGR")); SendDlgItemMessage(hDlg, IDC_COMBO_ORDER, CB_ADDSTRING, 0, (LPARAM) TEXT("Grayscale")); SendDlgItemMessage(hDlg, IDC_COMBO_ORDER, CB_SETCURSEL, pParm->nOrder, 0); //Bits Per Pixel SetDlgItemInt(hDlg, IDC_EDIT_BPP, pParm->nBitsPerPixel, FALSE); //Palette SendDlgItemMessage(hDlg, IDC_COMBO_PALETTE, CB_ADDSTRING, 0, (LPARAM) TEXT("Grayscale")); SendDlgItemMessage(hDlg, IDC_COMBO_PALETTE, CB_ADDSTRING, 0, (LPARAM) TEXT("LEAD Fixed Palette")); SendDlgItemMessage(hDlg, IDC_COMBO_PALETTE, CB_SETCURSEL, pParm->nPalette, 0); //Padding CheckDlgButton(hDlg, IDC_CHECK_PADDING, pParm->fPadding); nItem = (L_INT)SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_GETCURSEL, 0, 0); EnableRawDlgItems(hDlg, nItem == 0 || nItem == 5, nItem != 5); return(TRUE); case WM_COMMAND: switch(CTLID(wParam, lParam)) { case IDC_IMAGETYPE: // { if (HIWORD(wParam) == CBN_SELCHANGE) { pParm->nType = (L_INT)SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_GETCURSEL, 0, 0); if (pParm->nType != 0 && pParm->nType != 5) { pParm->nBitsPerPixel = 1; SetDlgItemInt(hDlg, IDC_EDIT_BPP, 1, FALSE); InvalidateRect(GetDlgItem(hDlg, IDC_EDIT_BPP), NULL, TRUE); } EnableRawDlgItems(hDlg, pParm->nType == 0 || pParm->nType == 5, pParm->nType != 5); //enable raw items if FILE_RAW selected } } break; case IDC_EDIT_BPP: //if (HIWORD(wParam) == CBN_SELCHANGE) { L_INT nBPP; L_BOOL bEnablePalette; nBPP = GetDlgItemInt(hDlg, IDC_EDIT_BPP, NULL, FALSE); bEnablePalette = (nBPP != 24) && (pParm->nType == 0); EnableWindow(GetDlgItem(hDlg, IDC_STATIC_PALETTE), bEnablePalette); EnableWindow(GetDlgItem(hDlg, IDC_COMBO_PALETTE), bEnablePalette); EnableRawDlgItems(hDlg, pParm->nType == 0 || pParm->nType == 5, pParm->nType != 5); //enable raw items if FILE_RAW selected } break; case IDOK: n = GetDlgItemInt(hDlg, IDC_EDIT_BPP, &fTranslated, FALSE); if (!fTranslated || n <= 0) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_EDIT_BPP)); SendDlgItemMessage(hDlg, IDC_EDIT_BPP, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); return(TRUE); } pParm->nBitsPerPixel = n; n = GetDlgItemInt(hDlg, IDC_IMAGEWIDTH, &fTranslated, FALSE); if (!fTranslated || n <= 0) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_IMAGEWIDTH)); SendDlgItemMessage(hDlg, IDC_IMAGEWIDTH, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); return(TRUE); } pParm->nWidth = n; n = GetDlgItemInt(hDlg, IDC_IMAGEHEIGHT, &fTranslated, FALSE); if (!fTranslated || n <= 0) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_IMAGEHEIGHT)); SendDlgItemMessage(hDlg, IDC_IMAGEHEIGHT, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); return(TRUE); } pParm->nHeight = n; n = GetDlgItemInt(hDlg, IDC_IMAGEHORZ, &fTranslated, FALSE); if (!fTranslated || n <= 0) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_IMAGEHORZ)); SendDlgItemMessage(hDlg, IDC_IMAGEHORZ, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); return(TRUE); } pParm->nHorz = n; n = GetDlgItemInt(hDlg, IDC_IMAGEVERT, &fTranslated, FALSE); if (!fTranslated || n <= 0) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_IMAGEVERT)); SendDlgItemMessage(hDlg, IDC_IMAGEVERT, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); return(TRUE); } pParm->nVert = n; GetDlgItemText(hDlg, IDC_IMAGEOFFSET, szText, sizeof(szText)); pParm->nOffset = stol(szText); pParm->fBlackOnWhite = IsDlgButtonChecked(hDlg, IDC_IMAGEBONW); pParm->fMSB = IsDlgButtonChecked(hDlg, IDC_IMAGEMSB); pParm->nType = (L_INT) SendDlgItemMessage(hDlg, IDC_IMAGETYPE, CB_GETCURSEL, 0, 0); pParm->nViewPerspective = (L_INT)SendDlgItemMessage(hDlg, IDC_COMBO_VIEWPERSPECTIVE, CB_GETCURSEL, 0, 0); pParm->nOrder = (L_INT)SendDlgItemMessage(hDlg, IDC_COMBO_ORDER, CB_GETCURSEL, 0, 0); pParm->nPalette = (L_INT)SendDlgItemMessage(hDlg, IDC_COMBO_PALETTE, CB_GETCURSEL, 0, 0); pParm->fPadding = IsDlgButtonChecked(hDlg, IDC_CHECK_PADDING); EndDialog (hDlg, wParam); return (TRUE); case IDCANCEL: EndDialog (hDlg, IDCANCEL); return (TRUE); } break; } return(FALSE); } /*====(SizeClientRect)===================================================== Description: Resizes the client window. Syntax : L_VOID SizeClientRect(HWND hWnd, L_INT nWidth, L_INT nHeight) Prototype : demo.h Parameters : hWnd Handle of the client window. nWidth New Width. nHeight New Height. Return Value: None. ==========================================================================*/ L_VOID SizeClientRect(HWND hWnd, L_INT nWidth, L_INT nHeight) { LPCHILDDATA pData=LOCKCHILDDATA(hWnd); RECT rcListBox={0,0,0,0}; HWND hParent; RECT rcWindow; if(pData) { hParent = GetParent (hWnd); if(IsWindow(pData->hListBox)&&pData->bListBoxVisible) { GetWindowRect(pData->hListBox,&rcListBox); MapWindowPoints(0,hParent,(LPPOINT)&rcListBox,2); rcListBox.right=(rcListBox.right-rcListBox.left)+SPLITWIDTH+1; } GetWindowRect(hWnd,&rcWindow); if(hParent) { ScreenToClient (hParent, (LPPOINT) & rcWindow.left); ScreenToClient (hParent, (LPPOINT) & rcWindow.right); } MoveWindow(hWnd,rcWindow.left,rcWindow.top, nWidth+rcListBox.right+(GetSystemMetrics(SM_CYFRAME)<<1)+GetSystemMetrics(SM_CYBORDER), nHeight+(GetSystemMetrics(SM_CXFRAME)<<1)+GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CXBORDER), TRUE); UNLOCKCHILDDATA(hWnd); } } /*====(DoDialogBoxParam)=================================================== Description: Creates a dialog box and returns the value selected by the user. Syntax : L_INT DoDialogBoxParam(L_INT nDialog, HWND hWnd, DLGPROC pfnDialog, LPARAM lParam) Prototype : demo.h Parameters : nDialog Demo IDD_... value of the dialog box. hWnd Handle of the owner of the dialog box. pfnDialog Function to be used for message processing by the dialog box. lParam Windows long parameter. Return Value: nRet Value returned by the function DialogBoxParam. ==========================================================================*/ L_INT DoDialogBoxParam(L_INT nDialog, HWND hWnd, DLGPROC pfnDialog, LPARAM lParam) { L_INT nRet; nRet = DialogBoxParam (hInst, MAKEINTRESOURCE (nDialog), hWnd, pfnDialog, lParam); return(nRet); } /*====(GetEffectsDelay)====================================================== Description: Gets the effect delay. Syntax : L_INT GetEffectsDelay (HWND hWnd, L_UINT L_FAR*pDelay) Prototype : demo.h Parameters : hWnd Handle of a window. pDelay Pointer to initial value of the delay. Return Value: TRUE or FALSE to indicate whether a delay has been set or not. ==========================================================================*/ L_BOOL GetEffectsDelay (HWND hWnd, L_UINT L_FAR*pDelay) { RANGEPARM Parm; lstrcpy (Parm.szTitle, TEXT("Effect Delay")); lstrcpy (Parm.szLabel, TEXT("&Delay")); Parm.nValue = *pDelay; Parm.nMin = 0; Parm.nMax = 100; Parm.nStep = 1; Parm.nPage = 10; switch (DoDialogBoxParam (IDD_RANGE, hWnd, (DLGPROC) RangeDlgProc, (LPARAM) (LPRANGEPARM) &Parm)) { case IDOK: *pDelay = Parm.nValue; return TRUE; case IDCANCEL: default: return FALSE; break; } } /*====(GetZoomFactor)====================================================== Description: Gets the zoom factor for the image. Syntax : L_INT GetZoomFactor (HWND hWnd, L_INT nInit) Prototype : demo.h Parameters : hWnd Handle of a window. nInit Initial value of the control. Return Value: Zoom Factor. ==========================================================================*/ L_INT GetZoomFactor (HWND hWnd, L_INT nInit) { RANGEPARM Parm; lstrcpy (Parm.szTitle, TEXT("Zoom Factor")); lstrcpy (Parm.szLabel, TEXT("&Percentage")); Parm.nValue = nInit; Parm.nMin = 1; Parm.nMax = 800; Parm.nStep = 1; Parm.nPage = 100; switch (DoDialogBoxParam (IDD_RANGE, hWnd, (DLGPROC) RangeDlgProc, (LPARAM) (LPRANGEPARM) &Parm)) { case IDOK: break; case IDCANCEL: default: Parm.nValue = -1; break; } return (Parm.nValue); } /*====(GetDirectory)====================================================== Description: Gets a directory name Syntax : L_INT GetDirectory (HWND hWnd, L_TCHAR L_FAR*pszDirectory) Prototype : demo.h Parameters : hWnd Handle of a window. pszDirectory Pointer to a buffer holding the directory name. Return Value: TRUE or FALSE to indicate whether a valid directory has been entered or not. ==========================================================================*/ L_BOOL GetDirectory (HWND hWnd, L_TCHAR L_FAR*pszDirectory) { switch (DoDialogBoxParam (IDD_DIRECTORY, hWnd, (DLGPROC) DirDlgProc, (LPARAM) pszDirectory)) { case IDOK: return TRUE; case IDCANCEL: default: return FALSE; } } /*====(GetImageParm)======================================================= Description: Gets additional parameters needed for headerless fax formats. Syntax : L_BOOL GetImageParm (HWND hWnd, LPIMAGEPARM pParm) Prototype : demo.h Parameters : hWnd Handle of a window. pParm Pointer to Image Parameter structure. Return Value: TRUE Load the image. FALSE Do not load the image. ==========================================================================*/ L_BOOL GetImageParm(HWND hWnd, LPIMAGEPARM pParm) { L_BOOL fRet; switch (DoDialogBoxParam (IDD_IMAGEPARM, hWnd, (DLGPROC) ImageDlgProc, (LPARAM) pParm)) { case IDOK: fRet = TRUE; break; case IDCANCEL: default: fRet = FALSE; break; } return (fRet); } /*====(L_FileError)======================================================== Description: Sets up parameters for an error message box. Syntax : L_VOID L_FileError (HWND hwnd, L_INT nCode, L_TCHAR* pTitle, L_TCHAR* pFilename) Prototype : demo.h Parameters : hwnd Handle of a window. nCode Error code to be displayed. pTitle Pointer to the title of the message box. pFilename Pointer to the filename associated with the error. Return Value: None. ==========================================================================*/ L_VOID L_FileError (HWND hwnd, L_INT nCode, L_TCHAR* pTitle, L_TCHAR* pFilename) { L_TCHAR ErrorBuf[1024]; switch (nCode) { case ERROR_NO_MEMORY: strprintf (ErrorBuf, TEXT("Not enough memory available!")); break; case ERROR_NO_BITMAP: strprintf (ErrorBuf, TEXT("Invalid bitmap handle!")); break; case ERROR_MEMORY_TOO_LOW: strprintf (ErrorBuf, TEXT("Not enough memory available!")); break; case ERROR_FILE_LSEEK: strprintf (ErrorBuf, TEXT("Error seeking to position!")); break; case ERROR_FILE_WRITE: strprintf (ErrorBuf, TEXT("Error writing file!")); break; case ERROR_FILE_GONE: strprintf (ErrorBuf, TEXT("File not present - abort!")); break; case ERROR_FILE_READ: strprintf (ErrorBuf, TEXT("Error reading file!")); break; case ERROR_INV_FILENAME: strprintf (ErrorBuf, TEXT("Invalid filename specified!")); break; case ERROR_FILE_FORMAT: strprintf (ErrorBuf, TEXT("Invalid file format!")); break; case ERROR_FILENOTFOUND: strprintf (ErrorBuf, TEXT("File not found!")); break; case ERROR_INV_RANGE: strprintf (ErrorBuf, TEXT("Invalid width/height!")); break; case ERROR_IMAGE_TYPE: strprintf (ErrorBuf, TEXT("Image format recognized, but sub-type not supported!")); break; case ERROR_INV_PARAMETER: strprintf (ErrorBuf, TEXT("Invalid parameter!")); break; case ERROR_FILE_OPEN: strprintf (ErrorBuf, TEXT("Not able to open file!")); break; case ERROR_UNKNOWN_COMP: strprintf (ErrorBuf, TEXT("Unknown compression format!")); break; case ERROR_FEATURE_NOT_SUPPORTED: strprintf (ErrorBuf, TEXT("Feature not supported!")); break; case ERROR_NOT_256_COLOR: strprintf (ErrorBuf, TEXT("VGA card only supports 256 colors (8 bit)!")); break; case ERROR_PRINTER: strprintf (ErrorBuf, TEXT("Printer error!")); break; case ERROR_CRC_CHECK: strprintf (ErrorBuf, TEXT("Data CRC check error!")); break; case ERROR_QFACTOR: strprintf (ErrorBuf, TEXT("Invalid QFactor specified!")); break; case ERROR_TARGAINSTALL: strprintf (ErrorBuf, TEXT("TARGA not installed!")); break; case ERROR_OUTPUTTYPE: strprintf (ErrorBuf, TEXT("Invalid compression format!")); break; case ERROR_XORIGIN: strprintf (ErrorBuf, TEXT("X origin specified invalid!")); break; case ERROR_YORIGIN: strprintf (ErrorBuf, TEXT("Y origin specified invalid!")); break; case ERROR_VIDEOTYPE: strprintf (ErrorBuf, TEXT("Invalid video mode!")); break; case ERROR_BITPERPIXEL: strprintf (ErrorBuf, TEXT("Invalid bits/pixel!")); break; case ERROR_WINDOWSIZE: strprintf (ErrorBuf, TEXT("Invalid window size!")); break; case ERROR_NORMAL_ABORT: strprintf (ErrorBuf, TEXT("Escape key pressed!")); break; case ERROR_NO_STAMP: strprintf (ErrorBuf, TEXT("Stamp not found!")); break; case ERROR_G3CODE_INVALID: strprintf (ErrorBuf, TEXT("Invalid group 3 data!")); break; case ERROR_G3CODE_EOF: case ERROR_G3CODE_EOL: strprintf (ErrorBuf, TEXT("Group3 code end of code!")); break; case ERROR_PREMATURE_EOF: strprintf (ErrorBuf, TEXT("Premature EOF at scanline!")); break; case ERROR_PREMATURE_EOL: case ERROR_UNCOMP_EOF: case ERROR_ACT_INCOMP: case ERROR_BAD_DECODE_STATE: strprintf (ErrorBuf, TEXT("Premature end-of-line code!")); break; case ERROR_VERSION_NUMBER: strprintf (ErrorBuf, TEXT("Bad version number!")); break; case ERROR_TWAIN_NODSM: strprintf (ErrorBuf, TEXT("Source manager not found!")); break; case ERROR_TWAIN_BUMMER: strprintf (ErrorBuf, TEXT("Failure due to unknown causes!")); break; case ERROR_TWAIN_LOWMEMORY: strprintf (ErrorBuf, TEXT("Not enough memory to perform operation!")); break; case ERROR_TWAIN_NODS: strprintf (ErrorBuf, TEXT("No Data Source!")); break; case ERROR_TWAIN_MAXCONNECTIONS: strprintf (ErrorBuf, TEXT("DS is connected to max possible apps!")); break; case ERROR_TWAIN_OPERATIONERROR: strprintf (ErrorBuf, TEXT("DS or DSM reported error, app shouldn't!")); break; case ERROR_TWAIN_BADCAP: strprintf (ErrorBuf, TEXT("Unknown capability!")); break; case ERROR_TWAIN_BADPROTOCOL: strprintf (ErrorBuf, TEXT("Unrecognized MSG DG DAT combination!")); break; case ERROR_TWAIN_BADVALUE: strprintf (ErrorBuf, TEXT("Data parameter out of range!")); break; case ERROR_TWAIN_SEQERROR: strprintf (ErrorBuf, TEXT("DG DAT MSG out of expected sequence!")); break; case ERROR_TWAIN_BADDEST: strprintf (ErrorBuf, TEXT("Unknown destination App/Src in DSM_Entry!")); break; case ERROR_NOT_ENOUGH_IMAGES: strprintf (ErrorBuf, TEXT("Not enough images to complete the process!")); break; case ERROR_IMAGE_EMPTY: strprintf (ErrorBuf, TEXT("Image is empty!")); break; case ERROR_NO_CHANGE: strprintf (ErrorBuf, TEXT("The image hasn't changed!")); break; case ERROR_LZW_LOCKED: strprintf (ErrorBuf, TEXT("LZW capability is required to load/save this file!")); break; case ERROR_DOCUMENT_NOT_ENABLED: strprintf (ErrorBuf, TEXT("Express capability is required to use this function!")); break; case ERROR_MEDICAL_NOT_ENABLED: strprintf (ErrorBuf, TEXT("Medical Express capability is required to use this function!")); break; case ERROR_JBIG_NOT_ENABLED: strprintf (ErrorBuf, TEXT("JBIG capability is required to use this function!")); break; case ERROR_FPX_FILE_IN_USE: strprintf (ErrorBuf, TEXT("Error accessing file. The file is probably already open!")); break; #if defined(WIN32) && !defined(_ALPHA_) case ERROR_ISIS_NOCURSCANNER: strprintf (ErrorBuf, TEXT("No ISIS Scanner selected!")); break; case ERROR_ISIS_CANCEL: strprintf (ErrorBuf, TEXT("ISIS Operation canceled!")); break; case ERROR_ISIS_SCANDRIVER_NOT_LOADED: strprintf (ErrorBuf, TEXT("ISIS Driver failed to load")); break; case ERROR_ISIS_BAD_TAG_OR_VALUE: case ERROR_ISIS_NOT_READY: case ERROR_ISIS_JAM: case ERROR_ISIS_SCANNER_ERROR: case ERROR_ISIS_BUSY: case ERROR_ISIS_FILE_ERROR: case ERROR_ISIS_NETWORK_ERROR: strprintf (ErrorBuf, TEXT("ISIS Scanner Error acquiring image!")); break; case ERROR_ISIS_NO_PAGE: strprintf (ErrorBuf, TEXT("No Page in ISIS Scanner!")); break; #endif case ERROR_USER_ABORT: case SUCCESS_DLG_CANCEL: return; break; case ERROR_TWAIN_CANCELED: case ERROR_TWAIN_CANCEL: { L_INT nRet; TW_CAPABILITY twCap; L_BOOL bUseFeeder = TRUE; pTW_ONEVALUE pOneVal = NULL; twCap.Cap = CAP_FEEDERENABLED; twCap.ConType = TWON_ONEVALUE; twCap.hContainer = NULL; nRet = L_TwainGetCapability(g_hTwainSession, &twCap, LTWAIN_PROPERTIES_GETCURRENT); if (nRet != TWAIN_SUCCESS) return; pOneVal = (pTW_ONEVALUE)GlobalLock(twCap.hContainer); if (pOneVal->ItemType != TWTY_BOOL) bUseFeeder = FALSE; else bUseFeeder = pOneVal->Item; GlobalUnlock(twCap.hContainer); GlobalFree(twCap.hContainer); if (bUseFeeder) strprintf(ErrorBuf, TEXT("Internal Error: out of paper")); else strprintf(ErrorBuf, TEXT("TWAIN Operation canceled!")); } break; case ERROR_PDF_BAD_INITIALIZATION_FILES: if( IDYES == MessageBox ( hwnd,TEXT("LEADTOOLS PDF plugin is not found, do you want to download the plugin now?"), pTitle,MB_ICONEXCLAMATION | MB_YESNO)) { ShellExecute(hwnd, TEXT("open"), TEXT("http://www.leadtools.com/ReleaseDownloads/v14/LEADTOOLSPDFRuntime.exe"), NULL, NULL, SW_SHOWNORMAL); } return; break; default: if(nCode >= ERROR_FPX_INVALID_FORMAT_ERROR && nCode <= ERROR_FPX_INVALID_TILE) strprintf (ErrorBuf, TEXT("Internal FlashPix error!")); else strprintf (ErrorBuf, TEXT("Internal or Unrecognized Error!")); break; } fMessageBox (hwnd, pTitle, MB_ICONEXCLAMATION | MB_OK, TEXT("%s\nLEADTOOLS DLL Error (%d)\n%s"), pFilename, nCode, ErrorBuf); return; } /*====(fMessageBox)======================================================== Description: Creates a message box. Syntax : L_INT fMessageBox (HWND hWnd, L_TCHAR* pCaption, UINT wType, L_TCHAR* pFormat,...) Prototype : demo.h Parameters : hWnd Handle of a window. pCaption Pointer to the title of the message box. wType Type of the message box. pFormat Format of the message box. Return Value: X Return value of Window's MessageBox function. ==========================================================================*/ L_INT fMessageBox (HWND hWnd, L_TCHAR* pCaption, UINT wType, L_TCHAR* pFormat,...) { L_TCHAR szText[256]; va_list ap; va_start (ap, pFormat); #ifdef _ALPHA_ wvsprintf (szText,pFormat,ap); #else wvsprintf (szText, pFormat, ap); #endif va_end (ap); return (MessageBox (hWnd, szText, pCaption, wType)); } /*====(BuildChildListCB)====================================================== Description: Child window enumeration procedure used by BuildChildList Syntax : L_BOOL CALLBACK L_EXPORT BuildChildListCB(HWND hWnd, LPARAM lParam) Prototype : demo.h Parameters : hWnd Handle of the child window. lParam Pointer to an LPCHILDLIST variable Return Value: TRUE To continue enumeration ==========================================================================*/ L_BOOL CALLBACK L_EXPORT BuildChildListCB (HWND hWnd, LPARAM lParam) { LPCHILDLIST pList; if(GetParent(hWnd)==hWndClient) { if (GetWindow (hWnd, GW_OWNER)) return(TRUE); pList = *((LPCHILDLIST L_FAR *) lParam); if(!pList) pList = GlobalAllocPtr(GHND, sizeof(CHILDLIST)); else pList = GlobalReAllocPtr(pList, sizeof(CHILDLIST) + (sizeof(HWND) * pList->nCount), GMEM_MOVEABLE); if(!pList) return(FALSE); pList->ahWnd[pList->nCount++] = hWnd; *((LPCHILDLIST L_FAR *) lParam) = pList; } return(TRUE); } /*====(BuildChildList)====================================================== Description: Returns a list of child window handles Syntax : LPCHILDLIST BuildChildList (L_VOID) Parameters : None Return Value: Pointer to child list ==========================================================================*/ LPCHILDLIST BuildChildList(L_VOID) { LPCHILDLIST pList = NULL; EnumChildWindows(hWndClient, BuildChildListCB, (LPARAM) (LPCHILDLIST L_FAR *) &pList); return(pList); } /*====(ClrMergeDlgProc)====================================================== Description: Processes Color Merge dialog box messages. Syntax : L_BOOL CALLBACK L_EXPORT ClrMergeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Handle of the dialog box. message Message to be processed. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE/FALSE Depends on the message. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT ClrMergeDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPCHILDLIST pList; static LPCLRMERGEPARM pParm; L_TCHAR szTitle[_MAX_PATH]; L_INT i; switch (message) { case WM_INITDIALOG: pParm = (LPCLRMERGEPARM) lParam; pList = BuildChildList(); if(!pList) { EndDialog (hDlg, IDCANCEL); return (TRUE); } for(i = 0; i < pList->nCount; i++) { GetChildTitle(pList->ahWnd[i], szTitle); SendDlgItemMessage(hDlg, IDC_CLRLIST1, CB_ADDSTRING, 0, (LPARAM) szTitle); SendDlgItemMessage(hDlg, IDC_CLRLIST2, CB_ADDSTRING, 0, (LPARAM) szTitle); SendDlgItemMessage(hDlg, IDC_CLRLIST3, CB_ADDSTRING, 0, (LPARAM) szTitle); SendDlgItemMessage(hDlg, IDC_CLRLIST4, CB_ADDSTRING, 0, (LPARAM) szTitle); } SendDlgItemMessage(hDlg, IDC_CLRLIST1, CB_SETCURSEL, 0, 0); SendDlgItemMessage(hDlg, IDC_CLRLIST2, CB_SETCURSEL, 0, 0); SendDlgItemMessage(hDlg, IDC_CLRLIST3, CB_SETCURSEL, 0, 0); SendDlgItemMessage(hDlg, IDC_CLRLIST4, CB_SETCURSEL, 0, 0); switch(pParm->nFlag) { case COLORSEP_RGB: CheckDlgButton(hDlg, IDC_CLRRGB, TRUE); SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Blue")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Green")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Red")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); break; case COLORSEP_CMYK: CheckDlgButton(hDlg, IDC_CLRCMYK, TRUE); SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Cyan")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Magenta")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Yellow")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_SHOW); break; case COLORSEP_HSV: CheckDlgButton(hDlg, IDC_CLRHSV, TRUE); SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Hue")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Saturation")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Value")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); break; case COLORSEP_HLS: CheckDlgButton(hDlg, IDC_CLRHLS, TRUE); SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Hue")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Lightness")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Saturation")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); break; case COLORSEP_CMY: CheckDlgButton(hDlg, IDC_CLRCMY, TRUE); SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Cyan")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Magenta")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Yellow")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); break; } return (TRUE); case WM_COMMAND: switch (CTLID(wParam, lParam)) { case IDC_CLRCMYK: switch(NOTIFYCODE(wParam, lParam)) { case BN_CLICKED: SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Cyan")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Magenta")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Yellow")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_SHOW); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_SHOW); return(TRUE); } break; case IDC_CLRRGB: switch(NOTIFYCODE(wParam, lParam)) { case BN_CLICKED: SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Red")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Green")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Blue")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); return(TRUE); } break; case IDC_CLRHSV: switch(NOTIFYCODE(wParam, lParam)) { case BN_CLICKED: SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Hue")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Saturation")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Value")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); return(TRUE); } break; case IDC_CLRHLS: switch(NOTIFYCODE(wParam, lParam)) { case BN_CLICKED: SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Hue")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Lightness")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Saturation")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); return(TRUE); } break; case IDC_CLRCMY: switch(NOTIFYCODE(wParam, lParam)) { case BN_CLICKED: SetDlgItemText(hDlg, IDC_CLRLABEL1, TEXT("&Cyan")); SetDlgItemText(hDlg, IDC_CLRLABEL2, TEXT("&Magenta")); SetDlgItemText(hDlg, IDC_CLRLABEL3, TEXT("&Yellow")); ShowWindow(GetDlgItem(hDlg, IDC_CLRLABEL4), SW_HIDE); ShowWindow(GetDlgItem(hDlg, IDC_CLRLIST4), SW_HIDE); return(TRUE); } break; case IDOK: if(IsDlgButtonChecked(hDlg, IDC_CLRRGB)) pParm->nFlag = COLORSEP_RGB; else if(IsDlgButtonChecked(hDlg, IDC_CLRCMYK)) pParm->nFlag = COLORSEP_CMYK; else if(IsDlgButtonChecked(hDlg, IDC_CLRHSV)) pParm->nFlag = COLORSEP_HSV; else if(IsDlgButtonChecked(hDlg, IDC_CLRHLS)) pParm->nFlag = COLORSEP_HLS; else pParm->nFlag = COLORSEP_CMY; pParm->ahWnd[0] = pList->ahWnd[(L_INT) SendDlgItemMessage(hDlg, IDC_CLRLIST1, CB_GETCURSEL, 0, 0)]; pParm->ahWnd[1] = pList->ahWnd[(L_INT) SendDlgItemMessage(hDlg, IDC_CLRLIST2, CB_GETCURSEL, 0, 0)]; pParm->ahWnd[2] = pList->ahWnd[(L_INT) SendDlgItemMessage(hDlg, IDC_CLRLIST3, CB_GETCURSEL, 0, 0)]; pParm->ahWnd[3] = pList->ahWnd[(L_INT) SendDlgItemMessage(hDlg, IDC_CLRLIST4, CB_GETCURSEL, 0, 0)]; GlobalFreePtr(pList); EndDialog (hDlg, wParam); return (TRUE); case IDCANCEL: GlobalFreePtr(pList); EndDialog (hDlg, wParam); return (TRUE); } } return (FALSE); } /*====(GetClrMergeParm)====================================================== Description: Gets the parameters needed for color merging. Syntax : L_BOOL GetClrMergeParm (HWND hWnd, LPCLRMERGEPARM pParm) Prototype : demo.h Parameters : hWnd Handle of a window. pParm Pointer to Rotate Parameter structure. Return Value: TRUE Merge the image. FALSE Do not merge the image. ==========================================================================*/ L_BOOL GetClrMergeParm(HWND hWnd, LPCLRMERGEPARM pParm) { L_BOOL fRet; switch (DoDialogBoxParam (IDD_CLRMERGE, hWnd, (DLGPROC) ClrMergeDlgProc, (LPARAM) pParm)) { case IDOK: fRet = TRUE; break; case IDCANCEL: default: fRet = FALSE; break; } return (fRet); } /*====(UnderlayDlgProc)====================================================== Description: Processes Underlay dialog box messages. Syntax : L_BOOL CALLBACK L_EXPORT UnderlayDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Handle of the dialog box. message Message to be processed. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE/FALSE Depends on the message. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT UnderlayDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPCHILDLIST pList; static LPUNDERLAYPARM pParm; L_TCHAR szTitle[_MAX_PATH]; L_INT i; switch (message) { case WM_INITDIALOG: pParm = (LPUNDERLAYPARM) lParam; pList = BuildChildList(); if(!pList) { EndDialog (hDlg, IDCANCEL); return (TRUE); } for(i = 0; i < pList->nCount; i++) { GetChildTitle(pList->ahWnd[i], szTitle); SendDlgItemMessage(hDlg, IDC_ULAYPATTERN, CB_ADDSTRING, 0, (LPARAM) szTitle); } SendDlgItemMessage(hDlg, IDC_ULAYPATTERN, CB_SETCURSEL, 0, 0); CheckDlgButton(hDlg, pParm->fStretch ? IDC_ULAYSTRETCH : IDC_ULAYTILE, TRUE); return (TRUE); case WM_COMMAND: switch (CTLID(wParam, lParam)) { case IDOK: pParm->fStretch = IsDlgButtonChecked(hDlg, IDC_ULAYSTRETCH); pParm->hWnd = pList->ahWnd[(L_INT) SendDlgItemMessage(hDlg, IDC_ULAYPATTERN, CB_GETCURSEL, 0, 0)]; GlobalFreePtr(pList); EndDialog (hDlg, wParam); return (TRUE); case IDCANCEL: GlobalFreePtr(pList); EndDialog (hDlg, wParam); return (TRUE); } } return (FALSE); } /*====(GetUnderlayParm)====================================================== Description: Gets the parameters needed for underlaying. Syntax : L_BOOL GetUnderlayParm (HWND hWnd, LPUNDERLAYPARM pParm) Prototype : demo.h Parameters : hWnd Handle of a window. pParm Pointer to Rotate Parameter structure. Return Value: TRUE underlay the image. FALSE Do not underlay the image. ==========================================================================*/ L_BOOL GetUnderlayParm (HWND hWnd, LPUNDERLAYPARM pUnderlayParm) { L_BOOL fRet; pUnderlayParm->hWnd = NULL; pUnderlayParm->fStretch = FALSE; switch (DoDialogBoxParam (IDD_UNDERLAY, hWnd, (DLGPROC) UnderlayDlgProc, (LPARAM) pUnderlayParm)) { case IDOK: fRet = TRUE; break; case IDCANCEL: default: fRet = FALSE; break; } return (fRet); } L_BOOL CALLBACK L_EXPORT AnimationDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPCHILDLIST pList; static LPANIMATIONPARM pParm; L_TCHAR szTitle[_MAX_PATH]; LPCHILDDATA pData; L_INT i, j; L_INT nWidth, nHeight; HDC hdc; BITMAPHANDLE Bitmap; switch (message) { case WM_INITDIALOG: pParm = (LPANIMATIONPARM) lParam; pList = BuildChildList(); if(!pList) { EndDialog (hDlg, IDCANCEL); return (TRUE); } L_CreateBitmapList(&pParm->hList); for(i = 0; i < pList->nCount; i++) { memset ( szTitle, 0, (sizeof(L_TCHAR)*_MAX_PATH)); GetChildTitle(pList->ahWnd[i], szTitle); SendDlgItemMessage(hDlg, IDC_ANIMATIONSOURCELIST, LB_ADDSTRING, 0, (LPARAM) szTitle); ShowHorizontal ( GetDlgItem ( hDlg, IDC_ANIMATIONSOURCELIST ) ) ; } SendDlgItemMessage(hDlg, IDC_ANIMATIONSOURCELIST, LB_SETCURSEL, 0, 0); EnableWindow (GetDlgItem (hDlg, IDC_ANIMATIONSUB), FALSE); EnableWindow (GetDlgItem (hDlg, IDOK), FALSE); return (TRUE); case WM_COMMAND: switch (CTLID(wParam, lParam)) { case IDC_ANIMATIONPLAYLIST: switch (NOTIFYCODE(wParam, lParam)) { case LBN_SELCHANGE: i = (L_INT) SendDlgItemMessage(hDlg, IDC_ANIMATIONPLAYLIST, LB_GETCURSEL, 0, 0); EnableWindow (GetDlgItem (hDlg, IDC_ANIMATIONSUB), i != LB_ERR); EnableWindow (GetDlgItem (hDlg, IDOK), i != LB_ERR); return(TRUE); case LBN_DBLCLK: goto animation_sub; } break; case IDC_ANIMATIONSOURCELIST: switch (NOTIFYCODE(wParam, lParam)) { case LBN_DBLCLK: goto animation_add; } break; case IDC_ANIMATIONADD: animation_add: i = (L_INT) SendDlgItemMessage(hDlg, IDC_ANIMATIONSOURCELIST, LB_GETCURSEL, 0, 0); pData = LOCKCHILDDATA(pList->ahWnd[i]); L_CopyBitmap(&Bitmap, &pData->ActiveBitmap, sizeof(BITMAPHANDLE)); L_InsertBitmapListItem(pParm->hList, (L_UINT) -1, &Bitmap); memset ( szTitle, 0, (sizeof(L_TCHAR)*_MAX_PATH)); GetChildTitle(pList->ahWnd[i], szTitle); j = (L_INT) SendDlgItemMessage(hDlg, IDC_ANIMATIONPLAYLIST, LB_ADDSTRING, 0, (LPARAM) szTitle); ShowHorizontal ( GetDlgItem ( hDlg, IDC_ANIMATIONPLAYLIST ) ) ; SendDlgItemMessage(hDlg, IDC_ANIMATIONPLAYLIST, LB_SETCURSEL, (WPARAM) j, 0); EnableWindow (GetDlgItem (hDlg, IDC_ANIMATIONSUB), TRUE); EnableWindow (GetDlgItem (hDlg, IDOK), TRUE); UNLOCKCHILDDATA(pList->ahWnd[i]); return (TRUE); case IDC_ANIMATIONSUB: animation_sub: i = (L_INT) SendDlgItemMessage(hDlg, IDC_ANIMATIONPLAYLIST, LB_GETCURSEL, 0, 0); L_DeleteBitmapListItems(pParm->hList, i, 1); j = (L_INT) SendDlgItemMessage(hDlg, IDC_ANIMATIONPLAYLIST, LB_DELETESTRING, (WPARAM) i, 0); j = (L_INT) SendDlgItemMessage(hDlg, IDC_ANIMATIONPLAYLIST, LB_SETCURSEL, (WPARAM) min(j - 1, i), 0); EnableWindow (GetDlgItem (hDlg, IDC_ANIMATIONSUB), j != LB_ERR); EnableWindow (GetDlgItem (hDlg, IDOK), j != LB_ERR); return (TRUE); case IDOK: nWidth = nHeight = 0; L_GetBitmapListCount(pParm->hList, (L_UINT L_FAR *) &j); for(i = 0; i < j; i++) { L_GetBitmapListItem(pParm->hList, i, &Bitmap, sizeof(BITMAPHANDLE)); nWidth = max(Bitmap.Left + Bitmap.Width, nWidth); nHeight = max(Bitmap.Top + Bitmap.Height, nHeight); } hdc = GetDC(hDlg); L_CreateBitmap (&pParm->Bitmap, sizeof(BITMAPHANDLE), TYPE_CONV, nWidth, nHeight, (L_INT) (GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES)), ORDER_BGR, NULL, BOTTOM_LEFT, NULL, 0); ReleaseDC(hDlg, hdc); GlobalFreePtr(pList); EndDialog (hDlg, wParam); return (TRUE); case IDCANCEL: L_DestroyBitmapList(pParm->hList); GlobalFreePtr(pList); EndDialog (hDlg, wParam); return (TRUE); } } return (FALSE); } L_BOOL GetAnimationParm(HWND hWnd, LPANIMATIONPARM pParm) { L_BOOL fRet; switch (DoDialogBoxParam (IDD_ANIMATION, hWnd, (DLGPROC) AnimationDlgProc, (LPARAM) pParm)) { case IDOK: fRet = TRUE; break; case IDCANCEL: default: fRet = FALSE; break; } return (fRet); } L_BOOL CALLBACK L_EXPORT FrameSettingsDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static LPFRAMESETTINGSPARM pParm; L_BOOL fTranslated; L_INT nLeft, nTop; L_TCHAR szText[256]; switch (message) { case WM_INITDIALOG: pParm = (LPFRAMESETTINGSPARM) lParam; CheckDlgButton (hDlg, IDC_ANIFRAMECOLOR, pParm->fTransparency); CheckDlgButton (hDlg, IDC_ANIFRAMEINPUT, pParm->fWaitUserInput); strprintf(szText, TEXT("%lu"), (L_UINT32) pParm->uDelay); SetDlgItemText(hDlg, IDC_ANIFRAMEDELAY, szText); strprintf(szText, TEXT("0x%.8lX"), (L_UINT32) pParm->crTransparency); SetDlgItemText(hDlg, IDC_ANIFRAMECOLORBOX, szText); SendDlgItemMessage(hDlg, IDC_ANIFRAMEDISPOSAL, CB_ADDSTRING, 0, (LPARAM) TEXT("None")); SendDlgItemMessage(hDlg, IDC_ANIFRAMEDISPOSAL, CB_ADDSTRING, 0, (LPARAM) TEXT("Leave")); SendDlgItemMessage(hDlg, IDC_ANIFRAMEDISPOSAL, CB_ADDSTRING, 0, (LPARAM) TEXT("Restore Background")); SendDlgItemMessage(hDlg, IDC_ANIFRAMEDISPOSAL, CB_ADDSTRING, 0, (LPARAM) TEXT("Restore Previous")); SendDlgItemMessage(hDlg, IDC_ANIFRAMEDISPOSAL, CB_SETCURSEL, (WPARAM) pParm->uDisposalMethod, 0); SetDlgItemInt(hDlg, IDC_ANIFRAMELEFT, pParm->nLeft, TRUE); SetDlgItemInt(hDlg, IDC_ANIFRAMETOP, pParm->nTop, TRUE); CheckDlgButton (hDlg, IDC_ANIFRAMEALL, pParm->fApplytoall); return (TRUE); case WM_COMMAND: switch (CTLID(wParam, lParam)) { case IDC_CHOOSECOLOR: // don't allow the palette colors to be changed here if( GetColor(hDlg, pParm->pBitmap, &pParm->crTransparency, NULL) ) { strprintf(szText, TEXT("0x%.8lX"), (L_UINT32) pParm->crTransparency); SetDlgItemText(hDlg, IDC_ANIFRAMECOLORBOX, szText); } break; case IDOK: nLeft = (L_INT) GetDlgItemInt (hDlg, IDC_ANIFRAMELEFT, &fTranslated, TRUE); if(!fTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_ANIFRAMELEFT)); return(FALSE); } nTop = (L_INT) GetDlgItemInt (hDlg, IDC_ANIFRAMETOP, &fTranslated, TRUE); if(!fTranslated) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_ANIFRAMETOP)); return(FALSE); } GetDlgItemText(hDlg, IDC_ANIFRAMEDELAY, szText, sizeof(szText)); pParm->uDelay = stoul(szText, NULL, 10); GetDlgItemText(hDlg, IDC_ANIFRAMECOLORBOX, szText, sizeof(szText)); pParm->crTransparency = stoul(szText, NULL, 0); pParm->nLeft = nLeft; pParm->nTop = nTop; pParm->fTransparency = IsDlgButtonChecked (hDlg, IDC_ANIFRAMECOLOR); pParm->fWaitUserInput = IsDlgButtonChecked (hDlg, IDC_ANIFRAMEINPUT); pParm->fApplytoall = IsDlgButtonChecked (hDlg, IDC_ANIFRAMEALL); pParm->uDelay = (L_UINT32) GetDlgItemInt (hDlg, IDC_ANIFRAMEDELAY, NULL, FALSE); pParm->uDisposalMethod = (L_UINT) SendDlgItemMessage(hDlg, IDC_ANIFRAMEDISPOSAL, CB_GETCURSEL, 0, 0); EndDialog (hDlg, wParam); return (TRUE); case IDCANCEL: EndDialog (hDlg, wParam); return (TRUE); } } return (FALSE); } L_BOOL GetFrameSettingsParm(HWND hWnd, LPFRAMESETTINGSPARM pParm) { L_BOOL fRet; switch (DoDialogBoxParam (IDD_ANIFRAME, hWnd, (DLGPROC) FrameSettingsDlgProc, (LPARAM) pParm)) { case IDOK: fRet = TRUE; break; case IDCANCEL: default: fRet = FALSE; break; } return (fRet); } L_BOOL MyChooseColor(HWND hWnd, LPCOLORREF pColor) { static COLORREF CustomColors[16] = { RGB(0, 0, 0), RGB(128, 0, 0), RGB(0, 128, 0), RGB(128, 128, 0), RGB(0, 0, 128), RGB(128, 0, 128), RGB(0, 128, 128), RGB(128, 128, 128), RGB(192, 192, 192), RGB(255, 0, 0), RGB(0, 255, 0), RGB(255, 255, 0), RGB(0, 0, 255), RGB(255, 0, 255), RGB(0, 255, 255), RGB(255, 255, 255), }; CHOOSECOLOR color; // make sure the color we have is in the custom colors // CustomColors[15] = *pColor; _fmemset(&color, 0, sizeof(CHOOSECOLOR)); color.lStructSize = sizeof(CHOOSECOLOR); color.hwndOwner = hWnd; color.rgbResult = *pColor; color.lpCustColors = CustomColors; color.Flags = CC_FULLOPEN | CC_RGBINIT; if( ChooseColor(&color) ) { *pColor = color.rgbResult; return TRUE; } else return FALSE; } L_BOOL GetColor(HWND hWnd, pBITMAPHANDLE pBitmap, COLORREF FAR *pColor, L_BOOL L_FAR*pbColorsChanged) { static COLORREF rgbColor = RGB(0, 0, 0); if(pbColorsChanged) *pbColorsChanged = FALSE; // I want to use this function to diplay the current palette (pColor is NULL) // and to pick a transparent color (pColor != NULL) if(!pColor) pColor = &rgbColor; if( pBitmap->BitsPerPixel > 8 ) return MyChooseColor(hWnd, pColor); else { COLORPARM colorparm; colorparm.nColors = pBitmap->nColors; colorparm.hPal = L_DupBitmapPalette(pBitmap); L_GetBitmapColors(pBitmap, 0, pBitmap->nColors, colorparm.pColors); if( colorparm.nColors <= 0 ) return 0; /* some error occurred */ if( *pColor & 0xFF000000 ) colorparm.nColorIndex = (L_INT)(*pColor & 0x00FFFFFF); else colorparm.nColorIndex = GetNearestPaletteIndex(colorparm.hPal, *pColor); colorparm.nColorIndex = max(0, min(colorparm.nColorIndex,colorparm.nColors-1)); colorparm.pbColorsChanged = pbColorsChanged; switch( DoDialogBoxParam(IDD_BITMAPCOLORS, hWnd, BitmapColorsDlgProc, (LPARAM)(LPCOLORPARM)&colorparm) ) { case IDOK: *pColor = PALETTEINDEX(colorparm.nColorIndex); // I have changed the palette. Update the bitmap handle if(colorparm.pbColorsChanged && *colorparm.pbColorsChanged) L_SetBitmapPalette(pBitmap, colorparm.hPal); DeleteObject(colorparm.hPal); return TRUE; default: DeleteObject(colorparm.hPal); return FALSE; } } } L_VOID SetCurrentColor( HWND hDlg, LPRGBQUAD palColors, L_INT nColorIndex ) { /* set the current color to be palColors[nColorIndex] */ InvalidateRect( GetDlgItem(hDlg,IDC_CURRENTCOLOR), NULL, FALSE ); SetDlgItemInt( hDlg, IDC_CURRENTRED, palColors[nColorIndex].rgbRed, FALSE ); SetDlgItemInt( hDlg, IDC_CURRENTGREEN, palColors[nColorIndex].rgbGreen, FALSE ); SetDlgItemInt( hDlg, IDC_CURRENTBLUE, palColors[nColorIndex].rgbBlue, FALSE ); } L_VOID GenerateColorLayout( HWND hDlg, LPCOLORLAYOUT pColorLayout, L_INT nColors, L_INT L_FAR *deltaX, L_INT L_FAR *deltaY) { RECT rcControl; pColorLayout->nTotalColors = nColors; pColorLayout->nCols = 16; /* the number of rows. The last row might not be full */ pColorLayout->nRows = (nColors + pColorLayout->nCols - 1) / pColorLayout->nCols; /* the size in rcControl is in screen coordinates */ GetWindowRect( GetDlgItem(hDlg,IDC_COLORARRAY), &rcControl ); /* pick some arbitrary values for the gaps */ /* make sure the gaps are at least 3 to be able to draw the focus rectangle around the selected color */ pColorLayout->nDeltaWidth = 4; pColorLayout->nDeltaHeight = 4; /* calculate the width and height of the boxes as if you had 16x16 rows */ /* substract 4 so that nOffsetX is at least 2 to be able to draw the focus rectangle around the very first box */ pColorLayout->nBoxWidth = (RECTWIDTH(&rcControl) - 4 - pColorLayout->nDeltaWidth * (16 - 1)) / 16; pColorLayout->nBoxHeight = (RECTHEIGHT(&rcControl) - 4 - pColorLayout->nDeltaHeight * (16 - 1)) / 16; /* determine the required width for the button */ if( pColorLayout->nRows == 1 ) pColorLayout->nCols = nColors; /* I won't be using deltaX, but calculate it anyway */ *deltaX = pColorLayout->nCols * (pColorLayout->nBoxWidth + pColorLayout->nDeltaWidth) - pColorLayout->nDeltaWidth; *deltaX -= RECTWIDTH(&rcControl); /* this is the value I really need */ *deltaY = pColorLayout->nRows * (pColorLayout->nBoxHeight + pColorLayout->nDeltaHeight) - pColorLayout->nDeltaHeight; *deltaY -= RECTHEIGHT(&rcControl); /* for an aesthetic effect, split what's left in two */ pColorLayout->nOffsetX = RECTWIDTH(&rcControl) - (pColorLayout->nBoxWidth + pColorLayout->nDeltaWidth) * (16 - 1) - pColorLayout->nBoxWidth; pColorLayout->nOffsetX /= 2; pColorLayout->nOffsetY = 0; } L_VOID DrawColoredRectangle( HDC hDC, L_INT left, L_INT top, L_INT width, L_INT height, COLORREF color) { LOGBRUSH logbrush; HBRUSH hBrush, hOldBrush; HPEN hPen, hOldPen; logbrush.lbStyle = BS_SOLID; logbrush.lbColor = color; hBrush = CreateBrushIndirect(&logbrush); hOldBrush = SelectObject( hDC, hBrush ); hPen = CreatePen(PS_INSIDEFRAME, 3, RGB(0,0,0)); hOldPen = SelectObject( hDC, hPen ); Rectangle( hDC, left, top, left + width, top + height ); SelectObject( hDC, hOldBrush ); DeleteObject( hBrush ); SelectObject( hDC, hOldPen ); DeleteObject( hPen ); } L_VOID DrawColorPalette( HDC hDC, HPALETTE hPal, LPCOLORLAYOUT colorlayout, LPRGBQUAD pal, L_INT nIndex ) { L_INT row, col; L_INT index; RECT rect; HPALETTE hOldPalette; hOldPalette = SelectPalette( hDC, hPal, FALSE ); RealizePalette( hDC ); for( row = 0; row < colorlayout->nRows; row++ ) for( col = 0; col < colorlayout->nCols; col++ ) { index = row * colorlayout->nCols + col; if( index >= colorlayout->nTotalColors ) break; DrawColoredRectangle( hDC, colorlayout->nOffsetX + col *(colorlayout->nBoxWidth+colorlayout->nDeltaWidth), colorlayout->nOffsetY + row *(colorlayout->nBoxHeight+colorlayout->nDeltaHeight), colorlayout->nBoxWidth, colorlayout->nBoxHeight, PALETTEINDEX(index) ); } SelectPalette( hDC, hOldPalette, TRUE ); RealizePalette( hDC ); row = nIndex / colorlayout->nCols; col = nIndex % colorlayout->nCols; SetRect( &rect, 1, 1, colorlayout->nBoxWidth - 1, colorlayout->nBoxHeight - 1 ); OffsetRect( &rect, colorlayout->nOffsetX + col *(colorlayout->nBoxWidth+colorlayout->nDeltaWidth), colorlayout->nOffsetY + row *(colorlayout->nBoxHeight+colorlayout->nDeltaHeight) ); DrawFocusRect( hDC, &rect ); } L_VOID ResizeDlgItem(HWND hDlg, L_INT nID, L_INT dx, L_INT dy) { RECT rc; HWND hwndItem; if( nID ) hwndItem = GetDlgItem(hDlg, nID); else hwndItem = hDlg; GetWindowRect(hwndItem, &rc); if( nID ) { ScreenToClient(hDlg, (LPPOINT) &rc.left); ScreenToClient(hDlg, (LPPOINT) &rc.right); } MoveWindow(hwndItem, rc.left, rc.top, rc.right - rc.left + dx, rc.bottom - rc.top + dy, FALSE); } L_VOID OffsetDlgItem(HWND hDlg, L_INT nID, L_INT dx, L_INT dy) { RECT rc; HWND hwndItem; hwndItem = GetDlgItem(hDlg, nID); GetWindowRect(hwndItem, &rc); ScreenToClient(hDlg, (LPPOINT) &rc.left); ScreenToClient(hDlg, (LPPOINT) &rc.right); MoveWindow(hwndItem, rc.left + dx, rc.top + dy, rc.right - rc.left, rc.bottom - rc.top, FALSE); } L_BOOL CALLBACK L_EXPORT BitmapColorsDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { LPDRAWITEMSTRUCT lpDraw; L_INT deltaX, deltaY; L_INT i; switch (message) { case WM_INITDIALOG: pParm = (LPCOLORPARM) lParam; SetCurrentColor(hDlg, pParm->pColors, pParm->nColorIndex); if(pParm->pbColorsChanged) *pParm->pbColorsChanged = FALSE; nIndex = pParm->nColorIndex; /* get the number of rows and columns with colored boxes, the width and height of a box and the width and height of the space between boxes */ GenerateColorLayout(hDlg, &colorlayout, pParm->nColors, &deltaX, &deltaY); if( deltaY ) { ResizeDlgItem( hDlg, IDC_COLORARRAY, 0, deltaY ); ResizeDlgItem( hDlg, IDC_COLORARRAYFRAME, 0, deltaY ); for( i = IDC_FIRSTCOLORITEM; i <= IDC_LASTCOLORITEM; i++ ) OffsetDlgItem( hDlg, i, 0, deltaY + 5); OffsetDlgItem( hDlg, IDOK, 0, deltaY + 5); OffsetDlgItem( hDlg, IDCANCEL, 0, deltaY + 5); /* specify 0 to resize the dialog box */ ResizeDlgItem( hDlg, 0, 0, deltaY ); } /* subclass the button so that we can intercept the clicking */ pfnDefaultButtonProc = (WNDPROC)SetWindowLong(GetDlgItem(hDlg,IDC_COLORARRAY), GWL_WNDPROC, (LONG)ColorArrayWindowProc); return (TRUE); case WM_DRAWITEM: lpDraw = (LPDRAWITEMSTRUCT)lParam; if( wParam == IDC_CURRENTCOLOR && lpDraw->itemAction == ODA_DRAWENTIRE ) { HPALETTE hOldPalette = SelectPalette(lpDraw->hDC,pParm->hPal,FALSE); RealizePalette(lpDraw->hDC); DrawColoredRectangle( lpDraw->hDC, 0, 0, RECTWIDTH(&lpDraw->rcItem), RECTHEIGHT(&lpDraw->rcItem), PALETTEINDEX(nIndex) ); SelectPalette(lpDraw->hDC,hOldPalette,TRUE); } else if( wParam == IDC_COLORARRAY && lpDraw->itemAction == ODA_DRAWENTIRE ) DrawColorPalette( lpDraw->hDC, pParm->hPal, &colorlayout, pParm->pColors, nIndex ); break; case WM_COMMAND: switch (CTLID(wParam, lParam)) { case IDOK: pParm->nColorIndex = nIndex; SetWindowLong(GetDlgItem(hDlg,IDC_COLORARRAY), GWL_WNDPROC, (LONG)pfnDefaultButtonProc); EndDialog (hDlg, wParam); return (TRUE); case IDCANCEL: if(pParm->pbColorsChanged && *pParm->pbColorsChanged) { // I have allocated a new palette. We need to delete it. DeleteObject(pParm->hPal); pParm->hPal = NULL; *pParm->pbColorsChanged = FALSE; } SetWindowLong(GetDlgItem(hDlg,IDC_COLORARRAY), GWL_WNDPROC, (LONG)pfnDefaultButtonProc); EndDialog (hDlg, wParam); return (TRUE); case IDC_CURRENTCOLOR: ChangeColor(hDlg, nIndex); return TRUE; } } return (FALSE); } L_INT GetColorIndex( LPCOLORLAYOUT colorlayout, L_INT x, L_INT y ) { L_INT row, col; x -= colorlayout->nOffsetX; y -= colorlayout->nOffsetY; if( x < 0 || y < 0 ) return -1; col = x / (colorlayout->nBoxWidth + colorlayout->nDeltaWidth); row = y / (colorlayout->nBoxHeight + colorlayout->nDeltaHeight); x %= colorlayout->nBoxWidth + colorlayout->nDeltaWidth; y %= colorlayout->nBoxHeight + colorlayout->nDeltaHeight; if( x >= colorlayout->nBoxWidth || y >= colorlayout->nBoxHeight ) return -1; return row * colorlayout->nCols + col; } HPALETTE MyCreatePalette(L_INT nColors, LPRGBQUAD pColors) { typedef struct _LOGPALETTE256 { WORD palVersion; WORD palNumEntries; PALETTEENTRY palColors[256]; } LOGPALETTE256; LOGPALETTE256 pal; L_INT i; pal.palVersion = 0x300; pal.palNumEntries = nColors; for(i = 0; i < nColors; i++) { pal.palColors[i].peRed = pColors[i].rgbRed; pal.palColors[i].peGreen = pColors[i].rgbGreen; pal.palColors[i].peBlue = pColors[i].rgbBlue; pal.palColors[i].peFlags = 0; } return CreatePalette((LPLOGPALETTE)&pal); } L_BOOL ChangeColor(HWND hWnd, L_INT nIndex) { COLORREF color; // change the colors only if the caller enabled us to do so if(!pParm->pbColorsChanged) return FALSE; color = (pParm->pColors[nIndex].rgbBlue << 16) | (pParm->pColors[nIndex].rgbGreen << 8) | pParm->pColors[nIndex].rgbRed; if(MyChooseColor(hWnd, &color)) { pParm->pColors[nIndex].rgbBlue = (BYTE)(color >> 16); pParm->pColors[nIndex].rgbGreen = (BYTE)(color >> 8); pParm->pColors[nIndex].rgbRed = (BYTE)color; // if pParm->bUpdated then I have created a palette already if(*pParm->pbColorsChanged) DeleteObject(pParm->hPal); else *pParm->pbColorsChanged = TRUE; // note that this line would work properly only if the structure alignment is <= 2 bytes pParm->hPal = MyCreatePalette(pParm->nColors, pParm->pColors); InvalidateRect(hWnd,NULL,FALSE); SetCurrentColor(hWnd, pParm->pColors, nIndex); return TRUE; } return FALSE; } LRESULT CALLBACK ColorArrayWindowProc(HWND hWnd, L_UINT Msg, WPARAM wParam, LPARAM lParam) { L_INT nNewIndex; L_INT row, col; switch (Msg) { case WM_LBUTTONDOWN: nNewIndex = GetColorIndex( &colorlayout, LOWORD(lParam), HIWORD(lParam) ); if(nNewIndex >= 0 && nNewIndex < colorlayout.nTotalColors) if(nNewIndex != nIndex) { HDC hDC = GetDC(hWnd); RECT rect; /* get rid of the old focus rectangle */ row = nIndex / colorlayout.nCols; col = nIndex % colorlayout.nCols; SetRect( &rect, 1, 1, colorlayout.nBoxWidth - 1, colorlayout.nBoxHeight - 1 ); OffsetRect( &rect, colorlayout.nOffsetX + col *(colorlayout.nBoxWidth+colorlayout.nDeltaWidth), colorlayout.nOffsetY + row *(colorlayout.nBoxHeight+colorlayout.nDeltaHeight) ); DrawFocusRect( hDC, &rect ); /* set the new index */ nIndex = nNewIndex; /* paint the new focus rectangle */ row = nIndex / colorlayout.nCols; col = nIndex % colorlayout.nCols; SetRect( &rect, 1, 1, colorlayout.nBoxWidth - 1, colorlayout.nBoxHeight - 1 ); OffsetRect( &rect, colorlayout.nOffsetX + col *(colorlayout.nBoxWidth+colorlayout.nDeltaWidth), colorlayout.nOffsetY + row *(colorlayout.nBoxHeight+colorlayout.nDeltaHeight) ); DrawFocusRect( hDC, &rect ); ReleaseDC( hWnd, hDC ); } else ChangeColor(hWnd, nIndex); SetCurrentColor(GetParent(hWnd), pParm->pColors, nIndex); return 0; case WM_LBUTTONDBLCLK: ChangeColor(hWnd, GetColorIndex( &colorlayout, LOWORD(lParam), HIWORD(lParam) )); return 0; case WM_PALETTECHANGED: if( (HWND)wParam != hWnd ) { InvalidateRect(hWnd,NULL,FALSE); UpdateWindow(hWnd); } return 0; case WM_QUERYNEWPALETTE: return 1; default: return CallWindowProc(pfnDefaultButtonProc, hWnd, Msg, wParam, lParam); }; } L_INT GetThreshold (HWND hWnd, L_TCHAR* pszTitle, L_INT nInit) { RANGEPARM Parm; lstrcpy (Parm.szTitle, pszTitle); lstrcpy (Parm.szLabel, TEXT("&Threshold")); Parm.nValue = nInit; Parm.nMin = 0; Parm.nMax = 255; Parm.nStep = 1; Parm.nPage = 2; switch (DoDialogBoxParam (IDD_RANGE, hWnd, (DLGPROC) RangeDlgProc, (LPARAM) (LPRANGEPARM) &Parm)) { case IDOK: break; case IDCANCEL: default: Parm.nValue = -1; break; } return (Parm.nValue); } L_BOOL IsValidDirectory(L_TCHAR L_FAR*pszDirectory) { // 16 bit version of schdir and sgetcwd use near pointers so we // use arrays allocated in the data segment (by using static) static L_TCHAR szCurrentDir[_MAX_PATH]; static L_TCHAR szDir[_MAX_PATH]; L_BOOL retval; // save the current directory sgetcwd(szCurrentDir, sizeof(szCurrentDir)); // 16 bit version of _tchdir can't use far pointers lstrcpy(szDir, pszDirectory); retval = schdir(szDir) != -1; // restore the previous current directory schdir(szCurrentDir); return retval; } /*====(DirDlgProc)====================================================== Description: Gets the name of a directory. Syntax : L_BOOL CALLBACK L_EXPORT DirDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Prototype : demo.h Parameters : hDlg Handle of the dialog box. message Message to be processed. wParam Windows word parameter. lParam Windows long parameter. Return Value: TRUE/FALSE Depends on the message. ==========================================================================*/ L_BOOL CALLBACK L_EXPORT DirDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { L_TCHAR szDir[_MAX_PATH]; L_TCHAR L_FAR*pszDirectory; switch (message) { case WM_INITDIALOG: SetDlgItemText(hDlg, IDC_DIRECTORY, (L_TCHAR L_FAR*)lParam); SetWindowLong(hDlg, DWL_USER, lParam); SetFocus (GetDlgItem (hDlg, IDC_DIRECTORY)); return(FALSE); case WM_COMMAND: switch(CTLID(wParam, lParam)) { case IDOK: GetDlgItemText(hDlg, IDC_DIRECTORY, (L_TCHAR L_FAR*)szDir, _MAX_PATH); szDir[_MAX_PATH-1] = 0; // make sure the string is NULL terminated // check that we have an existing, valid directory if(!IsValidDirectory(szDir)) { MessageBeep (0); SetFocus (GetDlgItem (hDlg, IDC_DIRECTORY)); #ifdef WIN32 SendDlgItemMessage(hDlg, IDC_DIRECTORY, EM_SETSEL, 0, -1); #else SendDlgItemMessage(hDlg, IDC_DIRECTORY, EM_SETSEL, TRUE, MAKELPARAM(0, -1)); #endif return(TRUE); } // get the addres of the buffer to copy the directory name to pszDirectory = (L_TCHAR L_FAR*)GetWindowLong(hDlg, DWL_USER); lstrcpy(pszDirectory, szDir); EndDialog (hDlg, IDOK); return(TRUE); case IDCANCEL: EndDialog (hDlg, IDCANCEL); return (TRUE); } break; } return(FALSE); } /*--------------------------------------------------------------------------+ | Function :IsMultiPageFormat | Desc :determines wether the givin file supports multipage or not | Return : | Notes : +--------------------------------------------------------------------------*/ L_BOOL IsMultiPageFormat(L_INT nFileFormat) { L_INT i; L_BOOL bSupportExist=FALSE; L_INT nMultiPageFormats[24]= { FILE_JTIF,FILE_LEAD2JTIF,FILE_LEAD1JTIF, FILE_GIF,FILE_TIFLZW,FILE_TIFLZW_CMYK,FILE_TIFLZW_YCC, FILE_TIF,FILE_TIF_CMYK,FILE_TIF_YCC,FILE_TIF_PACKBITS, FILE_TIF_PACKBITS_CMYK,FILE_TIF_PACKBITS_YCC, FILE_PCX,FILE_WFX_G3_1D,FILE_WFX_G4,FILE_CCITT_GROUP4, FILE_CCITT,FILE_CCITT_GROUP3_1DIM,FILE_CCITT_GROUP3_2DIM, FILE_FPX,FILE_FPX_SINGLE_COLOR,FILE_FPX_JPEG,FILE_FPX_JPEG_QFACTOR }; for(i=0;i<(sizeof(nMultiPageFormats)/sizeof(nMultiPageFormats[0]));i++) { if(nFileFormat==nMultiPageFormats[i]) { bSupportExist = TRUE; break; } } return bSupportExist; } /*--------------------------------------------------------------------------+ | Function :IsMultiPageSupportAvailable | Desc :determines wether the givin file supports multipage or not | Return : | Notes : +--------------------------------------------------------------------------*/ L_BOOL IsMultiPageSupportAvailable(L_TCHAR L_FAR* lpFileName) { FILEINFO FileInfo; L_BOOL bSupportExist=FALSE; #ifdef WIN32 if(lpFileName&&lstrlen(lpFileName)) #else if(lpFileName&&_fstrlen(lpFileName)) #endif if(L_FileInfo(lpFileName,&FileInfo,sizeof(FILEINFO),0,NULL)==SUCCESS) { bSupportExist = IsMultiPageFormat(FileInfo.Format); } return(bSupportExist); } /*--------------------------------------------------------------------------+ | Function :GetProperQualityFactor | Desc :returns the correct quality factor for the specified file format | Return : | Notes : +--------------------------------------------------------------------------*/ L_INT GetProperQualityFactor(L_INT nFileFormat) { L_INT nQualityFactor; switch(nFileFormat) { case FILE_JTIF: nQualityFactor=JTIF; break; case FILE_LEAD1JTIF: nQualityFactor=LEAD1JTIF; break; case FILE_LEAD2JTIF: nQualityFactor=LEAD2JTIF; break; case FILE_TIF: nQualityFactor=TIFF_CCITT; break; case FILE_CCITT: nQualityFactor=TIFF_CCITT; break; case FILE_CCITT_GROUP3_1DIM: nQualityFactor=TIFF_CCITTG3_FAX1D; break; case FILE_CCITT_GROUP3_2DIM: nQualityFactor=TIFF_CCITTG3_FAX2D; break; case FILE_CCITT_GROUP4: nQualityFactor=TIFF_CCITTG4_FAX; break; case FILE_TIF_CMYK: case FILE_TIF_YCC: case FILE_TIF_PACKBITS: case FILE_TIF_PACKBITS_CMYK: case FILE_TIF_PACKBITS_YCC: case FILE_TIFLZW: case FILE_TIFLZW_CMYK: case FILE_TIFLZW_YCC: case FILE_WFX_G3_1D: case FILE_WFX_G4: case FILE_PCX: case FILE_GIF: default : nQualityFactor=LEAD; } return(nQualityFactor); } HPALETTE CreateFixedPaintPalette(HWND hWnd, pBITMAPHANDLE pBitmap) { HDC hdc = GetDC(hWnd); L_UINT32 ulFlags = L_GetDisplayMode (); HPALETTE hPalette; L_SetDisplayMode (DISPLAYMODE_FIXEDPALETTE, DISPLAYMODE_FIXEDPALETTE); if(fNetscapePalette) L_SetDisplayMode (DISPLAYMODE_NETSCAPEPALETTE, DISPLAYMODE_NETSCAPEPALETTE); hPalette = L_CreatePaintPalette (hdc, pBitmap); L_SetDisplayMode (DISPLAYMODE_RESETPOSITIONS, ulFlags); ReleaseDC(hWnd, hdc); return hPalette; } L_BOOL ProcessMessages() { MSG msg; while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) { PostQuitMessage(0); return FALSE; } TranslateMessage (&msg); DispatchMessage (&msg); } return TRUE; } L_VOID PaintThisBitmap(HWND hWnd, pBITMAPHANDLE pBitmap, LPRECT prcDest, LPRECT prcDestClip, HPALETTE hPalette) { L_UINT32 ulFlags = L_GetDisplayMode (); HDC hdc = GetDC(hWnd); HPALETTE hOldPalette; switch (nDitherMode) { case IDM_ORDEREDDITHERING: L_SetDisplayMode (DISPLAYMODE_ORDEREDDITHER, DISPLAYMODE_ORDEREDDITHER); break; case IDM_ERRORDIFFUSION: L_SetDisplayMode (DISPLAYMODE_ORDEREDDITHER, 0); break; } L_SetDisplayMode (DISPLAYMODE_FAVORBLACK|DISPLAYMODE_SCALETOGRAY, nBitonalFlags); L_SetDisplayMode (DISPLAYMODE_RESAMPLE|DISPLAYMODE_BICUBIC, nPaintResizeFlags); L_SetDisplayMode (DISPLAYMODE_FIXEDPALETTE, DISPLAYMODE_FIXEDPALETTE); if(fNetscapePalette) L_SetDisplayMode (DISPLAYMODE_NETSCAPEPALETTE, DISPLAYMODE_NETSCAPEPALETTE); if(hPalette) { hOldPalette = SelectPalette(hdc, hPalette, TRUE); RealizePalette(hdc); } L_PaintDC (hdc, pBitmap, NULL, NULL, prcDest, prcDestClip, SRCCOPY ); L_SetDisplayMode (DISPLAYMODE_RESETPOSITIONS, ulFlags); if(hPalette) SelectPalette(hdc, hOldPalette, TRUE); ReleaseDC(hWnd, hdc); } #define DICOM_LOAD_MSG TEXT("This demo loads raster images stored in DICOM files.\n") \ TEXT("For full DICOM support, refer to the LEADTOOLS Medical Imaging demos.") L_VOID DisplayDICOMLoadMsg(HWND hWnd, pFILEINFO pInfo, L_TCHAR L_FAR* pszFilename) { FILEINFO fi; L_INT nFormat; memset(&fi, 0, sizeof(FILEINFO)); if(bDICOMLoadMsg) { if(pInfo) nFormat = pInfo->Format; else { L_FileInfo(pszFilename, &fi, sizeof(FILEINFO), 0, NULL); nFormat = fi.Format; } switch(nFormat) { case FILE_DICOM_GRAY: case FILE_DICOM_COLOR: case FILE_DICOM_RLE_GRAY: case FILE_DICOM_RLE_COLOR: case FILE_DICOM_JPEG_GRAY: case FILE_DICOM_JPEG_COLOR: bDICOMLoadMsg = FALSE; //only do this one time MessageBox(hWnd, DICOM_LOAD_MSG, TEXT("DICOM Load Information"), MB_OK); break; } } return; } #define DICOM_SAVE_MSG TEXT("This demo can only be used to create a 'Secondary Capture Image Storage' DICOM Dataset.\n") \ TEXT("All elements in the Dataset will be set to appropriate default values.\n") \ TEXT("For full DICOM support, refer to the LEADTOOLS Medical Imaging demos.") L_VOID DisplayDICOMSaveMsg(HWND hWnd, L_INT nFormat) { if(bDICOMSaveMsg) { switch(nFormat) { case FILE_DICOM_GRAY: case FILE_DICOM_COLOR: case FILE_DICOM_RLE_GRAY: case FILE_DICOM_RLE_COLOR: case FILE_DICOM_JPEG_GRAY: case FILE_DICOM_JPEG_COLOR: bDICOMSaveMsg = FALSE; //only do this one time MessageBox(hWnd, DICOM_SAVE_MSG, TEXT("DICOM Save Information"), MB_OK); break; } } return; } L_VOID ChangeFont (HWND hWnd) { HFONT hFont ; LOGFONT LogFont ; HDC hDC ; hDC = GetDC ( NULL ) ; //create the default font LogFont.lfHeight = -MulDiv ( 8, GetDeviceCaps ( hDC, LOGPIXELSY ), 72 ) ; ReleaseDC ( NULL, hDC ) ; LogFont.lfWidth = 0 ; LogFont.lfEscapement = 0 ; LogFont.lfOrientation = 0 ; LogFont.lfWeight = FW_NORMAL ; LogFont.lfItalic = FALSE ; LogFont.lfUnderline = FALSE ; LogFont.lfStrikeOut = FALSE ; LogFont.lfCharSet = DEFAULT_CHARSET ; LogFont.lfOutPrecision = OUT_STROKE_PRECIS ; LogFont.lfClipPrecision = CLIP_STROKE_PRECIS ; LogFont.lfQuality = DRAFT_QUALITY ; LogFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE ; lstrcpy ( LogFont.lfFaceName, TEXT ( "MS Shell Dlg" ) ) ; hFont = CreateFontIndirect ( &LogFont ) ; SendMessage ( hWnd == hWndStatus ? GetDlgItem ( hWnd, IDC_TITLE ) : hWnd, WM_SETFONT, ( WPARAM ) hFont, ( LPARAM ) 1 ) ; } L_BOOL IsDir(L_TCHAR L_FAR* pszPath) { L_BOOL bRet; L_TCHAR buffer[L_MAXPATH]; /* Get the current working directory */ _tgetcwd(buffer, L_MAXPATH); /* attempt to set dir */ #ifndef WIN32 if(!lstrcpy(szPath, pszPath)) return(TRUE); if(!_tchdir(szPath)) #else if(!_tchdir(pszPath)) #endif /* it worked, so it is a directory */ bRet = TRUE; else /* must not be a directory */ bRet = FALSE; /* reset dir */ _tchdir(buffer); return bRet; }