home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------- Parallax Standard C_File ----------------------------
-
- C_File : demo.c
-
- Purpose : C API sample program source file. Use for the reference about
- writing own C-API based programs.
-
-
- --------------------------------------------------------------------------------
- Copyright (c)1996 Parallax Software , All rights reserved.
- ------------------------------------------------------------------------------*/
-
- #pragma warning ( disable:4115 ) /* type name definition in parenthesis */
- #pragma warning ( disable:4201 ) /* nonstandard extension used: nameless struct/union */
- #pragma warning ( disable:4214 ) /* nonstandard extension used: bit field types other than int */
- #pragma warning ( disable:4514 ) /* unreferenced inline/local function has been removed */
-
-
- #include <windows.h>
- #include <commdlg.h>
- #include <in_api.h>
- #include <stdlib.h>
- #include <malloc.h>
-
- #include "resource.h"
-
- #ifdef _WIN32
-
- #define EXPORT( ret ) __declspec( dllexport ) ret WINAPI
- #define MALLOC(x) malloc(x)
- #define FREE(x) free(x)
- #define SWALLOW_ARG(x) {if(x);}
-
- #else
-
- #define EXPORT( ret ) ret FAR PASCAL __export
- #define MALLOC(x) _fmalloc(x)
- #define FREE(x) _ffree(x)
- #define SWALLOW_ARG(x) {if(x);}
-
- #endif
-
-
- /* Function prototypes */
-
- /* window functions */
- EXPORT(LRESULT) MainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
- EXPORT(LRESULT) ExternalWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
- EXPORT(LRESULT) EroicaExtWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );
-
- /* callbacks for notifications */
- EXPORT(void) NFY_CloseDocwin( IN_DOCWIN docwinID );
- EXPORT(void) NFY_MenuIntercept( IN_DOCWIN docwinID, unsigned menuID );
- EXPORT(BOOL) QRY_CloseDocwin( IN_DOCWIN docwinID, BOOL FAR *pCanClose );
-
- /* static functions */
- static BOOL _InitApplication( HINSTANCE hInstance );
- static BOOL _InitInstance( HINSTANCE hInstance, int nCmdShow );
- static void _LogMessage( LPCSTR message );
- static void _FileOpen( HWND hWnd, WPARAM mode );
- static void _DumpWindows( void );
- static void _EroicaVersion( void );
- static int _NewLayer( IN_DOCWIN docwinID );
- static int _SetTool( IN_DOCWIN docwinID, UINT toolType );
- static int _SetToolMenuCheck( HWND hWnd, UINT menuID );
- static void _DumpLayer( IN_DOCWIN docwin, IN_PAGE page, int layerNumber, IN_LAYER layer );
- static void _DumpPage( IN_DOCWIN docwin, IN_PAGE page );
- static void _DumpWindow( IN_DOCWIN docwin );
-
-
- /* Logging macros */
- #define _FMTMSG(fmt,v) { char m[1024]; wsprintf(m,fmt,v); _LogMessage(m); }
- #define _FMTMSG2(fmt,v1,v2) { char m[1024]; wsprintf(m,fmt,v1,v2); _LogMessage(m); }
- #define _FMTMSG3(fmt,v1,v2,v3) { char m[1024]; wsprintf(m,fmt,v1,v2,v3); _LogMessage(m); }
- #define _FMTMSG4(fmt,v1,v2,v3,v4) { char m[1024]; wsprintf(m,fmt,v1,v2,v3,v4); _LogMessage(m); }
- #define _FMTMSG5(fmt,v1,v2,v3,v4,v5) { char m[1024]; wsprintf(m,fmt,v1,v2,v3,v4,v5); _LogMessage(m); }
-
-
- /* Window classes */
- #define FRAME_CLASS_NAME "CAPIDemo:Frame"
- #define EXTERNAL_CLASS_NAME "CAPIDemo:External"
- #define EROICA_EXT_CLASS_NAME "CAPIDemo:EroicaExternal"
-
-
- /* Application globals */
- HINSTANCE hInst;
- HWND hFrameWnd;
- HWND hLogWnd;
- HMENU mainMenu;
-
-
- /* Functions for advise callbacks */
- FARPROC lpfnNotifyMenuIntercept;
- FARPROC lpfnNotifyCloseDocwin;
- FARPROC lpfnQueryCloseDocwin;
-
-
- /* main program entry point */
-
- int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
- {
- MSG msg;
- int error;
-
- /* dummy parameter check */
- SWALLOW_ARG( lpCmdLine );
-
- /* hPrevInstace has no effect in WIN32 */
- #ifdef _WIN32
- SWALLOW_ARG( hPrevInstance );
- #else
- if ( hPrevInstance ) {
- return( FALSE );
- }
- #endif
-
-
- /* Initialize application startup */
- hInst = hInstance;
- if (!_InitApplication( hInstance )) {
- return( FALSE );
- }
-
- hFrameWnd = NULL;
- hLogWnd = NULL;
- lpfnNotifyCloseDocwin = NULL;
- lpfnNotifyMenuIntercept = NULL;
- lpfnQueryCloseDocwin = NULL;
-
- /* Start API */
- error = IN_Startup( hInstance );
- if ( error < 0 ) {
- MessageBox( NULL, "Couldn't connect Eroiica. Check if Eroiica is running and not busy.", "Application Error", MB_ICONSTOP | MB_OK );
- return( FALSE );
- }
-
- /* Initialize specific instance startup */
- if (!_InitInstance( hInstance, nCmdShow )) {
- MessageBox( NULL, "Couldn't initialize instance", "Application Error", MB_ICONSTOP | MB_OK );
- return( FALSE );
- }
-
- /* Message loop */
- while (GetMessage( &msg, (HWND)NULL, (UINT)NULL, (UINT)NULL )) {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
-
- /* Unregister any notifies */
- if ((error = IN_UnregisterNotify( IN_NFY_MENU_INTERCEPT, 0, (ULONG) lpfnNotifyMenuIntercept )) != IN_ERR_SUCCESS)
- _FMTMSG( "Can't unregister menu intercept notify for docwin %lu", 0 );
-
- /* Release resources */
- if (lpfnNotifyCloseDocwin)
- FreeProcInstance( lpfnNotifyCloseDocwin );
- if (lpfnQueryCloseDocwin)
- FreeProcInstance( lpfnQueryCloseDocwin );
- if (lpfnNotifyMenuIntercept)
- FreeProcInstance( lpfnNotifyMenuIntercept );
-
- return( msg.wParam );
- }
-
-
-
- /* Initialize the application */
-
- BOOL _InitApplication( HINSTANCE hInstance )
- {
- WNDCLASS wc;
-
- /* Frame window */
- wc.style = (UINT)NULL;
- wc.lpfnWndProc = (WNDPROC)MainWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APP_ICON ) );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = GetStockObject( WHITE_BRUSH );
- wc.lpszMenuName = "CAPIDemoMainMenu";
- wc.lpszClassName = FRAME_CLASS_NAME;
-
- if (!RegisterClass( &wc ))
- return( FALSE );
-
- /* External window controlled by Eroica */
- wc.style = (UINT)NULL;
- wc.lpfnWndProc = (WNDPROC) EroicaExtWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 4;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APP_ICON ) );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = GetStockObject( WHITE_BRUSH );
- wc.lpszMenuName = "CAPIDemoIntControlMenu";
- wc.lpszClassName = EROICA_EXT_CLASS_NAME;
-
- if (!RegisterClass( &wc ))
- return( FALSE );
-
- /* External window controlled by us */
- wc.style = (UINT)NULL;
- wc.lpfnWndProc = (WNDPROC) ExternalWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 4;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_APP_ICON ) );
- wc.hCursor = LoadCursor( NULL, IDC_ARROW );
- wc.hbrBackground = GetStockObject( WHITE_BRUSH );
- wc.lpszMenuName = "CAPIDemoExtControlMenu";
- wc.lpszClassName = EXTERNAL_CLASS_NAME;
-
- if (!RegisterClass( &wc ))
- return( FALSE );
-
- return( TRUE );
- }
-
-
-
- /* Initialize the current instance of the application */
-
- static BOOL _InitInstance( HINSTANCE hInstance, int nCmdShow )
- {
- RECT rect;
- int error;
-
- /* Create the frame window */
- hFrameWnd = CreateWindow( FRAME_CLASS_NAME, "Eroica C-API Demo",
- WS_OVERLAPPEDWINDOW | WS_BORDER | WS_SYSMENU,
- 0, 0, 600, 400,
- NULL, NULL, hInstance, NULL );
- if (!hFrameWnd)
- return( FALSE );
-
- /* Make the window visible */
- ShowWindow( hFrameWnd, nCmdShow );
- UpdateWindow( hFrameWnd );
-
- /* Get the mainMenu handle */
- mainMenu = GetMenu( hFrameWnd );
-
- /* Tell Eroica to send notifications to us */
- IN_SetAdviseHWnd( hFrameWnd );
-
- /* Locate advise functions */
- lpfnNotifyCloseDocwin = MakeProcInstance( (FARPROC) NFY_CloseDocwin, hInstance );
- lpfnNotifyMenuIntercept = MakeProcInstance( (FARPROC) NFY_MenuIntercept, hInstance );
- lpfnQueryCloseDocwin = MakeProcInstance( (FARPROC) QRY_CloseDocwin, hInstance );
-
- /* Set up a notify on menu intercepts */
- if ((error = IN_RegisterNotify( IN_NFY_MENU_INTERCEPT, 0, (ULONG) lpfnNotifyMenuIntercept )) != IN_ERR_SUCCESS)
- _FMTMSG( "Can't register menu intercept notify for docwin %lu", 0 );
-
- /* Tell Eroica which menuIDs to intercept */
- if ((error = IN_InterceptMenuAction( IN_CMD_FILE_SAVE, TRUE )) != IN_ERR_SUCCESS)
- _LogMessage ( "Can't register menu intercept for FILE | SAVE " );
- if ((error = IN_InterceptMenuAction( IN_CMD_FILE_SAVEAS, TRUE )) != IN_ERR_SUCCESS)
- _LogMessage ( "Can't register menu intercept for FILE | SAVE AS" );
-
-
- /* Open up the log window */
- GetClientRect( hFrameWnd, &rect );
- hLogWnd = CreateWindow( "listbox", NULL,
- WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER | WS_VSCROLL | LBS_NOINTEGRALHEIGHT,
- 0, 0, rect.right - rect.left, rect.bottom - rect.top,
- hFrameWnd, NULL, hInstance, NULL );
-
- return( TRUE );
- }
-
-
-
- /* Frame window message handler */
-
- EXPORT(LRESULT) MainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
- {
- LRESULT result;
-
- /* Give Eroica a crack at the message */
- if (IN_MessageHook( hWnd, message, wParam, lParam, &result ))
- return( result );
-
- switch (message) {
- case WM_COMMAND:
- switch (wParam) {
- case IDM_FILE_OPEN_INT_EROICA:
- case IDM_FILE_OPEN_EXT_LOCAL:
- case IDM_FILE_OPEN_EXT_EROICA:
- _FileOpen( hWnd, wParam );
- return( 1 );
-
- case IDM_FILE_DUMP_WINDOWS:
- _DumpWindows();
- return( 1 );
-
- case IDM_EDIT_CLEAR:
- SendMessage( hLogWnd, LB_RESETCONTENT, 0, 0 );
- return( 1 );
-
- case IDM_MARKUP_NEWLAYER:
- _NewLayer( 0 );
- return( 1 );
-
- case IDM_MARKUP_TOOL_CIRCLE:
- if (_SetTool( 0, IN_TOOL_CIRCLE ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_CIRCLE );
- return( 1 );
-
- case IDM_MARKUP_TOOL_LINE:
- if (_SetTool( 0, IN_TOOL_LINE ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_LINE );
- return( 1 );
-
- case IDM_MARKUP_TOOL_BOX:
- if (_SetTool( 0, IN_TOOL_BOX ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_BOX );
- return( 1 );
-
- case IDM_MARKUP_TOOL_TEXT:
- if (_SetTool( 0, IN_TOOL_TEXT ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_TEXT );
- return( 1 );
-
- case IDM_HELP_VERSION:
- _EroicaVersion();
- return( 1 );
-
- case IDM_EXIT:
- PostMessage( hWnd, WM_CLOSE, 0, 0L );
- return( 1 );
- }
- break;
-
- case WM_DESTROY:
- IN_Shutdown();
- PostQuitMessage( 0 );
- return( 0 );
- }
-
- return( DefWindowProc( hWnd, message, wParam, lParam ) );
- }
-
-
-
- /* Add a string to the window output */
-
- static void _LogMessage( LPCSTR message )
- {
- LONG index;
-
- index = (LONG)SendMessage( hLogWnd, LB_ADDSTRING, 0, (LONG)(LPSTR) message );
- SendMessage( hLogWnd, LB_SETCURSEL, (WPARAM) index, 0 );
- SendMessage( hLogWnd, LB_SETCURSEL, (WPARAM) -1, 0 );
- }
-
-
-
- /* File|Open: Open a file in Eroica and then attach two advises */
- /* to the opened document. We want to know when the user requests to */
- /* close the document, as well as when it actually gets closed */
-
- static void _FileOpen( HWND hWnd, WPARAM mode )
- {
- OPENFILENAME ofn;
- char filename[512];
- char title[81];
- int error;
- SHORT docwinCount;
- IN_DOCWIN docwins[1];
-
- filename[0] = '\0';
-
- /* Common file-open dialog initialization */
- ofn.lStructSize = sizeof( ofn );
- ofn.hwndOwner = hWnd;
- ofn.hInstance = NULL;
- ofn.lpstrFilter = "All Files\0*.*\0";
- ofn.lpstrCustomFilter = NULL;
- ofn.nMaxCustFilter = 0;
- ofn.nFilterIndex = 0;
- ofn.lpstrFile = filename;
- ofn.nMaxFile = sizeof( filename ) - 1;
- ofn.lpstrFileTitle = title;
- ofn.nMaxFileTitle = sizeof( title ) - 1;
- ofn.lpstrInitialDir = NULL;
- ofn.lpstrTitle = "Open File In Eroica";
- ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
- ofn.lpstrDefExt = NULL;
- ofn.lCustData = (DWORD)NULL;
- ofn.lpfnHook = NULL;
- ofn.lpTemplateName = NULL;
-
- if (GetOpenFileName( &ofn )) {
-
- switch (mode) {
- case IDM_FILE_OPEN_INT_EROICA:
- error = IN_OpenDocumentWindow( IN_LOCN_DISK, filename, 1, &docwinCount, docwins );
-
- /* Set up advises */
- if (error == IN_ERR_SUCCESS) {
- _FMTMSG2( "%s opened in docwin %lu", (LPCSTR) filename, docwins[0] );
-
- /* Tell us when it closes */
- error = IN_RegisterNotify( IN_NFY_CLOSE_DOCWIN, docwins[0], (ULONG) lpfnNotifyCloseDocwin );
- if (error != IN_ERR_SUCCESS)
- _FMTMSG( "Can't register close notify for docwin %lu", docwins[0] );
-
- /* Ask us if we should close it */
- error = IN_RegisterQuery( IN_QRY_CLOSE_DOCWIN, docwins[0], (ULONG) lpfnQueryCloseDocwin );
- if (error != IN_ERR_SUCCESS)
- _FMTMSG( "Can't register close query for docwin %lu", docwins[0] );
- } else {
- _FMTMSG2( "Error code %d when trying to open %s", error, (LPCSTR) filename );
- }
- break;
-
- case IDM_FILE_OPEN_EXT_LOCAL:
- {
- HWND hDocWnd;
-
- if ((hDocWnd = CreateWindow( EXTERNAL_CLASS_NAME, "Locally Controlled Document", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- hWnd, NULL, hInst, NULL)) != NULL) {
- SetWindowLong( hDocWnd, 0, 0 );
- if ((error = IN_RegisterExternalDocumentWindow( hDocWnd, docwins )) == IN_ERR_SUCCESS) {
- SetWindowLong( hDocWnd, 0, docwins[0] );
- if ((error = IN_OpenExternalDocumentWindow( docwins[0], IN_LOCN_DISK, filename, "External Document Window", IN_FLAG_SCROLLBAR_BOTH )) == IN_ERR_SUCCESS) {
- docwinCount = 1;
- InvalidateRect( hDocWnd, NULL, FALSE );
- UpdateWindow( hDocWnd );
- } else
- PostMessage( hDocWnd, WM_CLOSE, 0, 0 );
- } else {
- PostMessage( hDocWnd, WM_CLOSE, 0, 0 );
- }
- } else {
- #ifdef _WIN32
- error = GetLastError();
- #else
- error = 126;
- #endif
- _FMTMSG( "Windows Error %d, cannot redirect window to Eroiica (WIN32 barrier).", error );
- }
-
- break;
- }
-
- case IDM_FILE_OPEN_EXT_EROICA:
- {
- HWND hDocWnd;
-
- if ((hDocWnd = CreateWindow( EROICA_EXT_CLASS_NAME, "Eroica Controlled Document", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- hWnd, NULL, hInst, NULL)) != NULL) {
- SetWindowLong( hDocWnd, 0, 0 );
- if ((error = IN_RegisterExternalDocumentWindow( hDocWnd, docwins )) == IN_ERR_SUCCESS) {
- if ((error = IN_OpenExternalDocumentWindow( docwins[0], IN_LOCN_DISK, filename, "External Document Window", IN_FLAG_SCROLLBAR_BOTH )) == IN_ERR_SUCCESS) {
- IN_HandleExternalDocumentWindow( docwins[0], IN_EXTMODE_ALL );
- SetWindowLong( hDocWnd, 0, docwins[0] );
- docwinCount = 1;
- InvalidateRect( hDocWnd, NULL, FALSE );
- UpdateWindow( hDocWnd );
- } else
- PostMessage( hDocWnd, WM_CLOSE, 0, 0 );
- } else
- PostMessage( hDocWnd, WM_CLOSE, 0, 0 );
- } else {
- #ifdef _WIN32
- error = GetLastError();
- #else
- error = 126;
- #endif
- _FMTMSG( "Error %d, cannot create controlled window.", error );
- }
- break;
- }
- }
- }
- }
-
-
-
- /* Dump some information we know about the layer */
-
- static void _DumpLayer( IN_DOCWIN docwin, IN_PAGE page, int layerNumber, IN_LAYER layer )
- {
- char title[100];
-
- SWALLOW_ARG( docwin );
- SWALLOW_ARG( page );
-
- if (IN_GetTitle( layer, 100, title ) == IN_ERR_SUCCESS)
- _FMTMSG3( " Layer %u: '%s', ID=%lu", layerNumber, (LPCSTR) title, layer );
- }
-
-
-
- /* Create a new layer on the active document window */
-
- static int _NewLayer( IN_DOCWIN docwinID )
- {
- IN_PAGE activePage;
- IN_LAYER NewLayerID;
- char errorBuffer[64];
- int error;
-
- /* Get the active page for the active document window */
- if ((error = IN_GetPageID( docwinID, 0, &activePage )) != IN_ERR_SUCCESS) {
- MessageBox( hFrameWnd, "Unable to get the pageID for the active document window", "Error Message", MB_APPLMODAL );
- return( FALSE );
- }
-
- /* Add a new layer to the active page */
- if ((error = IN_NewLayer( activePage, IN_LAYER_FULLEDIT, &NewLayerID )) != IN_ERR_SUCCESS) {
- wsprintf( errorBuffer, "Unable to add a layer to page (PAGEID:%lu)", activePage );
- MessageBox( hFrameWnd, (LPCSTR)errorBuffer, (LPCSTR)"Error Message", MB_APPLMODAL );
- return( FALSE );
- }
-
- return( TRUE );
- }
-
-
- /* Dump the layers on this page as well as some information we know */
- /* about the page */
-
- static void _DumpPage( IN_DOCWIN docwin, IN_PAGE page )
- {
- SHORT numberLayers;
- SHORT pageNumber;
- char title[100];
- int error;
- SHORT tmp;
- IN_LAYER_PTR layers;
- IN_PAGE activePage;
-
- /* Get some information about this page */
- IN_GetPageNumber( page, &pageNumber );
- IN_GetTitle( page, 100, title );
- IN_GetNumberLayers( docwin, page, &numberLayers );
- IN_GetPageID( docwin, 0, &activePage );
- _FMTMSG5( " Page %u: '%s', ID=%lu,%s Layer count: %u", pageNumber, (LPCSTR) title, page, activePage == page ? (LPCSTR) " Active," : (LPCSTR) "", numberLayers );
-
- if (numberLayers) {
- if ((layers = (IN_LAYER_PTR) MALLOC( numberLayers * sizeof( IN_LAYER ) )) != NULL) {
- error = IN_GetLayerIDs( page, numberLayers, &tmp, layers );
- if (error == IN_ERR_SUCCESS)
- for (tmp = 0; tmp < numberLayers; ++tmp)
- _DumpLayer( docwin, page, tmp+1, layers[tmp] );
- FREE( layers );
- }
- }
- }
-
-
-
- /* Dump the pages that are displayed in this document, as well as some */
- /* information we know about the document window */
-
- static void _DumpWindow( IN_DOCWIN docwin )
- {
- SHORT numberPages;
- char title[100];
- int error;
- IN_PAGE_PTR pages;
- IN_DOCWIN activeDocwin;
- SHORT tmp;
-
- /* Get the title of the window */
- title[0] = '\0';
- IN_GetTitle( docwin, 100, title );
- IN_GetActiveDocumentWindow( &activeDocwin );
- IN_GetNumberPages( docwin, &numberPages );
- _FMTMSG4( "Document Window ID %lu: '%s',%s Page count: %u", docwin, (LPCSTR) title, activeDocwin == docwin ? (LPCSTR) " Active," : (LPCSTR) "", numberPages );
-
- /* Get the pages in the window */
- if (numberPages)
- if ((pages = (IN_PAGE_PTR) MALLOC( numberPages * sizeof( IN_PAGE ) )) != NULL) {
- error = IN_GetPageIDs( docwin, numberPages, &tmp, pages );
- if (error == IN_ERR_SUCCESS)
- for (tmp = 0; tmp < numberPages; ++tmp)
- _DumpPage( docwin, pages[tmp] );
- FREE( pages );
- }
- }
-
-
-
- /* Dump information about all of the document windows that are currently */
- /* open in Eroica */
-
- static void _DumpWindows( void )
- {
- SHORT docwinCount;
- IN_DOCWIN_PTR docwins;
- int error;
- int i;
-
- /* Get the document windows that are currently open */
- error = IN_GetNumberDocumentWindows( &docwinCount );
- if (error == IN_ERR_SUCCESS) {
- _FMTMSG( " %u document windows found", docwinCount );
- if (docwinCount)
- if ((docwins = (IN_DOCWIN_PTR) MALLOC( docwinCount * sizeof( IN_DOCWIN ) )) != NULL) {
- error = IN_GetDocumentWindows( 100, &docwinCount, docwins );
- if (error == IN_ERR_SUCCESS)
- for (i = 0; i < docwinCount; ++i)
- _DumpWindow( docwins[i] );
- FREE( docwins );
- }
- } else {
- _FMTMSG( "Couldn't get window count. Error %d", error );
- }
- }
-
-
-
- /* Get and display the version of Eroica that we are attached to */
-
- static void _EroicaVersion( void )
- {
- int error;
- SHORT major, minor, build;
- char szVersion[24];
-
- error = IN_GetIMVersion( &major, &minor, &build, sizeof( szVersion ), szVersion );
- if (error == IN_ERR_SUCCESS) {
- _FMTMSG4( "Eroica Version %u.%u.%u (%s)", major, minor, build, (LPCSTR) szVersion );
- } else {
- _FMTMSG( "Can't get Eroica version. Error %d", error );
- }
- }
-
-
-
- /* This function is called when a menu item has been activated and */
- /* an IN_NFY_MENU_INTERCEPT advise has been sent out */
-
- EXPORT(void) NFY_MenuIntercept( IN_DOCWIN docwinID, unsigned menuID )
- {
- char message[256];
-
- switch (menuID) {
- case IN_CMD_FILE_SAVE:
- wsprintf( message, "Someone has select the FILE|SAVE menu option in Eroica for docwinID %lu. Enter user intercept function here", docwinID );
- MessageBox( hFrameWnd, (LPCSTR)message, (LPCSTR)"Menu Item Intercepted", MB_APPLMODAL );
- break;
-
- case IN_CMD_FILE_SAVEAS:
- wsprintf( message, "Someone has select the FILE|SAVE AS menu option in Eroica for docwinID %lu. Enter user intercept function here", docwinID );
- MessageBox( hFrameWnd, (LPCSTR)message, (LPCSTR)"Menu Item Intercepted", MB_APPLMODAL );
- break;
-
- default:
- break;
- }
- }
-
-
-
- /* This function is called when a document window that we have placed */
- /* an IN_NFY_CLOSE_DOCWIN advise request on has closed */
-
- EXPORT(void) NFY_CloseDocwin( IN_DOCWIN docwinID )
- {
- _FMTMSG( "CloseDocwin %ld", docwinID );
- }
-
-
-
- /* This function sets the appropriate tool item to checked */
- static int _SetTool( IN_DOCWIN docwinID, UINT toolType )
- {
- int error;
-
- /* Set the tool type */
- if ((error = IN_SetTool( docwinID, toolType )) != IN_ERR_SUCCESS) {
- _FMTMSG( "Tool type was not set (TOOL:%d)", toolType );
- }
-
- return( TRUE );
- }
-
-
-
- /* This function sets the appropriate tool item to checked */
- static int _SetToolMenuCheck( HWND hWnd, UINT menuID )
- {
- HMENU hMenu = GetMenu( hWnd );
-
- /* Turn all the checks off */
- CheckMenuItem( hMenu, IDM_MARKUP_TOOL_CIRCLE, MF_UNCHECKED );
- CheckMenuItem( hMenu, IDM_MARKUP_TOOL_LINE, MF_UNCHECKED );
- CheckMenuItem( hMenu, IDM_MARKUP_TOOL_BOX, MF_UNCHECKED );
- CheckMenuItem( hMenu, IDM_MARKUP_TOOL_TEXT, MF_UNCHECKED );
-
- /* Now set the onen active */
- CheckMenuItem( hMenu, menuID, MF_CHECKED );
-
- return( TRUE );
- }
-
-
-
- /* This function is called when a document window that we have placed
- * an IN_QRY_CLOSE_DOCWIN advise request been requested to close.
- *
- * The user is presented with a Yes/No/Cancel dialog asking whether the
- * document window should be closed or not.
- *
- * Yes indicates that the window can close
- * No indicates that the window shouldn't close
- * Cancel indicates that we have no opinion and let it close if nobody
- * else wants it to stay open
- */
-
- EXPORT(BOOL) QRY_CloseDocwin( IN_DOCWIN docwinID, BOOL FAR *pCanClose )
- {
- char msgText[50];
- BOOL msgProcessed;
-
- wsprintf( msgText, "Close Docwin ID %lu?", docwinID );
- switch (MessageBox( hFrameWnd, msgText, "Close DocwinID Query", MB_YESNOCANCEL )) {
- case IDYES:
- *pCanClose = TRUE;
- msgProcessed = TRUE;
- _FMTMSG( "CloseDocwin(%lu)? Yes", docwinID );
- break;
-
- case IDNO:
- *pCanClose = FALSE;
- msgProcessed = TRUE;
- _FMTMSG( "CloseDocwin(%lu)? No", docwinID );
- break;
-
- case IDCANCEL:
- default:
- msgProcessed = FALSE;
- _FMTMSG( "CloseDocwin(%lu)? Ignored", docwinID );
- break;
- }
-
- return( msgProcessed );
- }
-
-
-
- /* This function is the callback for the external window that we control */
- /* by giving Eroica explicitly a chance at processing the message */
-
- EXPORT(LRESULT) ExternalWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
- {
- IN_DOCWIN docwinID = GetWindowLong( hWnd, 0 );
-
- /* Give Eroica a chance at the message */
- if (message != WM_COMMAND || (wParam < FIRST_MENU_COMMAND_ID || wParam > LAST_MENU_COMMAND_ID))
- if (IN_ProcessExternalWindowMessage( hWnd, message, wParam, lParam ))
- return( 0 );
-
- switch (message) {
- case WM_CLOSE:
- IN_UnregisterExternalDocumentWindow( docwinID );
- break;
-
- case WM_COMMAND:
- switch (wParam) {
- case IDM_EXIT:
- PostMessage( hWnd, WM_CLOSE, 0, 0 );
- return( 1 );
-
- case IDM_VIEW_FIT:
- IN_SetZoom( docwinID, 3 );
- return( 1 );
-
- case IDM_MARKUP_NEWLAYER:
- _NewLayer( docwinID );
- return( 1 );
-
- case IDM_MARKUP_TOOL_CIRCLE:
- if (_SetTool( docwinID, IN_TOOL_CIRCLE ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_CIRCLE );
- return( 1 );
-
- case IDM_MARKUP_TOOL_LINE:
- if (_SetTool( docwinID, IN_TOOL_LINE ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_LINE );
- return( 1 );
-
- case IDM_MARKUP_TOOL_BOX:
- if (_SetTool( docwinID, IN_TOOL_BOX ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_BOX );
- return( 1 );
-
- case IDM_MARKUP_TOOL_TEXT:
- if (_SetTool( docwinID, IN_TOOL_TEXT ))
- _SetToolMenuCheck( hWnd, IDM_MARKUP_TOOL_TEXT );
- return( 1 );
- }
- }
-
- return( DefWindowProc( hWnd, message, wParam, lParam ) );
- }
-
-
-
- /* This function is the callback for the external window that
- /* we let Eroica control */
-
- EXPORT(LRESULT) EroicaExtWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
- {
- IN_DOCWIN docwinID = GetWindowLong( hWnd, 0 );
- /* int mode; */
-
- switch (message) {
- case WM_CLOSE:
- if (docwinID)
- IN_UnregisterExternalDocumentWindow( docwinID );
- break;
-
- case WM_SIZE:
- switch (wParam) {
- case SIZE_MAXIMIZED:
- case SIZE_MINIMIZED:
- case SIZE_RESTORED:
- if (docwinID)
- IN_ResetExternalDocumentWindowSize( docwinID );
- break;
- }
- break;
-
- case WM_COMMAND:
- switch (wParam) {
- case IDM_EXIT:
- PostMessage( hWnd, WM_CLOSE, 0, 0 );
- return( 0 );
-
- case IDM_VIEW_FIT:
- if (docwinID)
- IN_SetZoom( docwinID, 3 );
- return( 1 );
-
- case IDM_VIEW_ZOOMIN:
- if (docwinID)
- IN_SetZoom( docwinID, 1 );
- return( 1 );
-
- case IDM_VIEW_ZOOMOUT:
- if (docwinID)
- IN_SetZoom( docwinID, 2 );
- return( 1 );
-
- }
- }
-
- return( DefWindowProc( hWnd, message, wParam, lParam ) );
- }
-
-
- /* DEMO.C */
- /* end of file */
-
-
-