// not UNIX
// Environment.cpp : implementation file
//

#include "stdafx.h"
#include "Strawberry.h"

#include "StrawberryDoc.h"
#include "StrawberryView.h"
#include "Dialog.h"
#include "New_Class.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//  Angel
#include "dispdrv.h"

BOOL CALLBACK MyEnumProcedure(MY_HANDLE hModule, LPCTSTR  lpszType, LPTSTR  lpszName, LONG  lParam);
HICON GetIconFromInstance(HINSTANCE hInstance, LPCTSTR nIndex );
BOOL LoadIconFromInstance(HINSTANCE hInstance, LPCTSTR nIndex, BYTE* icon); 

#define _OBJECT_ 0
#define _METHOD_ 1
#define _PROPERTY_ 2

static DWORD CALLBACK MyStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
  DWORD i, k;
  
  for(i=0; i<(DWORD)cb; string2[i]=pbBuff[i], i++);
  string2[i]=0;
  if (ch_set)
    ChangeCharset(0, ch_set, (BYTE *)string2, (BYTE *)string2, &k, default_char);
  *pcb = cb;
  return 0;
}
static DWORD CALLBACK StreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
  int i=0;
  char** ppText = (char**) dwCookie;
  char* pText = *ppText;
  for(; i<cb && pText[i]; pbBuff[i]=pText[i], i++);
  *ppText+=i;
  *pcb = i;
  return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    ON_BN_CLICKED(IDC_NEXTVERSIONS, OnNextVersions)
    ON_WM_PAINT()
    ON_BN_CLICKED(IDC_BUTTON_REG, OnButtonReg)
END_MESSAGE_MAP()

void CAboutDlg::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    dcMem.CreateCompatibleDC(&dc);
    bmp1.LoadBitmap(IDB_ABOUT1);
    bmp2.LoadBitmap(IDB_ABOUT2);
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(15, 20, 162, 112, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(15, 20, 162, 112, &dcMem, 0, 0, SRCPAINT);
    // Do not call CDialog::OnPaint() for painting messages
}

BOOL CAboutDlg::OnInitDialog() 
{
    CDialog::OnInitDialog();
#ifdef UNICODE
#if PROF==2
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("professional edition for Windows XP/NT"));
#elif SHAREWARE
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("evaluation copy for Windows XP/NT"));
#elif PROF==1
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("middle edition for Windows XP/NT"));
#else    
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("light edition for Windows XP/NT"));
#endif    
#else  // UNICODE  
#if PROF==2
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("professional edition for Windows 98/Me"));
#elif SHAREWARE
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("evaluation copy for Windows 98/Me"));
#elif PROF==1
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("middle edition for Windows 98/Me"));
#else    
  GetDlgItem(IDC_STATIC8)->SetWindowText(_T("light edition for Windows 98/Me"));
#endif    
#endif // UNICODE
    ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->
       SetBackgroundColor(FALSE, GetSysColor(COLOR_3DFACE));
#if SHAREWARE
    if (!(status_fl&128))  //Not Registered
      GetDlgItem(IDC_NEXTVERSIONS)->SetWindowText(_T("About Professional Edition..."));
#elif PROF==0
    GetDlgItem(IDC_NEXTVERSIONS)->SetWindowText(_T("About Professional Edition..."));
#endif    
    if (status_fl&128)  //Registered
    {
      GetDlgItem(IDC_BUTTON_REG)->SetWindowText(_T("Unregister"));
      GetDlgItem(IDC_STATIC_LIS)->SetWindowText(_T("This product is licensed to:"));
      GetDlgItem(IDC_RICHEDIT1)->SetWindowText(RegName + _T("\r\n") + RegFrom + _T("\r\nProduct ID: ") +RegProdID);
      CHARFORMAT cf;
      cf.crTextColor=RGB(255, 0, 0);
      cf.dwMask=CFM_COLOR;
      cf.dwEffects=0; // not CFE_AUTOCOLOR
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->
        SetSel(RegName.GetLength()+ RegFrom.GetLength() + 14, -1);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSelectionCharFormat(cf);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSel(0, 0);
    }
#if SHAREWARE
    else
    {
#if 0
      GetDlgItem(IDC_RICHEDIT1)->SetWindowText(_T("This program is shareware.\r\n\
You have right to use it for three months\r\n\
only if you have the magazine:\r\nCHIP and its CD."));
#elif 1
      GetDlgItem(IDC_RICHEDIT1)->SetWindowText(_T("This program is shareware.\r\n\
You have right to use it for one month\r\nevaluation period."));
#else
      GetDlgItem(IDC_RICHEDIT1)->SetWindowText(_T("This program is not a freeware.\r\n\
You have right to use it for three months\r\n\
only if you bought a password for it."));
#endif  // 0 or 1
     CHARFORMAT cf;
      cf.dwMask=CFM_COLOR;
      cf.dwEffects=0; // not CFE_AUTOCOLOR
      cf.crTextColor=RGB(0, 0, 255);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->
              SetSel(0, -1);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSelectionCharFormat(cf);
#if 1
      cf.crTextColor=RGB(255, 0, 0);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->
              SetSel(103, 107);  // 103, 123
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSelectionCharFormat(cf);
#endif  // 0 or 1
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSel(0, 0);
    }
#endif // SHAREWARE   
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

void CAboutDlg::OnButtonReg() 
{
  if (status_fl&128)  //Registered
  {
    if (MessageBox(_T("    Are you sure that you want to unregister\
 this program. You will lose the possibility to build EXE files and\
 if you want to register again then you should rewrite your\
 registration information."),
      _T("Warning"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2)==IDYES)
    {
      GetDlgItem(IDC_BUTTON_REG)->SetWindowText(_T("Register..."));
      GetDlgItem(IDC_STATIC_LIS)->SetWindowText(
       _T("This copy of Strawberry Prolog is still not registered."));
      GetDlgItem(IDC_RICHEDIT1)->SetWindowText(_T(""));
// Source code for passwords coding - its missing
//***
      status_fl&=M1^128;
    }
  }
  else
  {
    CdRegister regDlg;
    regDlg.DoModal();
    if (status_fl&128)  //Registered
    {
      GetDlgItem(IDC_BUTTON_REG)->SetWindowText(_T("Unregister"));
      GetDlgItem(IDC_STATIC_LIS)->SetWindowText(_T("This product is licensed to:"));
      GetDlgItem(IDC_RICHEDIT1)->SetWindowText(RegName + _T("\r\n") + RegFrom + _T("\r\nProduct ID: ") +RegProdID);
      CHARFORMAT cf;
      cf.crTextColor=RGB(255, 0, 0);
      cf.dwMask=CFM_COLOR;
      cf.dwEffects=0; // not CFE_AUTOCOLOR
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->
              SetSel(RegName.GetLength()+ RegFrom.GetLength() + 14, -1);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSelectionCharFormat(cf);
      ((CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT1))->SetSel(0, 0);
    }
  }
}

void CAboutDlg::OnNextVersions() 
{
#if SHAREWARE
  if (!(status_fl&128))  //Not Registered
    HtmlHelp((DWORD_PTR)_T("ver\\Professional_and_Middle.html"), HH_DISPLAY_TOPIC);
    //ShellExecute(NULL, NULL, ProgramPath+"Help\\ver\\Professional_and_Middle.html", NULL, NULL, SW_SHOWNORMAL);
  else
#elif PROF   
  HtmlHelp((DWORD_PTR)_T("ver\\Versions.html"), HH_DISPLAY_TOPIC);
#else    
  HtmlHelp((DWORD_PTR)_T("ver\\Professional_and_Middle.html"), HH_DISPLAY_TOPIC);
#endif    
  EndDialog(IDOK);
}
/////////////////////////////////////////////////////////////////////////////
// CLoopCheck dialog


CLoopCheck::CLoopCheck(CWnd* pParent /*=NULL*/)
    : CDialog(CLoopCheck::IDD, pParent)
{
}


void CLoopCheck::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CLoopCheck, CDialog)
    ON_WM_PAINT()
    ON_BN_CLICKED(IDC_MORE_INFO, OnMoreInfo)
END_MESSAGE_MAP()

// CLoopCheck message handlers

void CLoopCheck::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    dcMem.CreateCompatibleDC(&dc);
    bmp1.LoadBitmap(IDB_BITMAP_LOOP2);
    bmp2.LoadBitmap(IDB_BITMAP_LOOP);
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(260, 30, 110, 88, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(260, 30, 110, 88, &dcMem, 0, 0, SRCPAINT);
    // Do not call CDialog::OnPaint() for painting messages
}

void CLoopCheck::OnMoreInfo() 
{
  HtmlHelp((DWORD_PTR)_T("env\\Loop_Check.html"), HH_DISPLAY_TOPIC);
  EndDialog(IDOK);
}
/////////////////////////////////////////////////////////////////////////////
// CdRead dialog


CdRead::CdRead(CWnd* pParent /*=NULL*/)
    : CDialog(CdRead::IDD, pParent)
{
}


void CdRead::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CdRead, CDialog)
    ON_WM_CREATE()
END_MESSAGE_MAP()

// CdRead message handlers
int CdRead::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CDialog::OnCreate(lpCreateStruct) == -1)
        return -1;
    return 0;
}

BOOL CdRead::OnInitDialog() 
{
  CDialog::OnInitDialog();
  SetWindowText(TempStr2);
  if (gl_read&2)
  {
    char* pText = string2; DWORD k;
    
    ChangeCharset(M64, 0, (BYTE *)(LPCTSTR)TempStr, (BYTE *)string2, &k, default_char);
    EDITSTREAM es;
    es.dwCookie = (DWORD)&pText;
    es.pfnCallback = StreamInCallback; 
    ((CRichEditCtrl *)GetDlgItem(IDC_RICHEDIT1))->
      StreamIn((CP_UTF8 << 16) | SF_USECODEPAGE | SF_TEXT, es);
  }
  GetDlgItem(IDC_RICHEDIT1)->SetFocus();
  return FALSE;  // return TRUE unless you set the focus to a control
                // EXCEPTION: OCX Property Pages should return FALSE
}

void CdRead::OnOK() 
{
  EDITSTREAM es;
  es.pfnCallback = MyStreamOutCallback; 
  string2[0]=0;
  ((CRichEditCtrl *)GetDlgItem(IDC_RICHEDIT1))->
    StreamOut((CP_UTF8 << 16) | SF_USECODEPAGE | SF_TEXT, es);
  TempStr=make_long((BYTE *)string2);
  if (gl_read&1)
  {
    DWORD i=1, j=0;
    for (string[0]='\"'; string2[j]; j++)
    {
      if (string2[j]=='\"')
        string[i++]=string2[j];
      string[i++]=string2[j];
    }
    string[i++]='\"';
    string[i]=0;
    f_end=i;
  }
  else
  {
    strcpy(string, string2);
    f_end=strlen(string);
  }
  CDialog::OnOK();
}

/////////////////////////////////////////////////////////////////////////////
// CpgSettings property page

IMPLEMENT_DYNCREATE(CpgSettings, CPropertyPage)

CpgSettings::CpgSettings() : CPropertyPage(CpgSettings::IDD)
{
  m_Font.CreateFontIndirect(&pInfo->m_lf);
  pInfo->m_Settings&=(M1^0x1000);
  m_Colors2=pInfo->m_Colors;
  m_bChanged=FALSE;
  
  m_FixFirstRandom = ((pInfo->m_Settings&8)!=0);
  m_AutoPrStack = ((pInfo->m_Settings&1)!=0);
  m_FullAsFail = ((pInfo->m_Settings&4)!=0);
  m_UseDefMem = ((pInfo->m_Settings&32)!=0);
  m_UseDefFont = ((pInfo->m_Settings&16)!=0);
  m_DontRecompile = ((pInfo->m_Settings&256)!=0);
  m_NotWithLight = ((pInfo->m_Settings&512)!=0);
  m_DontEdit = ((pInfo->m_Settings&1024)!=0);
  m_ExecuteExe = ((pInfo->m_Settings&2048)!=0);
}

