//---------------------------------------------------------------------------

#include <windows.h>
#include <commctrl.h>
#include <dir.h>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include "Main.h"
#include "sfxrc.h"

//---------------------------------------------------------------------------
HWND hDlg; //global variable to store our window handle
HINSTANCE hInst; //global variable to store our program's instance
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  MInstance = hInstance;
  // support for environment variable %TICKS%
  itoa(GetTickCount(), PathBuf, 10);
  SetEnvironmentVariable("TICKS", PathBuf);
  // initialize common controls (for the progress bar and listview)
  InitCommonControls();
    // needs less code than ParamStr(0)
  GetModuleFileName(0, PathBuf, sizeof(PathBuf));
  VStr_ExeName = new char[MAXPATH]; // needs to be large enough to hold spanned archive names
  strcpy(VStr_ExeName, PathBuf);
  // open the archive file (i myself!)

  // for debugging we don't open ourselves but the file to debug
//  strcpy(VStr_ExeName, "F:\\temp\\testref.exe");
//  strcpy(VStr_ExeName, "A:\\testref.exe");
  if((VH_InFile = CreateFile(VStr_ExeName, GENERIC_READ, FILE_SHARE_READ, NULL,
                         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)) == INVALID_HANDLE_VALUE)
       ErrorHalt(Err_Archive, VStr_ExeName);
  Make_CRC32Table();
  // read the TSFXFileHeader record (and the appended strings) from the file
  GetDefParams();
  SHFILEINFO sfi = {0}; // to get shell image list handle
  VH_ShellImageList = SHGetFileInfo(VStr_ExeName, 0,
                                   &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
  // Display the dialog
  DialogBox(hInstance,Str_Dlg_Main , NULL, reinterpret_cast<DLGPROC>(MainDialogProc));
  return 0;
}
//---------------------------------------------------------------------------
