/*********************************************************************** * DLLDEMO32.CPP - demo of VTG32.DLL usage * Copyright Unigraf 1996, 1997, 1998 * * NOTE! * All the VTG.DLL related stuff is colleced into the * DLLDemo() function. The other functions contain things * that has to be done in applications written in C for * Windows in order to show a window and some text in it. * * This example does the following with the VTG.DLL: * - get VTG.DLL version * - get value of O.K. replies from VTG.DLL (in order * to be compatible with old versions of the VTG.DLL, * this value can be changed in the .ini file). * - Check if any VTG card is installed. Select the first installed * card, if not found use silent mode. * - Read the cards version. * - Install a VTG color file in the card. * - Install a VTG timing file in the card. * - Install a VTG picture file in the card. * * The results from the different calls are shown in the window * created by this example application. */ #include #include #include #include "vtg32.h" #define min(a,b) (((a) < (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b)) int VTG_OK; int numlines = 0; struct { char str[200]; } messages[10]; long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ; void DLLDemo (void); /*********************************************************************** * * WinMain - the usual Windows main function where it * all starts from. * */ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { static char szAppName[] = "DLLDem32" ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; if (!hPrevInstance) { wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; RegisterClass (&wndclass) ; } hwnd = CreateWindow (szAppName, "VTG32.DLL Demo", WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, nCmdShow) ; DLLDemo (); UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } /*********************************************************************** * * WinMain - the usual Windows main function where it * all starts from. * */ long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { static short cxChar, cxCaps, cyChar, cxClient, cyClient, nMaxWidth, nVscrollPos, nVscrollMax, nHscrollPos, nHscrollMax ; HDC hdc ; short i, x, y, nPaintBeg, nPaintEnd, nVscrollInc, nHscrollInc ; PAINTSTRUCT ps ; TEXTMETRIC tm ; switch (message) { case WM_CREATE: hdc = GetDC (hwnd) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmAveCharWidth ; cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ; cyChar = tm.tmHeight + tm.tmExternalLeading ; ReleaseDC (hwnd, hdc) ; nMaxWidth = 40 * cxChar + 22 * cxCaps ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; nVscrollMax = max (0, numlines + 2 - cyClient / cyChar) ; nVscrollPos = min (nVscrollPos, nVscrollMax) ; SetScrollRange (hwnd, SB_VERT, 0, nVscrollMax, FALSE) ; SetScrollPos (hwnd, SB_VERT, nVscrollPos, TRUE) ; nHscrollMax = max (0, 2 + (nMaxWidth - cxClient) / cxChar) ; nHscrollPos = min (nHscrollPos, nHscrollMax) ; SetScrollRange (hwnd, SB_HORZ, 0, nHscrollMax, FALSE) ; SetScrollPos (hwnd, SB_HORZ, nHscrollPos, TRUE) ; return 0 ; case WM_VSCROLL: switch (wParam) { case SB_TOP: nVscrollInc = -nVscrollPos ; break ; case SB_BOTTOM: nVscrollInc = nVscrollMax - nVscrollPos ; break ; case SB_LINEUP: nVscrollInc = -1 ; break ; case SB_LINEDOWN: nVscrollInc = 1 ; break ; case SB_PAGEUP: nVscrollInc = min (-1, -cyClient / cyChar) ; break ; case SB_PAGEDOWN: nVscrollInc = max (1, cyClient / cyChar) ; break ; case SB_THUMBTRACK: nVscrollInc = LOWORD (lParam) - nVscrollPos ; break ; default: nVscrollInc = 0 ; } nVscrollInc = max (-nVscrollPos, min (nVscrollInc, nVscrollMax - nVscrollPos)) ; if (nVscrollInc != 0) { nVscrollPos += nVscrollInc ; ScrollWindow (hwnd, 0, -cyChar * nVscrollInc, NULL, NULL) ; SetScrollPos (hwnd, SB_VERT, nVscrollPos, TRUE) ; UpdateWindow (hwnd) ; } return 0 ; case WM_HSCROLL: switch (wParam) { case SB_LINEUP: nHscrollInc = -1 ; break ; case SB_LINEDOWN: nHscrollInc = 1 ; break ; case SB_PAGEUP: nHscrollInc = -8 ; break ; case SB_PAGEDOWN: nHscrollInc = 8 ; break ; case SB_THUMBPOSITION: nHscrollInc = LOWORD (lParam) - nHscrollPos ; break ; default: nHscrollInc = 0 ; } nHscrollInc = max (-nHscrollPos, min (nHscrollInc, nHscrollMax - nHscrollPos)) ; if (nHscrollInc != 0) { nHscrollPos += nHscrollInc ; ScrollWindow (hwnd, -cxChar * nHscrollInc, 0, NULL, NULL) ; SetScrollPos (hwnd, SB_HORZ, nHscrollPos, TRUE) ; } return 0 ; case WM_KEYDOWN: switch (wParam) { case VK_HOME: SendMessage (hwnd, WM_VSCROLL, SB_TOP, 0L) ; break ; case VK_END: SendMessage (hwnd, WM_VSCROLL, SB_BOTTOM, 0L) ; break ; case VK_PRIOR: SendMessage (hwnd, WM_VSCROLL, SB_PAGEUP, 0L) ; break ; case VK_NEXT: SendMessage (hwnd, WM_VSCROLL, SB_PAGEDOWN, 0L) ; break ; case VK_UP: SendMessage (hwnd, WM_VSCROLL, SB_LINEUP, 0L) ; break ; case VK_DOWN: SendMessage (hwnd, WM_VSCROLL, SB_LINEDOWN, 0L) ; break ; case VK_LEFT: SendMessage (hwnd, WM_HSCROLL, SB_PAGEUP, 0L) ; break ; case VK_RIGHT: SendMessage (hwnd, WM_HSCROLL, SB_PAGEDOWN, 0L) ; break ; } return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; nPaintBeg = max (0, nVscrollPos + ps.rcPaint.top / cyChar - 1) ; nPaintEnd = min (numlines, nVscrollPos + ps.rcPaint.bottom / cyChar) ; for (i = nPaintBeg ; i < nPaintEnd ; i++) { x = cxChar * (1 - nHscrollPos) ; y = cyChar * (1 - nVscrollPos + i) ; TextOut (hdc, x, y, messages[i].str, lstrlen (messages[i].str)) ; } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } /*********************************************************************** * * DLLDemo - the actual demo of how to use VTG.DLL * */ void DLLDemo (void) { int cardNum = 0; /* Card number 0: silent mode */ char buffer[200] = ""; char *colorFile = "COL-01.VTC"; char *timingFile = "TIM-01.VTT"; char *pictureFile = "PAT-01.VTP"; char cards[8][80], buf[800]; int i; /*--------------- Read version of VTG.DLL ---------------*/ GetVTGDLLVersion(buffer); if (strcmp(buffer, "") != 0) sprintf(messages[numlines].str, "DLL version : %s", buffer); else sprintf(messages[numlines].str, "DLL version can't be read"); numlines++; /*----- Get return value, when DLL functions return successfully -----*/ VTG_OK = GetValueOfVTG_OK(); sprintf(messages[numlines].str, "VTG_OK = %d", VTG_OK); numlines++; /*--------------- Check if any VTG card is found -----------*/ if(VtgCardScan(buf)) { sscanf(buf,"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", &cards[0],&cards[1],&cards[2],&cards[3], &cards[4],&cards[5],&cards[6],&cards[7]); /*-- Search for installed cards from the list of alternatives ----*/ for(i=0;i<8;i++) { if ( strcmp(cards[i],"No_card") != 0) { if(IsVTGCardPresent(i+1)) { if(cardNum==0) cardNum = i+1; sprintf(messages[numlines].str, "%d. card found (%s)", i+1, cards[i]); numlines++; } } } } if (cardNum == 0){ sprintf(messages[numlines].str, "VTG Card is not present"); numlines++; } /*--------------- Open the VTG card ------------------------*/ cardNum = VTG_OpenCard(cardNum); if(cardNum < 0) { sprintf (messages[numlines].str, "VTGOpenCard failed"); numlines++; return; } /*------------------ Read VTG card version ------------------*/ if (GetVtgCardVersion(cardNum, buffer) == 0) { sprintf (messages[numlines].str, "VTG Card is present but version can not be read"); numlines++; return; } sprintf(messages[numlines].str, "VTG card version is \"%s\"", buffer); numlines++; /*------------------ Set colour file ------------------*/ if (VTGFile_col(cardNum, colorFile) != VTG_OK) { GetVTGErrorMessage(GetVTGError(cardNum), buffer); sprintf(messages[numlines++].str, "Setting of colour file \"%s\" failed", colorFile); sprintf(messages[numlines++].str, "Error: %s", buffer); return; } sprintf(messages[numlines++].str, "Colour file \"%s\" is set", colorFile); /*------------------ Set timing file ------------------*/ if (VTGFile_tim(cardNum, timingFile) != VTG_OK) { GetVTGErrorMessage(GetVTGError(cardNum), buffer); sprintf(messages[numlines++].str, "Setting of timing file \"%s\" failed", timingFile); sprintf(messages[numlines++].str, "Error: %s", buffer); return; } sprintf(messages[numlines++].str, "Timing file \"%s\" is set", timingFile); /*------------------ Set picture file ------------------*/ if (VTGFile_pic(cardNum, pictureFile) != VTG_OK) { GetVTGErrorMessage(GetVTGError(cardNum), buffer); sprintf(messages[numlines++].str, "Setting of picture file \"%s\" failed", pictureFile); sprintf(messages[numlines++].str, "Error: %s", buffer); return; } sprintf(messages[numlines++].str, "Picture file \"%s\" is set", pictureFile); VTG_CloseCard(cardNum); return; }