CpgSettings::~CpgSettings()
{
}

void CpgSettings::DoDataExchange(CDataExchange* pDX)
{
  CPropertyPage::DoDataExchange(pDX);
  DDX_Check(pDX, IDC_CHECK1, m_FixFirstRandom);
  DDX_Check(pDX, IDC_CHECK3, m_AutoPrStack);
  DDX_Check(pDX, IDC_CHECK4, m_FullAsFail);
  DDX_Check(pDX, IDC_CHECK9, m_DontRecompile);
  DDX_Check(pDX, IDC_CHECK11, m_DontEdit);
  if (pInfo!=&DefaultProject)
  {
    DDX_Check(pDX, IDC_CHECK10, m_NotWithLight);
    DDX_Check(pDX, IDC_CHECK12, m_ExecuteExe);
    DDX_Check(pDX, IDC_CHECK5, m_UseDefMem);
    DDX_Check(pDX, IDC_CHECK6, m_UseDefFont);
  }
}


BEGIN_MESSAGE_MAP(CpgSettings, CPropertyPage)
    ON_BN_CLICKED(IDC_CHANGE_FONT, OnChangeFont)
    ON_WM_PAINT()
    ON_BN_CLICKED(IDC_CHECK6, OnDefaultFont)
    ON_BN_CLICKED(IDC_CHECK5, OnDefaultMem)
END_MESSAGE_MAP()

// CpgSettings message handlers

void CpgSettings::OnChangeFont() 
{
  LOGFONT lf;
  m_Font.GetLogFont(&lf);
  CFontDialog dialog(&lf, CF_EFFECTS | CF_SCREENFONTS | CF_SHOWHELP, NULL, this);
  dialog.m_cf.rgbColors=m_Colors2;
  if (dialog.DoModal()==IDOK)
  {
    dialog.GetCurrentFont(&lf);
    m_Font.DeleteObject();
    m_Font.CreateFontIndirect(&lf);
    InvalidateRect(NULL, TRUE);
    m_Colors2=dialog.GetColor();
    m_bChanged=TRUE;
  }
}

void CpgSettings::OnOK() 
{
#if PROF
  if (pInfo->m_Settings&1024) // Don't edit this project
    if (IDYES!=MessageBox(
      _T("This project is forbidden for edition. Do you want to edit it anyway."),_T("Warning"),
        MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2))
    {
#else
  if (pInfo->m_Settings&(1024|512)) // Don't edit this project | Not working with the Light edition
  {
      MessageBox(
      _T("   You cannot change this project in the light edition. For this you need middle or professional edition."),_T("Strawberry Prolog - Light edition"),
        MB_ICONSTOP | MB_OK);
#endif
      pInfo->m_Settings|=0x1000;
      return;
    }
  if (m_bChanged)
  {
    m_Font.GetLogFont(&pInfo->m_lf);
    pInfo->m_Colors=m_Colors2;
  }
  if ((m_bChanged && !m_UseDefFont) || (m_UseDefFont != ((pInfo->m_Settings&16)!=0)))
  {  
    CHARFORMAT cf;
    CProjectInfo *pInfo3=(m_UseDefFont)?&DefaultProject:pInfo;
    my_strcpy(cf.szFaceName, pInfo3->m_lf.lfFaceName);
    // -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
    cf.yHeight=-pInfo3->m_lf.lfHeight*15;
    if (cf.yHeight <190) cf.yHeight=190; //plamen test
    cf.crTextColor=pInfo3->m_Colors;
    cf.dwMask=CFM_COLOR | CFM_FACE | CFM_SIZE  | CFM_BOLD | CFM_ITALIC| CFM_STRIKEOUT | CFM_UNDERLINE;
    cf.dwEffects=0;
    if (pInfo3->m_lf.lfWeight>500)
      cf.dwEffects|=CFE_BOLD;
    if (pInfo3->m_lf.lfItalic)
      cf.dwEffects|=CFE_ITALIC;
    if (pInfo3->m_lf.lfUnderline)
      cf.dwEffects|=CFE_STRIKEOUT;
    if (pInfo3->m_lf.lfStrikeOut)
      cf.dwEffects|=CFE_UNDERLINE;
    if (pInfo!=&DefaultProject)
      pActivePj->GetView()->GetRichEditCtrl().SetDefaultCharFormat(cf);
    else
    {
      CStrawberryDoc *pDoc;
      POSITION pos=pDocTemplate1->GetFirstDocPosition();
      while (pos)
      {
        pDoc=(CStrawberryDoc*)pDocTemplate1->GetNextDoc(pos);
        if (pDoc->m_pInfo->m_Settings&16)
          pDoc->GetView()->GetRichEditCtrl().SetDefaultCharFormat(cf);
      }
      pos=pDocTemplate2->GetFirstDocPosition();
      while (pos)
      {
        pDoc=(CStrawberryDoc*)pDocTemplate2->GetNextDoc(pos);
        if (pDoc->m_FileType!=5)
          pDoc->GetView()->GetRichEditCtrl().SetDefaultCharFormat(cf);
      }
      if (pOutput)
      {
        my_strcpy(cf_blue.szFaceName, cf.szFaceName);
        my_strcpy(cf_red.szFaceName, cf.szFaceName);
        my_strcpy(cf_black.szFaceName, cf.szFaceName);
        my_strcpy(cf_green.szFaceName, cf.szFaceName);
        cf_blue.yHeight=cf_red.yHeight=cf_black.yHeight=cf_green.yHeight=-DefaultProject.m_lf.lfHeight*15;
        if (cf_blue.yHeight <190) cf_blue.yHeight=cf_red.yHeight=cf_black.yHeight=cf_green.yHeight=190; //plamen test
        cf.crTextColor=c_output;
        pOutput->SetDefaultCharFormat(cf);
      }
    }
  }
  if (m_FixFirstRandom != ((pInfo->m_Settings&8)!=0))
    {pInfo->m_Settings^=8; m_bChanged=TRUE; }
  if (m_AutoPrStack != ((pInfo->m_Settings&1)!=0))
    {pInfo->m_Settings^=1; m_bChanged=TRUE; }
  if (m_FullAsFail != ((pInfo->m_Settings&4)!=0))
    {pInfo->m_Settings^=4; m_bChanged=TRUE; }
  if (m_UseDefMem != ((pInfo->m_Settings&32)!=0))
    {pInfo->m_Settings^=32; m_bChanged=TRUE; }
  if (m_UseDefFont != ((pInfo->m_Settings&16)!=0))
    {pInfo->m_Settings^=16; m_bChanged=TRUE; }
  if (m_DontRecompile != ((pInfo->m_Settings&256)!=0))
    {pInfo->m_Settings^=256; m_bChanged=TRUE; }
  if (m_NotWithLight != ((pInfo->m_Settings&512)!=0))
#if PROF
    {pInfo->m_Settings^=512; m_bChanged=TRUE; }
#else
    MessageBox(
      _T("You cannot set any project as such which cannot work with the Light edition."),
      _T("Strawberry Prolog - Light edition"), MB_ICONEXCLAMATION | MB_OK);
#endif
  if (m_DontEdit != ((pInfo->m_Settings&1024)!=0))
  {
    pInfo->m_Settings^=1024; m_bChanged=TRUE;
    if (pInfo!=&DefaultProject)
#if PROF
      pActivePj->GetView()->GetRichEditCtrl().SetOptions(ECOOP_XOR, ECO_READONLY);
#else
      pActivePj->GetView()->GetRichEditCtrl().SetOptions(ECOOP_OR, ECO_READONLY);
#endif
    else
    {
      POSITION pos=pDocTemplate2->GetFirstDocPosition();
      while (pos)
        ((CStrawberryDoc*)pDocTemplate2->GetNextDoc(pos))
          ->GetView()->GetRichEditCtrl().SetOptions(ECOOP_XOR, ECO_READONLY);
    }
  }
  if (m_ExecuteExe != ((pInfo->m_Settings&2048)!=0))
    {pInfo->m_Settings^=2048; m_bChanged=TRUE; }
  if (m_bChanged && pInfo!=&DefaultProject && (pActivePj->m_Star==2 || pActivePj->m_Star==3))
  {
    pActivePj->m_Star=5;
    pActivePj->GetView()->GetRichEditCtrl().SetModify(TRUE);
    ((CStrawberryView*)pActivePj->GetView())->OnChange();
  }
  CPropertyPage::OnOK();
}

void CpgSettings::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    if (!m_UseDefFont)
    {
      dc.SelectObject((HFONT)m_Font);
      dc.SetTextColor(m_Colors2);
      if (pInfo==&DefaultProject)
        TextOutA(dc.m_hDC, 14, 190, "This is the Default Window Font.", 31);
      else
        TextOut(dc.m_hDC, 14, 190, _T("This is the Window Font of ") + pActivePj->GetTitle(),
                 27+pActivePj->GetTitle().GetLength());
    }
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    int x, y, yp;
    dcMem.CreateCompatibleDC(&dc);
    if (pInfo==&DefaultProject)
    {
      bmp1.LoadBitmap(IDB_BITMAP_DEF2);
      bmp2.LoadBitmap(IDB_BITMAP_DEF);
      x=130; y=131; yp=20;
    }
    else
    {
      bmp1.LoadBitmap(IDB_BITMAP_PJ2);
      bmp2.LoadBitmap(IDB_BITMAP_PJ);
      x=98; y=110;  yp=41;
    }
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(280, yp, x, y, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(280, yp, x, y, &dcMem, 0, 0, SRCPAINT);
    // Do not call CPropertyPage::OnPaint() for painting messages
}

void CpgSettings::OnDefaultFont() 
{
  UpdateData();
  GetDlgItem(IDC_CHANGE_FONT)->EnableWindow(!m_UseDefFont);
  InvalidateRect(CRect(0, 168, 500, 1000), TRUE);
}

void CpgSettings::OnDefaultMem() 
{
  UpdateData();
  if (m_UseDefMem)
    ((CSettings*)GetOwner())->RemovePage(2);
  else
    ((CSettings*)GetOwner())->AddPage(&((CSettings*)GetOwner())->m_memory);
}

BOOL CpgSettings::OnInitDialog() 
{
    CPropertyPage::OnInitDialog();
    GetDlgItem(IDC_CHANGE_FONT)->EnableWindow(!m_UseDefFont);
    if (pInfo==&DefaultProject)
    {
      GetDlgItem(IDC_CHECK10)->SendMessage(WM_CLOSE);
      GetDlgItem(IDC_CHECK12)->SendMessage(WM_CLOSE);
      GetDlgItem(IDC_CHECK5)->SendMessage(WM_CLOSE);
      GetDlgItem(IDC_CHECK6)->SendMessage(WM_CLOSE);
    }
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CpgFiles property page

IMPLEMENT_DYNCREATE(CpgFiles, CPropertyPage)

CpgFiles::CpgFiles() : CPropertyPage(CpgFiles::IDD)
{
    m_EditAdd = pInfo->m_AddFile;
    m_EditDef = pInfo->m_DefFile;
}

CpgFiles::~CpgFiles()
{
}

void CpgFiles::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT_ADD, m_EditAdd);
    DDX_Text(pDX, IDC_EDIT_DEF, m_EditDef);
}


