Page 1 of 1

Using DLL function with Fivewin

Posted: Sat Jun 26, 2010 9:17 pm
by sygecom
Hello,
I need to print on the back of the check using the DLL chron32.dll I saw that has the function PLUS_EnviaBloco () that I believe can be used for printing on the back of checks, but I am not able to use only this function of the DLL, follow below as I am using in Fivewin and more in the example. C that came with the DLL, if someone could give me any tips on how to use this function with Fivewin, thank you.

examples already running less PL_EnviaBloco() :

Code: Select all

DLL FUNCTION PL_Abre ( idPorta AS 7 ) AS LONG PASCAL FROM "PLUS_Abre" LIB xChron32
DLL FUNCTION PL_UltimoErro ( idPorta AS 7 ) AS LONG PASCAL FROM "PLUS_UltimoErro" LIB xChron32
DLL FUNCTION PL_Fecha ( idPorta AS 7 ) AS LONG PASCAL FROM "PLUS_Fecha" LIB xChron32
DLL FUNCTION PL_Cheque ( idPorta AS 7 ,;
               nCampo AS 7 ,;
               sCampo AS LPSTR ) AS LONG PASCAL FROM "PLUS_CampoCheque" LIB xChron32
DLL FUNCTION PL_Status ( idPorta AS 7 ,;
               nCampo AS 7 ) AS LONG PASCAL FROM "PLUS_Status" LIB xChron32

DLL FUNCTION PL_Print ( idPorta AS 7 ) AS LONG PASCAL FROM "PLUS_ImprimeCheque" LIB xChron32
DLL FUNCTION PL_Ejeta ( idPorta AS 7 ) AS LONG PASCAL FROM "PLUS_Ejeta" LIB xChron32

DLL FUNCTION PL_EnviaBloco ( idPorta AS 7,;
                             cCampo AS STRING ,; // PTR(error) LPSTR(não imprime nada) CHAR (da erro)  STRING(não imprime)
                             nCampo AS 7 ) AS LONG PASCAL FROM "PLUS_EnviaBloco" LIB xChron32

DLL FUNCTION PL_EnviaByte ( idPorta AS 7,;
                             cCampo AS 7 ) AS LONG PASCAL FROM "PLUS_EnviaByte" LIB xChron32
 
Functions .C

Code: Select all

/**************************************************************************\
 *
 * Project     : Programa de Teste da DLL da Chronos
 *
 * Component   : TESTE.EXE
 *
 * Module Name : TESTE.C
 *
 * Description : Programa de Teste
 *
 * O.S.        : Windows 32 Bits (Win32s, Windows NT and Windows 95)
 * Language    : C (ANSI)
 * Compiler    : Borland C++ for Dos/Windows Version 4.52
 *
 * Comments    : 
 *
 * Vendor      : Analisa Consultoria em Informatica Ltda
 *
 * History Log :
 *
 *    Version Date      Author          Description
 *    ------- --------- --------------- -----------------------------------
 *    1.00    28/09/99  Carlos Yallouz  Created
 *    ---------------------------------------------------------------------
\**************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <ctl3d.h>
#include <stdio.h>
#include <stdarg.h>
#include <io.h>
#include <string.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <stdlib.h>
#include "teste.rh"
#include "chronos.h"

#ifdef __WIN32__
  char szMainClass[] = "TESTE_CHRONOS32";
  HANDLE    hLog = NULL;
#else
  char szMainClass[] = "TESTE_CHRONOS16";
  int       hLog = 0;
#endif

HINSTANCE hInstance;    // First Instance
HWND      hMain;        // Main Window
HWND      hClient;      // Client Window (Modeless Dialog)
char      szPathExec[256]; // Execution Path
HFONT     hfontClient;

#define MAX_EDITBUFF 32000

static int IdPorta = 1;

/**************************************************************************
  buff_AddLine
 **************************************************************************/
