home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sstoolkt.zip / banner.c next >
Text File  |  1996-10-22  |  7KB  |  200 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #define VERTICES 4
  4.  
  5. #include <os2.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include "..\savers.h"
  10. #include "banner.h"
  11. #include "..\wpslib.h"
  12.  
  13. #define MinorTickSpacing  0
  14. #define MinorTickSize     0
  15. #define MajorTickSpacing  1 
  16. #define MajorTickSize     5
  17. #define TextSpacing       2
  18.  
  19.  
  20. typedef struct set_t
  21.     {
  22.     SHORT Foreground;
  23.     SHORT Background;
  24.     CHAR szFamilyName[FACESIZE];
  25.     CHAR Text[256];
  26.     LONG TextLength;
  27.     SHORT Speed;
  28.     FONTDLG fdFontDlg;
  29.     BOOL FontSet;
  30.     }settings;
  31.  
  32.  
  33. POINTL TextPosition, maxptl, TextBox[TXTBOX_COUNT];
  34. RECTL rcl={{0},{0},{0},{0}};
  35. settings Set;
  36.  
  37. MRESULT EXPENTRY __export SaverProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  38. {
  39.     HPS hps;
  40.     static SIZEF sizef;
  41.     static PFNWP OldSaverProc;
  42.  
  43.     switch(msg)
  44.     {
  45.             case UM_INIT_SAVER: 
  46.             OldSaverProc = (PFNWP)mp2;
  47.               if(!FindSettings(WinQueryAnchorBlock(hwnd), hwnd, (ULONG)sizeof(settings), &Set, "BANNER", "MESSAGE"))
  48.             {
  49.                 Set.Background =CLR_BLACK;
  50.                 Set.Foreground =CLR_YELLOW;
  51.                 Set.Speed = -5;
  52.                 strcpy(&(Set.Text), "For God so loved the world, he gave his only begotten Son...");
  53.                 Set.TextLength = strlen(Set.Text);
  54.             }
  55.              sizef.cy = sizef.cx = MAKEFIXED(Set.fdFontDlg.lEmHeight,0);
  56.             rcl.yTop = maxptl.y = SHORT2FROMMP(mp1);
  57.             rcl.xRight = TextPosition.x = maxptl.x = SHORT1FROMMP(mp1);
  58.             hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
  59.             GpiQueryTextBox(hps, Set.TextLength, Set.Text, TXTBOX_COUNT, TextBox);
  60.             GpiConvert(hps, CVTC_WORLD, CVTC_DEVICE, TXTBOX_COUNT, TextBox);
  61.             WinFillRect(hps, &rcl, Set.Background);
  62.             WinEndPaint(hps);
  63.             TextPosition.y=rand()%(maxptl.y-(Set.fdFontDlg.lEmHeight*2))+ Set.fdFontDlg.lEmHeight; 
  64.             rcl.yBottom = TextPosition.y - Set.fdFontDlg.lEmHeight;
  65.             rcl.yTop =TextPosition.y + Set.fdFontDlg.lEmHeight;
  66.         return(0);
  67.  
  68.         case WM_PAINT:
  69.             hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
  70.                         if((TextPosition.x += Set.Speed) < (0-TextBox[3].x<<1))
  71.                         {
  72.                             TextPosition.x = maxptl.x;
  73.                             TextPosition.y=rand()%(maxptl.y-(Set.fdFontDlg.lEmHeight*2))+ Set.fdFontDlg.lEmHeight;
  74.                             rcl.yBottom = TextPosition.y -  Set.fdFontDlg.lEmHeight;
  75.                             rcl.yTop =TextPosition.y +  Set.fdFontDlg.lEmHeight;
  76.                           }
  77.                         else if(TextPosition.x > (maxptl.x-(TextBox[3].x<<1)))
  78.                         {
  79.                             GpiSetCharBox(hps, &sizef);
  80.                             GpiCreateLogFont(hps, NULL, 10L, &(Set.fdFontDlg.fAttrs));
  81.                             GpiSetCharSet(hps, 10L);
  82.                             GpiSetColor(hps, Set.Foreground);
  83.                             rcl.xLeft = TextPosition.x;
  84.                             rcl.xRight = TextPosition.x + (TextBox[3].x<<1);
  85.                             WinFillRect(hps, &rcl, Set.Background);
  86.                             /*get rid of the sprintf in the next statement*/
  87.                             GpiCharStringPosAt(hps, &TextPosition, NULL, 0L, Set.TextLength, Set.Text, NULL);
  88.                             GpiSetCharSet(hps, LCID_DEFAULT);
  89.                             GpiDeleteSetId(hps, 10L);
  90.                         }
  91.                         else
  92.                         {
  93.                              rcl.xLeft=0;
  94.                             WinScrollWindow(hwnd, Set.Speed, 0, &rcl, NULL, NULLHANDLE , NULL, NULL);
  95.                         }
  96.                         WinEndPaint(hps);
  97.         return(0);
  98.  
  99.  
  100.         case UM_KILL_SAVER:
  101.         default:
  102.         return OldSaverProc(hwnd, msg, mp1, mp2);
  103.     }
  104. }
  105.  
  106.  
  107. MRESULT EXPENTRY __export SetupProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  108. {
  109.     ULONG ulValue;
  110.     HPS hpsScreen;
  111.     HWND hwndFontDlg;
  112.  
  113.     switch(msg)
  114.     {
  115.         case WM_INITDLG:
  116.              if(!FindSettings(WinQueryAnchorBlock(hwnd), hwnd, (ULONG)sizeof(settings), (PVOID)&Set, "BANNER", "MESSAGE"))
  117.                {
  118.                 Set.Background =CLR_BLACK;
  119.                 Set.Foreground =CLR_YELLOW;
  120.                 Set.Speed = -5;
  121.                 strcpy(&(Set.Text), "For God so loved the world, he gave his only begotten Son...");
  122.                 Set.TextLength = strlen(Set.Text);
  123.             }
  124.             WinSendDlgItemMsg(hwnd, TID_MESSAGE, EM_SETTEXTLIMIT, MPFROM2SHORT(256,0), NULL);
  125.             WinSetDlgItemText(hwnd, TID_MESSAGE, (PSZ)Set.Text);
  126.             InitSlider (hwnd, SDID_SPEED,9,MinorTickSpacing,MinorTickSize, MajorTickSpacing,MajorTickSize, TextSpacing);
  127.             WinSendMsg(WinWindowFromID(hwnd, SDID_SPEED), SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),MPFROMSHORT(-1*Set.Speed));
  128.             WinSendDlgItemMsg(hwnd, Set.Background+200, BM_SETCHECK, (MPARAM)TRUE, (MPARAM)NULL);
  129.             WinSendDlgItemMsg(hwnd, Set.Foreground+300, BM_SETCHECK, (MPARAM)TRUE, (MPARAM)NULL);
  130.             WinShowWindow(hwnd, TRUE);
  131.         return(0);
  132.  
  133.         case WM_CONTROL:
  134.             ulValue = SHORT1FROMMP(mp1);
  135.             if((ulValue >= RID_SWHITE) && (ulValue <= RID_SYELLOW))
  136.             {
  137.                 WinSendDlgItemMsg(hwnd, Set.Background+200, BM_SETCHECK, FALSE, NULL);
  138.                 Set.Background = ulValue - 200;
  139.                 WinSendDlgItemMsg(hwnd, Set.Background+200, BM_SETCHECK, (MPARAM)TRUE, (MPARAM)NULL);
  140.             }
  141.             if((ulValue >= RID_FWHITE) && (ulValue <= RID_FYELLOW))
  142.             {
  143.                 WinSendDlgItemMsg(hwnd, Set.Foreground+300, BM_SETCHECK, FALSE, NULL);
  144.                 Set.Foreground = ulValue - 300;
  145.                 WinSendDlgItemMsg(hwnd, Set.Foreground+300, BM_SETCHECK, (MPARAM)TRUE, (MPARAM)NULL);
  146.             }
  147.             
  148.         return(0);
  149.  
  150.         case WM_COMMAND:
  151.             switch(SHORT1FROMMP(mp1))
  152.             {
  153.                 case DID_FONT:
  154.                     hpsScreen = WinGetPS(hwnd);
  155.                     if(!Set.FontSet)
  156.                     {
  157.                         memset(&(Set.fdFontDlg), 0, sizeof(FONTDLG));
  158.                         Set.fdFontDlg.cbSize = sizeof(FONTDLG);
  159.                         Set.fdFontDlg.usFamilyBufLen = FACESIZE;
  160.                         Set.fdFontDlg.fl = FNTS_INITFROMFATTRS | FNTS_HELPBUTTON | FNTS_CENTER;
  161.                         Set.fdFontDlg.fAttrs.usCodePage = 437;
  162.                         Set.FontSet = TRUE;
  163.                     }
  164.                     Set.fdFontDlg.pszFamilyname = Set.szFamilyName;
  165.                     Set.fdFontDlg.hpsScreen = hpsScreen;
  166.                     Set.fdFontDlg.pszPreview = Set.Text;
  167.                     Set.fdFontDlg.clrFore = Set.Foreground;
  168.                     Set.fdFontDlg.clrBack = Set.Background;
  169.                     Set.fdFontDlg.fAttrs.fsFontUse = FATTR_FONTUSE_NOMIX;
  170.                                                 
  171.                     hwndFontDlg = WinFontDlg(HWND_DESKTOP, hwnd, &(Set.fdFontDlg));
  172.                     if(hwndFontDlg && (Set.fdFontDlg.lReturn == DID_OK))
  173.                     {
  174.                         strcpy(Set.szFamilyName, Set.fdFontDlg.pszFamilyname);
  175.                     }
  176.                     WinDestroyWindow(hwndFontDlg);
  177.                     WinReleasePS(hpsScreen);
  178.                 return(0);
  179.  
  180.                 case DID_OK:
  181.                     Set.Speed = -1*(SHORT) WinSendDlgItemMsg(hwnd, SDID_SPEED, SLM_QUERYSLIDERINFO,MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE), NULL);
  182.                     if(!Set.Speed) Set.Speed= (-1);
  183.                     Set.TextLength = WinQueryDlgItemTextLength(hwnd, TID_MESSAGE);
  184.                     WinQueryDlgItemText(hwnd, TID_MESSAGE, Set.TextLength+1, Set.Text);
  185.                     if(!WriteSettings((WinQueryAnchorBlock(hwnd)), hwnd, (ULONG)sizeof(settings), (PVOID)&Set, "BANNER", "MESSAGE"))
  186.                     {
  187.                              WinMessageBox(HWND_DESKTOP, hwnd, "An error occured writing to the initialization file.", "WPSaver", 0, MB_OK|MB_ICONEXCLAMATION);
  188.                             if(!WinQueryWindowPtr(hwnd, 0))
  189.                                           exit(0);
  190.                     }                           
  191.                 case DID_CANCEL:
  192.                     WinDismissDlg(hwnd, TRUE);
  193.                 return(0);
  194.             
  195.             }
  196.         break;
  197.     }
  198.     return WinDefDlgProc(hwnd, msg, mp1, mp2);
  199. }
  200.