BEGIN_MESSAGE_MAP(CpgFiles, CPropertyPage)
    ON_BN_CLICKED(IDC_CHANGE, OnChangeAdd)
    ON_BN_CLICKED(IDC_CHANGE2, OnChangeDef)
    ON_BN_CLICKED(IDC_DEFAULT, OnDefaultAdd)
    ON_BN_CLICKED(IDC_DEFAULT2, OnDefaultDef)
    ON_BN_CLICKED(IDC_ADD, OnAdd)
    ON_BN_CLICKED(IDC_REMOVE, OnRemove)
    ON_BN_CLICKED(IDC_UP, OnUp)
    ON_BN_CLICKED(IDC_DOWN, OnDown)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CpgFiles message handlers

BOOL CpgFiles::OnInitDialog() 
{
    CPropertyPage::OnInitDialog();
    int size=pInfo->m_FilesList.GetSize();
    for (int i=0; i<size; i++)
      ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(pInfo->m_FilesList[i]);
    ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(0);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

void CpgFiles::OnOK() 
{
  if (pInfo->m_Settings&0x1000)
    return;
  BOOL bFlag=FALSE;
  CString str;
  int size=((CListBox*)GetDlgItem(IDC_LIST1))->GetCount();

  if (size==pInfo->m_FilesList.GetSize())
    for (int i=0; i<size; i++)
    {
      ((CListBox*)GetDlgItem(IDC_LIST1))->GetText(i, str);
      if (pInfo->m_FilesList[i]!=str)
      {  
        bFlag=TRUE;
        break;
      }
    }
  else
    bFlag=TRUE;
  if (bFlag)
  {
    pInfo->m_FilesList.RemoveAll();
    for (int i=0; i<size; i++)
    {
      ((CListBox*)GetDlgItem(IDC_LIST1))->GetText(i, str);
      pInfo->m_FilesList.Add(str);
    }
  }
  if (bFlag || pInfo->m_AddFile!=m_EditAdd || pInfo->m_DefFile!=m_EditDef)
  {
    pInfo->m_AddFile=m_EditAdd;
    pInfo->m_DefFile=m_EditDef;
    if (pInfo!=&DefaultProject && (pActivePj->m_Star==2 || pActivePj->m_Star==3))
    {
      pActivePj->m_Star=5;
      pActivePj->GetView()->GetRichEditCtrl().SetModify(TRUE);
      ((CStrawberryView*)pActivePj->GetView())->OnChange();
    }
  }
  CPropertyPage::OnOK();
}
void CpgFiles::OnChangeAdd() 
{
  if (SelectFile(m_EditAdd, m_hWnd, _T("Select ADD File"),
    _T("Add Files (*.add)\0*.add\0All Files (*.*)\0*.*\0")))
    GetDlgItem(IDC_EDIT_ADD)->SetWindowText(m_EditAdd);
}
void CpgFiles::OnChangeDef() 
{
  if (SelectFile(m_EditDef, m_hWnd, _T("Select DEF File"),
    _T("Definition Files (*.def)\0*.def\0All Files (*.*)\0*.*\0")))
    GetDlgItem(IDC_EDIT_DEF)->SetWindowText(m_EditDef);
}
void CpgFiles::OnDefaultAdd() 
{
    GetDlgItem(IDC_EDIT_ADD)->SetWindowText(_T("Standard.add"));
}
void CpgFiles::OnDefaultDef() 
{
    GetDlgItem(IDC_EDIT_DEF)->SetWindowText(_T("Standard.def"));
}
void CpgFiles::OnAdd() 
{
  CString str;
  
  if (SelectFile(str, m_hWnd, _T("Add File to the Project"),
    _T("Prolog Files (*.pro; *.txt)\0*.pro;*.txt\0All Files (*.*)\0*.*\0")))
  {
    int i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel()+1;
    ((CListBox*)GetDlgItem(IDC_LIST1))->InsertString(i, str);
    ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(i);
  }
}
void CpgFiles::OnRemove() 
{
  int i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();
  ((CListBox*)GetDlgItem(IDC_LIST1))->DeleteString(i);
  ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(i);
}
void CpgFiles::OnUp() 
{
  CString str;
  int i;

  i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();
  if (i!=LB_ERR && i>0)
  {
    ((CListBox*)GetDlgItem(IDC_LIST1))->GetText(i, str);
    ((CListBox*)GetDlgItem(IDC_LIST1))->DeleteString(i);
    ((CListBox*)GetDlgItem(IDC_LIST1))->InsertString(i-1, str);
    ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(i-1);
  }
}
void CpgFiles::OnDown() 
{
  CString str;
  int i;

  i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();
  if (i!=LB_ERR && i+1<((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() )
  {
    ((CListBox*)GetDlgItem(IDC_LIST1))->GetText(i, str);
    ((CListBox*)GetDlgItem(IDC_LIST1))->DeleteString(i);
    ((CListBox*)GetDlgItem(IDC_LIST1))->InsertString(i+1, str);
    ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(i+1);
  }
}

/////////////////////////////////////////////////////////////////////////////
// CpgBreakPoint property page

IMPLEMENT_DYNCREATE(CpgBreakPoint, CPropertyPage)

CpgBreakPoint::CpgBreakPoint() : CPropertyPage(CpgBreakPoint::IDD)
{
    m_Active = pInfo->m_Settings&2;
    m_Point = pInfo->m_Break_point;
}

CpgBreakPoint::~CpgBreakPoint()
{
}

void CpgBreakPoint::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
    DDX_Check(pDX, IDC_CHECK1, m_Active);
    DDX_Text(pDX, IDC_EDIT1, m_Point);
}


BEGIN_MESSAGE_MAP(CpgBreakPoint, CPropertyPage)
    ON_BN_CLICKED(IDC_CHECK1, OnActive)
    ON_WM_PAINT()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CpgBreakPoint message handlers
void CpgBreakPoint::OnOK() 
{
  if (pInfo->m_Settings&0x1000)
    return;
  if (m_Active != ((pInfo->m_Settings&2)!=0))
    pInfo->m_Settings^=2;
  pInfo->m_Break_point = m_Point;
    
  CPropertyPage::OnOK();
}

void CpgBreakPoint::OnActive() 
{
  UpdateData();
  CClientDC dc(this); // device context for painting
  dc.SetMapMode(MM_ISOTROPIC);
  dc.SetWindowExt(96, 96);
  int pix=dc.GetDeviceCaps(LOGPIXELSX);
  dc.SetViewportExt(pix, pix);
  CDC dcMem;
  CBitmap bmp1;
  CBitmap bmp2;
  int x,xp;
  dcMem.CreateCompatibleDC(&dc);
  if (m_Active)
  {
    bmp1.LoadBitmap(IDB_BITMAP_ACTIVE2);
    bmp2.LoadBitmap(IDB_BITMAP_ACTIVE);
    x=99;xp=260;
  }
  else
  {
    bmp1.LoadBitmap(IDB_BITMAP_PASIVE2);
    bmp2.LoadBitmap(IDB_BITMAP_PASIVE);
    x=82;xp=277;
  }
  dcMem.SelectObject(&bmp1);
  SelectObject(dc.m_hDC, hbrGrey);
  dc.BitBlt(260, 50, 99, 94, &dcMem, 0, 0, MERGECOPY);
  dcMem.SelectObject(&bmp2);
  dc.BitBlt(xp, 50, x, 94, &dcMem, 0, 0, SRCPAINT);
}

void CpgBreakPoint::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    int x,xp;
    dcMem.CreateCompatibleDC(&dc);
    if (m_Active)
    {
      bmp1.LoadBitmap(IDB_BITMAP_ACTIVE2);
      bmp2.LoadBitmap(IDB_BITMAP_ACTIVE);
      x=99;xp=260;
    }
    else
    {
      bmp1.LoadBitmap(IDB_BITMAP_PASIVE2);
      bmp2.LoadBitmap(IDB_BITMAP_PASIVE);
      x=82;xp=277;
    }
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(260, 50, 99, 94, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(xp, 50, x, 94, &dcMem, 0, 0, SRCPAINT);
    // Do not call CPropertyPage::OnPaint() for painting messages
}

/////////////////////////////////////////////////////////////////////////////
// CpgEXEfile property page

IMPLEMENT_DYNCREATE(CpgEXEfile, CPropertyPage)

CpgEXEfile::CpgEXEfile() : CPropertyPage(CpgEXEfile::IDD)
{
    m_FileName = pInfo->m_ExeFileName;
    m_Comments = pInfo->m_Comments;
    m_bSource = ((pInfo->m_Settings&64)!=0);
    m_bAddStandard = ((pInfo->m_Settings&0x2000)!=0);

  for (int i=0; i<744; m_Icon[i]=pInfo->m_Icon[i], i++);
}

CpgEXEfile::~CpgEXEfile()
{
}

void CpgEXEfile::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT1, m_FileName);
    DDX_Text(pDX, IDC_EDIT_COMMENTS, m_Comments);
    DDX_Check(pDX, IDC_SOURCE_CODE, m_bSource);
    DDX_Check(pDX, IDC_ADD_STANDARD, m_bAddStandard);
}


BEGIN_MESSAGE_MAP(CpgEXEfile, CPropertyPage)
    ON_BN_CLICKED(IDC_CHANGE_ICON, OnChangeIcon)
    ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
    ON_BN_CLICKED(IDC_DEFALT, OnDefalt)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CpgEXEfile message handlers

void CpgEXEfile::OnOK() 
{
  if (pInfo->m_Settings&0x1000)
    return;
  if (pInfo!=&DefaultProject)
    my_strcpy(string3, pActivePj->GetPathName());
  else if (pActiveFile)
    my_strcpy(string3, pActiveFile->GetPathName());
  else
  {
    my_strcpy(string3, _T("... (Default)"));
    return;
  }
  int i=0;
  for (; string3[i]!='.' && string3[i]!=0; i++);
  my_strcpy(string3+i, _T(".exe (Default)"));
  if (m_FileName==string3)
    m_FileName="... (Default)";
  for (i=0; pInfo->m_Icon[i]==m_Icon[i] && i<744; i++);
  BOOL m_bChanged=FALSE;
  if (m_bSource != ((pInfo->m_Settings&64)!=0))
    {pInfo->m_Settings^=64; m_bChanged=TRUE; }
  if (m_bAddStandard != ((pInfo->m_Settings&0x2000)!=0))
    {pInfo->m_Settings^=0x2000; m_bChanged=TRUE; }
  if (i<744 || m_bChanged || pInfo->m_ExeFileName!=m_FileName || pInfo->m_Comments!=m_Comments)
  {
    pInfo->m_ExeFileName=m_FileName;
    pInfo->m_Comments=m_Comments;
    for (i=0; i<744; pInfo->m_Icon[i]=m_Icon[i], i++);
    if (pInfo!=&DefaultProject && (pActivePj->m_Star==2 || pActivePj->m_Star==3))
    {
      pActivePj->m_Star=5;
      pActivePj->GetView()->GetRichEditCtrl().SetModify(TRUE);
      ((CStrawberryView*)pActivePj->GetView())->OnChange();
    }
  }
  CPropertyPage::OnOK();
}

void CpgEXEfile::OnChangeIcon() // Angel 
{
  CdIConlist IconList; 
  HICON hIcon = NULL;

  if (SelectFile(IconList.m_FileName, m_hWnd, _T("Select Icon"),
    _T("Icon Files (*.ico; *.exe; *.dll)\0*.ico;*.exe;*.dll\0All Files (*.*)\0*.*\0"), TRUE))
  {
    IconList.GetIcon(m_Icon);    
    DestroyIcon(hIcon); 
    hIcon=CreateIconFromResource(m_Icon, 744, TRUE, 0x00030000);
    ((CStatic*)GetDlgItem(IDC_ICON_PRJ))->SetIcon(hIcon);
  }
}

void CpgEXEfile::OnBrowse() 
{
  CString tem_FileName=m_FileName;

  if (SelectFile(tem_FileName, m_hWnd, _T("Select File"),
    _T("Exe Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0")))
  {
    m_FileName=tem_FileName;
    GetDlgItem(IDC_EDIT1)->SetWindowText(m_FileName);
  }
}