static void buff_AddLine (LPCSTR lpszLine)
{
  UINT uBuffSize;
  UINT uLineSize;

  uLineSize = lstrlen (lpszLine);
  uBuffSize = Edit_GetTextLength(hClient);

  while ((uLineSize+uBuffSize) > MAX_EDITBUFF)
  {
    Edit_SetSel(hClient, 0, Edit_LineIndex(hClient, 1));
    Edit_ReplaceSel(hClient, "");
    uBuffSize = Edit_GetTextLength(hClient);
  }

  //
  // Append to the end of the buffer.
  //

  Edit_SetSel(hClient, 0x7FFF, 0x7FFF);
  Edit_ReplaceSel(hClient, lpszLine);
  Edit_SetSel(hClient, 0x7FFF, 0x7FFF);

  if (hLog)
  {
    DWORD dwSize = uLineSize;

#ifdef __WIN32__
    WriteFile (hLog, lpszLine, dwSize, &dwSize, NULL);
#else
    write (hLog,lpszLine,(unsigned)dwSize);
#endif
  }
}

/****************************************/

void Printf (LPSTR szFormato,...)
{
  va_list argumentos;
  char szBuff[512];

  va_start(argumentos,szFormato);
  vsprintf (szBuff,szFormato,argumentos);
  va_end(argumentos);
  strcat (szBuff,"\r\n");
  buff_AddLine (szBuff);
}

/**************************************************************************
  TurnLogOnOff
 **************************************************************************/
static void TurnLogOnOff (void)
{
  HMENU hMenu = GetMenu (hMain);
  BOOL  Checked;
  char  szLogFile[256];

  if (hMenu)
  {
    Checked = (GetMenuState (hMenu,IDM_LOGFILE, MF_BYCOMMAND) & MF_CHECKED) != 0;
    if (!Checked)
    {
      sprintf (szLogFile,"%sCHRONOS.LOG",szPathExec);
#ifdef __WIN32__
      hLog = CreateFile (szLogFile,
                         GENERIC_WRITE,
                         FILE_SHARE_WRITE | FILE_SHARE_READ,
                         NULL,
                         CREATE_ALWAYS,
                         FILE_ATTRIBUTE_NORMAL,
                         NULL);
      if (hLog == INVALID_HANDLE_VALUE)
      {
        hLog = NULL;
        MessageBeep(0);
        return;
      }
#else
      hLog = open (szLogFile, O_CREAT | O_APPEND | O_BINARY | O_WRONLY,
                              S_IREAD | S_IWRITE);
      if (hLog == -1)
      {
        hLog = NULL;
        MessageBeep(0);
        return;
      }
#endif

      CheckMenuItem (hMenu,IDM_LOGFILE,MF_CHECKED | MF_BYCOMMAND);
    }
    else
    {
      if (hLog)
      {
#ifdef __WIN32__
        CloseHandle(hLog);
#else
        close (hLog);
#endif
        hLog = NULL;
      }
      CheckMenuItem (hMenu,IDM_LOGFILE,MF_UNCHECKED | MF_BYCOMMAND);
    }
  }
}

/**************************************************************************
  ClearLog
 **************************************************************************/
static void ClearLog (void)
{
  BOOL opened = FALSE;
  char szLogFile[256];

  if (hLog)
  {
    TurnLogOnOff();
    opened = TRUE;
  }

  sprintf (szLogFile,"%sCHRONOS.LOG",szPathExec);
#ifdef __WIN32__
  hLog = CreateFile (szLogFile,
                     GENERIC_WRITE,
                     FILE_SHARE_WRITE | FILE_SHARE_READ,
                     NULL,
                     CREATE_ALWAYS,
                     FILE_ATTRIBUTE_NORMAL,
                     NULL);

  if (hLog != INVALID_HANDLE_VALUE)
    CloseHandle(hLog);
#else
  hLog = open (szLogFile, O_CREAT | O_TRUNC | O_BINARY | O_WRONLY,
                          S_IREAD | S_IWRITE);

  if (hLog == -1)
    hLog = 0;
#endif

  hLog = NULL;

  if (opened)
    TurnLogOnOff();
}

