home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gsview13 / gsgrab / gsginit.c < prev    next >
C/C++ Source or Header  |  1995-12-09  |  5KB  |  131 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gsginit.c */
  19. /* initialisation functions for GSgrab */
  20.  
  21. #include <windows.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include "gsgrab.h"
  25.  
  26. #define WINDOWWIDTH    (130*char_size.x/4)
  27. #define WINDOWHEIGHT    (72*char_size.y/8)
  28. #define BUTTONWIDTH    (32*char_size.x/4)
  29. #define BUTTONHEIGHT    (14*char_size.y/8)
  30. int ibutton[NBUTTON] = {IDC_SETUP, IDC_CANCEL, IDC_HELP, IDC_ABOUT};
  31. char *tbutton[NBUTTON] = {"Setup", "Cancel", "Help", "About"};
  32. POINT pbutton[NBUTTON] = { {4,8}, {4, 28}, {48, 8}, {48,28} };
  33.  
  34. void
  35. init_window(void)
  36. {
  37. int i;
  38. WNDCLASS wndclass;
  39. WNDPROC    lpfnButtonProc;
  40. HDC hdc;
  41. TEXTMETRIC tm;
  42. HFONT hfont;
  43.  
  44.     /* register the window class */
  45.     wndclass.style = 0;
  46.     wndclass.lpfnWndProc = WndGSgrabProc;
  47.     wndclass.cbClsExtra = 0;
  48.     wndclass.cbWndExtra = 0;
  49.     wndclass.hInstance = phInstance;
  50.     wndclass.hIcon = hicongrab = LoadIcon(phInstance, MAKEINTRESOURCE(GRABICON));
  51.     wndclass.hCursor = LoadCursor((HINSTANCE)NULL, IDC_ARROW);
  52.     wndclass.hbrBackground =  GetStockObject(WHITE_BRUSH);
  53.     wndclass.lpszMenuName = NULL;
  54.     wndclass.lpszClassName = szAppName;
  55.     RegisterClass(&wndclass);
  56.  
  57.     hdc = GetDC(NULL);  /* desktop */
  58.     hfont = GetStockObject(SYSTEM_FIXED_FONT);
  59.     SelectObject(hdc, hfont);
  60.     GetTextMetrics(hdc, (LPTEXTMETRIC)&tm);
  61.     ReleaseDC(NULL, hdc);
  62.     char_size.x = tm.tmAveCharWidth;
  63.     char_size.y = tm.tmHeight;
  64.  
  65.     hwndgrab = CreateWindow(szAppName, (LPSTR)szAppName,
  66.           WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
  67.           CW_USEDEFAULT, CW_USEDEFAULT, 
  68.           WINDOWWIDTH, WINDOWHEIGHT,
  69.           NULL, NULL, phInstance, (void FAR *)NULL);
  70.  
  71.     /* add buttons */
  72.     lpfnButtonProc = (WNDPROC)MakeProcInstance((FARPROC)ButtonProc, phInstance);
  73.     GetClassInfo((HINSTANCE)NULL, "button", &wndclass);    /* get default button class info */
  74.     lpfnButtonWndProc = wndclass.lpfnWndProc;
  75.     
  76.     for (i=0; i<NBUTTON; i++) {
  77.         hbutton[i] = CreateWindow("button", (LPSTR)tbutton[i], 
  78.         WS_CHILD | WS_VISIBLE, 
  79.         pbutton[i].x*char_size.x/4, pbutton[i].y*char_size.y/8,
  80.         BUTTONWIDTH, BUTTONHEIGHT,
  81.         hwndgrab, (HMENU)ibutton[i], phInstance, NULL);
  82.         SetWindowLong(hbutton[i], GWL_WNDPROC, (LONG)lpfnButtonProc);
  83.     }
  84.     SetFocus(GetDlgItem(hwndgrab, IDC_SETUP));
  85.     return;
  86. }
  87.  
  88. void
  89. init_profile(void)
  90. {
  91. char buf[64];
  92.     GetPrivateProfileString(szOptionSection, "Ghostscript", szDefCommand, szGhostscript, sizeof(szGhostscript), szIniName);
  93.     GetPrivateProfileString(szOptionSection, "Printer", "", szPrinter, sizeof(szPrinter), szIniName);
  94.     GetPrivateProfileString(szOptionSection, "Resolution", "", szResolution, sizeof(szResolution), szIniName);
  95.     GetPrivateProfileString(szOptionSection, "Port", szUnknown, szPort, sizeof(szPort), szIniName);
  96.     GetPrivateProfileString(szOptionSection, "Interval", "10", szInterval, sizeof(szInterval), szIniName);
  97.     interval = atoi(szInterval);
  98.     if (interval > 60) {
  99.         interval = 60;
  100.         strcpy(szInterval, "60");
  101.     }
  102.  
  103.     GetWindowsDirectory(szGrabFile, sizeof(szGrabFile));
  104.     strcat(szGrabFile,"\\GSGRAB");
  105.     strcpy(szCommand, szGhostscript);
  106.     strcat(szCommand, " -dNOPAUSE -sDEVICE=");
  107.     strcat(szCommand, szPrinter);
  108.     strcat(szCommand, " -r");
  109.     strcat(szCommand, szResolution);
  110.     if (strcmp(szPort, szUnknown)!=0) {
  111.         strcat(szCommand, " -sOutputFile=");
  112.         strcat(szCommand, szPort);
  113.     }
  114.     strcat(szCommand, " ");
  115.     strcat(szCommand, szGrabFile);
  116.     strcat(szCommand, " quit.ps");
  117. /*
  118.     strcat(szCommand, "-c quit");
  119. */
  120.     if (strlen(szCommand) >= 127)
  121.         MessageBox(hwndgrab, "Ghostscript command line is too long", szAppName, MB_OK);
  122.  
  123.     GetPrivateProfileString(szOptionSection, "Version", "", buf, sizeof(buf), szIniName);
  124.     if (strcmp(buf, GSGRAB_VERSION)) {
  125.         /* changed or new version */
  126.         PostMessage(hwndgrab, WM_COMMAND, IDC_SETUP, (LPARAM)0);
  127.         WinHelp(hwndgrab,szHelpName,HELP_KEY,(DWORD)"Installation");
  128.     }
  129. }
  130.  
  131.