BOOL CpgEXEfile::OnInitDialog() 
{
  HICON hIcon; // Angel
  CPropertyPage::OnInitDialog();
#if PROF<2
  GetDlgItem(IDC_STATIC_WARN)->SetWindowText(_T("Warning: These options do not play effect in the Light and Middle editions."));
#endif  
  hIcon=CreateIconFromResource(m_Icon, 744, TRUE, 0x00030000);
  ((CStatic*)GetDlgItem(IDC_ICON_PRJ))->SetIcon(hIcon);
  
  if (m_FileName=="... (Default)")
  {
    if (pInfo!=&DefaultProject)
      my_strcpy(string3, pActivePj->GetPathName());
    else if (pActiveFile)
      my_strcpy(string3, pActiveFile->GetPathName());
    else
    {
      GetDlgItem(IDC_EDIT1)->SetWindowText(_T("... (Default)"));
      goto e1;
    }
    int i=0;
    for (; string3[i]!='.' && string3[i]!=0; i++);
    my_strcpy(string3+i, _T(".exe (Default)"));
    GetDlgItem(IDC_EDIT1)->SetWindowText(string3);
  }
e1:
  return TRUE;  // return TRUE unless you set the focus to a control
                // EXCEPTION: OCX Property Pages should return FALSE
}

void CpgEXEfile::OnDefalt() 
{
  if (pInfo!=&DefaultProject)
    my_strcpy(string3, pActivePj->GetPathName());
  else if (pActiveFile)
    my_strcpy(string3, pActiveFile->GetPathName());
  else
  {
    GetDlgItem(IDC_EDIT1)->SetWindowText(_T("... (Default)"));
    return;
  }
  int i=0;
  for (; string3[i]!='.' && string3[i]!=0; i++);
  my_strcpy(string3+i, _T(".exe (Default)"));
  GetDlgItem(IDC_EDIT1)->SetWindowText(string3);
}

/////////////////////////////////////////////////////////////////////////////
// CpgMemory property page

IMPLEMENT_DYNCREATE(CpgMemory, CPropertyPage)

CpgMemory::CpgMemory() : CPropertyPage(CpgMemory::IDD)
{
    m_StackStart = pInfo->STACK_start/4;
    m_VarStart = (pInfo->BUDA_start-MAX_VARS)/1024;
    m_LinkStart = pInfo->BUDA_S_start/256;
    m_Stack = (STACK2+8)/4;
    m_Var = BUDA3/1024;
    m_Link = (BUDA_S2+MAX_VARS)/256;
    m_StackMax = pInfo->STACK_max/4;
    m_VarMax = (pInfo->BUDA_max-MAX_VARS)/1024;
    m_LinkMax = pInfo->BUDA_S_max/256;
}

CpgMemory::~CpgMemory()
{
}