/**************************************************************************
  Implementacao das Funcoes de Acesso para Teste
 **************************************************************************/

typedef struct tagPARAMETROS {
  int NParam;      // Numero de Parametros
  LPSTR Prototipo; // Prototipacao da Funcao
  LPSTR Titulo[5]; // Titulo do Parametro
  LPSTR Param [5]; // Ponteiro para os parametros
  int   TamMax[5]; // Tamanho Maximo do Parametro
} PARAMETROS,
  FAR *LPPARAMETROS;

static PARAMETROS Param;

/////////////////////////////////////////////////////////////////////////////

#pragma argsused
BOOL CALLBACK _export CallBackParam (HWND hwnd,
                                    UINT uMsg,
                                    WPARAM wParam,
                                    LPARAM lParam)
{
   switch (uMsg)
   {
     case WM_INITDIALOG:
          {
            int i;

            SetDlgItemText (hwnd,ID_FUNCAO,Param.Prototipo);
            SetDlgItemInt (hwnd,ID_PORTA,IdPorta,FALSE);

            for (i=0; i < Param.NParam; i++)
            {
              SetDlgItemText (hwnd,ID_TXTPARAM1+i, Param.Titulo[i]);
              SetDlgItemText (hwnd,ID_PARAM1+i, "");
              Edit_LimitText (GetDlgItem (hwnd, ID_PARAM1+i),Param.TamMax[i]);

              ShowWindow (GetDlgItem (hwnd,ID_TXTPARAM1+i), SW_SHOW);
              ShowWindow (GetDlgItem (hwnd,ID_PARAM1+i), SW_SHOW);
            }
          }
          return TRUE;

     case WM_COMMAND:
          switch (GET_WM_COMMAND_ID (wParam,lParam))
          {
            case IDOK:
                 {
                   int i;

                   for (i=0; i < Param.NParam; i++)
                     GetDlgItemText (hwnd,ID_PARAM1+i,
                                     Param.Param[i],
                                     Param.TamMax[i]);
                 }
                 EndDialog (hwnd,TRUE);
                 break;

            case IDCANCEL:
                 EndDialog (hwnd,FALSE);
                 break;
          }
          break;
   }

   return FALSE;
}


//////////////////////////////

static void set_porta (int porta)
{
  HMENU hMenu = GetSubMenu (hMain,0);
  char szLinha[128];
  int i;

  if (!porta)
    porta = 1;

  for (i = 1; i <= 9; i++)
    if (i == porta)
      CheckMenuItem (hMenu, i, MF_BYCOMMAND | MF_CHECKED);
    else
      CheckMenuItem (hMenu, i, MF_BYCOMMAND | MF_UNCHECKED);

  sprintf (szLinha,"Teste Chronos: COM%d",porta);
  SetWindowText (hMain,szLinha);

  IdPorta = porta;
}

///////////////////////

static BOOL pede_parametros (void)
{
  return DialogBox (hInstance,
                    MAKEINTRESOURCE(D_PARAMETROS),
                    hMain,
                    (DLGPROC)CallBackParam);
}

///////////////////////

static void mostra_resultado (int Resultado)
{
  Printf ("Retorno = %d",Resultado);
}

///////////////////////

static void exec_abre (void)
{
  Printf ("PLUS_Abre (%d)",IdPorta);
  mostra_resultado (PLUS_Abre (IdPorta));
}


///////////////////////

