//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
USERES("francabld4.res");
USERC("Paulo.rc");
USEUNIT("c_sal.cpp");
USEOBJ("fra99bld.obj");
//---------------------------------------------------------------------------
#include <windows.h>
#define IDD_EDIT      201
#define SHAPESIZE 40
char myscreen[80];		// buffer  for input
char where[80];
LONG WINAPI /*FAR PASCAL*/ WndProc(HWND,UINT,WPARAM,LPARAM);
char questiontext[80]="Enter data here:";
char szPFranca[]="PFranca";
int firstime=1;
int xloc=0,yloc=0,xsize=640,ysize=480;
extern void copy(char * dest, char * source);
extern void repaint(HDC);
extern void useit(HDC);
// Remove next line for Microsoft C++ compile
#pragma argsused
  HWND hWnd;
  MSG  lpMsg;
  WNDCLASS wcApp;
  HDC  hdc;
  HMENU hMenu;
  HPEN hPen;
  PAINTSTRUCT ps;
  static FARPROC fpfnTextDiaProc;
  static HWND hInst1,hInst2;
int yesno (char * question)
{
  return MessageBox(hWnd, question,
	"Chose Yes or No:", MB_YESNO | MB_ICONQUESTION) == IDYES;
}
// Text dialog processing function:

BOOL FAR PASCAL TextDiaProc(HWND hdlg,UINT messg,
                            WPARAM wParam,LPARAM lParam)
{
 //HDC hdc2;
 LPCSTR newtitle=questiontext;
 switch (messg)
  {
  case WM_INITDIALOG:
    SetWindowText(hdlg,newtitle);
    SetFocus(hdlg);
    return FALSE;
  case WM_COMMAND:
    switch (wParam)
    {
      case IDOK:
        GetDlgItemText(hdlg,IDD_EDIT,myscreen,80);
        EndDialog(hdlg,TRUE);
        break;
      case IDCANCEL:
        EndDialog(hdlg,FALSE);
        break;
      default:
       TextOut(hdc,20,20,questiontext,15);
		  return FALSE;
	 }
	 break;
  default:
    return FALSE;
  }
return TRUE;
}
void askwords(char *where,int maxsize,char *question)
{
  copy(questiontext,question);
  DialogBox(hInst2,"TextInputDiaBox",hWnd,fpfnTextDiaProc);
  copy(where,myscreen);
  myscreen[maxsize]=0;
}
// main function:
int PASCAL WinMain(HINSTANCE hInst,HINSTANCE hPreInst,
                   LPSTR lpszCmdLine,int nCmdShow)
{

  if (!hPreInst) {
    wcApp.lpszClassName=szPFranca;
    wcApp.hInstance    =hInst;
    wcApp.lpfnWndProc  =WndProc;
    wcApp.hCursor      =LoadCursor(NULL,IDC_ARROW);
    wcApp.hIcon        =NULL;
    wcApp.lpszMenuName =NULL;
    wcApp.hbrBackground=GetStockObject(WHITE_BRUSH);
    wcApp.style        =CS_HREDRAW|CS_VREDRAW;
    wcApp.cbClsExtra   =0;
    wcApp.cbWndExtra   =0;
    if (!RegisterClass (&wcApp))
      return FALSE;
  }
  hWnd=CreateWindow(szPFranca,"Paulo Franca's C++",
		    WS_OVERLAPPEDWINDOW,xloc,yloc,xsize,ysize,
		    /*CW_USEDEFAULT,
                    CW_USEDEFAULT,CW_USEDEFAULT,
		    CW_USEDEFAULT,
		    */
		    (HWND)NULL,(HMENU)NULL,
                    (HANDLE)hInst,(LPSTR)NULL);
  if (!SetTimer(hWnd,1,100,NULL)) {
    MessageBox(hWnd,"Too many timers started!",
               szPFranca,MB_OK);
    return FALSE;
  }
  ShowWindow(hWnd,nCmdShow);
  UpdateWindow(hWnd);
  while (GetMessage(&lpMsg,NULL,NULL,NULL)) {
    TranslateMessage(&lpMsg);
    DispatchMessage(&lpMsg);
  }
  return(lpMsg.wParam);
}
// Windows processing function:
LONG WINAPI /*FAR PASCAL*/ WndProc(HWND hWnd,UINT messg,
                        WPARAM wParam,LPARAM lParam)
{
  PAINTSTRUCT ps;
  HDC hdc;
  //RECT rShape;
  static int sStep,xClientview,yClientview,
               xCenterCoord,yCenterCoord;

  switch (messg)
  {
    case WM_CREATE:
      hInst1=((LPCREATESTRUCT) lParam)->hInstance;
      hInst2=((LPCREATESTRUCT) lParam)->hInstance;
      fpfnTextDiaProc=MakeProcInstance((FARPROC)TextDiaProc,
				       hInst2);
    break;
    case WM_SIZE:
      sStep=2;
      xCenterCoord=(xClientview=LOWORD(lParam))/2;
      yCenterCoord=(yClientview=HIWORD(lParam))/2;
    break;

    case WM_TIMER:

    break;

    case WM_PAINT:
// This is the important part *****************

	 hdc=BeginPaint(hWnd,&ps);
    if (firstime++==1)
    {
     repaint( hdc);
    }
	  EndPaint(hWnd,&ps);
// End of Custom part *********************
      break;
    case WM_DESTROY:
      KillTimer(hWnd,1);
      PostQuitMessage(0);
      break;
    default:
      return(DefWindowProc(hWnd,messg,wParam,lParam));
  }
  return(0L);
}

// paulo2.cpp was included above
//---------------------------------------------------------------------------

/*WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
        try
        {
                 Application->Initialize();
                 Application->Run();
        }
        catch (Exception &exception)
        {
                 Application->ShowException(&exception);
        }
        return 0;
}
//---------------------------------------------------------------------------
*/