void CpgMemory::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
    if (pDX->m_bSaveAndValidate)
    {
      DDX_Text(pDX, IDC_EDIT1, m_StackStart);
      if (m_StackStart<2)
      {
        AfxMessageBox(_T("Stack Start must be at lest 2."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT2, m_VarStart);
      if (m_VarStart<2)
      {                                         // Change MAX_VARS here
        AfxMessageBox(_T("Variable Start must be at lest 2."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT3, m_LinkStart);
      if (m_LinkStart<MAX_VARS/256)
      {                                         // Change MAX_VARS here
        AfxMessageBox(_T("Links Start must be at lest 16."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT7, m_StackMax);
      if (m_StackMax<m_StackStart)
      {
        AfxMessageBox(_T("Stack Maximum must be bigger or equel to the Start."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT8, m_VarMax);
      if (m_VarMax<m_VarStart)
      {
        AfxMessageBox(_T("Variable Maximum must be bigger or equel to the Start."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT9, m_LinkMax);
      if (m_LinkMax<m_LinkStart)
      {
        AfxMessageBox(_T("Links Maximum must be bigger or equel to the Start."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT4, m_Stack);
      if (m_StackMax<m_Stack || m_Stack<m_StackStart)
      {
        AfxMessageBox(_T("Stack must be between the Start and the Maximum."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT5, m_Var);
      if (m_VarMax<m_Var || m_Var<m_VarStart)
      {
        AfxMessageBox(_T("Variables must be between the Start and the Maximum."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
      DDX_Text(pDX, IDC_EDIT6, m_Link);
      if (m_LinkMax<m_Link || m_Link<m_LinkStart)
      {
        AfxMessageBox(_T("Links must be between the Start and the Maximum."), MB_ICONEXCLAMATION, 0);
        pDX->Fail();
      }
    }
    else
    {
        DDX_Text(pDX, IDC_EDIT1, m_StackStart);
        DDX_Text(pDX, IDC_EDIT2, m_VarStart);
        DDX_Text(pDX, IDC_EDIT3, m_LinkStart);
        DDX_Text(pDX, IDC_EDIT4, m_Stack);
        DDX_Text(pDX, IDC_EDIT5, m_Var);
        DDX_Text(pDX, IDC_EDIT6, m_Link);
        DDX_Text(pDX, IDC_EDIT7, m_StackMax);
        DDX_Text(pDX, IDC_EDIT8, m_VarMax);
        DDX_Text(pDX, IDC_EDIT9, m_LinkMax);
    }
}


BEGIN_MESSAGE_MAP(CpgMemory, CPropertyPage)
    ON_BN_CLICKED(IDC_SD1, OnSetDef1)
    ON_BN_CLICKED(IDC_SD2, OnSetDef2)
    ON_BN_CLICKED(IDC_SD3, OnSetDef3)
    ON_BN_CLICKED(IDC_SD4, OnSetDef4)
    ON_BN_CLICKED(IDC_SD5, OnSetDef5)
    ON_BN_CLICKED(IDC_SD6, OnSetDef6)
    ON_BN_CLICKED(IDC_SD7, OnSetDef7)
    ON_BN_CLICKED(IDC_SD8, OnSetDef8)
    ON_BN_CLICKED(IDC_SD9, OnSetDef9)
END_MESSAGE_MAP()

// CpgMemory message handlers

void CpgMemory::OnOK() 
{
  if (pInfo->m_Settings&0x1000)
    return;
  if (pInfo->STACK_start != 4*m_StackStart || (pInfo->BUDA_start-MAX_VARS)/1024 != m_VarStart
        || pInfo->BUDA_S_start/256 != m_LinkStart || pInfo->STACK_max != 4*m_StackMax
         || (pInfo->BUDA_max-MAX_VARS)/1024 != m_VarMax || pInfo->BUDA_S_max/256 != m_LinkMax)
  {
    pInfo->STACK_start = 4*m_StackStart;
    pInfo->BUDA_start = 1024*m_VarStart+MAX_VARS;
    pInfo->BUDA_S_start = 256*m_LinkStart;
    pInfo->STACK_max = 4*m_StackMax;
    pInfo->BUDA_max = 1024*m_VarMax+MAX_VARS;
    pInfo->BUDA_S_max = 256*m_LinkMax;
    if (pInfo!=&DefaultProject && (pActivePj->m_Star==2 || pActivePj->m_Star==3))
    {
      pActivePj->m_Star=5;
      pActivePj->GetView()->GetRichEditCtrl().SetModify(TRUE);
      ((CStrawberryView*)pActivePj->GetView())->OnChange();
    }
  }
    if (4*m_Stack != STACK2+8)
  {
    MitiUnlock();
    if (hTemp=GlobalReAlloc(hStack, 16*m_Stack, GMEM_MOVEABLE))
    {
      hStack=hTemp;
      STACK2=4*m_Stack-8;
    }
    MitiLock();
  }
    if (m_Var != BUDA3/1024)
  {
    MitiUnlock();
    if (hTemp=GlobalReAlloc(hBuda1, 4*(1024*m_Var+MAX_VARS), GMEM_MOVEABLE))
    {
      hBuda1=hTemp;
      if (hTemp=GlobalReAlloc(hBuda2, 4*(1024*m_Var+MAX_VARS), GMEM_MOVEABLE))
      {
        hBuda2=hTemp;
        BUDA3=1024*m_Var;
      }
    }
    MitiLock();
  }
    if (m_Link != (BUDA_S2+MAX_VARS)/256)
  {
    MitiUnlock();
    if (hTemp=GlobalReAlloc(hLink, 1024*m_Link, GMEM_MOVEABLE))
    {
      hLink=hTemp;
      BUDA_S2=256*m_Link-MAX_VARS;
    }
    MitiLock();
  }
    CPropertyPage::OnOK();
}

void CpgMemory::OnSetDef1() 
{
  GetDlgItem(IDC_EDIT1)->SetWindowText(_T("500"));
}
void CpgMemory::OnSetDef2() 
{
  GetDlgItem(IDC_EDIT2)->SetWindowText(_T("2"));
}
void CpgMemory::OnSetDef3() 
{
  GetDlgItem(IDC_EDIT3)->SetWindowText(_T("32"));
}
void CpgMemory::OnSetDef4() 
{
  CString str;
  GetDlgItem(IDC_EDIT1)->GetWindowText(str);
  GetDlgItem(IDC_EDIT4)->SetWindowText(str);
}
void CpgMemory::OnSetDef5() 
{
  CString str;
  GetDlgItem(IDC_EDIT2)->GetWindowText(str);
  GetDlgItem(IDC_EDIT5)->SetWindowText(str);
}
void CpgMemory::OnSetDef6() 
{
  CString str;
  GetDlgItem(IDC_EDIT3)->GetWindowText(str);
  GetDlgItem(IDC_EDIT6)->SetWindowText(str);
}
void CpgMemory::OnSetDef7() 
{
  GetDlgItem(IDC_EDIT7)->SetWindowText(_T("16000"));
}
void CpgMemory::OnSetDef8() 
{
  GetDlgItem(IDC_EDIT8)->SetWindowText(_T("1016"));
}
void CpgMemory::OnSetDef9() 
{
  GetDlgItem(IDC_EDIT9)->SetWindowText(_T("4096"));
}
/////////////////////////////////////////////////////////////////////////////
// CpgCGI property page

IMPLEMENT_DYNCREATE(CpgCGI, CPropertyPage)

CpgCGI::CpgCGI() : CPropertyPage(CpgCGI::IDD)
{
    m_Get = pInfo->m_GetMethod;
    m_Post = pInfo->m_PostMethod;
    m_Arguments = pInfo->m_ProgArg;
}

CpgCGI::~CpgCGI()
{
}

void CpgCGI::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_EDIT_ARGUMENTS, m_Arguments);
    DDX_Text(pDX, IDC_EDIT_GET, m_Get);
    DDX_Text(pDX, IDC_EDIT_POST, m_Post);
}


BEGIN_MESSAGE_MAP(CpgCGI, CPropertyPage)
        // NOTE: the ClassWizard will add message map macros here
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CpgCGI message handlers

void CpgCGI::OnOK() 
{
  if (pInfo->m_Settings&0x1000)
    return;

  if (pInfo->m_GetMethod!=m_Get || pInfo->m_PostMethod!=m_Post || pInfo->m_ProgArg!=m_Arguments)
  {
    pInfo->m_GetMethod=m_Get;
    pInfo->m_PostMethod=m_Post;
    pInfo->m_ProgArg=m_Arguments;
    if (pInfo!=&DefaultProject && (pActivePj->m_Star==2 || pActivePj->m_Star==3))
    {
      pActivePj->m_Star=5;
      pActivePj->GetView()->GetRichEditCtrl().SetModify(TRUE);
      ((CStrawberryView*)pActivePj->GetView())->OnChange();
    }
  }
  CPropertyPage::OnOK();
}
/////////////////////////////////////////////////////////////////////////////
// CpgCharSet dialog

IMPLEMENT_DYNAMIC(CpgCharSet, CPropertyPage)
CpgCharSet::CpgCharSet() : CPropertyPage(CpgCharSet::IDD)
{
  m_UseInstead = ((pInfo->m_Settings&0x10000)!=0);
  m_nCharSet = (pInfo->m_Settings&0x7e0000)/0x20000;
}

CpgCharSet::~CpgCharSet()
{
}

void CpgCharSet::DoDataExchange(CDataExchange* pDX)
{
  CPropertyPage::DoDataExchange(pDX);
  DDX_Check(pDX, IDC_CHECK1, m_UseInstead);
}

BEGIN_MESSAGE_MAP(CpgCharSet, CPropertyPage)
  ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedAddExotic)
  ON_BN_CLICKED(IDC_BUTTON4, OnBnClickedSelect)
END_MESSAGE_MAP()


// CpgCharSet message handlers
BOOL CpgCharSet::OnInitDialog() 
{
  CPropertyPage::OnInitDialog();
  
  CString ch_set_str=_T("The selected Char Set is: ");
  ch_set_str+=Char_Sets[m_nCharSet];
  GetDlgItem(IDC_STATIC2)->SetWindowText(ch_set_str);
  
  if (m_nCharSet>10)
  {
    m_AddExotic=0;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Hide Exotic Char Sets"));
  }
  else
  {
    m_AddExotic=1;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Add Exotic Char Sets"));
  }
  for (int i=0; i<(m_AddExotic?11:CHAR_SETS); i++)
    ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(TempStr=Char_Sets[i]);
  ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(m_nCharSet);
  return TRUE;  // return TRUE unless you set the focus to a control
                // EXCEPTION: OCX Property Pages should return FALSE
}
void CpgCharSet::OnOK() 
{
  if (pInfo->m_Settings&0x1000)
    return;
  BOOL m_bChanged=FALSE;
  int i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();
  if (i!=LB_ERR && i!=m_nCharSet)
  {
    CString ch_set_str=_T("Do you want to select the char set ");
    ch_set_str+=Char_Sets[i];
    if (IDYES==MessageBox(ch_set_str, _T("What to select"), MB_ICONQUESTION | MB_YESNO))
      m_nCharSet=i;
  }
  if (m_nCharSet != (pInfo->m_Settings&0x7e0000)/0x20000)
  {
    pInfo->m_Settings&=0xff81ffff;
    pInfo->m_Settings|=0x20000*m_nCharSet;
    m_bChanged=TRUE;
  }
  if (m_UseInstead != ((pInfo->m_Settings&0x10000)!=0))
    {pInfo->m_Settings^=0x10000; m_bChanged=TRUE; }
  if (m_bChanged && pInfo!=&DefaultProject && (pActivePj->m_Star==2 || pActivePj->m_Star==3))
  {
    pActivePj->m_Star=5;
    pActivePj->GetView()->GetRichEditCtrl().SetModify(TRUE);
    ((CStrawberryView*)pActivePj->GetView())->OnChange();
  }
  CPropertyPage::OnOK();
}

void CpgCharSet::OnBnClickedAddExotic()
{
  if (m_AddExotic)
  {
    m_AddExotic=0;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Hide Exotic Char Sets"));
    for (int i=11; i<=CHAR_SETS; i++)
      ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(TempStr=Char_Sets[i]);
  }
  else
  {
    m_AddExotic=1;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Add Exotic Char Sets"));
    for (int i=11; i<=CHAR_SETS; i++)
      ((CListBox*)GetDlgItem(IDC_LIST1))->DeleteString(11);
  }
}

void CpgCharSet::OnBnClickedSelect()
{
  int i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();
  if (i==LB_ERR)
    MessageBox(_T("You have to select a Char Set from the list."),
    _T("Nothing is selected"), MB_ICONSTOP | MB_OK);
  else
  {
    m_nCharSet=i;
    CString ch_set_str=_T("The selected Char Set is: ");
    ch_set_str+=Char_Sets[m_nCharSet];
    GetDlgItem(IDC_STATIC2)->SetWindowText(ch_set_str);
  }
}
// CdOpenWith dialog

IMPLEMENT_DYNAMIC(CdOpenWith, CDialog)
CdOpenWith::CdOpenWith(CWnd* pParent /*=NULL*/)
	: CDialog(CdOpenWith::IDD, pParent)
{
  m_nCharSet = (DefaultProject.m_Settings&0x7e0000)/0x20000;
  m_UseInstead = ((DefaultProject.m_Settings&0x10000)!=0);
}

CdOpenWith::~CdOpenWith()
{
}

void CdOpenWith::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
  DDX_Check(pDX, IDC_CHECK1, m_UseInstead);
}


BEGIN_MESSAGE_MAP(CdOpenWith, CDialog)
  ON_BN_CLICKED(IDC_BUTTON1, OnAddExotic)
//  ON_WM_LBUTTONDBLCLK()
  ON_LBN_DBLCLK(IDC_LIST1, OnLbnDblclkList1)
END_MESSAGE_MAP()


// CdOpenWith message handlers
BOOL CdOpenWith::OnInitDialog() 
{
  CDialog::OnInitDialog();
  CString ch_set_str=_T("The default Char Set is: ");
  ch_set_str+=Char_Sets[m_nCharSet];
  GetDlgItem(IDC_STATIC2)->SetWindowText(ch_set_str);
  
  if (m_nCharSet>10)
  {
    m_AddExotic=0;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Hide Exotic Char Sets"));
  }
  else
  {
    m_AddExotic=1;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Add Exotic Char Sets"));
  }
  if (gl_open&2)
    GetDlgItem(IDOK)->SetWindowText(_T("Save As..."));
  else
    GetDlgItem(IDOK)->SetWindowText(_T("Open..."));
  for (int i=0; i<(m_AddExotic?11:CHAR_SETS); i++)
    ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(TempStr=Char_Sets[i]);
  ((CListBox*)GetDlgItem(IDC_LIST1))->SetCurSel(m_nCharSet);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}
void CdOpenWith::OnOK() 
{
  UpdateData();
  int i=((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel();
  if (i==LB_ERR)
  {
    gl_open=0;
    MessageBox(_T("Nothing is selected."), _T("Strawberry Prolog"), MB_ICONSTOP | MB_OK);
  }
  else
    gl_open=i*0x20000+m_UseInstead*0x10000+4;
  CDialog::OnOK();
}
void CdOpenWith::OnLbnDblclkList1()
{
  OnOK();
}
void CdOpenWith::OnAddExotic()
{
  if (m_AddExotic)
  {
    m_AddExotic=0;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Hide Exotic Char Sets"));
    for (int i=11; i<=CHAR_SETS; i++)
      ((CListBox*)GetDlgItem(IDC_LIST1))->AddString(TempStr=Char_Sets[i]);
  }
  else
  {
    m_AddExotic=1;
    GetDlgItem(IDC_BUTTON1)->SetWindowText(_T("Add Exotic Char Sets"));
    for (int i=11; i<=CHAR_SETS; i++)
      ((CListBox*)GetDlgItem(IDC_LIST1))->DeleteString(11);
  }
}

/////////////////////////////////////////////////////////////////////////////
// CSettings

IMPLEMENT_DYNAMIC(CSettings, CPropertySheet)

CSettings::CSettings(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
    :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
  AddPage(&m_settings);
  AddPage(&m_files);
  AddPage(&m_break);
  if ((pInfo->m_Settings&32)==0)
    AddPage(&m_memory);
  AddPage(&m_pgCharSet);
  AddPage(&m_EXEfile);
  AddPage(&m_CGI);
}

CSettings::CSettings(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
    :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
  AddPage(&m_settings);
  AddPage(&m_files);
  AddPage(&m_break);
  if ((pInfo->m_Settings&32)==0)
    AddPage(&m_memory);
  AddPage(&m_pgCharSet);
  AddPage(&m_EXEfile);
  AddPage(&m_CGI);
}

CSettings::~CSettings()
{
}


BEGIN_MESSAGE_MAP(CSettings, CPropertySheet)
END_MESSAGE_MAP()

// CSettings message handlers

/////////////////////////////////////////////////////////////////////////////
// CpgEnvironment property page

IMPLEMENT_DYNCREATE(CpgEnvironment, CPropertyPage)

CpgEnvironment::CpgEnvironment() : CPropertyPage(CpgEnvironment::IDD)
{
  LOGFONT lf;
  InfoFont.GetLogFont(&lf);
  m_Font.CreateFontIndirect(&lf);
    m_OnlyPj = ((Environment&32)!=0);
    m_NextValid = ((Environment&8)!=0);
    m_StepValid = ((Environment&16)!=0);
    m_WordSel = ((Environment&256)!=0);
    m_Remember = ((Environment&0x4000)==0);
}

CpgEnvironment::~CpgEnvironment()
{
}

void CpgEnvironment::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
    DDX_Check(pDX, IDC_CHECK1, m_OnlyPj);
    DDX_Check(pDX, IDC_CHECK2, m_NextValid);
    DDX_Check(pDX, IDC_CHECK3, m_StepValid);
    DDX_Check(pDX, IDC_CHECK6, m_WordSel);
    DDX_Check(pDX, IDC_CHECK8, m_Remember);
}


BEGIN_MESSAGE_MAP(CpgEnvironment, CPropertyPage)
    ON_BN_CLICKED(IDC_BUTTON1, OnChangeInfoFont)
    ON_WM_PAINT()
END_MESSAGE_MAP()

// CpgEnvironment message handlers

void CpgEnvironment::OnChangeInfoFont() 
{
  LOGFONT lf;
  m_Font.GetLogFont(&lf);
  CFontDialog dialog(&lf, CF_SCREENFONTS | CF_SHOWHELP, NULL, this);
  if (dialog.DoModal()==IDOK)
  {
    dialog.GetCurrentFont(&lf);
    m_Font.DeleteObject();
    m_Font.CreateFontIndirect(&lf);
    InvalidateRect(NULL, TRUE);
  }
}

void CpgEnvironment::OnOK() 
{
  LOGFONT lf;
  m_Font.GetLogFont(&lf);
  InfoFont.DeleteObject();
  InfoFont.CreateFontIndirect(&lf);
  if (m_OnlyPj != (BOOL)(Environment&32))
    Environment^=32;
  if (m_NextValid != ((Environment&8)!=0))
    Environment^=8;
  if (m_StepValid != ((Environment&16)!=0))
    Environment^=16;
  if (m_Remember != ((Environment&0x4000)==0))
    Environment^=0x4000;
  if (m_WordSel != ((Environment&256)!=0))
  {
    Environment^=256;
    POSITION pos=pDocTemplate1->GetFirstDocPosition();
    while (pos)
      ((CStrawberryDoc*)pDocTemplate1->GetNextDoc(pos))
        ->GetView()->GetRichEditCtrl().SetOptions(ECOOP_XOR, ECO_AUTOWORDSELECTION);
    pos=pDocTemplate2->GetFirstDocPosition();
    while (pos)
      ((CStrawberryDoc*)pDocTemplate2->GetNextDoc(pos))
        ->GetView()->GetRichEditCtrl().SetOptions(ECOOP_XOR, ECO_AUTOWORDSELECTION);
  }
  CPropertyPage::OnOK();
}

void CpgEnvironment::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    dc.SelectObject((HFONT)m_Font);
    TextOutA(dc.m_hDC, 14, 168, "This is the Information Font.", 29);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    dcMem.CreateCompatibleDC(&dc);
    bmp1.LoadBitmap(IDB_BITMAP_ENVIRON2);
    bmp2.LoadBitmap(IDB_BITMAP_ENVIRON);
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(280, 41, 98, 94, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(280, 41, 98, 94, &dcMem, 0, 0, SRCPAINT);
    // Do not call CPropertyPage::OnPaint() for painting messages
}
/////////////////////////////////////////////////////////////////////////////
// CpgView property page

IMPLEMENT_DYNCREATE(CpgView, CPropertyPage)

CpgView::CpgView() : CPropertyPage(CpgView::IDD)
{
    m_Splash = ((Environment&512)!=0);
    m_BigToolBar = ((Environment&1024)!=0);
    m_ToolBar = ((Environment&64)!=0);
    m_StatusBar = ((Environment&128)!=0);
    m_AtTop = ((Environment&0x1000)!=0);
    m_AutomaticScroll = ((Environment&0x2000)==0);
    m_FlatToolBar = ((Environment&0x8000)==0);
}

CpgView::~CpgView()
{
}

void CpgView::DoDataExchange(CDataExchange* pDX)
{
  CPropertyPage::DoDataExchange(pDX);
  DDX_Check(pDX, IDC_CHECK1, m_Splash);
  DDX_Check(pDX, IDC_CHECK2, m_BigToolBar);
  DDX_Check(pDX, IDC_CHECK4, m_ToolBar);
  DDX_Check(pDX, IDC_CHECK5, m_StatusBar);
  DDX_Check(pDX, IDC_CHECK7, m_AtTop);
  DDX_Check(pDX, IDC_CHECK8, m_AutomaticScroll);
  DDX_Check(pDX, IDC_CHECK9, m_FlatToolBar);
}


BEGIN_MESSAGE_MAP(CpgView, CPropertyPage)
    ON_WM_PAINT()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CpgView message handlers


void CpgView::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    dcMem.CreateCompatibleDC(&dc);
    bmp1.LoadBitmap(IDB_BITMAP_VIEW2);
    bmp2.LoadBitmap(IDB_BITMAP_VIEW);
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(275, 40, 105, 96, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(275, 40, 105, 96, &dcMem, 0, 0, SRCPAINT);
    // Do not call CPropertyPage::OnPaint() for painting messages
}

void CpgView::OnOK() 
{
  if (m_ToolBar != ((Environment&64)!=0))
    Environment^=64;
  if (m_StatusBar != ((Environment&128)!=0))
    Environment^=128;
  if (m_Splash != ((Environment&512)!=0))
    Environment^=512;
  if (m_BigToolBar != ((Environment&1024)!=0))
    Environment^=1024;
  if (m_AtTop != ((Environment&0x1000)!=0))
  {
    Environment^=0x1000;
    if (pProofTree)
    {
      if (m_AtTop)
        pProofTree->SetWindowPos(&wndTopMost, 0,0,0,0,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
      else
        pProofTree->SetWindowPos(&wndNoTopMost, 0,0,0,0,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
    }
  }
  if (m_AutomaticScroll != ((Environment&0x2000)==0)) //invert
    Environment^=0x2000;
  if (m_FlatToolBar != ((Environment&0x8000)==0)) //invert
    Environment^=0x8000;
  CPropertyPage::OnOK();
}
/////////////////////////////////////////////////////////////////////////////
// CpgSyntaxColor property page

IMPLEMENT_DYNCREATE(CpgSyntaxColor, CPropertyPage)

CpgSyntaxColor::CpgSyntaxColor() : CPropertyPage(CpgSyntaxColor::IDD)
{
  m_Font.CreateFontIndirect(&DefaultProject.m_lf);
  m_OnFileOpen=((Environment&0x10000)==0);
#if PROF
  m_EveryTextChange=((Environment&0x40000)==0);
  m_WhenEnter=((Environment&0x20000)!=0);
#else
  m_EveryTextChange=0;
  m_WhenEnter=((Environment&0x40000)==0);
#endif
  for(int i=0; i<LAST_COLOR; i++)
    m_synt_color[i]=m_synt_color_cus[i]=synt_color[i];
}

CpgSyntaxColor::~CpgSyntaxColor()
{
}

BOOL CpgSyntaxColor::OnInitDialog() 
{
    CPropertyPage::OnInitDialog();
    m_CB_Type.AddString(_T("Comment"));
    m_CB_Type.AddString(_T("String"));
    m_CB_Type.AddString(_T("Integer"));
    m_CB_Type.AddString(_T("Float"));
    m_CB_Type.AddString(_T("Object"));
    m_CB_Type.AddString(_T("Operator"));
    m_CB_Type.AddString(_T("Set Operator"));
    m_CB_Type.AddString(_T("Atom"));
    m_CB_Type.AddString(_T("Functor"));
    m_CB_Type.AddString(_T("Brackets ( [ {"));
    m_CB_Type.AddString(_T("Variable (global)"));
    m_CB_Type.AddString(_T("Variable (local)"));
    m_CB_Type.AddString(_T("Variable (anonymous)"));
    m_CB_Type.AddString(_T("Error (syntax)"));
    m_CB_Type.SetCurSel(0);
    
    m_CB_Color.AddString(_T("Red"));
    m_CB_Color.AddString(_T("Green"));
    m_CB_Color.AddString(_T("Light Green"));
    m_CB_Color.AddString(_T("Blue"));
    m_CB_Color.AddString(_T("Light Blue"));
    m_CB_Color.AddString(_T("Yellow"));
    m_CB_Color.AddString(_T("Orange"));
    m_CB_Color.AddString(_T("Violet"));
    m_CB_Color.AddString(_T("White"));
    m_CB_Color.AddString(_T("Grey"));
    m_CB_Color.AddString(_T("Black"));
    m_CB_Color.AddString(_T("Custom"));
    int i=Number(m_synt_color[0]);
    m_CB_Color.SetCurSel(i);
    GetDlgItem(IDC_BUTTON2)->EnableWindow(i==11);
   
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}
void CpgSyntaxColor::OnCbnSelchangeCombo1()
{
  int i=Number(m_synt_color[m_CB_Type.GetCurSel()]);
  m_CB_Color.SetCurSel(i);
  GetDlgItem(IDC_BUTTON2)->EnableWindow(i==11);
  MakeText(GetDC());
}
void CpgSyntaxColor::OnCbnSelchangeCombo2()
{
  int i=m_CB_Color.GetCurSel();
  if (i==11) // default
  {
    int j=m_CB_Type.GetCurSel();
    m_synt_color[j]=m_synt_color_cus[j];
    GetDlgItem(IDC_BUTTON2)->EnableWindow(1);
  }
  else
  {
    m_synt_color[m_CB_Type.GetCurSel()]=Color(i);
    GetDlgItem(IDC_BUTTON2)->EnableWindow(0);
  }
  MakeText(GetDC());
}
void CpgSyntaxColor::OnBnClickedButton1()
{
  int k=m_CB_Type.GetCurSel();
  int sys_cw=GetSysColor(COLOR_WINDOW);
  switch(k)
  {
   case 0: 
    m_synt_color[0]=((sys_cw&0xff)+((sys_cw&0xff00) >> 8)>440)?RGB(0,128,0):RGB(255,255,0);
    break;
   case 1: 
    m_synt_color[1]=RGB(255,0,0);
    break;
   case 2: 
    m_synt_color[2]=RGB(255,0,0);
    break;
   case 3: 
    m_synt_color[3]=RGB(255,0,0);
    break;
   case 4: 
    m_synt_color[4]=(((sys_cw&0xff00) >> 8)+((sys_cw&0xff0000) >> 16)>440)?RGB(255,0,255):RGB(0,255,255);
    break;
   case 5: 
    m_synt_color[5]=RGB(0, 0, 0);
    break;
   case 6: 
    m_synt_color[6]=RGB(0, 0, 255);
    break;
   case 7: 
    m_synt_color[7]=RGB(0,128,0);
    break;
   case 8: 
    m_synt_color[8]=RGB(0, 0, 255);
    break;
   case 9: 
    m_synt_color[9]=RGB(0, 0, 0);
    break;
   case 10: 
    m_synt_color[10]=RGB(255,0,0);
    break;
   case 11: 
    m_synt_color[11]=RGB(0,0,255);
    break;
   case 12: 
    m_synt_color[12]=RGB(255,0,255);
    break;
   case 13: 
    m_synt_color[13]=((sys_cw&0xff)+((sys_cw&0xff00) >> 8)+((sys_cw&0xff0000) >> 16)>660)?RGB(128,128,128):RGB(255,255,255);
  }
  int i=Number(m_synt_color[k]);
  m_CB_Color.SetCurSel(i);
  GetDlgItem(IDC_BUTTON2)->EnableWindow(i==11);
  MakeText(GetDC());
}
void CpgSyntaxColor::OnBnClickedButton2()
{
  int k=m_CB_Type.GetCurSel();
  CColorDialog dialog(0, 0, this);
  dialog.m_cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_SHOWHELP | CC_ENABLEHOOK;//?hook
  dialog.m_cc.rgbResult= m_synt_color_cus[k];
  if (dialog.DoModal()==IDOK)
  {
    m_synt_color[k]=m_synt_color_cus[k]=dialog.m_cc.rgbResult;
    int i=Number(m_synt_color[k]);
    m_CB_Color.SetCurSel(i);
    GetDlgItem(IDC_BUTTON2)->EnableWindow(i==11);
    MakeText(GetDC());
  }
}
void CpgSyntaxColor::OnBnClickedButton3()
{
  int sys_cw=GetSysColor(COLOR_WINDOW);
  m_synt_color[0]=((sys_cw&0xff)+((sys_cw&0xff00) >> 8)>440)?RGB(0,128,0):RGB(255,255,0);
  m_synt_color[1]=RGB(255,0,0);
  m_synt_color[2]=RGB(255,0,0);
  m_synt_color[3]=RGB(255,0,0);
  m_synt_color[4]=(((sys_cw&0xff00) >> 8)+((sys_cw&0xff0000) >> 16)>440)?RGB(255,0,255):RGB(0,255,255);
  m_synt_color[5]=RGB(0, 0, 0);
  m_synt_color[6]=RGB(0, 0, 255);
  m_synt_color[7]=RGB(0,128,0);
  m_synt_color[8]=RGB(0, 0, 255);
  m_synt_color[9]=RGB(0, 0, 0);
  m_synt_color[10]=RGB(255,0,0);
  m_synt_color[11]=RGB(0,0,255);
  m_synt_color[12]=RGB(255,0,255);
  m_synt_color[13]=((sys_cw&0xff)+((sys_cw&0xff00) >> 8)+((sys_cw&0xff0000) >> 16)>660)?RGB(128,128,128):RGB(255,255,255);
  int i=Number(m_synt_color[m_CB_Type.GetCurSel()]);
  m_CB_Color.SetCurSel(i);
  GetDlgItem(IDC_BUTTON2)->EnableWindow(i==11);
  MakeText(GetDC());
}
void CpgSyntaxColor::OnPaint()
{
  CPaintDC dc(this); // device context for painting
  MakeText(&dc);
}
void CpgSyntaxColor::MakeText(CDC *dc)
{
  RECT TempRect;
  
  m_CB_Type.GetWindowRect(&TempRect);
  m_Point.x=TempRect.left;
  m_Point.y=TempRect.top;
  ::MapWindowPoints(NULL, m_CB_Type.GetParent()->m_hWnd, &m_Point, 1);
  dc->SelectObject((HFONT)m_Font);
  dc->SetTextAlign(TA_UPDATECP);
  dc->SetBkColor(GetSysColor(COLOR_WINDOW));
  
  int i=m_CB_Type.GetCurSel();
  if (i!=CB_ERR)
  {
    dc->MoveTo(m_Point.x+TempRect.right-TempRect.left+3, m_Point.y);
    dc->SetTextColor(m_synt_color[i]);
    TextOutA(dc->m_hDC, 0, 0, "Text", 4);
  }
  m_Point.y+=TempRect.bottom-TempRect.top;
  dc->MoveTo(m_Point.x, m_Point.y+15);
  dc->SetTextColor(m_synt_color[m_clist[0]=8]);
  TextOutA(dc->m_hDC, 0, 0, "p(", 2);
  m_pos[0]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[1]=11]);
  TextOutA(dc->m_hDC, 0, 0, "X", 1);
  m_pos[1]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[2]=8]);
  TextOutA(dc->m_hDC, 0, 0, ",", 1);
  m_pos[2]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[3]=9]);
  TextOutA(dc->m_hDC, 0, 0, "[", 1);
  m_pos[3]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[4]=1]);
  TextOutA(dc->m_hDC, 0, 0, "\"str\"", 5);
  m_pos[4]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[5]=9]);
  TextOutA(dc->m_hDC, 0, 0, ",", 1);
  m_pos[5]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[6]=7]);
  TextOutA(dc->m_hDC, 0, 0, "a", 1);
  m_pos[6]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[7]=9]);
  TextOutA(dc->m_hDC, 0, 0, ",", 1);
  m_pos[7]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[8]=4]);
  TextOutA(dc->m_hDC, 0, 0, "0j5", 3);
  m_pos[8]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[9]=9]);
  TextOutA(dc->m_hDC, 0, 0, "|", 1);
  m_pos[9]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[10]=12]);
  TextOutA(dc->m_hDC, 0, 0, "T", 1);
  m_pos[10]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[11]=9]);
  TextOutA(dc->m_hDC, 0, 0, "]", 1);
  m_pos[11]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[12]=8]);
  TextOutA(dc->m_hDC, 0, 0, ",", 1);
  m_pos[12]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[13]=3]);
  TextOutA(dc->m_hDC, 0, 0, "0.5", 3);
  m_pos[13]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[14]=5]);
  TextOutA(dc->m_hDC, 0, 0, "+", 1);
  m_pos[14]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[15]=10]);
  TextOutA(dc->m_hDC, 0, 0, "G_R", 3);
  m_pos[15]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[16]=8]);
  TextOutA(dc->m_hDC, 0, 0, ",", 1);
  m_pos[16]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[17]=2]);
  TextOutA(dc->m_hDC, 0, 0, "2", 1);
  m_pos[17]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[18]=5]);
  TextOutA(dc->m_hDC, 0, 0, "*", 1);
  m_pos[18]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[19]=11]);
  TextOutA(dc->m_hDC, 0, 0, "X", 1);
  m_pos[19]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[20]=8]);
  TextOutA(dc->m_hDC, 0, 0, ",", 1);
  m_pos[20]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[21]=12]);
  TextOutA(dc->m_hDC, 0, 0, "_", 1);
  m_pos[21]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[22]=8]);
  TextOutA(dc->m_hDC, 0, 0, ")", 1);
  m_pos[22]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[23]=13]);
  TextOutA(dc->m_hDC, 0, 0, ")", 1);
  m_pos[23]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[24]=5]);
  TextOutA(dc->m_hDC, 0, 0, ". ", 2);
  m_pos[24]=dc->GetCurrentPosition().x;
  dc->SetTextColor(m_synt_color[m_clist[25]=0]);
  TextOutA(dc->m_hDC, 0, 0, "% Com", 5);
  m_pos[25]=dc->GetCurrentPosition().x;
}
void CpgSyntaxColor::OnLButtonDown(UINT nFlags, CPoint point)
{
  if (point.y>=m_Point.y+10 && point.y<=m_Point.y+50 && point.x>=m_Point.x)
  {
    int k=0;
    for (; k<26 && point.x>m_pos[k]; k++);
    if (k<26)
    {
      m_CB_Type.SetCurSel(m_clist[k]);
      int i=Number(m_synt_color[m_clist[k]]);
      m_CB_Color.SetCurSel(i);
      GetDlgItem(IDC_BUTTON2)->EnableWindow(i==11);
      MakeText(GetDC());
    }  
  }  
  CPropertyPage::OnLButtonDown(nFlags, point);
}
int CpgSyntaxColor::Color(int Number)
{
  switch(Number)
  {
   case 0: // Red
    return RGB(255,0,0);
   case 1: // Green
    return RGB(0,128,0);
   case 2: // Light Green
    return RGB(0,255,0);
   case 3: // Blue
    return RGB(0,0,255);
   case 4: // Light Blue
    return RGB(0,255,255);
   case 5: // Yellow
    return RGB(255,255,0);
   case 6: // Orange
    return RGB(255,128,0);
   case 7: // Violet
    return RGB(255,0,255);
   case 8: // White
    return RGB(255,255,255);
   case 9: // Grey
    return RGB(128,128,128);
   case 10: // Black
    return RGB(0,0,0);
  }
  return RGB(0,0,0);
}
int CpgSyntaxColor::Number(int Color)
{
  switch(Color)
  {
   case RGB(255,0,0): // Red
    return 0;
   case RGB(0,128,0): // Green
    return 1;
   case RGB(0,255,0): // Light Green
    return 2;
   case RGB(0,0,255): // Blue
    return 3;
   case RGB(0,255,255): // Light Blue
    return 4;
   case RGB(255,255,0): // Yellow
    return 5;
   case RGB(255,128,0): // Orange
    return 6;
   case RGB(255,0,255): // Violet
    return 7;
   case RGB(255,255,255): // White
    return 8;
   case RGB(128,128,128): // Grey
    return 9;
   case RGB(0,0,0): // Black
    return 10;
   default: // Custom
    return 11;
  }
}
void CpgSyntaxColor::DoDataExchange(CDataExchange* pDX)
{
  CPropertyPage::DoDataExchange(pDX);
  // NOTE: the ClassWizard will add DDX and DDV calls here
  DDX_Control(pDX, IDC_COMBO1, m_CB_Type);
  DDX_Control(pDX, IDC_COMBO2, m_CB_Color);
  DDX_Check(pDX, IDC_CHECK1, m_OnFileOpen);
  DDX_Check(pDX, IDC_CHECK2, m_EveryTextChange);
  DDX_Check(pDX, IDC_CHECK4, m_WhenEnter);
}