static void exec_abre_ex (void)
{
  char  Velocidade[10];
  char  Paridade  [2];
  char  DataBits  [2];
  char  StopBits  [2];

  memset (&Param,0,sizeof(Param));
  Param.Prototipo = "PLUS_AbreEx (int IdPorta, long Velocidade, int Paridade, "
                                  "int DataBits, int StopBits)";
  Param.NParam = 4;
  Param.Titulo[0] = "&Velocidade";
  Param.Param[0] = Velocidade;
  Param.TamMax[0] = 9;

  Param.Titulo[1] = "&Paridade (0=N, 1=O, 2=E)";
  Param.Param[1] = Paridade;
  Param.TamMax[1] = 2;

  Param.Titulo[2] = "&DataBits (7 ou 8)";
  Param.Param[2] = DataBits;
  Param.TamMax[2] = 2;

  Param.Titulo[3] = "&StopBits (1 ou 2)";
  Param.Param[3] = StopBits;
  Param.TamMax[3] = 2;

  if (pede_parametros())
  {
    DWORD dwBaud;
    int   iParidade;
    int   iDataBits;
    int   iStopBits;

    dwBaud = atol (Velocidade);
    iParidade = atoi (Paridade);
    iDataBits = atoi (DataBits);
    iStopBits = atoi (StopBits);

    Printf ("PLUS_AbreEx (%d, %lu, %d, %d, %d)",IdPorta,dwBaud,iParidade,iDataBits, iStopBits);
    mostra_resultado (PLUS_AbreEx (IdPorta, dwBaud, iParidade, iDataBits, iStopBits));
  }
}

////////////////////////

static void exec_fecha (void)
{
  Printf ("PLUS_Fecha (%d)",IdPorta);
  mostra_resultado (PLUS_Fecha (IdPorta));
}

/////////////////////////

static void exec_enviabyte (void)
{
  char Linha[10];
  BYTE valor;

  memset (&Param,0,sizeof(Param));

  Param.Prototipo = "PLUS_EnviaByte (int IdPorta, int Byte)";
  Param.NParam = 1;
  Param.Titulo[0] = "&Byte";
  Param.Param[0] = Linha;
  Param.TamMax[0] = 2;

  if (pede_parametros ())
  {
    if (strlen (Linha) >= 2) // Dois Bytes ?
      valor = (BYTE)atoi (Linha);
    else
        valor = (BYTE)Linha[0];

    Printf ("PLUS_EnviaByte (%d, %u)",IdPorta, valor);
    mostra_resultado (PLUS_EnviaByte (IdPorta, valor));
  }
}

/////////////////////////

static void exec_enviabloco (void)
{
  char Linha[256];
  char Tamanho[10];
  int  cbSize;

  memset (Linha,0,sizeof(Linha));
  Tamanho[0] = 0;
  memset (&Param,0,sizeof(Param));

  Param.Prototipo = "PLUS_EnviaByte (int IdPorta, LPBYTE lpBuffer, int cbSize)";
  Param.NParam = 2;
  Param.Titulo[0] = "&lpBuffer";
  Param.Param[0] = Linha;
  Param.TamMax[0] = sizeof (Linha)-1;

  Param.Titulo[1] = "&cbSize";
  Param.Param[1] = Tamanho;
  Param.TamMax[1] = 4;

  if (pede_parametros ())
  {
    cbSize = atoi (Tamanho);
    if (cbSize > 255)
      cbSize = 255;

    Printf ("PLUS_EnviaBloco (%d, %s, %u)",IdPorta, Linha, cbSize);
    mostra_resultado (PLUS_EnviaBloco (IdPorta, (LPBYTE)Linha, cbSize));
  }
}

/////////////////////////

static void exec_habyte (void)
{
  Printf ("PLUS_HaByte (%d)",IdPorta);
  mostra_resultado (PLUS_HaByte (IdPorta));
}

/////////////////////////

static void exec_recebebyte (void)
{
  int result;
  Printf ("PLUS_RecebeByte (%d)",IdPorta);
  result = PLUS_RecebeByte (IdPorta);
  if ((result <= ' ') || (result >= 127))
    mostra_resultado (result);
  else
    Printf ("Retorno: Caractere %c",result);
}

/////////////////////////

static void exec_ultimoerro (void)
{
  Printf ("PLUS_UltimoErro (%d)",IdPorta);
  mostra_resultado (PLUS_UltimoErro (IdPorta));
}

/////////////////////////

