home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / PLUGIN / QVIEWER / QVPTRW16.EXE / SCCDVAPI.SCC / SAMPLE.C < prev    next >
C/C++ Source or Header  |  1995-09-15  |  7KB  |  303 lines

  1.     /*
  2.     |    ViewAPI Sample Source
  3.     |    Systems Compatibility Corporation
  4.     |    for Microsoft C 7.0
  5.     |
  6.     |    The sections commented with SCC show the ViewAPI,
  7.     |    everything else is structure.
  8.     */
  9.  
  10. #include <windows.h>        /* required for all windows programs */
  11. #include <commdlg.h>        /* required for common dialogs */
  12.  
  13. #include "sccvapi.h"        /* SCC include file for ViewAPI */
  14.  
  15. #include "sample.h"
  16. #include "sample.pro"
  17.  
  18. /*
  19. |    Globals
  20. */
  21.  
  22. HANDLE            hInst;                        /* Handle of the current instance */
  23. HWND                hMainWnd;                    /* Handle to top level window */
  24.  
  25. SCCVAPIPROC    pViewAPIFunc;                /* ViewAPI function pointer */
  26. HANDLE            hViewAPILibrary;            /* ViewAPI library handle */
  27. HANDLE            hViewer;                        /* ViewAPI handle */
  28. HWND                hViewerWnd;                    /* ViewAPI viewer window */
  29.  
  30. /*
  31. |    Routines
  32. */
  33.  
  34. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  35. HANDLE hInstance;
  36. HANDLE hPrevInstance;
  37. LPSTR lpCmdLine;
  38. int nCmdShow;
  39. {
  40. MSG    locMsg;
  41.  
  42.         /*
  43.         | Register window class if necessary
  44.         */
  45.  
  46.     if (!hPrevInstance)
  47.         {
  48.        WNDCLASS WndClass;
  49.  
  50.        WndClass.style = NULL;
  51.        WndClass.lpfnWndProc = DemoWndProc;
  52.        WndClass.cbClsExtra = NULL;
  53.        WndClass.cbWndExtra = NULL;
  54.        WndClass.hInstance = hInstance;
  55.        WndClass.hIcon = LoadIcon(hInstance,"DEMO_ICON");
  56.        WndClass.hCursor = NULL;
  57.        WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  58.        WndClass.lpszMenuName = (LPSTR) "DEMO_MENU";
  59.        WndClass.lpszClassName = (LPSTR) "DEMO_MAIN";
  60.  
  61.        if (!RegisterClass(&WndClass)) return(NULL);
  62.         }
  63.  
  64.         /*
  65.         | Save instance in global
  66.         */
  67.  
  68.     hInst = hInstance;
  69.  
  70.         /*
  71.         | Create main window
  72.       */
  73.  
  74.     hMainWnd = CreateWindow(
  75.             (LPSTR) "DEMO_MAIN",                                    /* window class    */
  76.             "ViewAPI Sample",                                        /* window name        */
  77.             WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,            /* window type     */
  78.         40,                                                        /* x position         */
  79.         40,                                                        /* y position         */
  80.         600,                                                        /* width               */
  81.         400,                                                        /* height            */
  82.         NULL,                                                        /* parent handle     */
  83.         NULL,                                                        /* menu or child ID*/
  84.         hInstance,                                                /* instance            */
  85.         NULL);                                                    /* additional info */
  86.  
  87.         /*
  88.         |    Confirm window was created
  89.         */
  90.  
  91.     if (!hMainWnd)
  92.         return (NULL);
  93.  
  94.     ShowWindow(hMainWnd,SW_SHOW);
  95.     UpdateWindow(hMainWnd);
  96.  
  97.         /*
  98.         |    GetMessage loop
  99.         */
  100.  
  101.     while (GetMessage(&locMsg,NULL,NULL,NULL))
  102.         {
  103.         TranslateMessage(&locMsg);
  104.         DispatchMessage(&locMsg);
  105.         }
  106.  
  107.    return (locMsg.wParam);       /* Returns the value from PostQuitMessage */
  108. }
  109.  
  110. LRESULT __export __far __pascal DemoWndProc(hWnd, message, wParam, lParam)
  111. HWND hWnd;                        
  112. UINT message;            
  113. WPARAM wParam;                    
  114. LPARAM lParam;                    
  115. {
  116.     switch (message)
  117.         {
  118.         case WM_DESTROY:
  119.  
  120.             if (pViewAPIFunc)
  121.                 {
  122.                 pViewAPIFunc(SCCVAPI_DEINIT,hViewer,NULL);
  123.                 FreeLibrary(hViewAPILibrary);
  124.                 }
  125.  
  126.             PostQuitMessage(0);
  127.             break;
  128.  
  129.         case WM_CLOSE:
  130.  
  131.             DestroyWindow(hWnd);
  132.             break;
  133.  
  134.         case WM_CREATE:
  135.  
  136.             hViewerWnd = NULL;
  137.  
  138.             DemoLoadViewAPI();
  139.  
  140.             if (pViewAPIFunc == NULL)
  141.                 {
  142.                 MessageBox(hWnd,"Viewers not available","ViewAPI Demonstration",MB_OK);
  143.                 }
  144.  
  145.             break;
  146.  
  147.         case WM_COMMAND:
  148.  
  149.             if (LOWORD(lParam) == 0) /* Menu */
  150.                 {
  151.                 switch (wParam)
  152.                     {
  153.                     case MENU_FILE_OPEN:
  154.                         DemoOpenFile(hWnd);
  155.                         break;
  156.  
  157.                     case MENU_FILE_PRINTD:
  158.                         DemoPrint(TRUE);
  159.                         break;
  160.  
  161.                     case MENU_FILE_PRINTND:
  162.                         DemoPrint(FALSE);
  163.                         break;
  164.                     }
  165.                 }
  166.  
  167.             break;
  168.  
  169.  
  170.         default:
  171.             return (DefWindowProc(hWnd, message, wParam, lParam));
  172.         }
  173.     return (0L);
  174. }
  175.  
  176. VOID DemoOpenFile(hWnd)
  177. HWND    hWnd;
  178. {
  179. OPENFILENAME    locOFN;
  180. BYTE                locFile[144];
  181. BYTE *            locFilter[] =
  182.                                     {
  183.                                     "All Files",
  184.                                     "*.*",
  185.                                     ""
  186.                                     };
  187.  
  188.     locFile[0] = 0x00;
  189.  
  190.     locOFN.lStructSize = sizeof(OPENFILENAME);
  191.     locOFN.hwndOwner = hWnd;
  192.     locOFN.hInstance = hInst;
  193.     locOFN.lpstrFilter = locFilter[0];
  194.     locOFN.lpstrCustomFilter = NULL;
  195.     locOFN.nMaxCustFilter = 0L;
  196.     locOFN.nFilterIndex = 1L;
  197.     locOFN.lpstrFile = locFile;
  198.     locOFN.nMaxFile = 144;
  199.     locOFN.lpstrFileTitle = NULL;
  200.     locOFN.nMaxFileTitle = 0;
  201.     locOFN.lpstrInitialDir = NULL;
  202.     locOFN.lpstrTitle = NULL;
  203.     locOFN.Flags = 0;
  204.     locOFN.lpstrDefExt = NULL;
  205.     locOFN.lCustData = NULL;
  206.     locOFN.lpfnHook = NULL;
  207.     locOFN.lpTemplateName = NULL;
  208.  
  209.     if (GetOpenFileName(&locOFN) == TRUE)
  210.         {
  211.  
  212. /*SCC*/            SCCVAPIVIEW        locView;
  213. /*SCC*/            SCCVAPICREATE    locCreate;
  214. /*SCC*/    
  215. /*SCC*/            if (pViewAPIFunc)
  216. /*SCC*/                {
  217. /*SCC*/                if (!pViewAPIFunc(SCCVAPI_EXIST,hViewer,&hViewerWnd))
  218. /*SCC*/                    {
  219. /*SCC*/                    locCreate.wSize = sizeof(SCCVAPICREATE);
  220. /*SCC*/                    locCreate.bShowToolbar = TRUE;
  221. /*SCC*/                    locCreate.bAllowLaunch = TRUE;
  222. /*SCC*/                    locCreate.bAllowPrint = TRUE;
  223. /*SCC*/                    locCreate.bAllowCopy = TRUE;
  224. /*SCC*/                    locCreate.bAllowSearch = TRUE;
  225. /*SCC*/    
  226. /*SCC*/                    hViewerWnd = (HWND) pViewAPIFunc(SCCVAPI_CREATE,hViewer,&locCreate);
  227. /*SCC*/                    }
  228. /*SCC*/    
  229. /*SCC*/                if (hViewerWnd)
  230. /*SCC*/                    {
  231. /*SCC*/                    locView.wSize = sizeof(SCCVAPIVIEW);
  232. /*SCC*/                    locView.hViewWnd = hViewerWnd;
  233. /*SCC*/                    lstrcpy(locView.szPathName,locFile);
  234. /*SCC*/                    locView.wViewAs = NULL;
  235. /*SCC*/                    locView.bUseDisplayName = FALSE;
  236. /*SCC*/                    locView.bDeleteOnClose = FALSE;
  237. /*SCC*/    
  238. /*SCC*/                    pViewAPIFunc(SCCVAPI_VIEW,hViewer,&locView);
  239. /*SCC*/    
  240. /*SCC*/                    ShowWindow(hViewerWnd,SW_SHOW);
  241. /*SCC*/                    }
  242. /*SCC*/                }
  243.  
  244.         }
  245. }
  246.  
  247. VOID DemoPrint(bDoDialog)
  248. BOOL    bDoDialog;
  249. {
  250. SCCVAPIPRINT        locPrint;
  251.  
  252. /*SCC*/        if (pViewAPIFunc)                                                        
  253. /*SCC*/            {
  254. /*SCC*/            if (pViewAPIFunc(SCCVAPI_EXIST,hViewer,&hViewerWnd))
  255. /*SCC*/                {
  256. /*SCC*/                locPrint.wSize = sizeof(SCCVAPIPRINT);
  257. /*SCC*/                locPrint.hViewWnd = hViewerWnd;
  258. /*SCC*/                locPrint.bDoDialog = bDoDialog;
  259. /*SCC*/    
  260. /*SCC*/                pViewAPIFunc(SCCVAPI_PRINT,hViewer,&locPrint);
  261. /*SCC*/                }
  262. /*SCC*/            }
  263.  
  264. }
  265.  
  266.     /*
  267.     |    DemoLoadViewAPI
  268.     |
  269.     |    pViewAPIFunc, hViewAPILibrary and hViewer are globals
  270.     */
  271.  
  272. VOID DemoLoadViewAPI()
  273. {
  274. SCCVAPIINIT    locInit;
  275.  
  276. /*SCC*/        hViewAPILibrary = NULL;
  277. /*SCC*/        pViewAPIFunc = NULL;
  278. /*SCC*/
  279. /*SCC*/        hViewAPILibrary = LoadLibrary("SCCVAPI.DLL");
  280. /*SCC*/
  281. /*SCC*/        if (hViewAPILibrary >= 32)
  282. /*SCC*/            {
  283. /*SCC*/            pViewAPIFunc = (SCCVAPIPROC) GetProcAddress(hViewAPILibrary,MAKEINTRESOURCE(100));
  284. /*SCC*/
  285. /*SCC*/            locInit.wSize = sizeof(SCCVAPIINIT);
  286. /*SCC*/            lstrcpy(locInit.szHeader,"ViewAPI Demonstration");
  287. /*SCC*/
  288. /*SCC*/            hViewer = (HANDLE)pViewAPIFunc(SCCVAPI_INIT,NULL,&locInit);
  289. /*SCC*/
  290. /*SCC*/            if (hViewer == NULL)
  291. /*SCC*/                {
  292. /*SCC*/                FreeLibrary(hViewAPILibrary);
  293. /*SCC*/                hViewAPILibrary = NULL;
  294. /*SCC*/                pViewAPIFunc = NULL;
  295. /*SCC*/                }
  296. /*SCC*/            }
  297. /*SCC*/        else
  298. /*SCC*/            {
  299. /*SCC*/            hViewAPILibrary = NULL;
  300. /*SCC*/            pViewAPIFunc = NULL;
  301. /*SCC*/            }
  302. }
  303.