home *** CD-ROM | disk | FTP | other *** search
- /*
- | ViewAPI Sample Source
- | Systems Compatibility Corporation
- | for Microsoft C 7.0
- |
- | The sections commented with SCC show the ViewAPI,
- | everything else is structure.
- */
-
- #include <windows.h> /* required for all windows programs */
- #include <commdlg.h> /* required for common dialogs */
-
- #include "sccvapi.h" /* SCC include file for ViewAPI */
-
- #include "sample.h"
- #include "sample.pro"
-
- /*
- | Globals
- */
-
- HANDLE hInst; /* Handle of the current instance */
- HWND hMainWnd; /* Handle to top level window */
-
- SCCVAPIPROC pViewAPIFunc; /* ViewAPI function pointer */
- HANDLE hViewAPILibrary; /* ViewAPI library handle */
- HANDLE hViewer; /* ViewAPI handle */
- HWND hViewerWnd; /* ViewAPI viewer window */
-
- /*
- | Routines
- */
-
- int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
- HANDLE hInstance;
- HANDLE hPrevInstance;
- LPSTR lpCmdLine;
- int nCmdShow;
- {
- MSG locMsg;
-
- /*
- | Register window class if necessary
- */
-
- if (!hPrevInstance)
- {
- WNDCLASS WndClass;
-
- WndClass.style = NULL;
- WndClass.lpfnWndProc = DemoWndProc;
- WndClass.cbClsExtra = NULL;
- WndClass.cbWndExtra = NULL;
- WndClass.hInstance = hInstance;
- WndClass.hIcon = LoadIcon(hInstance,"DEMO_ICON");
- WndClass.hCursor = NULL;
- WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
- WndClass.lpszMenuName = (LPSTR) "DEMO_MENU";
- WndClass.lpszClassName = (LPSTR) "DEMO_MAIN";
-
- if (!RegisterClass(&WndClass)) return(NULL);
- }
-
- /*
- | Save instance in global
- */
-
- hInst = hInstance;
-
- /*
- | Create main window
- */
-
- hMainWnd = CreateWindow(
- (LPSTR) "DEMO_MAIN", /* window class */
- "ViewAPI Sample", /* window name */
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, /* window type */
- 40, /* x position */
- 40, /* y position */
- 600, /* width */
- 400, /* height */
- NULL, /* parent handle */
- NULL, /* menu or child ID*/
- hInstance, /* instance */
- NULL); /* additional info */
-
- /*
- | Confirm window was created
- */
-
- if (!hMainWnd)
- return (NULL);
-
- ShowWindow(hMainWnd,SW_SHOW);
- UpdateWindow(hMainWnd);
-
- /*
- | GetMessage loop
- */
-
- while (GetMessage(&locMsg,NULL,NULL,NULL))
- {
- TranslateMessage(&locMsg);
- DispatchMessage(&locMsg);
- }
-
- return (locMsg.wParam); /* Returns the value from PostQuitMessage */
- }
-
- LRESULT __export __far __pascal DemoWndProc(hWnd, message, wParam, lParam)
- HWND hWnd;
- UINT message;
- WPARAM wParam;
- LPARAM lParam;
- {
- switch (message)
- {
- case WM_DESTROY:
-
- if (pViewAPIFunc)
- {
- pViewAPIFunc(SCCVAPI_DEINIT,hViewer,NULL);
- FreeLibrary(hViewAPILibrary);
- }
-
- PostQuitMessage(0);
- break;
-
- case WM_CLOSE:
-
- DestroyWindow(hWnd);
- break;
-
- case WM_CREATE:
-
- hViewerWnd = NULL;
-
- DemoLoadViewAPI();
-
- if (pViewAPIFunc == NULL)
- {
- MessageBox(hWnd,"Viewers not available","ViewAPI Demonstration",MB_OK);
- }
-
- break;
-
- case WM_COMMAND:
-
- if (LOWORD(lParam) == 0) /* Menu */
- {
- switch (wParam)
- {
- case MENU_FILE_OPEN:
- DemoOpenFile(hWnd);
- break;
-
- case MENU_FILE_PRINTD:
- DemoPrint(TRUE);
- break;
-
- case MENU_FILE_PRINTND:
- DemoPrint(FALSE);
- break;
- }
- }
-
- break;
-
-
- default:
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- return (0L);
- }
-
- VOID DemoOpenFile(hWnd)
- HWND hWnd;
- {
- OPENFILENAME locOFN;
- BYTE locFile[144];
- BYTE * locFilter[] =
- {
- "All Files",
- "*.*",
- ""
- };
-
- locFile[0] = 0x00;
-
- locOFN.lStructSize = sizeof(OPENFILENAME);
- locOFN.hwndOwner = hWnd;
- locOFN.hInstance = hInst;
- locOFN.lpstrFilter = locFilter[0];
- locOFN.lpstrCustomFilter = NULL;
- locOFN.nMaxCustFilter = 0L;
- locOFN.nFilterIndex = 1L;
- locOFN.lpstrFile = locFile;
- locOFN.nMaxFile = 144;
- locOFN.lpstrFileTitle = NULL;
- locOFN.nMaxFileTitle = 0;
- locOFN.lpstrInitialDir = NULL;
- locOFN.lpstrTitle = NULL;
- locOFN.Flags = 0;
- locOFN.lpstrDefExt = NULL;
- locOFN.lCustData = NULL;
- locOFN.lpfnHook = NULL;
- locOFN.lpTemplateName = NULL;
-
- if (GetOpenFileName(&locOFN) == TRUE)
- {
-
- /*SCC*/ SCCVAPIVIEW locView;
- /*SCC*/ SCCVAPICREATE locCreate;
- /*SCC*/
- /*SCC*/ if (pViewAPIFunc)
- /*SCC*/ {
- /*SCC*/ if (!pViewAPIFunc(SCCVAPI_EXIST,hViewer,&hViewerWnd))
- /*SCC*/ {
- /*SCC*/ locCreate.wSize = sizeof(SCCVAPICREATE);
- /*SCC*/ locCreate.bShowToolbar = TRUE;
- /*SCC*/ locCreate.bAllowLaunch = TRUE;
- /*SCC*/ locCreate.bAllowPrint = TRUE;
- /*SCC*/ locCreate.bAllowCopy = TRUE;
- /*SCC*/ locCreate.bAllowSearch = TRUE;
- /*SCC*/
- /*SCC*/ hViewerWnd = (HWND) pViewAPIFunc(SCCVAPI_CREATE,hViewer,&locCreate);
- /*SCC*/ }
- /*SCC*/
- /*SCC*/ if (hViewerWnd)
- /*SCC*/ {
- /*SCC*/ locView.wSize = sizeof(SCCVAPIVIEW);
- /*SCC*/ locView.hViewWnd = hViewerWnd;
- /*SCC*/ lstrcpy(locView.szPathName,locFile);
- /*SCC*/ locView.wViewAs = NULL;
- /*SCC*/ locView.bUseDisplayName = FALSE;
- /*SCC*/ locView.bDeleteOnClose = FALSE;
- /*SCC*/
- /*SCC*/ pViewAPIFunc(SCCVAPI_VIEW,hViewer,&locView);
- /*SCC*/
- /*SCC*/ ShowWindow(hViewerWnd,SW_SHOW);
- /*SCC*/ }
- /*SCC*/ }
-
- }
- }
-
- VOID DemoPrint(bDoDialog)
- BOOL bDoDialog;
- {
- SCCVAPIPRINT locPrint;
-
- /*SCC*/ if (pViewAPIFunc)
- /*SCC*/ {
- /*SCC*/ if (pViewAPIFunc(SCCVAPI_EXIST,hViewer,&hViewerWnd))
- /*SCC*/ {
- /*SCC*/ locPrint.wSize = sizeof(SCCVAPIPRINT);
- /*SCC*/ locPrint.hViewWnd = hViewerWnd;
- /*SCC*/ locPrint.bDoDialog = bDoDialog;
- /*SCC*/
- /*SCC*/ pViewAPIFunc(SCCVAPI_PRINT,hViewer,&locPrint);
- /*SCC*/ }
- /*SCC*/ }
-
- }
-
- /*
- | DemoLoadViewAPI
- |
- | pViewAPIFunc, hViewAPILibrary and hViewer are globals
- */
-
- VOID DemoLoadViewAPI()
- {
- SCCVAPIINIT locInit;
-
- /*SCC*/ hViewAPILibrary = NULL;
- /*SCC*/ pViewAPIFunc = NULL;
- /*SCC*/
- /*SCC*/ hViewAPILibrary = LoadLibrary("SCCVAPI.DLL");
- /*SCC*/
- /*SCC*/ if (hViewAPILibrary >= 32)
- /*SCC*/ {
- /*SCC*/ pViewAPIFunc = (SCCVAPIPROC) GetProcAddress(hViewAPILibrary,MAKEINTRESOURCE(100));
- /*SCC*/
- /*SCC*/ locInit.wSize = sizeof(SCCVAPIINIT);
- /*SCC*/ lstrcpy(locInit.szHeader,"ViewAPI Demonstration");
- /*SCC*/
- /*SCC*/ hViewer = (HANDLE)pViewAPIFunc(SCCVAPI_INIT,NULL,&locInit);
- /*SCC*/
- /*SCC*/ if (hViewer == NULL)
- /*SCC*/ {
- /*SCC*/ FreeLibrary(hViewAPILibrary);
- /*SCC*/ hViewAPILibrary = NULL;
- /*SCC*/ pViewAPIFunc = NULL;
- /*SCC*/ }
- /*SCC*/ }
- /*SCC*/ else
- /*SCC*/ {
- /*SCC*/ hViewAPILibrary = NULL;
- /*SCC*/ pViewAPIFunc = NULL;
- /*SCC*/ }
- }
-