static void exec_status (void)
{
  char Linha[10];
  int valor;

  memset (&Param,0,sizeof(Param));

  Param.Prototipo = "PLUS_Status (int IdPorta, int IdStatus)";
  Param.NParam = 1;
  Param.Titulo[0] = "&IdStatus";
  Param.Param[0] = Linha;
  Param.TamMax[0] = 2;

  if (pede_parametros ())
  {
    valor = atoi (Linha);

    Printf ("PLUS_Status (%d, %u)",IdPorta, valor);
    mostra_resultado (PLUS_Status (IdPorta, valor));
  }
}

/////////////////////////

static void exec_ejeta (void)
{
  Printf ("PLUS_Ejeta (%d)",IdPorta);
  mostra_resultado (PLUS_Ejeta (IdPorta));
}

////////////////////////

static void exec_programabancos (void)
{
  char Linha[256];
  char sBanco[10];
  int  Banco;

  memset (Linha,0,sizeof(Linha));
  sBanco[0] = 0;
  memset (&Param,0,sizeof(Param));

  Param.Prototipo = "PLUS_ProgramaBancos (int IdPorta, int Banco, LPSTR lpszPrograma)";
  Param.NParam = 2;
  Param.Titulo[0] = "&Banco";
  Param.Param[0] = sBanco;
  Param.TamMax[0] = 4;

  Param.Titulo[1] = "&lpszPrograma";
  Param.Param[1] = Linha;
  Param.TamMax[1] = sizeof(Linha)-1;

  if (pede_parametros ())
  {
    Banco = atoi (sBanco);
    Printf ("PLUS_ProgramaBancos (%d, %u, %s)",IdPorta, Banco, Linha);
    mostra_resultado (PLUS_ProgramaBancos (IdPorta, Banco, Linha));
  }
}

////////////////////////

static void exec_campocheque (void)
{
  char Linha[256];
  char sCampo[10];
  int  Campo;

  memset (Linha,0,sizeof(Linha));
  sCampo[0] = 0;
  memset (&Param,0,sizeof(Param));

  Param.Prototipo = "PLUS_CampoCheque (int IdPorta, int Campo, LPSTR lpszValorCampo)";
  Param.NParam = 2;
  Param.Titulo[0] = "&Campo";
  Param.Param [0] = sCampo;
  Param.TamMax[0] = 3;

  Param.Titulo[1] = "&lpszValorCampo";
  Param.Param[1] = Linha;
  Param.TamMax[1] = sizeof(Linha)-1;

  if (pede_parametros ())
  {
    Campo = atoi (sCampo);
     Printf ("PLUS_CampoCheque (%d, %u, %s)",IdPorta, Campo, Linha);
    mostra_resultado (PLUS_CampoCheque (IdPorta, Campo, Linha));
  }
}

////////////////////////

static void exec_campochequepermanente (void)
{
  char Linha[256];
  char sCampo[10];
  int  Campo;

  memset (Linha,0,sizeof(Linha));
  sCampo[0] = 0;
  memset (&Param,0,sizeof(Param));

  Param.Prototipo = "PLUS_CampoChequePermanente (int IdPorta, int Campo, LPSTR lpszValorCampo)";
  Param.NParam = 2;
  Param.Titulo[0] = "&Campo";
  Param.Param [0] = sCampo;
  Param.TamMax[0] = 3;

  Param.Titulo[1] = "&lpszValorCampo";
  Param.Param[1] = Linha;
  Param.TamMax[1] = sizeof(Linha)-1;

  if (pede_parametros ())
  {
    Campo = atoi (sCampo);
    Printf ("PLUS_CampoChequePermanente (%d, %u, %s)",IdPorta, Campo, Linha);
    mostra_resultado (PLUS_CampoChequePermanente (IdPorta, Campo, Linha));
  }
}

////////////////////////

static void exec_imprimecheque (void)
{
  Printf ("PLUS_ImprimeCheque (%d)",IdPorta);
  mostra_resultado (PLUS_ImprimeCheque (IdPorta));
}

///////////////////////

static void exec_inicialeitura (void)
{
  Printf ("PLUS_IniciaLeitura (%d)",IdPorta);
  mostra_resultado (PLUS_IniciaLeitura (IdPorta));
}

//////////////////////

