home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / blanker / spextn.zip / NEWSAVER.C < prev    next >
Text File  |  1990-06-15  |  9KB  |  301 lines

  1. #include <stdio.h>
  2.  
  3. FILE *fp;
  4. char filename[100];
  5. char fileroot[100];
  6.  
  7. void main(int argc,char **argv)
  8.  
  9. {
  10.     printf("newsaver - creates template for screen saver for Screen Peace\n");
  11.     printf("    by Anthony Andersen\n");
  12.     printf("This program is Public Domain\n\n");
  13.     if (argc == 1) {
  14.         printf("usage : newsaver filename\n\n");
  15.         printf("    where : filename is the name of the new screen saver project\n");
  16.         printf("            (no file extension)\n\n");
  17.         return;
  18.     }
  19.  
  20.     strcpy(fileroot,argv[1]);
  21.  
  22. /* make file */
  23.  
  24.     strcpy(filename,fileroot);
  25.     fp = fopen(filename,"wt");
  26.     if (fp == NULL) {
  27.         printf("ERROR - can't open file %s\n",filename);
  28.         return;
  29.     }
  30.  
  31.  
  32.     fprintf(fp,"all: %s.spx\n",fileroot);
  33.     fprintf(fp,"\n");
  34.     fprintf(fp,".c.obj:\n");
  35.     fprintf(fp,"    cl -c -Asnw -Gsw -Oas -Zpe -W3 $*.c >$*.err\n");
  36.     fprintf(fp,"\n");
  37.     fprintf(fp,"%s.obj: %s.c %s.h\n",fileroot,fileroot,fileroot);
  38.     fprintf(fp,"\n");
  39.     fprintf(fp,"%s.res: %s.rc %s.dlg\n",fileroot,fileroot,fileroot);
  40.     fprintf(fp,"    rc -r %s.rc\n",fileroot);
  41.     fprintf(fp,"\n");
  42.     fprintf(fp,"libentry.obj: libentry.asm\n");
  43.     fprintf(fp,"   masm -Mx libentry,libentry;\n");
  44.     fprintf(fp,"\n");
  45.     fprintf(fp,"%s.spx: libentry.obj %s.obj %s.def %s.res\n",fileroot,fileroot,fileroot,fileroot);
  46.     fprintf(fp,"    link %s libentry, %s.exe, , /NOE /NOD sdllcew libw, %s.def\n",fileroot,fileroot,fileroot);
  47.     fprintf(fp,"    rc %s.res\n",fileroot);
  48.     fprintf(fp,"    if exist %s.spx del %s.spx\n",fileroot,fileroot);
  49.     fprintf(fp,"    ren %s.exe %s.spx\n",fileroot,fileroot);
  50.     fprintf(fp,"\n");
  51.  
  52.     fclose(fp);
  53.     printf("created file %s\n",filename);
  54.  
  55. /* end */
  56.  
  57. /* def file */
  58.  
  59.     strcpy(filename,fileroot);
  60.     strcat(filename,".def");
  61.     fp = fopen(filename,"wt");
  62.     if (fp == NULL) {
  63.         printf("ERROR - can't open file %s\n",filename);
  64.         return;
  65.     }
  66.  
  67.     fprintf(fp,"LIBRARY   %s\n",fileroot);
  68.     fprintf(fp,"\n");
  69.     fprintf(fp,"EXETYPE   WINDOWS\n");
  70.     fprintf(fp,"\n");
  71.     fprintf(fp,"CODE      PRELOAD MOVEABLE DISCARDABLE\n");
  72.     fprintf(fp,"DATA      PRELOAD SINGLE\n");
  73.     fprintf(fp,"\n");
  74.     fprintf(fp,"HEAPSIZE  1024\n");
  75.     fprintf(fp,"\n");
  76.     fprintf(fp,"EXPORTS\n");
  77.     fprintf(fp,"    WEP                 @1 RESIDENTNAME\n");
  78.     fprintf(fp,"    saverinit           @2\n");
  79.     fprintf(fp,"    saverdraw           @3\n");
  80.     fprintf(fp,"    saverdlgproc        @4\n");
  81.     fprintf(fp,"    LibMain             @5\n");
  82.  
  83.     fclose(fp);
  84.     printf("created file %s\n",filename);
  85.  
  86. /* end */
  87.  
  88. /* c file */
  89.  
  90.     strcpy(filename,fileroot);
  91.     strcat(filename,".c");
  92.     fp = fopen(filename,"wt");
  93.     if (fp == NULL) {
  94.         printf("ERROR - can't open file %s\n",filename);
  95.         return;
  96.     }
  97.  
  98.  
  99.     fprintf(fp,"#include <windows.h>\n");
  100.     fprintf(fp,"\n");
  101.     fprintf(fp,"#include \"%s.h\"\n",fileroot);
  102.     fprintf(fp,"\n");
  103.     fprintf(fp,"#define IDD_CHECKBOX 10\n");
  104.     fprintf(fp,"\n");
  105.     fprintf(fp,"unsigned long seed;\n");
  106.     fprintf(fp,"char buffer[10];\n");
  107.     fprintf(fp,"int  enabled;\n");
  108.     fprintf(fp,"\n");
  109.     fprintf(fp,"\n");
  110.     fprintf(fp,"char savername[] = \"Generic Saver\";\n");
  111.     fprintf(fp,"char appname[] = \"Screen Peace\";\n");
  112.     fprintf(fp,"char keyname[] = \"Generic On\";\n");
  113.     fprintf(fp,"\n");
  114.     fprintf(fp,"/* this is called by the default dll entry code during the  */\n");
  115.     fprintf(fp,"/* load library call - always happens BEFORE any other call */\n");
  116.     fprintf(fp,"/* in the dll.                                              */\n");
  117.     fprintf(fp,"\n");
  118.     fprintf(fp,"int FAR PASCAL LibMain(hModule, wDataSeg, cbHeapSize, lpszCmdLine)\n");
  119.     fprintf(fp,"\n");
  120.     fprintf(fp,"HANDLE    hModule;\n");
  121.     fprintf(fp,"WORD     wDataSeg;\n");
  122.     fprintf(fp,"WORD     cbHeapSize;\n");
  123.     fprintf(fp,"LPSTR    lpszCmdLine;\n");
  124.     fprintf(fp,"\n");
  125.     fprintf(fp,"{\n");
  126.     fprintf(fp,"\n");
  127.     fprintf(fp,"   /* set up things here */\n");
  128.     fprintf(fp,"\n");
  129.     fprintf(fp,"    GetProfileString(appname,keyname,\"y\",buffer,9);\n");
  130.     fprintf(fp,"    if (buffer[0] != 'n' && buffer[0] != 'N') {\n");
  131.     fprintf(fp,"        enabled = TRUE;\n");
  132.     fprintf(fp,"    }\n");
  133.     fprintf(fp,"    return (1);\n");
  134.     fprintf(fp,"}\n");
  135.     fprintf(fp,"\n");
  136.     fprintf(fp,"\n");
  137.     fprintf(fp,"/* this is called by Windows when the dll is released */\n");
  138.     fprintf(fp,"\n");
  139.     fprintf(fp,"int FAR PASCAL WEP (bSystemExit)\n");
  140.     fprintf(fp,"int  bSystemExit;\n");
  141.     fprintf(fp,"\n");
  142.     fprintf(fp,"{\n");
  143.     fprintf(fp,"    /* get rid of things you allocated in the LibMain proc here */\n");
  144.     fprintf(fp,"\n");
  145.     fprintf(fp,"    return (1);\n");
  146.     fprintf(fp,"}\n");
  147.     fprintf(fp,"\n");
  148.     fprintf(fp,"/* this is called (probably lots of times) by Screen Peace */\n");
  149.     fprintf(fp,"/* be careful not to allocate memory in here               */\n");
  150.     fprintf(fp,"\n");
  151.     fprintf(fp,"char FAR * FAR PASCAL saverinit(BOOL far *savenabled)\n");
  152.     fprintf(fp,"\n");
  153.     fprintf(fp,"{\n");
  154.     fprintf(fp,"    /* tell enable state */\n");
  155.     fprintf(fp,"\n");
  156.     fprintf(fp,"    *savenabled = enabled;\n");
  157.     fprintf(fp,"\n");
  158.     fprintf(fp,"    /* this next is optional but it may be used in future versions */\n");
  159.     fprintf(fp,"\n");
  160.     fprintf(fp,"    return(savername);\n");
  161.     fprintf(fp,"}\n");
  162.     fprintf(fp,"\n");
  163.     fprintf(fp,"/* dialog proc for user customization */\n");
  164.     fprintf(fp,"\n");
  165.     fprintf(fp,"BOOL FAR PASCAL saverdlgproc(HWND hdlg,unsigned message,WORD wparam,LONG lparam)\n");
  166.     fprintf(fp,"\n");
  167.     fprintf(fp,"{\n");
  168.     fprintf(fp,"    switch (message) {\n");
  169.     fprintf(fp,"\n");
  170.     fprintf(fp,"    case WM_INITDIALOG:\n");
  171.     fprintf(fp,"        SendDlgItemMessage(hdlg,IDD_CHECKBOX,BM_SETCHECK,enabled,0);\n");
  172.     fprintf(fp,"        return (TRUE);\n");
  173.     fprintf(fp,"\n");
  174.     fprintf(fp,"    case WM_COMMAND:\n");
  175.     fprintf(fp,"        if (wparam == IDOK) {\n");
  176.     fprintf(fp,"            enabled = (int)SendDlgItemMessage(hdlg,IDD_CHECKBOX,BM_GETCHECK,0,0);\n");
  177.     fprintf(fp,"            if (enabled) buffer[0] = 'y';\n");
  178.     fprintf(fp,"            else buffer[0] = 'n';\n");
  179.     fprintf(fp,"            buffer[1] = 0;\n");
  180.     fprintf(fp,"            WriteProfileString(appname,keyname,buffer);\n");
  181.     fprintf(fp,"            EndDialog(hdlg,TRUE);\n");
  182.     fprintf(fp,"            return (TRUE);\n");
  183.     fprintf(fp,"        }\n");
  184.     fprintf(fp,"        else if (wparam == IDCANCEL) {\n");
  185.     fprintf(fp,"            EndDialog(hdlg,FALSE);\n");
  186.     fprintf(fp,"            return (TRUE);\n");
  187.     fprintf(fp,"        }\n");
  188.     fprintf(fp,"      break;\n");
  189.     fprintf(fp,"    }\n");
  190.     fprintf(fp,"\n");
  191.     fprintf(fp,"    return (FALSE);\n");
  192.     fprintf(fp,"}\n");
  193.     fprintf(fp,"\n");
  194.     fprintf(fp,"/* returns pseudorandom number from 0 to x-1 */\n");
  195.     fprintf(fp,"\n");
  196.     fprintf(fp,"int arand(int x)\n");
  197.     fprintf(fp,"{\n");
  198.     fprintf(fp,"    seed = seed*0x343fd+0x269ec3;\n");
  199.     fprintf(fp,"    return (int)(((seed>>16)&0x7fff)*x>>15);\n");
  200.     fprintf(fp,"}\n");
  201.     fprintf(fp,"\n");
  202.     fprintf(fp,"/* the main drawing routine */\n");
  203.     fprintf(fp,"\n");
  204.     fprintf(fp,"VOID FAR PASCAL saverdraw(HWND hwnd,HDC hdc,HANDLE hinst,BOOL (FAR PASCAL *yieldproc)(VOID)) \n");
  205.     fprintf(fp,"\n");
  206.     fprintf(fp,"{\n");
  207.     fprintf(fp,"    RECT   rect;\n");
  208.     fprintf(fp,"    HBRUSH hbrush;\n");
  209.     fprintf(fp,"\n");
  210.     fprintf(fp,"    GetWindowRect(hwnd,&rect);\n");
  211.     fprintf(fp,"\n");
  212.     fprintf(fp,"    /* seed the pseudorandom number generator */\n");
  213.     fprintf(fp,"\n");
  214.     fprintf(fp,"    seed = GetTickCount();\n");
  215.     fprintf(fp,"\n");
  216.     fprintf(fp,"    hbrush = GetStockObject(BLACK_BRUSH);\n");
  217.     fprintf(fp,"\n");
  218.     fprintf(fp,"    /* You MUST \"black out\" the screen if you want the screen black */\n");
  219.     fprintf(fp,"\n");
  220.     fprintf(fp,"    FillRect(hdc,&rect,hbrush);\n");
  221.     fprintf(fp,"\n");
  222.     fprintf(fp,"    /* make sure to call yieldproc OFTEN - windows is locked up until */\n");
  223.     fprintf(fp,"    /* yieldproc is called.                                           */\n");
  224.     fprintf(fp,"\n");
  225.     fprintf(fp,"    while ((*yieldproc)()) {\n");
  226.     fprintf(fp,"\n");
  227.     fprintf(fp,"    }\n");
  228.     fprintf(fp,"\n");
  229.     fprintf(fp,"}\n");
  230.  
  231.     fclose(fp);
  232.     printf("created file %s\n",filename);
  233.  
  234. /* end */
  235.  
  236. /* res file */
  237.  
  238.     strcpy(filename,fileroot);
  239.     strcat(filename,".rc");
  240.     fp = fopen(filename,"wt");
  241.     if (fp == NULL) {
  242.         printf("ERROR - can't open file %s\n",filename);
  243.         return;
  244.     }
  245.  
  246.     fprintf(fp,"#include \"windows.h\"\n");
  247.     fprintf(fp,"\n");
  248.     fprintf(fp,"RCINCLUDE %s.dlg\n",fileroot);
  249.  
  250.  
  251.     fclose(fp);
  252.     printf("created file %s\n",filename);
  253.  
  254. /* end */
  255.  
  256. /* dlg file */
  257.  
  258.     strcpy(filename,fileroot);
  259.     strcat(filename,".dlg");
  260.     fp = fopen(filename,"wt");
  261.     if (fp == NULL) {
  262.         printf("ERROR - can't open file %s\n",filename);
  263.         return;
  264.     }
  265.  
  266.     fprintf(fp,"DIALOGBOX DIALOG LOADONCALL MOVEABLE DISCARDABLE 13, 35, 110, 80\n");
  267.     fprintf(fp,"STYLE WS_DLGFRAME | WS_POPUP\n");
  268.     fprintf(fp,"BEGIN\n");
  269.     fprintf(fp,"    CONTROL \"OK\", 1, \"button\", BS_DEFPUSHBUTTON | WS_TABSTOP | WS_CHILD, 40, 59, 30, 14\n");
  270.     fprintf(fp,"    CONTROL \"Generic Screen Saver\", 101, \"static\", SS_CENTER | WS_CHILD, 10, 8, 90, 8\n");
  271.     fprintf(fp,"    CONTROL \"by Someone\", 102, \"static\", SS_CENTER | WS_CHILD, 10, 22, 90, 8\n");
  272.     fprintf(fp,"    CONTROL \"Enabled\", 10, \"button\", BS_AUTOCHECKBOX | WS_TABSTOP | WS_CHILD, 35, 41, 40, 12\n");
  273.     fprintf(fp,"END\n");
  274.     fprintf(fp,"\n");
  275.  
  276.  
  277.     fclose(fp);
  278.     printf("created file %s\n",filename);
  279.  
  280. /* end */
  281.  
  282. /* dlg file */
  283.  
  284.     strcpy(filename,fileroot);
  285.     strcat(filename,".h");
  286.     fp = fopen(filename,"wt");
  287.     if (fp == NULL) {
  288.         printf("ERROR - can't open file %s\n",filename);
  289.         return;
  290.     }
  291.  
  292.     fprintf(fp,"\n");
  293.  
  294.     fclose(fp);
  295.     printf("created file %s\n",filename);
  296.  
  297. /* end */
  298.  
  299. }
  300. 
  301.