/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 10 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[] []*/ /*[] File scrnsvr.c []*/ /*[] []*/ /*[]=====================================================================[]*/ /*------------------------------------------------------------------------- We have made the assumption that the user has the knowledge of programming in C and Windows. This demo program demonstrates the use of the LEAD Paint Effects API functions to build a complete screen saver application. After compiling this demo, place the resulting file (lead.scr) in the windows (or winnt) folder. You can than configure the screen saver by going to Display->settings->screen saver, and choosing "LEAD" or "LEAD Screen Saver". The name of the screen saver appearing in control panel depends on your operating system. For more information on this inconsistency, please refer to the Microsoft Knowledge base Article ID: Q137250. For testing purposes, passing the /s option as a command line option will display the screen saver. No command line argument will display the screen saver configuration dialog box. Note: There are 2000+ paint effects and paint transitions. This screen saver is configured give the user the option of selecting around 100 of these. All 2000 effects are listed in the globals.h file, but most are commented out. To include additional effects, open the globals.h file and uncomment any effects you want to include. This screen saver is configured to allow the user to enter a maximum of MAX_IMAGES (25) in the configuration dialog box. Change this value and recompile to allow for more images. --------------------------------------------------------------------------*/ #include "all.h" #include "globals.h" #include "process.h" HANDLE hInst ; // Take a handle to current instance L_UINT wTimer = 0 ; // Timer id //----Protypes of Dialog Procedures used in PropertySheet- BOOL CALLBACK MainDlgProc (HWND, UINT, WPARAM, LPARAM) ; BOOL CALLBACK PaintEfxProc (HWND, UINT, WPARAM, LPARAM) ; BOOL CALLBACK TransProc (HWND, UINT, WPARAM, LPARAM) ; BOOL CALLBACK TextProc (HWND, UINT, WPARAM, LPARAM) ; #ifdef UNICODE static BOOL CALLBACK SetFontEnumProce ( HWND hWnd, LPARAM lParam ); void GenerateDefaultFont ( HFONT* phFont ) ; void SetControlFont ( HWND hWnd, HFONT hFont ) ; static HFONT ghDefFont = NULL ; #endif// UNICODE //------------------------------------------------------------- // RegisterDialogClasses() // // Parameters: // hInst Identifier of an instance of the module registering the window classes // // Description: // Registers any nonstandard window classes required by a screen saver's configuration dialog box. // ----------------------------------------------------------- BOOL WINAPI RegisterDialogClasses(HINSTANCE hInst) { return 1; } //------------------------------------------------------------- // ScreenSaverConfigureDialog() // // Parameters: // hWnd Identifier of the configuration dialog box. // Msg Message that was sent to the screen saver's configuration dialog box. // wParam Additional message-specific information. // lParam Additional message-specific information. // // Description: // Receives messages sent to a screen saver’s configuration dialog box // ----------------------------------------------------------- BOOL CALLBACK ScreenSaverConfigureDialog(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { L_INT iRetVal ; switch(Msg) { case WM_INITDIALOG : UNLOCKSUPPORT() ; // Filling the DlgProc Array DlgProc[0]= (DLGPROC) MainDlgProc; DlgProc[1]= (DLGPROC) PaintEfxProc; DlgProc[2]= (DLGPROC) TransProc; DlgProc[3]= (DLGPROC) TextProc; #ifdef UNICODE iRetVal=CreateKey (HKEY_CURRENT_USER, &hKey,TEXT("Control Panel\\Screen Saver.LEAD(Unicode)")); // Create a new Key #else iRetVal=CreateKey (HKEY_CURRENT_USER, &hKey,TEXT("Control Panel\\Screen Saver.LEAD")); // Create a new Key #endif // UNICODE //Create key if no exist if(iRetVal==REGCREATE_NEWKEY) AddValue(&hKey ,TEXT("ImageCount"), 0); RegistryToAllImage(hKey); CreateMyPropSheet(hWnd,hInst, DlgProc); EndDialog(hWnd, 42); #ifdef UNICODE GenerateDefaultFont ( &ghDefFont ) ; SetControlFont ( hWnd, ghDefFont ) ; #endif// UNICODE return FALSE; ///This was for "extra" dialog before Property Sheet case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: case IDCANCEL: EndDialog(hWnd, 42);// Exit from dialog break; case IDC_SETTINGS : CreateMyPropSheet(hWnd,hInst, DlgProc); // create a property sheet break ; } break; #ifdef UNICODE case WM_DESTROY: if ( NULL != ghDefFont ) { DeleteObject ( ghDefFont ) ; ghDefFont = NULL ; } break; #endif default: return FALSE;// End of WM_COMMAND case break; /****/ } return TRUE; // End of ScreenSaverConfigureDialog } //function ScreenSaverConfigureDialog //------------------------------------------------------------- // ScreenSaverProc() // // Parameters: // hWnd Identifier of the configuration dialog box. // Msg Message that was sent to the screen saver's configuration dialog box. // wParam Additional message-specific information. // lParam Additional message-specific information. // // Description: // Receives messages sent to the specified screen saver window. // ----------------------------------------------------------- LONG CALLBACK ScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { RECT rect; int iRetVal; static int iPass = 0; //pass number of a special effect static int iImageIndex = 0; static unsigned int uiOldDisplay; hWndScr=hWnd; switch (msg) { case WM_CREATE: UNLOCKSUPPORT(); iPass = 0; iImageIndex = 0; #ifdef UNICODE iRetVal=CreateKey (HKEY_CURRENT_USER, &hKey,TEXT("Control Panel\\Screen Saver.LEAD(Unicode)")); #else iRetVal=CreateKey (HKEY_CURRENT_USER, &hKey,TEXT("Control Panel\\Screen Saver.LEAD")); #endif // UNICODE //key created for the first time if(iRetVal==REGCREATE_NEWKEY) AddValue(&hKey ,TEXT("ImageCount"), 0); RegistryToAllImage(hKey); wTimer = SetTimer(hWnd, 0, 500, NULL); // set the timer uiOldDisplay =L_SetDisplayMode(DISPLAYMODE_FIXEDPALETTE, DISPLAYMODE_FIXEDPALETTE); break;// End of WM_CREATE case case WM_TIMER: { pEfxPaintInfoDef pInfo; if (AllImage_GetCount() ==0) { MessagePleaseInitialize(hWnd); return 0; } pInfo = AllImage_GetPaintInfo(iImageIndex); GetClientRect(hWnd,&rect); DrawFrame(hWnd, FALSE, &rect, iImageIndex, iPass, EfxCallBack); iPass++; if (iPass == (int)pInfo->uMaxPass) { iPass = 0; iImageIndex = (iImageIndex+1) % AllImage_GetCount(); } } return 0;// End of WM_TIMER case case WM_DESTROY: if (wTimer) KillTimer(hWnd, wTimer); // if timer has been created then destroy it RegCloseKey (hKey ); L_SetDisplayMode(DISPLAYMODE_RESETPOSITIONS , uiOldDisplay); break; } //default message handler for screen savers return DefScreenSaverProc(hWnd, msg, wParam, lParam); } // ScreenSaverProc //------------------------------------------------------------- // MainDlgProc() // // Parameters: // hWnd Identifier of the configuration dialog box. // Msg Message that was sent to the screen saver's configuration dialog box. // wParam Additional message-specific information. // lParam Additional message-specific information. // // Description: // Dialog procedure for main dialog of property sheet // ----------------------------------------------------------- BOOL CALLBACK MainDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) { L_INT code; HWND hwndFocus = (HWND) wParam; // handle of window receiving focus static BITMAPHANDLE myBitmap; // take a handle to a bitmap static RECT previewRect ; // preview rectangle HWND hListBox ; // take window handle to a list box static unsigned long hThread; HPALETTE hOldPalette = NULL; HPALETTE hNewPalette = NULL; static PREVIEW_PARAM previewParam; int iCount; int nMaxTextLen; switch(iMsg) { case WM_INITDIALOG : //MainDlgProc GetClientRect(GetDlgItem(hDlg,IDC_PREVIEW),&previewRect); MapWindowPoints(GetDlgItem(hDlg,IDC_PREVIEW),hDlg,(LPPOINT) &previewRect,2); AllImageToListBox(hDlg); iCount = AllImage_GetCount(); if (iCount >= 0) ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), 0); UpdateMainDlgButtons(hDlg); srand((int) GetCurrentTime()); // Seed the random number generator nMaxTextLen = GetMaxTextLen(GetDlgItem(hDlg, IDC_IMGLIST)); SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, nMaxTextLen, 0); L_DlgInit(DLG_INIT_COLOR); break; case WM_COMMAND : switch(LOWORD(wParam)) { L_INT iIndex; BOOL bInvalidImage; BOOL bImageLimitExceeded; L_TCHAR szErrorMsg[MAX_ERROR_STRING]; case IDC_ADD : if (AddSelectedFiles(hDlg, &bInvalidImage, &bImageLimitExceeded) == SUCCESS) { InvalidateRect(GetDlgItem(hDlg,IDC_PREVIEW), NULL, TRUE); PropSheet_Changed(GetParent(hDlg),hDlg); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), AllImage_GetCount()-1); UpdateMainDlgButtons(hDlg); nMaxTextLen = GetMaxTextLen(GetDlgItem(hDlg, IDC_IMGLIST)); SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, nMaxTextLen, 0); PropSheet_QuerySiblings(GetParent(hDlg), LIST_BOX_MAX_WIDTH, nMaxTextLen); } lstrcpy(szErrorMsg, TEXT("")); if (bImageLimitExceeded) wsprintf(szErrorMsg, TEXT("Maximum of %d images\n"), MAX_IMAGES); if (bInvalidImage) lstrcat(szErrorMsg, TEXT("Invalid Image File(s)")); if (bImageLimitExceeded | bInvalidImage) MessageBox(hDlg, szErrorMsg, NULL, MB_ICONWARNING); break; case IDC_REMOV : iIndex=ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); if(iIndex != LB_ERR) { ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), iIndex); if(iIndex != 0) ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iIndex-1); else ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iIndex); AllImage_Delete(iIndex); PropSheet_QuerySiblings(GetParent(hDlg), LIST_BOX_DELETE_STRING, iIndex); nMaxTextLen = GetMaxTextLen(GetDlgItem(hDlg, IDC_IMGLIST)); SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, nMaxTextLen, 0); PropSheet_QuerySiblings(GetParent(hDlg), LIST_BOX_MAX_WIDTH, nMaxTextLen); InvalidateRect(GetDlgItem(hDlg,IDC_PREVIEW), NULL, TRUE); } UpdateMainDlgButtons(hDlg); PropSheet_Changed(GetParent(hDlg),hDlg); break; case IDC_TEST : previewParam.hDlg = hDlg; SetRect(&previewParam.rect, previewRect.left, previewRect.top, previewRect.right, previewRect.bottom); DisableMainDlgButtons(hDlg); if(!bThreadFlag ) _beginthread(PreviewThread,0,&previewParam); break; case IDC_STOP: bThreadFlag = FALSE; //EnableWindow(GetDlgItem(hDlg,IDC_STOP),FALSE); //EnableWindow(GetDlgItem(hDlg,IDC_TEST),TRUE); SetFocus(GetDlgItem(hDlg,IDC_IMGLIST)); //SetFocus(GetDlgItem(hDlg,IDC_IMGLIST)); break; case IDC_UP : hListBox=GetDlgItem(hDlg,IDC_IMGLIST); iIndex=ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); if(iIndex !=0 && iIndex != LB_ERR) { AllImage_Swap(iIndex, iIndex-1); ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), iIndex); ListBox_InsertString(GetDlgItem(hDlg,IDC_IMGLIST),iIndex-1,AllImage_GetName(iIndex-1)); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iIndex-1) ; PropSheet_QuerySiblings(GetParent(hDlg), LIST_BOX_SWAP_STRING, iIndex); UpdateMainDlgButtons(hDlg); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_DOWN : hListBox=GetDlgItem(hDlg,IDC_IMGLIST); //take a handle to list box iIndex=ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); // get the currently selected cell if((iIndex !=ListBox_GetCount(GetDlgItem(hDlg,IDC_IMGLIST))-1) && iIndex != LB_ERR) { AllImage_Swap(iIndex, iIndex+1); ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), iIndex+1); ListBox_InsertString(GetDlgItem(hDlg,IDC_IMGLIST),iIndex,AllImage_GetName(iIndex)); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iIndex+1) ; PropSheet_QuerySiblings(GetParent(hDlg), LIST_BOX_SWAP_STRING, iIndex+1); UpdateMainDlgButtons(hDlg); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_IMGLIST : if(HIWORD(wParam)==LBN_SELCHANGE ) if(!bThreadFlag ) { UpdatePreviewImage( hDlg, &previewRect); UpdateMainDlgButtons(hDlg); } return TRUE; //break; } break; // end of case WM_COMMAND case WM_DRAWITEM: if (AllImage_GetCount() > 0) if (wParam == IDC_PREVIEW) { UpdatePreviewImage( hDlg, &previewRect); } break; case WM_NOTIFY : code = ((NMHDR FAR *) lParam)->code ; // Specify notification code switch(code) { case PSN_APPLY: AllImageToRegistry ( hKey); //EnableWindow break; case PSN_SETACTIVE: if (AllImage_GetCount() > 0) ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); break; case PSN_KILLACTIVE: iListBoxIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); bThreadFlag = FALSE; //stop preview if running break; } break; default: return DefWindowProc(hDlg, iMsg, wParam, lParam); break; } SetFocus(GetDlgItem(hDlg,IDC_IMGLIST)); return( TRUE ); } //function MainDlgProc //------------------------------------------------------------- // PaintEfxProc() // // Parameters: // hWnd Identifier of the configuration dialog box. // Msg Message that was sent to the screen saver's configuration dialog box. // wParam Additional message-specific information. // lParam Additional message-specific information. // // Description: // Dialog procedure for Paint Effects settings page of property sheet // ----------------------------------------------------------- BOOL CALLBACK PaintEfxProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) { L_UINT code ; L_INT i ; LPDRAWITEMSTRUCT lpDraw; CHOOSECOLOR ChooseClr ; static RECT previewRect; static BITMAPHANDLE myBitmap; int iIndex, iReturn; pEfxPaintInfoDef pPaintInfo; BOOL bRetval; switch(iMsg) { case PSM_QUERYSIBLINGS : switch (wParam) { case LIST_BOX_ADD_STRING: iReturn = ListBox_AddString(GetDlgItem(hDlg,IDC_IMGLIST),lParam ); break; case LIST_BOX_DELETE_STRING: ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), lParam); break; case LIST_BOX_SWAP_STRING: ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), lParam); ListBox_InsertString(GetDlgItem(hDlg,IDC_IMGLIST),lParam-1,AllImage_GetName(lParam-1)); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), lParam-1) ; break; case LIST_BOX_MAX_WIDTH: SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, lParam, 0); break; }; return TRUE; case WM_INITDIALOG : //PaintEfxProc { //total number of effects int iEffectCount = sizeof(EffectStyle) / sizeof(EffectStyle[0]); int nMaxTextLen; GetClientRect(GetDlgItem(hDlg,IDC_PREVIEW),&previewRect); MapWindowPoints(GetDlgItem(hDlg,IDC_PREVIEW),hDlg,(LPPOINT) &previewRect,2); AllImageToListBox(hDlg); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); pPaintInfo = AllImage_GetPaintInfo(iListBoxIndex); // fill effect styles for (i = 0; i < iEffectCount; i++) { ComboBox_AddString(GetDlgItem(hDlg,IDC_EFFECT1), EffectStyle[i].szEffectName); ComboBox_AddString(GetDlgItem(hDlg,IDC_EFFECT2), EffectStyle[i].szEffectName); ComboBox_AddString(GetDlgItem(hDlg,IDC_EFFECT3), EffectStyle[i].szEffectName); ComboBox_AddString(GetDlgItem(hDlg,IDC_EFFECT4), EffectStyle[i].szEffectName); ComboBox_AddString(GetDlgItem(hDlg,IDC_EFFECT5), EffectStyle[i].szEffectName); } OneImageToPaintDlg(hDlg); nMaxTextLen = GetMaxTextLen(GetDlgItem(hDlg, IDC_IMGLIST)); SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, nMaxTextLen, 0); return TRUE; } case WM_DRAWITEM : if (AllImage_GetCount() > 0) { if (wParam == IDC_PREVIEW) { UpdatePreviewImage( hDlg, &previewRect); } iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); pPaintInfo = AllImage_GetPaintInfo(iIndex); //Repaint buttons with colors currently selected lpDraw=(LPDRAWITEMSTRUCT)lParam; switch (lpDraw->CtlID) { case IDC_TCLR: FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pPaintInfo->crTransparency)); break; case IDC_WNCLR: FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pPaintInfo->crWand)); break; } } return TRUE; case WM_COMMAND : iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); pPaintInfo = AllImage_GetPaintInfo(iIndex); switch(LOWORD(wParam)) { case IDCANCEL: case IDOK: MessageBox(NULL, TEXT("PaintEfxProc IDOK"), TEXT(""), MB_OK); break; case IDC_TCLR : // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pPaintInfo->crTransparency = ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_TCLR), pPaintInfo->crTransparency); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_WNCLR : // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pPaintInfo->crWand=ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_WNCLR), pPaintInfo->crWand); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_CHECK_TRANS: { L_BOOL bTransparency; //set transparancy flag with the value retreived from IDC_CHECK1 bTransparency = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECK_TRANS)); if (bTransparency != pPaintInfo->fTransparency) { PropSheet_Changed(GetParent(hDlg),hDlg); pPaintInfo->fTransparency = bTransparency; } } break; case IDC_CHECK_FULLSCREEN : { L_BOOL bFullScreen; bFullScreen = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECK_FULLSCREEN)); if (bFullScreen != pPaintInfo->fFullScreen) { pPaintInfo->fFullScreen = bFullScreen; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_DELAYPE : { L_UINT uDelay; uDelay = GetDlgItemInt(hDlg,IDC_DELAYPE,&bRetval,FALSE); if (uDelay > MAX_DELAY) uDelay = MAX_DELAY; if (uDelay != pPaintInfo->uDelay) { //set the value of delay pPaintInfo->uDelay=uDelay; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_GRCLR : { unsigned long ulGrain; // set the value of grain ulGrain = GetDlgItemInt(hDlg,IDC_GRCLR,&bRetval,FALSE); if (ulGrain<1) ulGrain = 1; if (ulGrain>MAX_GRAIN) ulGrain = MAX_GRAIN; if (ulGrain != pPaintInfo->uGrain) { pPaintInfo->uGrain=ulGrain; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_WNSIZE : { L_UINT uWandWidth; uWandWidth = GetDlgItemInt(hDlg,IDC_WNSIZE,&bRetval,FALSE); if (uWandWidth != pPaintInfo->uWandWidth) { //set the value of wand size pPaintInfo->uWandWidth=pPaintInfo->uWandWidth; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_NUMPASS : { // set the value of number of passes unsigned long ulTempMaxPass; ulTempMaxPass = GetDlgItemInt(hDlg,IDC_NUMPASS,&bRetval,FALSE); if (ulTempMaxPass < 1) ulTempMaxPass = 1; else if (ulTempMaxPass > 5) ulTempMaxPass = 5; if (ulTempMaxPass != pPaintInfo->uMaxPass) { pPaintInfo->uMaxPass=ulTempMaxPass; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_EFFECT1 : { L_UINT uEffect; uEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_EFFECT1)) ; if (uEffect != pPaintInfo->uEffect[0]) { // specify effect type for the first pass pPaintInfo->uEffect[0]=uEffect; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_EFFECT2 : // specify effect type for the second pass { L_UINT uEffect; uEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_EFFECT2)) ; if (uEffect != pPaintInfo->uEffect[1]) { // specify effect type for the first pass pPaintInfo->uEffect[1]=uEffect; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_EFFECT3 : // specify effect type for the third pass { L_UINT uEffect; uEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_EFFECT3)) ; if (uEffect != pPaintInfo->uEffect[2]) { // specify effect type for the first pass pPaintInfo->uEffect[2]=uEffect; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_EFFECT4 : // specify effect type for the fourth pass { L_UINT uEffect; uEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_EFFECT4)) ; if (uEffect != pPaintInfo->uEffect[3]) { // specify effect type for the first pass pPaintInfo->uEffect[3]=uEffect; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_EFFECT5 : // specify effect type for the fifth pass { L_UINT uEffect; uEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_EFFECT5)) ; if (uEffect != pPaintInfo->uEffect[4]) { // specify effect type for the first pass pPaintInfo->uEffect[4]=uEffect; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_IMGLIST : if(HIWORD(wParam)==LBN_SELCHANGE ) if(!bThreadFlag ) { UpdatePreviewImage( hDlg, &previewRect); OneImageToPaintDlg(hDlg); } break; } return TRUE; case WM_NOTIFY : code = ((NMHDR FAR *) lParam)->code ; // Specify notification code switch(code) { case PSN_APPLY: AllImageToRegistry ( hKey); break; case PSN_SETACTIVE: iListBoxIndex = UpdatePaintEfxDlgButtons(hDlg); pPaintInfo = AllImage_GetPaintInfo(iListBoxIndex); break; case PSN_KILLACTIVE: iListBoxIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); break; } return TRUE; case WM_DESTROY: L_DlgFree(); break; } return DefWindowProc(hDlg, iMsg, wParam, lParam); } //------------------------------------------------------------- // TransProc() // // Parameters: // hWnd Identifier of the configuration dialog box. // Msg Message that was sent to the screen saver's configuration dialog box. // wParam Additional message-specific information. // lParam Additional message-specific information. // // Description: // Dialog procedure for Transition settings page of property sheet // ----------------------------------------------------------- BOOL CALLBACK TransProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) { L_UINT code; int i; LPDRAWITEMSTRUCT lpDraw; CHOOSECOLOR ChooseClr; static RECT previewRect ; static BITMAPHANDLE myBitmap; int iReturn; pEfxPaintTransitionDef pTrans; int iIndex; switch(iMsg) { case PSM_QUERYSIBLINGS : switch (wParam) { case LIST_BOX_ADD_STRING: iReturn = ListBox_AddString(GetDlgItem(hDlg,IDC_IMGLIST),lParam ); break; case LIST_BOX_DELETE_STRING: ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), lParam); break; case LIST_BOX_SWAP_STRING: ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), lParam); ListBox_InsertString(GetDlgItem(hDlg,IDC_IMGLIST),lParam-1,AllImage_GetName(lParam-1)); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), lParam-1) ; break; case LIST_BOX_MAX_WIDTH: SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, lParam, 0); break; }; return TRUE; case WM_INITDIALOG : //TransProc { //total number of effects int iEffectCount = sizeof(EffectStyle) / sizeof(EffectStyle[0]); int iFillCount = sizeof(FillStyle) / sizeof(FillStyle[0]); int nMaxTextLen; GetClientRect(GetDlgItem(hDlg,IDC_PREVIEW),&previewRect); MapWindowPoints(GetDlgItem(hDlg,IDC_PREVIEW),hDlg,(LPPOINT) &previewRect,2); AllImageToListBox(hDlg); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); pTrans = AllImage_GetTrans(iListBoxIndex); // fill effect styles for (i = 0; i < iEffectCount; i++) ComboBox_AddString(GetDlgItem(hDlg,IDC_EFFSTYL),EffectStyle[i].szEffectName ); for (i = 0; i < iFillCount; i++) ComboBox_AddString(GetDlgItem(hDlg,IDC_FILLSTYL), FillStyle[i].szFillName ); OneImageToTransDlg(hDlg); nMaxTextLen = GetMaxTextLen(hDlg); SendMessage( GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, nMaxTextLen, 0); return TRUE; } case WM_COMMAND : iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); pTrans = AllImage_GetTrans(iIndex); switch(LOWORD(wParam)) { case IDC_FORECOLOR : // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pTrans->crFore = ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_FORECOLOR), pTrans->crFore); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_WANDCOLOR : // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pTrans->crWand = ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_WANDCOLOR), pTrans->crWand); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_BACKCOLOR : // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pTrans->crBack = ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_BACKCOLOR), pTrans->crBack); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_CHECK_ERSBCK : { L_BOOL fEraseBck; fEraseBck = Button_GetCheck(GetDlgItem(hDlg,IDC_CHECK_ERSBCK)); if (fEraseBck != pTrans->fEraseBck) { //set the Erase Background flag with the value retreived from IDC_ERSBCK pTrans->fEraseBck= fEraseBck; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_EFFSTYL : { L_UINT uEffect; uEffect = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_EFFSTYL)) ; if (uEffect != pTrans->uEffect) { pTrans->uEffect=uEffect; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_FILLSTYL : { L_UINT uTransition; uTransition = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_FILLSTYL )) ; if (uTransition != pTrans->uTransition[0]) { pTrans->uTransition[0]= uTransition; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_DELAYTR : { L_UINT uDelay; uDelay=GetDlgItemInt(hDlg,IDC_DELAYTR,NULL,FALSE); if (uDelay > MAX_DELAY) uDelay = MAX_DELAY; if (uDelay != pTrans->uDelay) { pTrans->uDelay= uDelay; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_WANDSIZE : { L_UINT uWandWidth; uWandWidth=GetDlgItemInt(hDlg,IDC_WANDSIZE,NULL,FALSE); if (uWandWidth != pTrans->uWandWidth) { pTrans->uWandWidth=uWandWidth; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_GRAIN : { unsigned long ulGrain; ulGrain = GetDlgItemInt(hDlg,IDC_GRAIN,NULL,FALSE); if (ulGrain<1) ulGrain = 1; if (ulGrain>MAX_GRAIN) ulGrain = MAX_GRAIN; if (ulGrain != pTrans->uGrain) { pTrans->uGrain= ulGrain; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_GRSTEPS : { unsigned long ulGradientSteps; ulGradientSteps = GetDlgItemInt(hDlg,IDC_GRSTEPS,NULL,FALSE); if (ulGradientSteps < MIN_GRADIENT_STEPS) ulGradientSteps = MIN_GRADIENT_STEPS; if (ulGradientSteps > MAX_GRADIENT_STEPS) ulGradientSteps = MAX_GRADIENT_STEPS; if (ulGradientSteps != pTrans->uSteps) { pTrans->uSteps= ulGradientSteps; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_DELAYPE : { L_UINT uDelay; uDelay=GetDlgItemInt(hDlg,IDC_DELAYPE,NULL,FALSE); if (uDelay > MAX_DELAY) uDelay = MAX_DELAY; if (uDelay != pTrans->uDelay) { pTrans->uDelay=uDelay; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_IMGLIST : if(HIWORD(wParam)==LBN_SELCHANGE ) if(!bThreadFlag ) { UpdatePreviewImage( hDlg, &previewRect); OneImageToTransDlg(hDlg); } break; } return TRUE; case WM_DRAWITEM : if (AllImage_GetCount() > 0) { if (wParam == IDC_PREVIEW) { UpdatePreviewImage( hDlg, &previewRect); } iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); pTrans = AllImage_GetTrans(iIndex); //Repaint buttons with colors currently selected lpDraw=(LPDRAWITEMSTRUCT)lParam; switch (lpDraw->CtlID) { case IDC_WANDCOLOR : FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pTrans->crWand)); break; case IDC_BACKCOLOR : FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pTrans->crBack)); break; case IDC_FORECOLOR : FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pTrans->crFore)); break; } } return TRUE; break; case WM_NOTIFY : code = ((NMHDR FAR *) lParam)->code ; switch(code) { case PSN_APPLY: //write out registry entries AllImageToRegistry ( hKey); break; case PSN_SETACTIVE: iListBoxIndex = UpdateTransDlgButtons(hDlg); pTrans = AllImage_GetTrans(iListBoxIndex); break; case PSN_KILLACTIVE: iListBoxIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); break; } break; return TRUE; } return DefWindowProc(hDlg, iMsg, wParam, lParam); } //------------------------------------------------------------- // TextProc() // // Parameters: // hWnd Identifier of the configuration dialog box. // Msg Message that was sent to the screen saver's configuration dialog box. // wParam Additional message-specific information. // lParam Additional message-specific information. // // Description: // Dialog procedure for Text settings page of property sheet // ----------------------------------------------------------- BOOL CALLBACK TextProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) { L_UINT code; int i; LPDRAWITEMSTRUCT lpDraw; static CHOOSECOLOR ChooseClr; static RECT previewRect ; // preview rectangle static BITMAPHANDLE myBitmap; int iReturn; pEfxDrawTextDef pText; int iIndex; switch(iMsg) { case PSM_QUERYSIBLINGS : switch (wParam) { case LIST_BOX_ADD_STRING: iReturn = ListBox_AddString(GetDlgItem(hDlg,IDC_IMGLIST),lParam ); break; case LIST_BOX_DELETE_STRING: ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), lParam); break; case LIST_BOX_SWAP_STRING: ListBox_DeleteString(GetDlgItem(hDlg,IDC_IMGLIST), lParam); ListBox_InsertString(GetDlgItem(hDlg,IDC_IMGLIST),lParam-1,AllImage_GetName(lParam-1)); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), lParam-1) ; break; case LIST_BOX_MAX_WIDTH: SendMessage(GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, lParam, 0); break; }; return TRUE; break; case WM_INITDIALOG : { int iEffectCount = sizeof(TxtStyle) / sizeof(TxtStyle[0]); int nMaxTextLen; GetClientRect(GetDlgItem(hDlg,IDC_PREVIEW),&previewRect); MapWindowPoints(GetDlgItem(hDlg,IDC_PREVIEW),hDlg,(LPPOINT) &previewRect,2); AllImageToListBox(hDlg); ListBox_SetCurSel(GetDlgItem(hDlg,IDC_IMGLIST), iListBoxIndex); pText = AllImage_GetText(iListBoxIndex); for (i = 0; i < iEffectCount; i++) ComboBox_AddString(GetDlgItem(hDlg,IDC_TXTSTYL),TxtStyle[i]); OneImageToTextDlg(hDlg); nMaxTextLen = GetMaxTextLen(hDlg); SendMessage( GetDlgItem(hDlg, IDC_IMGLIST), LB_SETHORIZONTALEXTENT, nMaxTextLen, 0); return TRUE; } case WM_COMMAND : iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); pText = AllImage_GetText(iIndex); switch(LOWORD(wParam)) { case IDC_TEXTCLR1: // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pText->crText=ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_TEXTCLR1), pText->crText); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_BORDERCLR : // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pText->crHilite =ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_BORDERCLR), pText->crHilite); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_SHADCLR: // open a dialog for choosing a color if (ChooseAColor(hDlg,&ChooseClr)) { pText->crShadow=ChooseClr.rgbResult; RePaintButton(GetDlgItem(hDlg,IDC_SHADCLR), pText->crShadow); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_TEXT : { L_TCHAR cText[MAX_SIZE_TEXT]; // text string GetDlgItemText(hDlg,IDC_TEXT,cText,MAX_SIZE_TEXT); if (lstrcmp(pText->cText, cText) != 0) { lstrcpy(pText->cText, cText); PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_FONTTYPE : //choose font button if (LChooseFont (hDlg, pText, iIndex) ) { RePaintButton(GetDlgItem(hDlg,IDC_TEXTCLR1), pText->crText); PropSheet_Changed(GetParent(hDlg),hDlg); } break; case IDC_TXTSTYL : { L_UINT uFlags; uFlags = ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_TXTSTYL)) ; if (uFlags != pText->uFlags) { pText->uFlags= uFlags; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_TXTANGL : { L_INT nTextAngle; nTextAngle = GetDlgItemInt(hDlg,IDC_TXTANGL,NULL,FALSE); if (nTextAngle < 0) nTextAngle = 0; if (nTextAngle > 3599) nTextAngle = 3599; if (pText->nAngle != nTextAngle) { pText->nAngle= nTextAngle; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_DELAYPE : { L_UINT uDelay; uDelay=GetDlgItemInt(hDlg,IDC_DELAYPE,NULL,FALSE); if (uDelay > MAX_DELAY) uDelay = MAX_DELAY; if (uDelay != pText->uDelay) { pText->uDelay=uDelay; PropSheet_Changed(GetParent(hDlg),hDlg); } } break; case IDC_IMGLIST : if(HIWORD(wParam)==LBN_SELCHANGE ) if(!bThreadFlag ) { UpdatePreviewImage( hDlg, &previewRect); OneImageToTextDlg(hDlg); } break; } return TRUE; case WM_DRAWITEM : if (AllImage_GetCount() > 0) { if (wParam == IDC_PREVIEW) { UpdatePreviewImage( hDlg, &previewRect); } iIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); pText = AllImage_GetText(iIndex); //Repaint buttons with colors currently selected lpDraw=(LPDRAWITEMSTRUCT)lParam; switch (lpDraw->CtlID) { case IDC_TEXTCLR1: FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pText->crText )); break; case IDC_BORDERCLR : FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pText->crHilite )); break; case IDC_SHADCLR : FillRect( lpDraw->hDC,&lpDraw->rcItem, CreateSolidBrush(pText->crShadow )); break; } } return TRUE; break; case WM_NOTIFY : code = ((NMHDR FAR *) lParam)->code ; switch(code) { case PSN_APPLY: //write out registry entries AllImageToRegistry ( hKey); break; case PSN_SETACTIVE: iListBoxIndex = UpdateTextDlgButtons(hDlg); pText = AllImage_GetText(iListBoxIndex); break; case PSN_KILLACTIVE: iListBoxIndex = ListBox_GetCurSel(GetDlgItem(hDlg,IDC_IMGLIST)); break; } break; return TRUE; } return DefWindowProc(hDlg, iMsg, wParam, lParam); } #ifdef UNICODE BOOL CALLBACK SetFontEnumProce ( HWND hWnd, LPARAM lParam ) { SendMessage ( hWnd, WM_SETFONT, ( WPARAM ) lParam, ( LPARAM ) TRUE ) ; return TRUE ; } void SetControlFont ( HWND hWnd, HFONT hFont ) { if ( NULL != hFont ) { EnumChildWindows ( hWnd, SetFontEnumProce, ( LPARAM ) hFont ) ; } } void GenerateDefaultFont ( HFONT* phFont ) { HFONT hDefFont = NULL ; HDC hDC = NULL ; LOGFONT LogFont ; hDC = GetDC ( NULL ) ; 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 ( "Tahoma" ) ) ; *phFont = CreateFontIndirect ( &LogFont ) ; } #endif // UNICODE