static void exec_cancelaleitura (void)
{
  Printf ("PLUS_FinalizaLeitura (%d)",IdPorta);
  mostra_resultado (PLUS_FinalizaLeitura (IdPorta));
}

//////////////////////

static void exec_leitura (void)
{
  char Linha[256];
  int  result;

  Printf ("PLUS_Leitura (%d, %p, 255)",IdPorta, Linha);

  result = PLUS_Leitura (IdPorta, Linha, 255);
  mostra_resultado (result);

  if (result == 1)
     Printf ("Buffer Lido: %s",Linha);
}

static void exec_lecmc7(void)
{
    int result;

    Printf ("PLUS_LeCMC7 (%d)",IdPorta);
    result = PLUS_SolicitaLeitura(IdPorta);

    mostra_resultado (result);
}

/**************************************************************************

  CallBackMain - CallBack for Main Window

 **************************************************************************/
long CALLBACK _export CallBackMain (HWND   hwnd,
                                    UINT   msg,
                                    WPARAM wParam,
                                    LPARAM lParam)
{
   switch (msg) {
    case WM_CREATE:
            hMain = hwnd;
         set_porta (0);
         PostMessage (hwnd,WM_COMMAND,IDM_ABOUT,0l);
         return 0;

    case WM_SIZE:
         /* Make sure the edit control always occupies the entire
             * client area.
          */
            if (hClient)
         {
            RECT rc;

            GetClientRect(hwnd, &rc);
            //
            // Outset border
                //
            InflateRect(&rc, 1, 1);
            MoveWindow(hClient, rc.top, rc.left, rc.right - rc.left, rc.bottom - rc.top, TRUE);
          }
          break;

    case WM_COMMAND:
         switch (GET_WM_COMMAND_ID(wParam,lParam))
         {

           case IDM_ABOUT&#058;
                #ifdef __WIN32__
                  Printf ("<Programa de Teste da CHRON32.DLL>");
                #else
                        Printf ("<Programa de Teste da CHRON16s.DLL>");
                     #endif

                     Printf ("\tCopyright © 1999 CHRONOS S.A\r\n"
                        "\tVersão 1.03 - Marco de 2000");
                     break;

           case IDM_EXIT:
                PostMessage (hwnd,WM_CLOSE,0,0l);
                break;

           case IDM_LOGFILE:
                TurnLogOnOff();
                break;

           case IDM_CLEARLOG:
                ClearLog();
                break;

           case IDM_SELALL:
                Edit_SetSel(hClient, 0, 32767);
                break;

           case IDM_DELETE:
                Edit_SetSel(hClient, 0, 32767);
                Edit_ReplaceSel(hClient, "");
                break;

           case IDM_COPY:
                     PostMessage(hClient, WM_COPY, 0, 0L);
                break;

                // Funcoes
           case IDM_ABRE:
                exec_abre();
                break;

           case IDM_ABREX:
                exec_abre_ex();
                break;

           case IDM_FECHA:
                exec_fecha();
                break;

           case IDM_ENVIABYTE:
                exec_enviabyte();
                break;

           case IDM_ENVIABLOCO:
                exec_enviabloco();
                break;

              case IDM_HABYTE:
                exec_habyte();
                     break;

           case IDM_RECEBEBYTE:
                exec_recebebyte();
                break;

           case IDM_ULTIMOERRO:
                exec_ultimoerro();
                break;

           case IDM_STATUS:
                exec_status();
                break;

           case IDM_EJETA:
                exec_ejeta();
                break;

           case IDM_PROGRAMABANCOS:
                exec_programabancos();
                break;

           case IDM_CAMPOCHEQUE:
                exec_campocheque();
                break;

              case IDM_CAMPOCHEQUEP:
                exec_campochequepermanente();
                break;

           case IDM_IMPRIMECHEQUE:
                exec_imprimecheque();
                break;

           case IDM_INICIALEITURA:
                exec_inicialeitura();
                break;

           case IDM_CANCELALEITURA:
                exec_cancelaleitura();
                break;

           case IDM_LEITURA:
                exec_leitura();
                     break;
              case CM_PLUSLECMC:
                    exec_lecmc7();
                    break;
              case IDM_COM1:
              case IDM_COM2:
              case IDM_COM3:
           case IDM_COM4:
           case IDM_COM5:
           case IDM_COM6:
           case IDM_COM7:
           case IDM_COM8:
           case IDM_COM9:
                set_porta (GET_WM_COMMAND_ID(wParam,lParam) - IDM_COM1 + 1);
                break;
         }
         break;

    case WM_CLOSE:
         DestroyWindow (hwnd);
         return 0;

    case WM_DESTROY:
         PostQuitMessage (0);
         return 0;
  }

  return DefWindowProc (hwnd, msg, wParam, lParam);
}

