/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[] []*/ /*[] Funcs.c []*/ /*[]=====================================================================[]*/ #include "all.h" //------------------------------------------------------------- // MessagePleaseInitialize() // // Parameters: // hWnd handle to screen window // // Description: // Displays a message reminding user to initialize the screen saver // ----------------------------------------------------------- void MessagePleaseInitialize(HWND hWnd) { RECT screenRect; OneImageInfoDef oneImage; pEfxDrawTextDef pText; PLOGFONT pFont; GetClientRect(hWnd,&screenRect); OneImageInfoDefault(&oneImage, TEXT("")); pText = &oneImage.ImageDrawText; pFont = &oneImage.ImageLogFont; lstrcpy(pText->cText, TEXT("Please Initialize LEAD Screen Saver from Control Panel, Display, Screen Saver")); pFont->lfHeight =52; pFont->lfWidth =52; DrawYourText(hWnd, &screenRect, pText, pFont, FALSE); } //MessagePleaseInitialize //------------------------------------------------------------- // IsValidImage() // // Parameters: // szFileName File name // // Description: // Tests to see if a filename is a valid image file // // Returns // SUCCESS: File name is a valid image file // <=0: LEAD error // ----------------------------------------------------------- int IsValidImage(TCHAR *szFileName) { int iRet; BITMAPHANDLE LeadBitmap; iRet = L_LoadFile( szFileName, &LeadBitmap,sizeof(BITMAPHANDLE), 0, //default bits per pixel ORDER_BGR, 0, //flags NULL, //callback NULL, //user data NULL, NULL); return iRet; } //------------------------------------------------------------- // AddOneFile() // // Parameters: // hDlg handle to main dialog of property sheet // szFileName image file name // pbMaxFileLimit set to TRUE if attempt to add exceeds MAX_IMAGE // // Description: // If the szFileName is a valid image, it is added to the list boxes // of all four dialog boxes of property sheet. // // Returns // TRUE: szFileName was successfully added to list boxes // FALSE: szFileName is not a valid image file // ----------------------------------------------------------- BOOL AddOneFile(HWND hDlg, TCHAR *szFileName, PBOOL pbMaxFileLimit) { OneImageInfoDef OneImageInfo; int iReturn; BOOL bRet; bRet = FALSE; *pbMaxFileLimit = TRUE; if (AllImage_GetCount() < MAX_IMAGES) { *pbMaxFileLimit = FALSE; if (IsValidImage(szFileName) == SUCCESS ) { OneImageInfoDefault(&OneImageInfo, szFileName); AllImage_Add( &OneImageInfo); iReturn = ListBox_AddString(GetDlgItem(hDlg,IDC_IMGLIST), szFileName ); PropSheet_QuerySiblings(GetParent(hDlg), LIST_BOX_ADD_STRING, (LPARAM)szFileName); bRet = TRUE; } } return bRet; }//AddOneFile 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; } } //------------------------------------------------------------- // AddSelectedFiles() // // Parameters: // hDlg: handle to main dialog of property sheet // pbInvalidImage: some of the selected images were not valid // pbMaxImageLimit: attempted to add more than MAX_IMAGES images // // Description: // Displays common dialog, and adds one or more selected files // to image list box // // Returns // TRUE: one or more images added to image list box // FALSE: no images added to image list box // ----------------------------------------------------------- BOOL AddSelectedFiles(HWND hDlg, PBOOL pbInvalidImage, PBOOL pbMaxImageLimit) { OPENDLGPARAMS FoParm; // for use with L_DlgFileOpen BOOL bAddedOneImage, bTooManyImages; int iReturn; bAddedOneImage = FALSE; *pbInvalidImage = FALSE; *pbMaxImageLimit = FALSE; memset(&FoParm, 0, sizeof (OPENDLGPARAMS)); FoParm.uStructSize =sizeof (OPENDLGPARAMS); FoParm.uDlgFlags = DLG_OPEN_SHOW_FILEINFO | DLG_OPEN_SHOW_PREVIEW | DLG_OPEN_USEFILESTAMP; iReturn= OpenFileDialog(hDlg, &FoParm); if (iReturn==SUCCESS_DLG_OK) { int i = 0; for(i=0; i < FoParm.nNumOfFiles; ++i ) { bAddedOneImage = AddOneFile(hDlg, FoParm.pFileData[i].szFileName, &bTooManyImages); *pbMaxImageLimit = *pbMaxImageLimit | bTooManyImages; *pbInvalidImage = !bAddedOneImage; } CleanOpenDlgParam(&FoParm); } return bAddedOneImage; } //------------------------------------------------------------- // AllImage_Add() // // Parameters: // pImageInfo pointer to ImageInfo structure // // Description: // Adds a single image name and settings to the AllImage global structure // ----------------------------------------------------------- BOOL AllImage_Add(pOneImageInfoDef pImageInfo) { int index; if (AllImage.uImageCount < MAX_IMAGES) { index = AllImage.uImageCount; AllImage.ImageInfoArrayPtr[index] = (pOneImageInfoDef)malloc(sizeof(OneImageInfoDef)); *(AllImage.ImageInfoArrayPtr[index]) = *pImageInfo; AllImage.uImageCount++; return TRUE; } else return FALSE; } //------------------------------------------------------------- // AllImage_Delete() // // Parameters: // deleteIndex index of image to delete // // Description: // Deletes a single image name and settings from the AllImage global structure // ----------------------------------------------------------- void AllImage_Delete(int deleteIndex) { int i; free(AllImage.ImageInfoArrayPtr[deleteIndex]); AllImage.uImageCount--; for (i=deleteIndex; iImagePaintInfo; } pEfxPaintTransitionDef AllImage_GetTrans(int index) { return &AllImage.ImageInfoArrayPtr[index]->ImagePaintTransition; } pEfxDrawTextDef AllImage_GetText(int index) { return &AllImage.ImageInfoArrayPtr[index]->ImageDrawText; } PLOGFONT AllImage_GetFont(int index) { return &AllImage.ImageInfoArrayPtr[index]->ImageLogFont; } L_TCHAR *AllImage_GetName(int index) { return AllImage.ImageInfoArrayPtr[index]->lpzImageName; } //------------------------------------------------------------- // AllImage_GetCount() // AllImage_SetCount() // // Parameters: // // Description: // Gets or sets the counter that identifies the number of images // in the global AllImage structure //------------------------------------------------------------- int AllImage_GetCount() { return AllImage.uImageCount; } void AllImage_SetCount(int count) { AllImage.uImageCount = count; } //------------------------------------------------------------- // AllImage_Swap() // // Parameters: // index1: index of first image to swap // index2: index of second image to swap // // Description: // Swaps two images in the global AllImage structure //------------------------------------------------------------- void AllImage_Swap(int index1, int index2) { pOneImageInfoDef pTemp; pTemp = AllImage.ImageInfoArrayPtr[index1]; AllImage.ImageInfoArrayPtr[index1] = AllImage.ImageInfoArrayPtr[index2]; AllImage.ImageInfoArrayPtr[index2] = pTemp; } //------------------------------------------------------------- // UpdateMainDlgButtons() // // Parameters: // hDlg: handle to dialog // // Description: // Enables or disables all of the buttons on the Main Dialog //------------------------------------------------------------- void UpdateMainDlgButtons(HWND hDlg) { int iCount, iIndex; // enable and disable buttons iCount = AllImage_GetCount(); iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); //returns -1 initially EnableWindow(GetDlgItem(hDlg,IDC_IMGLIST), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_DOWN), (iIndex != iCount -1) && (iIndex >= 0) ); EnableWindow(GetDlgItem(hDlg,IDC_UP), iIndex > 0 ); EnableWindow(GetDlgItem(hDlg,IDC_REMOV),iCount > 0); EnableWindow(GetDlgItem(hDlg,IDC_ADD), iCount < MAX_IMAGES); EnableWindow(GetDlgItem(hDlg,IDC_IMGLIST),TRUE); EnableWindow(GetDlgItem(hDlg,IDC_TEST),iCount > 0); } //------------------------------------------------------------- // UpdatePaintEfxDlgButtons() // // Parameters: // hDlg: handle to dialog // // Description: // Enables or disables all of the controls on the Paint Effects // settings dialog //------------------------------------------------------------- int UpdatePaintEfxDlgButtons(HWND hDlg) { int iCount; // enable and disable buttons iCount = AllImage_GetCount(); if (iCount > 0) { ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); OneImageToPaintDlg(hDlg); } EnableWindow(GetDlgItem(hDlg,IDC_IMGLIST), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_NUMPASS), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_DELAYPE), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_TCLR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_CHECK_TRANS), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_WNSIZE), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_WNCLR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_GRCLR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_CHECK_FULLSCREEN), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_EFFECT1), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_EFFECT2), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_EFFECT3), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_EFFECT4), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_EFFECT5), (iCount > 0) ); return iCount; } //------------------------------------------------------------- // UpdateTransDlgButtons() // // Parameters: // hDlg: handle to dialog // // Description: // Enables or disables all of the controls on the Transition Effects // settings dialog //------------------------------------------------------------- int UpdateTransDlgButtons(HWND hDlg) { int iCount; iCount = AllImage_GetCount(); if (iCount > 0) { ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); OneImageToTransDlg(hDlg); } EnableWindow(GetDlgItem(hDlg,IDC_IMGLIST), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_PREVIEW), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_EFFSTYL), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_FILLSTYL), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_DELAYTR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_WANDSIZE), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_FORECOLOR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_GRAIN), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_WANDCOLOR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_BACKCOLOR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_CHECK_ERSBCK), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_GRSTEPS), (iCount > 0) ); return iCount; } //------------------------------------------------------------- // UpdateTextDlgButtons() // // Parameters: // hDlg: handle to dialog // // Description: // Enables or disables all of the controls on the Text // settings dialog //------------------------------------------------------------- int UpdateTextDlgButtons(HWND hDlg) { int iCount; iCount = AllImage_GetCount(); if (iCount > 0) { ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); OneImageToTextDlg(hDlg); } EnableWindow(GetDlgItem(hDlg,IDC_IMGLIST), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_PREVIEW), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_TEXT), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_TXTSTYL), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_TEXTCLR1), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_BORDERCLR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_DELAYPE), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_STATIC), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_SHADCLR), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_TXTANGL), (iCount > 0) ); EnableWindow(GetDlgItem(hDlg,IDC_FONTTYPE), (iCount > 0) ); return iCount; } //------------------------------------------------------------- // DisableMainDlgButtons() // // Parameters: // // Description: // Disable other controls when you begin preview //------------------------------------------------------------- void DisableMainDlgButtons(HWND hDlg) { EnableWindow(GetDlgItem(hDlg,IDC_DOWN),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_UP),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_REMOV),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_ADD),FALSE); EnableWindow(GetDlgItem(hDlg,IDC_IMGLIST),FALSE); } //DisableMainDlgButtons //------------------------------------------------------------- // DrawWithEffect() // // Parameters: // hWnd: handle to window // pDestRect: RECT structure corresponding to paint surface // pBitmapHandle: pointer to LEAD bitmap // pEfxPaintInfo: pointer to Paint Effects structure // iPass: pass number of effect // AbortCallback: callback function used to abort effect when user stops screen saver // // Description: // Paints the image with an effect. Used for screen saver, and preview. // // Return Value: // ERROR_USER_ABORT--user causes transition to abort // SUCCESS --transition completes //------------------------------------------------------------- L_INT DrawWithEffect( HWND hWnd, PRECT pDestRect, pBITMAPHANDLE pBitmapHandle, pEfxPaintInfoDef pEfxPaintInfo, L_INT iPass, STATUSCALLBACK AbortCallback) { HDC hdc; // Device context for current window HPALETTE hOldPalette = NULL; // Temporary copy of current system palette HPALETTE hNewPalette = NULL; // Palette used to paint L_INT iRet; STATUSCALLBACK lpfnOldStatusCB; // Pointer to previous STATUSCALLBACK function L_VOID L_FAR* pOldStatusCBData; L_UINT uEffect; hdc = GetDC (hWnd); hNewPalette = L_CreatePaintPalette ( hdc, pBitmapHandle ); if(hNewPalette !=NULL) { hOldPalette = SelectPalette (hdc, hNewPalette, FALSE); RealizePalette (hdc); } lpfnOldStatusCB = L_GetStatusCallBack(&pOldStatusCBData); L_SetStatusCallBack(AbortCallback, NULL,NULL,NULL); uEffect = EffectStyle[pEfxPaintInfo->uEffect[iPass % MAXTRANSITIONS]].iEffectIndex; iRet = L_EfxPaintBitmap ( hdc, // device context pBitmapHandle, // bitmap to paint NULL, // source rectangle NULL, // source clip rectangle pDestRect, // destination rectangle NULL, // display destination clipping rectangle uEffect, // transition effect pEfxPaintInfo->uGrain, // graining size pEfxPaintInfo->uDelay, // delay between graining steps 0, 0, iPass+1, // step number for the pattern brush pEfxPaintInfo->uMaxPass, // maximum steps for the pattern brush pEfxPaintInfo->fTransparency, // transparency flag pEfxPaintInfo->crTransparency, // transparency color pEfxPaintInfo->uWandWidth, // wand width pEfxPaintInfo->crWand, // wand color SRCCOPY ); // Windows raster operation code L_SetStatusCallBack (lpfnOldStatusCB, pOldStatusCBData,NULL,NULL); // Restore the previous STATUSCALLBACK function if ( hNewPalette ) { SelectPalette (hdc, hOldPalette, FALSE); DeleteObject (hNewPalette); } ReleaseDC ( hWnd, hdc ); return iRet; }//function DrawWithEffect //------------------------------------------------------------- // DrawTransition() // // Parameters: // hWnd: handle to window // pDestRect: RECT structure corresponding to paint surface // pTrans : pointer to Transition Effects structure // iPass: pass number of effect // AbortCallback: callback function used to abort effect when user stops screen saver // // Description: // Paints the transition with an effect. Used for screen saver, and preview. // // Return Value: // ERROR_USER_ABORT--user causes transition to abort // SUCCESS --transition completes //------------------------------------------------------------- L_INT DrawTransition( HWND hWnd, RECT *pDestRect, pEfxPaintTransitionDef pTrans, STATUSCALLBACK AbortCallback) { L_INT iRetval; HDC hdc; STATUSCALLBACK lpfnOldStatusCB; L_VOID L_FAR* pOldStatusCBData; hdc = GetDC (hWnd); lpfnOldStatusCB = L_GetStatusCallBack(&pOldStatusCBData); L_SetStatusCallBack(AbortCallback, NULL,NULL,NULL); iRetval= L_EfxPaintTransition ( hdc, // device context FillStyle[pTrans->uTransition[0]].iFillIndex, // transition effect to paint EFX_TRANS_SOLID pTrans->crBack, // background color, red pTrans->crFore, // foreground color, blue pTrans->uSteps, // gradient color steps pDestRect, // destination rectangle EffectStyle[ pTrans->uEffect].iEffectIndex, // effect to apply when painting the transition pTrans->uGrain, // graining size pTrans->uDelay, // delay between graining steps 0, 0, 1, // step number for the pattern brush 1, // maximum steps for the pattern brush FALSE, // do not use transparency 0, // no transparent color pTrans->uWandWidth, // wand width pTrans->crWand, // wand color SRCCOPY ); // Windows raster operation code //EFX_TRANS_GRADIENT_CONE_MAX L_SetStatusCallBack (lpfnOldStatusCB, pOldStatusCBData,NULL,NULL); // Restore the previous STATUSCALLBACK function ReleaseDC ( hWnd, hdc ); return iRetval; } //function DrawTransition //------------------------------------------------------------- // DrawYourText() // // Parameters: // hWnd: handle to window // pDestRect: RECT structure corresponding to paint surface // pText : pointer to Text structure // pFont: pointer to FONT structure // bIsPreview: boolean value indicating if preview or actual screen saver // // Description: // Paints the transition with an effect. Used for screen saver, and preview. //------------------------------------------------------------- L_VOID DrawYourText( HWND hWnd, RECT *pDestRect,const pEfxDrawTextDef pText, PLOGFONT pFont, BOOL bIsPreview) { HDC hdc; HFONT hFont; LOGFONT lftemp; RECT rect; if (lstrcmp(pText->cText,TEXT(""))==0) return; rect = *pDestRect; hdc = GetDC (hWnd); memcpy(&lftemp, pFont,sizeof(*pFont)); if (bIsPreview) // || (pDestRect->right - pDestRect->left < 300) ) { int heightFactor; int widthFactor; RECT screenRect; GetClientRect(hWnd,&screenRect); heightFactor = (screenRect.bottom - screenRect.top)/(pDestRect->bottom - pDestRect->top); widthFactor = (screenRect.right - screenRect.left)/(pDestRect->right - pDestRect->left); lftemp.lfHeight=logfont.lfHeight/heightFactor ; //5 lftemp.lfWidth =logfont.lfWidth /widthFactor ; //5 //SetRect(&rect,pDestRect->left,pDestRect->top,pDestRect->right,pDestRect->bottom); } hFont=CreateFontIndirect(&lftemp); // paint the required Text L_EfxDrawRotated3dText ( hdc, //Device context (LPTSTR)pText->cText, //Text to draw &rect, //destination rectangle pText->nAngle, //Rotation Angle pText->uFlags | //style flags for 3D text EFX_TEXT_HCENTER | EFX_TEXT_VCENTER | EFX_TEXT_WORDWRAP, 2, //horizontal shadow position 2, //vertical shadow position pText->crText, //text color pText->crShadow, //shadow color pText->crHilite, //border color hFont, //Font used NULL); //No image DeleteObject(hFont); ReleaseDC ( hWnd, hdc ); Sleep(pText->uDelay); return; } //function DrawYourText //------------------------------------------------------------- // CreateMyPropSheet() // // Parameters: // hWnd: handle to window where the property sheet will be created // hInstance: handle to an instance // DlgProc[4]: array of 4 dialog procedures each of which corresponds to a page // // Description: // Used to create a property sheet with 4 pages for configuring the screen saver //------------------------------------------------------------- L_VOID CreateMyPropSheet(HWND hwnd,HINSTANCE hInstance ,DLGPROC DlgProc[]) { PROPSHEETPAGE PropPage[MAXPAGES]; PROPSHEETHEADER PropSHeader; int i; PropPage[0].pszTemplate =TEXT("IDD_MAIN") ; PropPage[0].pszTitle = TEXT("Main Settings"); PropPage[1].pszTemplate = TEXT("IDD_PAINTEFX"); PropPage[1].pszTitle = TEXT("Paint Effect"); PropPage[2].pszTemplate =TEXT("IDD_TRANS1") ; PropPage[2].pszTitle = TEXT("Transition Effect"); PropPage[3].pszTemplate = TEXT("IDD_TEXT"); PropPage[3].pszTitle = TEXT("Text"); for (i=0; ilStructSize = sizeof (CHOOSECOLOR) ; pChooseClr->hwndOwner = hwnd ; pChooseClr->hInstance = NULL ; pChooseClr->rgbResult = pChooseClr->rgbResult; pChooseClr->lpCustColors = crCustColors ; pChooseClr->Flags = CC_RGBINIT | CC_FULLOPEN ; pChooseClr->lCustData = 0L ; pChooseClr->lpfnHook = NULL ; pChooseClr->lpTemplateName = NULL ; bRet= ChooseColor (pChooseClr) ; return bRet; } //function ChooseAColor //------------------------------------------------------------- // OneImageInfoToRegistry() // // Parameters: // hKey: handle to main key in registry // pImageInfo: pointer to single image in AllImage global structure // uIndex: index of image settings to copy to registry. // to initialize the Color common dialog box. // Description: // Copies all settings for a single image to the registry // //------------------------------------------------------------- L_VOID OneImageInfoToRegistry (HKEY hKey, OneImageInfoDef *pImageInfo, L_UINT uIndex) { TCHAR ImageName[_MAX_FNAME]; HKEY hNewKey; pEfxPaintInfoDef pInfo; pEfxPaintTransitionDef pTrans; pEfxDrawTextDef pText; PLOGFONT pFont; pInfo = AllImage_GetPaintInfo(uIndex); pTrans = AllImage_GetTrans(uIndex); pText = AllImage_GetText(uIndex); pFont = AllImage_GetFont(uIndex); wsprintf(ImageName, TEXT("Image%d"), uIndex); CreateKey(hKey, &hNewKey, ImageName); //Initialize ImageName AddStringValue(&hNewKey, TEXT("ImageName"), pImageInfo->lpzImageName); //Initialize Key for PaintInfo structure AddValue (&hNewKey ,TEXT("PaintInfo.uEffect[0]") ,pInfo->uEffect[0] ); AddValue (&hNewKey ,TEXT("PaintInfo.uEffect[1]") ,pInfo->uEffect[1] ); AddValue (&hNewKey ,TEXT("PaintInfo.uEffect[2]") ,pInfo->uEffect[2] ); AddValue (&hNewKey ,TEXT("PaintInfo.uEffect[3]") ,pInfo->uEffect[3] ); AddValue (&hNewKey ,TEXT("PaintInfo.uEffect[4]") ,pInfo->uEffect[4] ); AddValue (&hNewKey ,TEXT("PaintInfo.uGrain") ,pInfo->uGrain ); AddValue (&hNewKey ,TEXT("PaintInfo.uDelay") ,pInfo->uDelay ); AddValue (&hNewKey ,TEXT("PaintInfo.uWandWidth") ,pInfo->uWandWidth ); AddValue (&hNewKey ,TEXT("PaintInfo.uMaxPass") ,pInfo->uMaxPass ); AddValue (&hNewKey ,TEXT("PaintInfo.fTransparency") ,pInfo->fTransparency ); AddValue (&hNewKey ,TEXT("PaintInfo.fFullScreen") ,pInfo->fFullScreen ); AddValue (&hNewKey ,TEXT("PaintInfo.crTransparency") ,pInfo->crTransparency ); AddValue (&hNewKey ,TEXT("PaintInfo.crWand") ,pInfo->crWand ); //Initialize Key for EfxPaintTransition structure AddValue (&hNewKey ,TEXT("PaintTrans.uTransition") ,pTrans->uTransition[0] ); AddValue (&hNewKey ,TEXT("PaintTrans.crBack") ,pTrans->crBack ); AddValue (&hNewKey ,TEXT("PaintTrans.crFore") ,pTrans->crFore ); AddValue (&hNewKey ,TEXT("PaintTrans.uSteps") ,pTrans->uSteps ); AddValue (&hNewKey ,TEXT("PaintTrans.uEffect") ,pTrans->uEffect ); AddValue (&hNewKey ,TEXT("PaintTrans.uGrain") ,pTrans->uGrain ); AddValue (&hNewKey ,TEXT("PaintTrans.uDelay") ,pTrans->uDelay ); AddValue (&hNewKey ,TEXT("PaintTrans.fTransparency") ,pTrans->fTransparency ); AddValue (&hNewKey ,TEXT("PaintTrans.fFullScreen") ,pInfo->fFullScreen ); AddValue (&hNewKey ,TEXT("PaintTrans.fEraseBck") ,pTrans->fEraseBck ); AddValue (&hNewKey ,TEXT("PaintTrans.crTransparency") ,pTrans->crTransparency ); AddValue (&hNewKey ,TEXT("PaintTrans.uWandWidth") ,pTrans->uWandWidth ); AddValue (&hNewKey ,TEXT("PaintTrans.crWand") ,pTrans->crWand ); //Initialize Key For DrawText. AddValue (&hNewKey ,TEXT("DrawText.crText") ,pText->crText); AddValue (&hNewKey ,TEXT("DrawText.crFore") ,pText->crFore); AddValue (&hNewKey ,TEXT("DrawText.crShadow") ,pText->crShadow ); AddValue (&hNewKey ,TEXT("DrawText.crHilite") ,pText->crHilite ); AddStringValue (&hNewKey ,TEXT("DrawText.cText") ,pText->cText ); AddValue (&hNewKey ,TEXT("DrawText.nAngle") ,pText->nAngle ); AddValue (&hNewKey ,TEXT("DrawText.uFlags") ,pText->uFlags ); AddValue (&hNewKey ,TEXT("DrawText.uDelay") ,pText->uDelay ); //Initialize Key For logfont structure AddValue (&hNewKey ,TEXT("logfont.lfWidth") ,pFont->lfWidth ); AddValue (&hNewKey ,TEXT("logfont.lfHeight") ,pFont->lfHeight ); AddValue (&hNewKey ,TEXT("logfont.lfWeight") ,pFont->lfWeight ); AddValue (&hNewKey ,TEXT("logfont.lfItalic") ,pFont->lfItalic ); AddValue (&hNewKey ,TEXT("logfont.lfUnderline"),pFont->lfUnderline); AddValue (&hNewKey ,TEXT("logfont.lfStrikeOut"),pFont->lfStrikeOut); //added below AddValue (&hNewKey ,TEXT("logfont.lfEscapement"),pFont->lfEscapement); AddValue (&hNewKey ,TEXT("logfont.lfOrientation"),pFont->lfOrientation); AddValue (&hNewKey ,TEXT("logfont.lfCharSet"),pFont->lfCharSet); AddValue (&hNewKey ,TEXT("logfont.lfOutPrecision"),pFont->lfOutPrecision); AddValue (&hNewKey ,TEXT("logfont.lfClipPrecision"),pFont->lfClipPrecision); AddValue (&hNewKey ,TEXT("logfont.lfQuality"),pFont->lfQuality); AddValue (&hNewKey ,TEXT("logfont.lfPitchAndFamily"),pFont->lfPitchAndFamily); AddStringValue (&hNewKey ,TEXT("logfont.lfFaceName") ,pFont->lfFaceName ); RegCloseKey(hNewKey); } //------------------------------------------------------------- // AllImageToRegistry() // // Parameters: // hKey: handle to main key in registry // to initialize the Color common dialog box. // Description: // Copies all settings for ALL images to the registry // //------------------------------------------------------------- L_VOID AllImageToRegistry (HKEY hKey) { int i; int iCount; int iExists; TCHAR ImageName[_MAX_FNAME]; iCount = AllImage_GetCount(); AddValue(&hKey ,TEXT("ImageCount"), iCount); // add number of images to key for (i=0; iright - pDisplayRect->left; lScreenHeight = pDisplayRect->bottom - pDisplayRect->top; if (lBitmapWidth * lScreenHeight > lBitmapHeight * lScreenWidth) { //make rect width equal to screen width pImageRect->left = pDisplayRect->left; pImageRect->right = pDisplayRect->left + lScreenWidth - 1; lRectHeight = lScreenWidth * lBitmapHeight / lBitmapWidth; pImageRect->top = pDisplayRect->top + (lScreenHeight - lRectHeight) / 2; pImageRect->bottom = pImageRect->top + lRectHeight; } else { //make rect height equal to screen height pImageRect->top = pDisplayRect->top; pImageRect->bottom = pDisplayRect->top + lScreenHeight - 1; lRectWidth = lScreenHeight * lBitmapWidth / lBitmapHeight; pImageRect->left = pDisplayRect->left + (lScreenWidth - lRectWidth) / 2; pImageRect->right = pImageRect->left + lRectWidth; } } //function RescaleRectFullScreen //------------------------------------------------------------- // DrawFrame() // // Parameters: // hWnd: handle to window to draw the single frame // lpDisplayRect: RECT structure for screen or preview // iImageIndex: index of AllImage structure image to display // iPass: pass number // AbortCallback: callback function used to abort effect when user stops screen saver // // Description: // Draws a single frame, including erasing background, drawing transition, and painting // a single pass. // // Returns: // SUCCESS --transition completes // ERROR_FILE_FORMAT --image was not valid--aborted // ERROR_USER_ABORT --user hit key or touched mouse to end screen saver //------------------------------------------------------------- L_INT DrawFrame(HWND hWnd, BOOL bIsPreview, LPRECT lpDisplayRect, int iImageIndex, int iPass, STATUSCALLBACK AbortCallback) { BITMAPHANDLE myBitmap; static RECT imageRect; //,rectScreen; static int x,y; BOOL bBitmapLoaded; HDC hdc; int iRet; pEfxPaintInfoDef pInfo; pEfxPaintTransitionDef pTrans; pEfxDrawTextDef pText; PLOGFONT pFont; int iBitmapWidth, iBitmapHeight, iDisplayWidth, iDisplayHeight; pInfo = AllImage_GetPaintInfo(iImageIndex); pTrans = AllImage_GetTrans(iImageIndex); pText = AllImage_GetText(iImageIndex); pFont = AllImage_GetFont(iImageIndex); //GetClientRect(hWnd,&rectScreen); //1. Get bitmapWidth, bitmapHeight //2. get destWidth, destHeight //3. if FullScreen then rescale imageRect to lpDisplayRect //4. if FullScreen, rescale bitmap to (destWidth, destHeight) coordinates // else if preview // Full Normal //------------------------------------------------------------------------ // //preview rescale imageRect rescale imageRect // to lpDisplayRect to 1/5 lpDisplayRect // //------------------------------------------------------------------------ // //real deal rescale imageRect nothing // to lpDisplayRect // //------------------------------------------------------------------------ bBitmapLoaded = L_LoadBitmap(AllImage_GetName(iImageIndex), &myBitmap, sizeof(BITMAPHANDLE),0, ORDER_BGR, NULL, NULL); if (bBitmapLoaded != SUCCESS) return ERROR_FILE_FORMAT; if(iPass==0) { iBitmapWidth = myBitmap.Width; iBitmapHeight = myBitmap.Height; iDisplayWidth = lpDisplayRect->right - lpDisplayRect->left; iDisplayHeight = lpDisplayRect->bottom - lpDisplayRect->top; if (pInfo->fFullScreen) { RescaleRectFullScreen(iBitmapWidth, iBitmapHeight, &imageRect, lpDisplayRect); } else //not full screen { if (bIsPreview) //if (lpDisplayRect->right - lpDisplayRect->left < 300) { //iBitmapWidth = (iBitmapWidth * lpDisplayRect->width) / fullscreen.width iBitmapWidth = iBitmapWidth / 5; iBitmapHeight = iBitmapHeight / 5; //Here is where you really need to shrink pImageRect by 1/5 RescaleRectFullScreen(iBitmapWidth, iBitmapHeight, &imageRect, lpDisplayRect); } //choose random location if( (iDisplayWidth <= iBitmapWidth) || (iDisplayHeight <= iBitmapHeight) ) { RescaleRectFullScreen(iBitmapWidth, iBitmapHeight, &imageRect, lpDisplayRect); } else { x = rand() % (iDisplayWidth - iBitmapWidth); y = rand() % (iDisplayHeight - iBitmapHeight); SetRect( &imageRect, lpDisplayRect->left + x, lpDisplayRect->top + y, lpDisplayRect->left + x + iBitmapWidth, lpDisplayRect->top + y + iBitmapHeight); } } //erase background if(pTrans->fEraseBck) { hdc=GetDC(hWnd); SelectObject(hdc,GetStockObject(BLACK_BRUSH)); Rectangle( hdc, lpDisplayRect->left, lpDisplayRect->top, lpDisplayRect->right, lpDisplayRect->bottom); ReleaseDC(hWnd,hdc); } //draw transition if(pTrans->uEffect != 0) { iRet = DrawTransition(hWnd,&imageRect /*lpDisplayRect*/,pTrans, AbortCallback); if (iRet == ERROR_USER_ABORT) return ERROR_USER_ABORT; } } iRet = DrawWithEffect( hWnd, &imageRect, &myBitmap , pInfo, iPass, AbortCallback ); if (iRet == ERROR_USER_ABORT) return ERROR_USER_ABORT; if (iPass== (int)pInfo->uMaxPass - 1) DrawYourText( hWnd, &imageRect,pText, pFont, bIsPreview); if(myBitmap.Flags.Allocated) L_FreeBitmap(&myBitmap); return SUCCESS; }// function DrawFrame //------------------------------------------------------------- // OneImageInfoDefault() // // Parameters: // pImageInfo: pointer to a single image info structure // lpzFileName: file name of image // // Description: // Fills a single image structure with random default values. // Used to specify initial values when user adds image to list. // //------------------------------------------------------------- L_VOID OneImageInfoDefault(OneImageInfoDef *pImageInfo, TCHAR *lpzFileName) { lstrcpy(pImageInfo->lpzImageName , lpzFileName); //Initialize ImagePaintInfo structure pImageInfo->ImagePaintInfo.uEffect[0] = rand() % EFFECT_COUNT; pImageInfo->ImagePaintInfo.uEffect[1] = rand() % EFFECT_COUNT; pImageInfo->ImagePaintInfo.uEffect[2] = rand() % EFFECT_COUNT; pImageInfo->ImagePaintInfo.uEffect[3] = rand() % EFFECT_COUNT; pImageInfo->ImagePaintInfo.uEffect[4] = rand() % EFFECT_COUNT; pImageInfo->ImagePaintInfo.uGrain = 30; pImageInfo->ImagePaintInfo.uDelay = 5; pImageInfo->ImagePaintInfo.uWandWidth = 20; pImageInfo->ImagePaintInfo.uMaxPass = 1; //(rand() % MAXTRANSITIONS) + 1 pImageInfo->ImagePaintInfo.fTransparency = FALSE; pImageInfo->ImagePaintInfo.fFullScreen = FALSE; pImageInfo->ImagePaintInfo.crTransparency = RGB(255,0,0); pImageInfo->ImagePaintInfo.crWand = RGB(255,0,0); //Initalize ImagePaintTransition structure pImageInfo->ImagePaintTransition.uTransition[0]=rand() % TRANSITION_COUNT; pImageInfo->ImagePaintTransition.crBack =RGB(rand()%255, rand()%255 ,rand()%255); pImageInfo->ImagePaintTransition.crFore =RGB(rand()%255, rand()%255 ,rand()%255); pImageInfo->ImagePaintTransition.uSteps =2; //valid: 2-255 pImageInfo->ImagePaintTransition.uEffect =rand() % EFFECT_COUNT; pImageInfo->ImagePaintTransition.uGrain =30; pImageInfo->ImagePaintTransition.uDelay =5; pImageInfo->ImagePaintTransition.fTransparency =FALSE ; pImageInfo->ImagePaintTransition.fFullScreen = FALSE; pImageInfo->ImagePaintTransition.fEraseBck =FALSE; pImageInfo->ImagePaintTransition.crTransparency=0; pImageInfo->ImagePaintTransition.uWandWidth =20; pImageInfo->ImagePaintTransition.crWand =RGB(rand()%255, rand()%255 ,rand()%255); //Initialize ImageDrawText structure lstrcpy(pImageInfo->ImageDrawText.cText, TEXT("LEAD Tools")); pImageInfo->ImageDrawText.crText =RGB(rand()%255, rand()%255 ,rand()%255); pImageInfo->ImageDrawText.crShadow =RGB(rand()%255, rand()%255 ,rand()%255); pImageInfo->ImageDrawText.crHilite =RGB(rand()%255, rand()%255 ,rand()%255); pImageInfo->ImageDrawText.nAngle =0 ; pImageInfo->ImageDrawText.uFlags =EFX_TEXT_NORMAL; pImageInfo->ImageDrawText.uDelay =2000; //2 seconds //Initialize logfont structure pImageInfo->ImageLogFont.lfHeight =26; pImageInfo->ImageLogFont.lfWidth =26; pImageInfo->ImageLogFont.lfEscapement =0; pImageInfo->ImageLogFont.lfOrientation =0; pImageInfo->ImageLogFont.lfWeight =FW_BOLD; pImageInfo->ImageLogFont.lfItalic =FALSE; pImageInfo->ImageLogFont.lfUnderline =FALSE; pImageInfo->ImageLogFont.lfStrikeOut =FALSE; pImageInfo->ImageLogFont.lfCharSet =DEFAULT_CHARSET; pImageInfo->ImageLogFont.lfOutPrecision =OUT_DEFAULT_PRECIS; pImageInfo->ImageLogFont.lfClipPrecision =CLIP_DEFAULT_PRECIS; pImageInfo->ImageLogFont.lfQuality =PROOF_QUALITY; pImageInfo->ImageLogFont.lfPitchAndFamily =DEFAULT_PITCH; lstrcpy(pImageInfo->ImageLogFont.lfFaceName,TEXT("Times New Roman")); } //InitializeImageInfo //------------------------------------------------------------- // RegistryToOneImage() // // Parameters: // hKey: handle to main key // pImageInfo: pointer to a single image info structure // index: index of image that receives registry information // // Description: // Copies registry information for a single image into the ImageInfo structure //------------------------------------------------------------- L_VOID RegistryToOneImage(HKEY hKey, OneImageInfoDef *pImageInfo, int index) { DWORD dwValue; L_TCHAR szBufferIt[_MAX_FNAME]; L_TCHAR szFontBuf[_MAX_FNAME]; L_TCHAR ImageName[_MAX_FNAME]; HKEY hNewKey; wsprintf(ImageName, TEXT("Image%d"), index); CreateKey (hKey, &hNewKey, ImageName ); //bombs here ReadStringValue(&hNewKey, TEXT("ImageName"), pImageInfo->lpzImageName); //Fill ImagePaintInfo structure with values from registry ReadValue (&hNewKey ,TEXT("PaintInfo.uEffect[0]"),&dwValue); pImageInfo->ImagePaintInfo.uEffect[0] = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uEffect[1]"),&dwValue); pImageInfo->ImagePaintInfo.uEffect[1] = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uEffect[2]"), &dwValue); pImageInfo->ImagePaintInfo.uEffect[2] = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uEffect[3]"),&dwValue); pImageInfo->ImagePaintInfo.uEffect[3] = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uEffect[4]"),&dwValue); pImageInfo->ImagePaintInfo.uEffect[4] = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uGrain"),&dwValue); pImageInfo->ImagePaintInfo.uGrain = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uDelay"), &dwValue) ; pImageInfo->ImagePaintInfo.uDelay = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uMaxPass"), &dwValue); pImageInfo->ImagePaintInfo.uMaxPass = dwValue ; ReadValue (&hNewKey ,TEXT("PaintInfo.fTransparency"),&dwValue); pImageInfo->ImagePaintInfo.fTransparency = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.fFullScreen"),&dwValue); pImageInfo->ImagePaintInfo.fFullScreen = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.crTransparency"),&dwValue); pImageInfo->ImagePaintInfo.crTransparency = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.uWandWidth"),& dwValue); pImageInfo->ImagePaintInfo.uWandWidth = dwValue; ReadValue (&hNewKey ,TEXT("PaintInfo.crWand"),&dwValue); pImageInfo->ImagePaintInfo.crWand = dwValue; //Fill ImagePaintTransition structure with values from registry ReadValue (&hNewKey ,TEXT("PaintTrans.uTransition"),&dwValue); pImageInfo->ImagePaintTransition.uTransition[0] = dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.crBack"),&dwValue); pImageInfo->ImagePaintTransition.crBack =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.crFore"), &dwValue); pImageInfo->ImagePaintTransition.crFore =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.uSteps"), &dwValue); pImageInfo->ImagePaintTransition.uSteps =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.uEffect"),&dwValue); pImageInfo->ImagePaintTransition.uEffect =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.uGrain"), &dwValue); pImageInfo->ImagePaintTransition.uGrain =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.uDelay"), &dwValue); pImageInfo->ImagePaintTransition.uDelay =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.fTransparency"),& dwValue); pImageInfo->ImagePaintTransition.fTransparency =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.fFullScreen"),& dwValue); pImageInfo->ImagePaintTransition.fFullScreen =dwValue; //must add uMaxPass ReadValue (&hNewKey ,TEXT("PaintTrans.fEraseBck"),& dwValue); pImageInfo->ImagePaintTransition.fEraseBck =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.crTransparency"),& dwValue); pImageInfo->ImagePaintTransition.crTransparency=dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.uWandWidth"),& dwValue); pImageInfo->ImagePaintTransition.uWandWidth =dwValue; ReadValue (&hNewKey ,TEXT("PaintTrans.crWand"), &dwValue); pImageInfo->ImagePaintTransition.crWand =dwValue; //Fill EfxDrawText structure with values from registry ReadStringValue (&hNewKey ,TEXT("DrawText.cText"),szBufferIt); lstrcpy(pImageInfo->ImageDrawText.cText,szBufferIt); ReadValue (&hNewKey ,TEXT("DrawText.crText"), &dwValue); pImageInfo->ImageDrawText.crText=dwValue; ReadValue (&hNewKey ,TEXT("DrawText.crFore"), &dwValue); pImageInfo->ImageDrawText.crFore=dwValue; ReadValue (&hNewKey ,TEXT("DrawText.crShadow"), &dwValue); pImageInfo->ImageDrawText.crShadow =dwValue; ReadValue (&hNewKey ,TEXT("DrawText.crHilite"),&dwValue); pImageInfo->ImageDrawText.crHilite =dwValue; ReadValue (&hNewKey ,TEXT("DrawText.nAngle"),&dwValue); pImageInfo->ImageDrawText.nAngle =dwValue; ReadValue (&hNewKey ,TEXT("DrawText.uFlags"),&dwValue); pImageInfo->ImageDrawText.uFlags =dwValue; ReadValue (&hNewKey ,TEXT("DrawText.uDelay"),&dwValue); pImageInfo->ImageDrawText.uDelay =dwValue; //Fill logfont structure with values from registry ReadValue (&hNewKey ,TEXT("logfont.lfWidth"), &dwValue); pImageInfo->ImageLogFont.lfWidth=dwValue ; ReadValue (&hNewKey ,TEXT("logfont.lfHeight"), &dwValue); pImageInfo->ImageLogFont.lfHeight=dwValue; ReadValue (&hNewKey ,TEXT("logfont.lfWeight"), &dwValue); pImageInfo->ImageLogFont.lfWeight=dwValue; ReadValue (&hNewKey ,TEXT("logfont.lfItalic"), &dwValue); pImageInfo->ImageLogFont.lfItalic=(BOOL)dwValue; ReadValue (&hNewKey ,TEXT("logfont.lfUnderline"), &dwValue); pImageInfo->ImageLogFont.lfUnderline=(BOOL)dwValue; ReadValue (&hNewKey ,TEXT("logfont.lfStrikeOut"), &dwValue); pImageInfo->ImageLogFont.lfStrikeOut=(BOOL)dwValue; //Added below ReadValue (&hNewKey ,TEXT("ImageLogFont.lfEscapement"), &dwValue); pImageInfo->ImageLogFont.lfEscapement=dwValue; ReadValue (&hNewKey ,TEXT("ImageLogFont.lfOrientation"), &dwValue); pImageInfo->ImageLogFont.lfOrientation=dwValue; ReadValue (&hNewKey ,TEXT("ImageLogFont.lfCharSet"), &dwValue); pImageInfo->ImageLogFont.lfCharSet= (BYTE)dwValue; ReadValue (&hNewKey ,TEXT("ImageLogFont.lfOutPrecision"), &dwValue); pImageInfo->ImageLogFont.lfOutPrecision=(BYTE)dwValue; ReadValue (&hNewKey ,TEXT("ImageLogFont.lfClipPrecision"), &dwValue); pImageInfo->ImageLogFont.lfClipPrecision=(BYTE)dwValue; ReadValue (&hNewKey ,TEXT("ImageLogFont.lfQuality"), &dwValue); pImageInfo->ImageLogFont.lfQuality=(BYTE)dwValue; ReadValue (&hNewKey ,TEXT("ImageLogFont.lfPitchAndFamily"), &dwValue); pImageInfo->ImageLogFont.lfPitchAndFamily=(BYTE)dwValue; //Added above ReadStringValue (&hNewKey ,TEXT("logfont.lfFaceName"),szFontBuf); lstrcpy(pImageInfo->ImageLogFont.lfFaceName,szFontBuf ); //MessageBox(NULL, "RegCloseKey2", "", MB_OK); RegCloseKey(*&hNewKey); } //function InitializeImageInfoFromKey //------------------------------------------------------------- // RegistryToAllImage() // // Parameters: // hKey: handle to main key // // Description: // Copies registry information for all images to AllImage global structure //------------------------------------------------------------- L_VOID RegistryToAllImage(HKEY hKey) { DWORD i; DWORD dwImageCount=0; OneImageInfoDef ImageInfo; AllImage_Init(); ReadValue (&hKey ,TEXT("ImageCount"), &dwImageCount); for (i=0; i < (int)dwImageCount; i++) { RegistryToOneImage( hKey, &ImageInfo,i); AllImage_Add(&ImageInfo); } } //------------------------------------------------------------- // PreviewThread() // // Parameters: // // Description: // Displays the screen saver in a preview window. //------------------------------------------------------------- L_VOID PreviewThread(PVOID pvoid) { unsigned long ulOldDisplay; pPREVIEW_PARAM previewParam; HDC hdc; pEfxPaintInfoDef pPaintInfo; int iImageIndex; int iRetVal, iPass, iCount; bThreadFlag =TRUE; ulOldDisplay =L_SetDisplayMode(DISPLAYMODE_FIXEDPALETTE, DISPLAYMODE_FIXEDPALETTE); //must reseed random number generator every time thread starts srand((int) GetCurrentTime() ); previewParam = (pPREVIEW_PARAM)pvoid; hdc=GetDC(previewParam->hDlg); //erase background SelectObject(hdc,GetStockObject(BLACK_BRUSH)); Rectangle( hdc, previewParam->rect.left, previewParam->rect.top, previewParam->rect.right, previewParam->rect.bottom); //hListBox=GetDlgItem(previewParam->hDlg,IDC_IMGLIST); iCount=AllImage_GetCount(); if (iCount > 0) { EnableWindow(GetDlgItem(previewParam->hDlg,IDC_STOP),TRUE); EnableWindow(GetDlgItem(previewParam->hDlg,IDC_TEST),FALSE); for (iImageIndex=0; (bThreadFlag); ) { pPaintInfo = AllImage_GetPaintInfo(iImageIndex); for (iPass = 0; iPass < (int)pPaintInfo->uMaxPass; iPass++) { iRetVal = DrawFrame(previewParam->hDlg, TRUE, &(previewParam->rect), iImageIndex, iPass, PreviewCallBack); if (iRetVal == ERROR_USER_ABORT) bThreadFlag = FALSE; } iImageIndex = (iImageIndex+1) % iCount; } } //bThreadFlag =FALSE; L_SetDisplayMode(DISPLAYMODE_RESETPOSITIONS , ulOldDisplay); UpdateMainDlgButtons(previewParam->hDlg); EnableWindow(GetDlgItem(previewParam->hDlg,IDC_STOP),FALSE); EnableWindow(GetDlgItem(previewParam->hDlg,IDC_TEST),TRUE); ReleaseDC(previewParam->hDlg,hdc); UpdatePreviewImage( previewParam->hDlg, &previewParam->rect); } //function PreviewThread //------------------------------------------------------------- // LChooseFont() // // Parameters: // hwnd: handle to the window on which will call the dialog // pText: pointer to structure storing FONT information // // Description: // Displays the font common dialog, returns information in LOGFONT structure, // and stores in EfxDrawTextDef structure. // // Returns: // TRUE if font selected // FALSE if cancelled //------------------------------------------------------------- BOOL LChooseFont(HWND hwnd, pEfxDrawTextDef pText, int iIndex) { CHOOSEFONT choosefont; BOOL bRetVal; choosefont.lStructSize = sizeof (CHOOSEFONT) ; choosefont.hwndOwner = hwnd ; choosefont.hDC = NULL ; choosefont.lpLogFont = AllImage_GetFont(iIndex); choosefont.rgbColors = pText->crText; //set the color for dialog box choosefont.iPointSize = 0 ; choosefont.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_EFFECTS ; //choosefont.rgbColors = RGB(255,0,0) ; choosefont.lCustData = 0L ; choosefont.lpfnHook = NULL ; choosefont.lpTemplateName = NULL ; choosefont.hInstance = NULL ; choosefont.lpszStyle = NULL ; choosefont.nFontType = 0 ; choosefont.nSizeMin = 0 ; choosefont.nSizeMax = 0 ; if (ChooseFont(&choosefont)) { pText->crText=choosefont.rgbColors; InvalidateRect( GetDlgItem(hwnd,IDC_TEXTCLR1),NULL,TRUE); bRetVal = TRUE; } else bRetVal = FALSE; return bRetVal; } //LChooseFont //------------------------------------------------------------- // StatusCallback() // // Parameters: // nPercent: Value from 1 to 100 indicating percent complete // // Description: // a callback function which is used to end screen saver effects // // Returns: // ERROR_USER_ABORT // SUCCESS //------------------------------------------------------------- // : L_INT L_EXPORT EXT_CALLBACK EfxCallBack (L_INT nPercent, L_VOID L_FAR*pUserData) { MSG msg; BOOL bRet; bRet = PeekMessage (&msg, NULL,WM_MOUSEFIRST , WM_MOUSELAST, PM_NOREMOVE); if(bRet) { DefScreenSaverProc(hWndScr,msg.message, msg.wParam, msg.lParam); return (ERROR_USER_ABORT); } bRet = PeekMessage (&msg, NULL, WM_KEYFIRST , WM_KEYLAST , PM_NOREMOVE); if(bRet) { DefScreenSaverProc(hWndScr,msg.message, msg.wParam, msg.lParam); return (ERROR_USER_ABORT); } return (SUCCESS); } //function StatusCallBack //------------------------------------------------------------- // PreviewCallBack() // // Parameters: // nPercent: Value from 1 to 100 indicating percent complete // // Description: // a callback function which is used to end the preview // // Returns: // ERROR_USER_ABORT // SUCCESS //------------------------------------------------------------- // PreviewCallBack : a callback function which is used to end the preview L_INT L_EXPORT EXT_CALLBACK PreviewCallBack (L_INT nPercent, L_VOID L_FAR*pUserData) { if (!bThreadFlag) return ERROR_USER_ABORT; return (SUCCESS); } //function PreviewCallBack //------------------------------------------------------------- // AllImageToListBox() // // Parameters: // hDlg handle to dialog // // Description: // Copies list of image names to the list box // ----------------------------------------------------------- void AllImageToListBox(HWND hDlg) { L_INT i,iCount; HWND hListBox; hListBox=GetDlgItem(hDlg,IDC_IMGLIST); // get the handle of the list of images iCount = AllImage_GetCount(); for(i=0;iuDelay,FALSE); SetDlgItemInt(hDlg,IDC_GRCLR, pInfo->uGrain,FALSE); SetDlgItemInt(hDlg,IDC_WNSIZE, pInfo->uWandWidth,FALSE); SetDlgItemInt(hDlg,IDC_NUMPASS, pInfo->uMaxPass,FALSE ); Button_SetCheck(GetDlgItem(hDlg,IDC_CHECK_TRANS), pInfo->fTransparency); Button_SetCheck(GetDlgItem(hDlg,IDC_CHECK_FULLSCREEN), pInfo->fFullScreen); RePaintButton(GetDlgItem(hDlg,IDC_TCLR), pInfo->crTransparency); RePaintButton(GetDlgItem(hDlg,IDC_WNCLR), pInfo->crWand); //Initialize combo boxes ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_EFFECT1), pInfo->uEffect[0] ); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_EFFECT2), pInfo->uEffect[1] ); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_EFFECT3), pInfo->uEffect[2] ); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_EFFECT4), pInfo->uEffect[3] ); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_EFFECT5), pInfo->uEffect[4] ); } ReleaseDC ( hDlg, hdc ); //Release the device context } //------------------------------------------------------------- // OneImageToTextDlg() // // Parameters: // hDlg handle to dialog // // Description: // Copies all data associated with a single image to the // Text Settings dialog box // ----------------------------------------------------------- void OneImageToTextDlg(HWND hDlg) { HDC hdc; HWND hListBox; int iIndex; pEfxDrawTextDef pInfo; hdc = GetDC (hDlg); hListBox=GetDlgItem(hDlg,IDC_IMGLIST); //take a handle to list box iIndex=ListBox_GetCurSel(hListBox); // get the currently selected cell if(iIndex != LB_ERR) { pInfo = AllImage_GetText(iIndex); SetDlgItemText(hDlg,IDC_TEXT,pInfo->cText); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_TXTSTYL), pInfo->uFlags ); SetDlgItemInt(hDlg,IDC_TXTANGL,pInfo->nAngle,FALSE ); RePaintButton(GetDlgItem(hDlg,IDC_TEXTCLR1), pInfo->crText); RePaintButton(GetDlgItem(hDlg,IDC_BORDERCLR), pInfo->crHilite); RePaintButton(GetDlgItem(hDlg,IDC_SHADCLR), pInfo->crShadow); SetDlgItemInt(hDlg,IDC_DELAYPE, pInfo->uDelay,FALSE); } ReleaseDC ( hDlg, hdc ); //Release the device context } //------------------------------------------------------------- // OneImageToTransDlg() // // Parameters: // hDlg handle to dialog // // Description: // Copies all data associated with a single image to the // Paint Transitions Settings dialog box // ----------------------------------------------------------- void OneImageToTransDlg(HWND hDlg) { HDC hdc; HWND hListBox; int iIndex; pEfxPaintTransitionDef pTrans; hdc = GetDC (hDlg); hListBox=GetDlgItem(hDlg,IDC_IMGLIST); //take a handle to list box iIndex=ListBox_GetCurSel(hListBox); // get the currently selected cell if(iIndex != LB_ERR) { pTrans = AllImage_GetTrans(iIndex); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_FILLSTYL), pTrans->uTransition[0]); ComboBox_SetCurSel(GetDlgItem(hDlg,IDC_EFFSTYL), pTrans->uEffect ); SetDlgItemInt(hDlg,IDC_DELAYTR,pTrans->uDelay,FALSE ); SetDlgItemInt(hDlg,IDC_WANDSIZE,pTrans->uWandWidth,FALSE ); SetDlgItemInt(hDlg,IDC_GRAIN,pTrans->uGrain ,FALSE ); SetDlgItemInt(hDlg,IDC_GRSTEPS, pTrans->uSteps,FALSE ); Button_SetCheck(GetDlgItem(hDlg,IDC_CHECK_ERSBCK), pTrans->fEraseBck ); RePaintButton(GetDlgItem(hDlg,IDC_FORECOLOR), pTrans->crFore); RePaintButton(GetDlgItem(hDlg,IDC_WANDCOLOR), pTrans->crWand); RePaintButton(GetDlgItem(hDlg,IDC_BACKCOLOR), pTrans->crBack); } ReleaseDC ( hDlg, hdc ); } //------------------------------------------------------------- // RegistryToListBox() // // Parameters: // hDlg handle to dialog // // Description: // Reads all the settings stored in the registry and transfers // them to the global "AllImage" structure // ----------------------------------------------------------- void RegistryToListBox(HWND hDlg) { RegistryToAllImage(HKEY_CURRENT_USER); AllImageToListBox(hDlg); bThreadFlag =FALSE ; } //------------------------------------------------------------- // UpdatePreviewImage() // // Parameters: // hDlg handle to dialog // pPreviewRect RECT structure that corresponds to preview // // Description: // Updates the image preview for the dialog hDlg // ----------------------------------------------------------- void UpdatePreviewImage(HWND hDlg, PRECT pPreviewRect) { HDC hdc; HPALETTE hNewPalette, hOldPalette; BITMAPHANDLE myBitmap; int iIndex; RECT imageRect; iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); if (iIndex >=0) { hdc = GetDC (hDlg); SelectObject(hdc,GetStockObject(GRAY_BRUSH /*BLACK_BRUSH*/ )); L_LoadBitmap (AllImage_GetName(iIndex),&myBitmap , sizeof(BITMAPHANDLE),0, ORDER_BGR, NULL, NULL); RescaleRectFullScreen(myBitmap.Width, myBitmap.Height, &imageRect, pPreviewRect); hNewPalette = L_CreatePaintPalette ( hdc, &myBitmap ); if(hNewPalette !=NULL) { hOldPalette = SelectPalette (hdc, hNewPalette, FALSE); RealizePalette (hdc); // Realize new palette } Rectangle( hdc, pPreviewRect->left, pPreviewRect->top, pPreviewRect->right, pPreviewRect->bottom); L_PaintDC (hdc, &myBitmap, NULL, NULL, &imageRect, NULL, SRCCOPY); if(myBitmap.Flags.Allocated) L_FreeBitmap(&myBitmap); if ( hNewPalette ) { SelectPalette (hdc, hOldPalette, FALSE); DeleteObject (hNewPalette); } ReleaseDC ( hDlg, hdc ); } } //------------------------------------------------------------- // GetTextPixelLength(hDC, pszText) // // Parameters: // hDC handle to device context // pszText pointer to string // // Description: // Updates the image preview for the dialog hDlg // ----------------------------------------------------------- L_INT GetTextPixelLength(HDC hDC, LPRECT lpRect, L_TCHAR *pszText) { L_INT nLen; nLen = 0; if (hDC != NULL) { nLen = DrawText( hDC, // handle to device context pszText, // pointer to string to draw lstrlen(pszText)-1, // string length, in characters lpRect, // pointer to structure with formatting dimensions DT_CALCRECT // text-drawing flags ); } return lpRect->right - lpRect->left; } //------------------------------------------------------------- // GetMaxTextLen(hWnd) // // Parameters: // hWnd handle to list box // // Description: // Returns length in pixels of longest file name in list box // ----------------------------------------------------------- L_INT GetMaxTextLen(HWND hWnd) { HDC hDC; L_INT nLen; L_INT nMax = 0; L_INT i; RECT rc, rcSave; GetClientRect(hWnd, &rcSave); hDC = GetDC(hWnd); for (i=0; ilpzImageName); if (nLen > nMax) nMax = nLen; } ReleaseDC(hWnd, hDC); return nMax; }