BEGIN_MESSAGE_MAP(CpgSyntaxColor, CPropertyPage)
  ON_WM_PAINT()
  ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
  ON_CBN_SELCHANGE(IDC_COMBO2, OnCbnSelchangeCombo2)
  ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
  ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
  ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
  ON_BN_CLICKED(IDC_CHECK2, OnBnClickedCheck2)
  ON_BN_CLICKED(IDC_CHECK4, OnBnClickedCheck4)
  ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

// CpgSyntaxColor message handlers

void CpgSyntaxColor::OnOK() 
{
  if (m_OnFileOpen != ((Environment&0x10000)==0))
    Environment^=0x10000;
#if PROF
  if (m_EveryTextChange != ((Environment&0x40000)==0))
    Environment^=0x40000;
  if (m_WhenEnter != ((Environment&0x20000)!=0))
    Environment^=0x20000;
#else
  Environment&=0xfffdffff;
  if (m_WhenEnter != ((Environment&0x40000)==0))
    Environment^=0x40000;
#endif
  for(int i=0; i<LAST_COLOR; i++)
    synt_color[i]=m_synt_color[i];
  CPropertyPage::OnOK();
}
void CpgSyntaxColor::OnBnClickedCheck2()
{
  if (((CButton*)GetDlgItem(IDC_CHECK2))->GetCheck())  
#if PROF
    ((CButton*)GetDlgItem(IDC_CHECK4))->SetCheck(0);
#else
  {
    MessageBox(_T("In the light edition you cannot refresh on every text change."), _T("Strawberry Prolog - Light edition"), MB_ICONSTOP | MB_OK);
    ((CButton*)GetDlgItem(IDC_CHECK2))->SetCheck(0);
  }  
#endif
}
void CpgSyntaxColor::OnBnClickedCheck4()
{
  if (((CButton*)GetDlgItem(IDC_CHECK4))->GetCheck())  
    ((CButton*)GetDlgItem(IDC_CHECK2))->SetCheck(0);
}
/////////////////////////////////////////////////////////////////////////////
// CpgColors property page