/**************************************************************************/

static BOOL AppInit(HINSTANCE hinst,
                    HINSTANCE hinstPrev,
                    int showCmd)
{
    WNDCLASS cls;
    LOGFONT  lf;
    int i;

    if (GetModuleFileName ((HMODULE)hInstance,szPathExec,sizeof(szPathExec)))
      for (i=strlen(szPathExec)-1; i; i--)
        if (szPathExec[i] == '\\')
        {
          szPathExec[i+1] = 0;
          break;
        }

    if (!hinstPrev)
    {
      hInstance = hinst;

      cls.hCursor        = LoadCursor(NULL, IDC_ARROW);
      cls.hIcon          = NULL; //LoadIcon(hInstance, MAKEINTRESOURCE(IDR_MAINICON));
      cls.lpszMenuName   = MAKEINTRESOURCE(M_MAIN);
      cls.lpszClassName  = szMainClass;
      cls.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
      cls.hInstance      = hInstance;
      cls.style          = CS_BYTEALIGNCLIENT;
      cls.lpfnWndProc    = CallBackMain;
      cls.cbWndExtra     = 0;
      cls.cbClsExtra     = 0;

      if (!RegisterClass(&cls))
      {
        return FALSE;
      }

      if (Ctl3dRegister(hInstance))
        Ctl3dAutoSubclass(hInstance);
    }
    else
      return FALSE;

    // Create the main window

    hMain = CreateWindow(szMainClass,               // Class name
                         "Teste Chronos",          // Caption
                          WS_OVERLAPPEDWINDOW,    // Style bits
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          (HWND)NULL,             // Parent window (no parent)
                          (HMENU)NULL,            // use class menu
                          (HINSTANCE)hInstance,   // handle to window instance
                          (LPSTR)NULL             // no params to pass on
                           );
    if (!hMain)
        return FALSE;

    hClient = CreateWindow("EDIT", NULL,
            WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL |
            ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE,
            0, 0, 0, 0,
            hMain, (HMENU)0, hInstance, NULL);

    if (!hClient)
        return FALSE;

    //
    // Use the small icon title font
    //

    SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, FALSE);
    hfontClient = CreateFontIndirect(&lf);
    if (hfontClient)
      FORWARD_WM_SETFONT(hClient, hfontClient, FALSE, SendMessage);

    ShowWindow(hClient, SW_SHOWNORMAL);

    ShowWindow (hMain,showCmd);
    UpdateWindow (hMain);

    return TRUE;
}
/**************************************************************************

  Program Entrypoint and main loop

 **************************************************************************/

#pragma argsused
int PASCAL WinMain (HINSTANCE hInst,
                    HINSTANCE hPrevInstance,
                    LPSTR  lpszArg,
                    int    nCmdShow)
{
  MSG       msg;

  if (!AppInit(hInst, hPrevInstance, nCmdShow))
    return FALSE;

  while (GetMessage (&msg, NULL, 0, 0))
  {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
  }

  #ifdef __WIN32__
    if (hLog)
      CloseHandle (hLog);
  #else
    if (hLog)
      close (hLog);
  #endif

  if (hfontClient)
    DeleteObject(hfontClient);

  if (!hPrevInstance)
    Ctl3dUnregister(hInstance);

  return msg.wParam;
}