home *** CD-ROM | disk | FTP | other *** search
-
- // File to create a window interface for ViewConvert
-
-
- #include <windows.h>
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "Tfundecl.h"
- #include "VOstd.h"
-
- CHAR *ProgName = __FILE__;
- VIEW view;
- BOOL save_as_ascii,
- convert_dynamics;
- CHAR *path;
- BOOL result;
-
-
- long APIENTRY WndProc(HWND, UINT, UINT, LONG);
- long APIENTRY HlpWndProc(HWND, UINT, UINT, LONG);
- int vwcnvrt( int, int, int, char *, CHAR * );
- void translate_args( int argc, char **argv, int *atob, int *btoa,
- int *dyn_convert, char **output_view, char **input_view);
-
- #define EDITID 1
- #define LOWORD /* Program won't work without this macro redefined */
-
- HWND hwnd;
- HWND hwndHlp, hwndClose;
- HANDLE hInstan, hInst;
-
- char *messages[6] = {
- " View converted. ",
- " Error saving view. View not saved.",
- " Error loading view. Conversion not done.",
- " warning: could not terminate cleanly.",
- "error in initialization. conversion not done"
- };
-
-
-
-
-
- int APIENTRY WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine,
- int nCmdShow )
- {
-
-
- MSG msg;
- WNDCLASS wndclass;
- char * szAppName = "vc";
- char * class_name = "ViewConvert";
- int argc=0;
- char **argv;
-
-
- hInstan = hInstance;
-
- make_argv(&argc,&argv,GetCommandLine());
-
- if ( argc > 2 )
- {
- int atob=0; /* true for ascii to binary conv. */
- int btoa=0; /* true for binary to ascii conv. */
- int dyn_convert=0; /* true to convert dynamics */
- char *input_name; /* source view name */
- char *output_name; /* output view name */
-
-
- /* if enough command line args are given, convert them */
- /* and call vwcnvrt, otherwise use davids' dialog to */
- /* get the args needed */
- translate_args(argc,argv,&atob,&btoa,&dyn_convert,&output_name,&input_name);
- vwcnvrt( atob, btoa, dyn_convert, input_name,output_name );
- }
- else
- {
- if (!hPrevInstance)
- {
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.hInstance = hInstance;
- wndclass.lpszClassName = class_name;
- wndclass.lpszMenuName = "dvmenu";
- wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
- wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
- wndclass.lpfnWndProc = WndProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
-
- RegisterClass(&wndclass);
- }
-
- hwnd = CreateWindow( class_name, class_name,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 640, 340,
- NULL,
- NULL,
- hInstance,
- NULL );
-
- ShowWindow( hwnd, nCmdShow );
-
- UpdateWindow( hwnd );
-
- while (GetMessage( &msg, NULL, 0, 0 ))
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
- return msg.wParam;
- }
- }
-
- LRESULT CALLBACK WndProc(HWND hwnd, UINT message, UINT wParam, LONG lParam)
- {
- HDC hdc;
- PAINTSTRUCT ps;
- RECT rect;
- HPEN hPen, oldPen;
- static HWND hwndButtonA, hwndButtonB, hwndButtonC;
- static HWND hwndEditA, hwndEditB, hwndOK, hwndClear, hwndCancel, hwndHelp;
- static int cxChar, cyChar;
- int t_length = 0;
- TEXTMETRIC tm;
- char * string = "off";
- WORD A_check = 0;
- WORD B_check = 0;
- char * text_in;
- char * text_out = "";
- static int atob = 0;
- static int btoa = 0;
- static int dyn_convert = 0;
-
-
- switch (message)
- {
- case WM_CREATE :
- hdc = GetDC(hwnd);
- SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
- GetTextMetrics(hdc, &tm);
- cxChar = tm.tmAveCharWidth;
- cyChar = tm.tmHeight + tm.tmExternalLeading;
-
-
- hwndButtonA = CreateWindow("button", " ascii to binary",
- WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
- cxChar, cyChar, (20 * cxChar),
- (7 * cyChar / 4), hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL);
-
- hwndButtonB = CreateWindow("button", " binary to ascii",
- WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
- cxChar, cyChar + 60, (20 * cxChar),
- (7 * cyChar / 4), hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL);
-
- hwndButtonC = CreateWindow("button", " Pre 8.0 dynamics",
- WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
- cxChar, cyChar + 120, (20 * cxChar),
- (7 * cyChar / 4), hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL);
-
- hPen = GetStockObject(WHITE_PEN);
-
- oldPen = SelectObject(hdc, hPen);
- TextOut(hwnd, cxChar + 200, cyChar + 400, "From", 7);
- SelectObject(hdc, oldPen);
-
-
- hwndEditA = CreateWindow("edit", NULL,
- ES_AUTOHSCROLL | WS_BORDER | WS_CHILD | WS_VISIBLE ,
- cxChar, cyChar + 220, 120, 60, hwnd,
- (HMENU) 1,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL );
-
- hwndEditB = CreateWindow("edit", NULL,
- ES_AUTOHSCROLL | WS_BORDER | WS_CHILD | WS_VISIBLE ,
- cxChar + 200, cyChar + 220, 120, 60, hwnd,
- (HMENU) 1,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL );
-
- hwndOK = CreateWindow( "button", " OK ",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- cxChar + 500, cyChar, 80, 60, hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL );
-
- hwndClear = CreateWindow( "button", " CLEAR ",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- cxChar + 500, cyChar+60, 80, 60, hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL );
-
- hwndCancel = CreateWindow( "button", " EXIT ",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- cxChar + 500, cyChar+120, 80, 60, hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL );
-
- hwndHelp = CreateWindow( "button", " HELP ",
- WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- cxChar + 500, cyChar+180, 80, 60, hwnd, 0,
- ((LPCREATESTRUCT)lParam)->hInstance,
- NULL );
-
-
-
- SendMessage(hwndButtonA, BM_SETCHECK, 1, 0L);
- ReleaseDC(hwnd, hdc);
- return 0;
-
-
- case WM_COMMAND :
-
- if ((LOWORD(lParam) == (long)hwndEditA) || (LOWORD(lParam) == (long)hwndEditB))
- return 0;
-
- if (LOWORD(lParam) == (long)hwndCancel)
- exit(0);
-
- if (LOWORD(lParam) == (long)hwndClose)
- CloseWindow( hwndHlp );
-
- if (LOWORD(lParam) == (long)hwndClear)
- {
- (WORD)SendMessage(hwndButtonA, BM_SETCHECK, 0, 0L);
- (WORD)SendMessage(hwndButtonB, BM_SETCHECK, 0, 0L);
- (WORD)SendMessage(hwndButtonC, BM_SETCHECK, 0, 0L);
- SetWindowText(hwndEditA, "");
- SetWindowText(hwndEditB, "");
- }
-
- if (LOWORD(lParam) == (long)hwndHelp)
- {
- HWND hwndHlp;
- HDC hdc;
- WNDCLASS hlpclass;
- LPCTSTR help_text;
- RECT rect;
-
-
- hlpclass.style = CS_HREDRAW | CS_VREDRAW;
- hlpclass.hInstance = hInst;
- hlpclass.lpszClassName = "help";
- hlpclass.lpszMenuName = "ViewConvert Help";
- hlpclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- hlpclass.hCursor = LoadCursor (NULL, IDC_ARROW);
- hlpclass.hbrBackground = GetStockObject(WHITE_BRUSH);
- hlpclass.lpfnWndProc = DefWindowProc;
- hlpclass.cbClsExtra = 0;
- hlpclass.cbWndExtra = 0;
-
- RegisterClass(&hlpclass);
-
- hwndHlp = CreateWindow( "help", "HELP",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 640, 340,
- NULL,
- NULL,
- hInst,
- NULL );
-
- ShowWindow(hwndHlp, SW_SHOWNORMAL);
-
- help_text = "VIEWCONV.EXE - View Conversion Utility \n \
- \n \
- This program converts a view file from binary to ASCII or from ASCII \n \
- to binary save format. \n \
- Select the \"Binary to ASCII\" or \"ASCII to Binary\" check box to specify \n \
- the type of conversion. \n \
- Select the \"Pre 8.0 Dynamics\" check box only if your view contains dynamics \n \
- created using a version of DataViews prior to 8.0. \n \
- \n \
- Type the name of the view file to be converted in the left text box and its \n \
- new file name in the right text box. Leaving the right text box empty will \n \
- result in the same filename being used. Full path names may be used to indicate \n \
- view files. \n \
- \n \
- Select \"OK\" to execute the conversion. \n \
- Select \"CLEAR\" to clear all text from the screen without exiting the program. \n \
- Select \"EXIT\" to exit the program without performing the conversion. \n ";
-
- rect.left = 10;
- rect.top = 10;
- rect.right = 640;
- rect.bottom = 400;
-
- hdc = GetDC(hwndHlp);
- DrawText(hdc, help_text, -1, &rect, 0);
- ReleaseDC(hwndHlp, hdc);
-
-
- }
-
- if (LOWORD(lParam) != (long)hwndButtonC)
- SendMessage((HWND)LOWORD(lParam), BM_SETCHECK,
- (WORD)!SendMessage((HWND)LOWORD(lParam), BM_GETCHECK, 0, 0L), 0L);
-
- A_check = (WORD)SendMessage(hwndButtonA, BM_GETCHECK, 0, 0L);
- B_check = (WORD)SendMessage(hwndButtonB, BM_GETCHECK, 0, 0L);
- dyn_convert = (WORD)SendMessage(hwndButtonC, BM_GETCHECK, 1, 0L);
-
- if (LOWORD(lParam) == (long)hwndButtonA)
- {
- SendMessage(hwndButtonA, BM_SETCHECK, 1, 0L);
- SendMessage(hwndButtonB, BM_SETCHECK, 0, 0L);
- atob = TRUE;
- btoa = FALSE;
- }
- else if (LOWORD(lParam) == (long)hwndButtonB)
- {
- SendMessage(hwndButtonB, BM_SETCHECK, 1, 0L);
- SendMessage(hwndButtonA, BM_SETCHECK, 0, 0L);
- atob = FALSE;
- btoa = TRUE;
- }
-
-
-
- if((WORD)SendMessage( hwndOK, BM_GETSTATE, 1, 0L ))
- {
- int result=0;
- t_length = GetWindowTextLength( hwndEditA );
- if (t_length == 0)
- {
- MessageBox(hwnd, "A filename must be provided.",
- "ViewConvert", MB_APPLMODAL );
- return 0;
- }
- text_in = (char *)malloc(t_length+1);
- GetWindowText( hwndEditA, text_in, t_length+1 );
-
- t_length = GetWindowTextLength( hwndEditB );
- text_out = (char *)malloc(t_length+1);
- GetWindowText( hwndEditB, text_out, t_length+1 );
-
- result = vwcnvrt( atob, btoa, dyn_convert, text_in, text_out );
- MessageBox(hwnd,messages[result],"ViewConvert",MB_APPLMODAL);
- }
-
- return 0;
-
- case WM_PAINT :
- hdc = BeginPaint( hwnd, &ps );
-
- GetClientRect( hwnd, &rect );
- TextOut(hdc, 11, 220, "From", 4);
- TextOut(hdc, 211, 220, "To", 2);
- EndPaint( hwnd, &ps );
-
- return 0;
-
- case WM_SETFOCUS :
- SetFocus(hwnd);
- return 0;
-
- case WM_DESTROY :
- PostQuitMessage (0);
- return 0;
- }
- return DefWindowProc( hwnd, message, wParam, lParam );
- }
-
-
-
- int vwcnvrt( int atob, int btoa, int dyn_convert, char * text_in, char * text_out )
- {
- LOCAL CHAR *Defaultpath = NULL; /* Use value of V_config var DVPATH */
- LOCAL CHAR * view_name;
- LOCAL CHAR * converted_view = "";
- INT save_as_ascii, len;
- INT convert_dynamics;
- int ret_val;
-
-
- ret_val = 0;
- view_name = text_in;
- save_as_ascii = btoa;
- convert_dynamics = dyn_convert;
-
- len = strlen(text_out);
- if (len)
- {
- converted_view = (char *)malloc(len+1);
- strcpy(converted_view, text_out);
- }
- else
- {
- converted_view = (char *)malloc(strlen(text_in)+1);
- strcpy(converted_view, text_in);
- }
-
- path = Defaultpath;
-
- if (!TInit (path, (CHAR *)NULL))
- {
-
- ret_val = 4;
- return( ret_val );
- }
-
- /* get source view */
- view = TviLoad (view_name);
-
-
- if (view)
- {
- if (convert_dynamics && TviTestDynamics(view))
- TviConvertDynamics(view);
- if (save_as_ascii) result = TviASCIISave(view, converted_view);
- else result = TviSave(view, converted_view);
- if (!result)
- ret_val = 1;
- else
- ret_val = 0;
-
- }
- else
- {
- ret_val = 2;
-
- (VOID)TTerminate();
-
- }
-
- /* tidy up and exit */
- if (!TviDestroy( view ))
- {
- (VOID)fprintf (stderr, " warning: could not destroy view.\n",
- ProgName);
- (VOID)TTerminate();
-
- }
- else if (!TTerminate())
- {
- ret_val = 3;
-
- }
-
- return( ret_val );
- }
-
- /** **/
- /** translate command line args. This set the variables **/
- /** needed to call the function vwcnvrt **/
- /** **/
- void translate_args( int argc, char **argv, int *atob, int *btoa,
- int *dyn_convert, char **output_view, char **input_view)
- {
-
- /* conversion direction depends on 1st arg */
- if (strcmp(argv[1],"a") == 0 || strcmp(argv[1],"A") == 0 )
- {
- *btoa = TRUE;
- *dyn_convert = FALSE;
- }
- else
- if (strcmp(argv[1],"b") == 0 || strcmp(argv[1],"B") == 0 )
- {
- *atob = TRUE;
- *dyn_convert = NO;
- }
- else
- if (strcmp(argv[1],"d") == 0 || strcmp(argv[1],"D") == 0 )
- {
- *atob = TRUE;
- *dyn_convert = YES;
- }
- else
- if (strcmp(argv[1],"ad") == 0 || strcmp(argv[1],"AD") == 0)
- {
- *btoa = YES;
- *dyn_convert = YES;
- }
- else
- if (strcmp(argv[1],"bd") == 0 || strcmp(argv[1],"BD") == 0)
- {
- *atob = TRUE;
- *dyn_convert = YES;
- }
- else
- {
- (VOID)fprintf (stderr,
- "%s: first argument must be 'a','b','d','ad' or 'bd' (not '%s').\n",
- ProgName, argv[1]);
- exit(EXIT_ERR);
- }
-
- if ( argc > 4 )
- path = argv[4];
-
- *input_view = argv[2];
- *output_view = argv[3];
-
- }
-
-
-
-
-