IMPLEMENT_DYNCREATE(CpgColors, CPropertyPage)

CpgColors::CpgColors() : CPropertyPage(CpgColors::IDD)
{
    c_black1=c_black;
    c_red1=c_red;
    c_green1=c_green;
    c_blue1=c_blue;
    c_violet1=c_violet;
    c_output1=c_output;
        // NOTE: the ClassWizard will add member initialization here
}

CpgColors::~CpgColors()
{
}

void CpgColors::DoDataExchange(CDataExchange* pDX)
{
    CPropertyPage::DoDataExchange(pDX);
        // NOTE: the ClassWizard will add DDX and DDV calls here
}


BEGIN_MESSAGE_MAP(CpgColors, CPropertyPage)
    ON_WM_CTLCOLOR()
    ON_BN_CLICKED(IDC_CHANGE1, OnChange1)
    ON_BN_CLICKED(IDC_CHANGE2, OnChange2)
    ON_BN_CLICKED(IDC_CHANGE3, OnChange3)
    ON_BN_CLICKED(IDC_CHANGE4, OnChange4)
    ON_BN_CLICKED(IDC_CHANGE5, OnChange5)
    ON_BN_CLICKED(IDC_CHANGE6, OnChange6)
    ON_BN_CLICKED(IDC_SETDEF, OnSetDefault)
END_MESSAGE_MAP()

// CpgColors message handlers

HBRUSH CpgColors::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
    HBRUSH hbr = CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
    
    switch(pWnd->GetDlgCtrlID())
    {
     case IDC_STATIC1:
      pDC->SetTextColor(c_black1);
      break;
     case IDC_STATIC2:
      pDC->SetTextColor(c_red1);
      break;
     case IDC_STATIC3:
      pDC->SetTextColor(c_green1);
      break;
     case IDC_STATIC4:
      pDC->SetTextColor(c_blue1);
      break;
     case IDC_STATIC5:
      pDC->SetTextColor(c_violet1);
      break;
     case IDC_STATIC6:
      pDC->SetTextColor(c_output1);
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
}
void CpgColors::OnChange1() 
{
  ChangeColor(&c_black1);
}
void CpgColors::OnChange2() 
{
  ChangeColor(&c_red1);
}
void CpgColors::OnChange3() 
{
  ChangeColor(&c_green1);
}
void CpgColors::OnChange4() 
{
  ChangeColor(&c_blue1);
}
void CpgColors::OnChange5() 
{
  ChangeColor(&c_violet1);
}
void CpgColors::OnChange6() 
{
  ChangeColor(&c_output1);
}
void CpgColors::ChangeColor(DWORD *color)
{
  CColorDialog dialog(0, 0, this);
  dialog.m_cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_SHOWHELP | CC_ENABLEHOOK;//?hook
  dialog.m_cc.rgbResult= *color;
  if (dialog.DoModal()==IDOK)
  {
    *color=dialog.m_cc.rgbResult;
    InvalidateRect(NULL, TRUE);
  }
}

void CpgColors::OnSetDefault() 
{
  c_black1=RGB(0, 0, 0);
  c_red1=RGB(255, 0, 0);
  c_green1=RGB(0, 127, 0);
  c_output1=c_blue1=RGB(0, 0, 255);
  c_violet1=RGB(255, 0, 255);
  InvalidateRect(NULL, TRUE);
}

void CpgColors::OnOK() 
{
  if (c_black!=c_black1 || c_red!=c_red1 || c_green!=c_green1
                        || c_blue!=c_blue1 || c_violet!=c_violet1)
  {
    c_black=c_black1;
    c_red=c_red1;
    c_green=c_green1;
    c_blue=c_blue1;
    c_violet=c_violet1;
    if (pStack)
      pStack->InvalidateRect(NULL, TRUE);
    if (pVariables)
      pVariables->InvalidateRect(NULL, TRUE);
    if (pProofTree)
      pProofTree->InvalidateRect(NULL, TRUE);
  }
  if (c_output!=c_output1)
  {
    CHARFORMAT cf;
    cf.crTextColor=c_output=c_output1;
    cf.dwMask=CFM_COLOR;
    cf.dwEffects=0; // Auto Color
    pOutput->SetDefaultCharFormat(cf);
  }
  CPropertyPage::OnOK();
}

/////////////////////////////////////////////////////////////////////////////
// CEnvironment

IMPLEMENT_DYNAMIC(CEnvironment, CPropertySheet)

CEnvironment::CEnvironment(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
    :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
  AddPage(&m_environment);
  AddPage(&m_view);
  AddPage(&m_syntax_color);
  AddPage(&m_colors);
}

CEnvironment::CEnvironment(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
    :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
  AddPage(&m_environment);
  AddPage(&m_view);
  AddPage(&m_syntax_color);
  AddPage(&m_colors);
}

CEnvironment::~CEnvironment()
{
}


BEGIN_MESSAGE_MAP(CEnvironment, CPropertySheet)
        // NOTE - the ClassWizard will add and remove mapping macros here.
END_MESSAGE_MAP()

// CEnvironment message handlers
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CdRegister dialog
CdRegister::CdRegister(CWnd* pParent /*=NULL*/)
    : CDialog(CdRegister::IDD, pParent)
{
    m_Name = "";
    m_From = "";
    m_ProductID = "";
    m_Password = "";
}

void CdRegister::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    if (pDX->m_bSaveAndValidate)
    {
      DDX_Text(pDX, IDC_EDIT1, RegName);
      DDX_Text(pDX, IDC_EDIT2, RegFrom);
      DDX_Text(pDX, IDC_EDIT3, RegProdID);
      DDX_Text(pDX, IDC_EDIT4, RegPassword);
// Source code for passwords coding - its missing
//***
      status_fl|=128;
    }
    else
    {
      DDX_Text(pDX, IDC_EDIT1, m_Name);
      DDX_Text(pDX, IDC_EDIT2, m_From);
      DDX_Text(pDX, IDC_EDIT3, m_ProductID);
      DDX_Text(pDX, IDC_EDIT4, m_Password);
    }
}


BEGIN_MESSAGE_MAP(CdRegister, CDialog)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CdRegister message handlers

void CdRegister::OnOK() 
{
    //UpdateData();
    CDialog::OnOK();
}

BOOL CdRegister::OnInitDialog() 
{
    CDialog::OnInitDialog();
    GetDlgItem(IDC_EDIT1)->SetFocus();
    return FALSE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////
// CdIConlist dialog
// Angel

CdIConlist::CdIConlist(CWnd* pParent /*=NULL*/)
    : CDialog(CdIConlist::IDD, pParent)
{
}


void CdIConlist::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CdIConlist, CDialog)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CdIConlist message handlers

BOOL CdIConlist::Create(LPSTR lpszClassName, LPSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
    // TODO: Add your specialized code here and/or call the base class
    return CDialog::Create(IDD, pParentWnd);
}


BOOL CdIConlist::OnInitDialog() 
{
   CDialog::OnInitDialog();
   int nIcons;

   m_ListCtrl.Create(WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_ICON | LVS_SINGLESEL,
              CRect(7,7,260,160), this, 105);   
    
   m_ListCtrl.SetImageList(&m_ImageList,LVSIL_NORMAL);
    
   nIcons=m_dwArray.GetSize();
   for(int i=0;i<nIcons;i++) m_ListCtrl.InsertItem(i,NULL,i);
  
   //m_ListCtrl.SetSelectionMark(1); Version 6   
 
   return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}




BOOL CALLBACK MyEnumProcedure(MY_HANDLE hModule, LPCTSTR  lpszType, LPTSTR  lpszName, LONG  lParam)    
{
  CDWordArray *pdwArray;

  pdwArray=(CDWordArray*) lParam;


  if( HIWORD(lpszName) == 0) pdwArray->Add((DWORD)lpszName);     

//  hIcon=GetIconFromInstance((HINSTANCE) hModule, lpszName);

  
  // hIcon=(HICON)LoadImage((HINSTANCE) hModule, lpszName, IMAGE_ICON, 32,32, LR_DEFAULTCOLOR); 
  // pImageList->Add(hIcon);
  // DestroyIcon(hIcon);

  return TRUE;
}


HICON GetIconFromInstance( HINSTANCE hInstance, LPCTSTR nIndex )
{
  HICON    hIcon = NULL;
  HRSRC    hRsrc = NULL;
  HGLOBAL    hGlobal = NULL;
  LPVOID    lpRes = NULL;
  int        nID;

  if( (hRsrc = FindResource( hInstance, nIndex, RT_GROUP_ICON )) == NULL )
      return NULL;
  if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
      return NULL;
  if( (lpRes = LockResource(hGlobal)) == NULL )
      return NULL;

  nID = LookupIconIdFromDirectory((unsigned char*) lpRes, TRUE );
  if( (hRsrc = FindResource( hInstance, MAKEINTRESOURCE(nID), RT_ICON )) == NULL )
      return NULL;
  if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
      return NULL;
  if( (lpRes = LockResource(hGlobal)) == NULL )
      return NULL;

  hIcon = CreateIconFromResource((unsigned char*) lpRes, SizeofResource(hInstance,hRsrc), TRUE, 0x00030000 );
  return hIcon;
}



BOOL LoadIconFromInstance(HINSTANCE hInstance, LPCTSTR nIndex, BYTE* icon) 
{
  HICON    hIcon = NULL;
  HRSRC    hRsrc = NULL;
  HGLOBAL    hGlobal = NULL;
  LPVOID    lpRes = NULL;
  int        nID;

  if( (hRsrc = FindResource( hInstance, nIndex, RT_GROUP_ICON )) == NULL )
        return NULL;   
  if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
      return NULL;
  if( (lpRes = LockResource(hGlobal)) == NULL )
      return NULL;

  nID = LookupIconIdFromDirectory((unsigned char*) lpRes, TRUE );
  if( (hRsrc = FindResource( hInstance, MAKEINTRESOURCE(nID), RT_ICON )) == NULL )
      return NULL;
  if( (hGlobal = LoadResource( hInstance, hRsrc )) == NULL )
      return NULL;
  if( (lpRes = LockResource(hGlobal)) == NULL )
      return NULL;

  memcpy(icon,lpRes,744);

 return true;   
}


BOOL CdIConlist::DestroyWindow() 
{
  int i;
  
  i=m_ListCtrl.GetNextItem(-1, LVNI_SELECTED);
  if (i==-1) i=0;

  m_index=m_dwArray.GetAt(i); 
  
  m_ListCtrl.DestroyWindow();
  m_ImageList.DeleteImageList();
  m_dwArray.RemoveAll();

  return CDialog::DestroyWindow();
}


void CdIConlist::GetIcon(BYTE *Icon)
{
  if (m_FileName.Find(_T(".ico"))>0)
  { 
    CFile IcoFile;

    IcoFile.Open(m_FileName,CFile::modeRead);
     // DON'T FORGET : to add validation code here !!!
      IcoFile.Seek(0x16,CFile::begin);
    IcoFile.Read(Icon,744);
    IcoFile.Close();
  }

  if ((m_FileName.Find(_T(".exe"))>0) || (m_FileName.Find(_T(".dll"))>0))
  {
    if( (m_hModule = LoadLibraryEx(m_FileName, NULL, LOAD_LIBRARY_AS_DATAFILE )) == NULL )
    {
      MessageBox(_T("Error Loading File - Choose a 32bit DLL or EXE"), _T("Error"), MB_OK );
      FreeLibrary(m_hModule);  
      return;
    }
    int nIcons=0;
     
    m_dwArray.SetSize(0);
  
    if( ! EnumResourceNames(m_hModule, RT_GROUP_ICON,(ENUMRESNAMEPROC)MyEnumProcedure,(LONG)&m_dwArray))
    {
      MessageBox(_T("Error Enumerating Icons"), _T("Error"), MB_OK );
      FreeLibrary(m_hModule);  
      return;
    }
 
    nIcons=m_dwArray.GetSize();

    if ((m_dwArray.GetUpperBound()==0) && (nIcons!=1))
    {
      MessageBox(_T("There are not icons in this file."), _T("Sorry"), MB_OK );
      FreeLibrary(m_hModule);  
      return;
    }

   m_ImageList.Create(32,32,TRUE,1,0);

   for(int j=0;j<nIcons;j++)
   {  HICON hIcon;
      hIcon=GetIconFromInstance((HINSTANCE) m_hModule,(LPCTSTR)m_dwArray.GetAt(j));
      m_ImageList.Add(hIcon);
      DestroyIcon(hIcon);
   }

   if (DoModal()==IDOK)
   {
     LoadIconFromInstance(m_hModule,(LPCTSTR) m_index, Icon);   
   }   
   
   FreeLibrary(m_hModule);
  }

}

/////////////////////////////////////////////////////////////////////////////
// CdComeStart dialog


CdComeStart::CdComeStart(CWnd* pParent /*=NULL*/)
    : CDialog(CdComeStart::IDD, pParent)
{
}


void CdComeStart::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CdComeStart, CDialog)
    ON_WM_PAINT()
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CdComeStart message handlers

void CdComeStart::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    dcMem.CreateCompatibleDC(&dc);
    bmp1.LoadBitmap(IDB_ABOUT1);
    bmp2.LoadBitmap(IDB_ABOUT2);
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(240, 50, 162, 112, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(240, 50, 162, 112, &dcMem, 0, 0, SRCPAINT);
    // Do not call CDialog::OnPaint() for painting messages
}

BOOL CdComeStart::OnInitDialog() 
{
    CDialog::OnInitDialog();
    
    GetDlgItem(IDC_EDIT1)->SetWindowText(string3);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}


/////////////////////////////////////////////////////////////////////////////
// CdComeEnd dialog

CdComeEnd::CdComeEnd(CWnd* pParent /*=NULL*/)
    : CDialog(CdComeEnd::IDD, pParent)
{
}


void CdComeEnd::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CdComeEnd, CDialog)
    ON_WM_PAINT()
    ON_BN_CLICKED(IDC_BUTTON, OnUnunstall)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CdComeEnd message handlers
void CdComeEnd::OnPaint() 
{
    CPaintDC dc(this); // device context for painting
    dc.SetMapMode(MM_ISOTROPIC);
    dc.SetWindowExt(96, 96);
    int pix=dc.GetDeviceCaps(LOGPIXELSX);
    dc.SetViewportExt(pix, pix);
    CDC dcMem;
    CBitmap bmp1;
    CBitmap bmp2;
    dcMem.CreateCompatibleDC(&dc);
    bmp1.LoadBitmap(IDB_BITMAP_ACTIVE2);
    bmp2.LoadBitmap(IDB_BITMAP_ACTIVE);
    dcMem.SelectObject(&bmp1);
    SelectObject(dc.m_hDC, hbrGrey);
    dc.BitBlt(260, 50, 99, 94, &dcMem, 0, 0, MERGECOPY);
    dcMem.SelectObject(&bmp2);
    dc.BitBlt(260, 50, 99, 94, &dcMem, 0, 0, SRCPAINT);
    // Do not call CDialog::OnPaint() for painting messages
}

BOOL CdComeEnd::OnInitDialog() 
{
    CDialog::OnInitDialog();
    
    GetDlgItem(IDC_EDIT1)->SetWindowText(string3);
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}
void CdComeEnd::OnUnunstall() 
{
  EndDialog(IDABORT);
}
