home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 December / PC Answers December 1995 (disc errors).iso / hobby / editbox / devel300 / st-main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-14  |  7.1 KB  |  234 lines

  1. /**************************************************************************************************
  2.  
  3.     SPELTEST
  4.     Program to test spelling checker.
  5.  
  6.     Written and copyright by Brian J Quinion 1995.
  7.  
  8.     Version for Microsoft Windows.
  9.     Version:  3.00
  10.     Date:     13 July 1995
  11.     Module:   ST-MAIN.C
  12.  
  13. **************************************************************************************************/
  14.  
  15.     /* include files common to all modules */
  16. #define EXTERN
  17.     #include "speltest.h"
  18.  
  19.     /* include files for this module only */
  20.     #pragma  hdrstop
  21.     /* NONE */
  22.  
  23. /***************************************************************************************************
  24.  
  25.     WinMain
  26.     -------
  27.     Main function for windows program
  28.  
  29.     Parameters : WinMain standard
  30.     Called by  : Windows OS
  31.     Calls      : 
  32.     Modifies   : 
  33.     Returns    : As standard
  34.  
  35. ***************************************************************************************************/
  36. #pragma argsused
  37. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  38. {
  39.     HWND            hWnd;
  40.     MSG             msg;
  41.  
  42.     if(hPrevInstance)
  43.     {
  44.     // Don't run another
  45.     return FALSE;
  46.     }
  47.  
  48.     // Make a copy of hInstance for global use
  49.     g.hInst=hInstance;
  50.  
  51.     // Get the program path
  52.     GetModuleFileName(g.hInst, g.szProgDir, MAXDIR);
  53.     *(strrchr(g.szProgDir, '\\'))='\0';
  54.  
  55.     // Load settings
  56.     LoadSettings();
  57.     if (!LoadResources())
  58.         return 0;
  59.  
  60.     // Start the main window
  61.     RegisterSPELTEST_MAIN();
  62.     hWnd=CreateWindow("SPELTEST_MAIN", "Spell Checker Tester", WS_OVERLAPPEDWINDOW, 10, 10, 400, 300,
  63.                       NULL, NULL, g.hInst, NULL);
  64.     ShowWindow(hWnd, SW_SHOW);
  65.  
  66.     // Enter the message loop
  67.     while (GetMessage(&msg, (HWND) NULL, 0, 0))
  68.     {
  69.         TranslateMessage(&msg);
  70.         DispatchMessage(&msg);
  71.     }
  72.  
  73.     // Save settings
  74.     SaveSettings();
  75.     FreeResources();
  76.  
  77.     return 0;
  78. }
  79.  
  80. /***************************************************************************************************
  81.  
  82.     LoadSettings
  83.     ------------
  84.     Load settings from the ini file and the dat file
  85.  
  86.     Parameters : none
  87.     Called by  : WinMain
  88.     Calls      : 
  89.     Modifies   :
  90.         o.SaveOptions        -
  91.     Returns    :
  92.  
  93. ***************************************************************************************************/
  94. void LoadSettings(void)
  95. {
  96. }
  97.  
  98. /***************************************************************************************************
  99.  
  100.     SaveSettings
  101.     ------------
  102.     Save settings to the ini file and the dat file
  103.  
  104.     Parameters : none
  105.     Called by  : WinMain
  106.     Calls      : 
  107.     Modifies   : ini and dat files
  108.     Returns    : nothing
  109.  
  110. ***************************************************************************************************/
  111. void SaveSettings(void)
  112. {
  113. }
  114.  
  115. /***************************************************************************************************
  116.  
  117.     LoadResources
  118.     -------------
  119.     Load resources, and initalise
  120.  
  121.     Parameters : none
  122.     Called by  : WinMain
  123.     Calls      : 
  124.     Modifies   :
  125.     Returns    :
  126.  
  127. ***************************************************************************************************/
  128. BOOL LoadResources(void)
  129. {
  130.     char            FileName[MAXPATH];
  131.     // Load the checkedt module - done like this so that the program
  132.     // could run without having the spelledt module available
  133.     // Loading a Lib file in the project would result in an error
  134.     // if the module was not available.
  135.  
  136.     // Get the path and try to load spellch3.dll
  137.     GetPrivateProfileString("Modules", "spellch3", "spellch3.dll", FileName, MAXPATH, "Spelledt.ini");
  138.     g.hModFull=LoadLibrary(FileName);
  139.     if (g.hModFull<HINSTANCE_ERROR)
  140.     {
  141.         MessageBox(NULL, "Unable to load the module 'spellch3.dll'", "Spell setup", MB_ICONSTOP);
  142.         return FALSE;
  143.     }
  144.     if (((FARPROC)g.LINK_SPCHK_Version=GetProcAddress(g.hModFull, "SPCHK_Version")) == NULL)
  145.     {
  146.         MessageBox(NULL, "Unable to find function 'SPCHK_Version' in module 'spellch3.dll'", "Spell setup", MB_ICONSTOP);
  147.         FreeModule(g.hModFull);
  148.         return FALSE;
  149.     }
  150.     if (g.LINK_SPCHK_Version()<300)
  151.     {
  152.         MessageBox(NULL, "Incorrect version of spellch3.dll", "Spell setup", MB_ICONSTOP);
  153.         FreeModule(g.hModFull);
  154.         return FALSE;
  155.     }
  156.     // Load the functions
  157.     (FARPROC)g.LINK_SPCHK_CheckWord=GetProcAddress(g.hModFull, "SPCHK_CheckWord");
  158.     (FARPROC)g.LINK_SPCHK_Options=GetProcAddress(g.hModFull, "SPCHK_Options");
  159.  
  160.     // Get the path and try to load spelledt.dll
  161.     GetPrivateProfileString("Modules", "spelledt", "spelledt.dll", FileName, MAXPATH, "Spelledt.ini");
  162.     g.hModQuick=LoadLibrary(FileName);
  163.     if (g.hModQuick<HINSTANCE_ERROR)
  164.     {
  165.         MessageBox(NULL, "Unable to load the module 'spelledt.dll'", "Spell setup", MB_ICONSTOP);
  166.         FreeModule(g.hModFull);
  167.         return FALSE;
  168.     }
  169.     if (((FARPROC)g.LINK_SPEDT_Version=GetProcAddress(g.hModQuick, "SPEDT_Version")) == NULL)
  170.     {
  171.         MessageBox(NULL, "Unable to find function 'SPEDT_Version' in module 'spellch3.dll'", "Spell setup", MB_ICONSTOP);
  172.         FreeModule(g.hModFull);
  173.         FreeModule(g.hModQuick);
  174.         return FALSE;
  175.     }
  176.     if (g.LINK_SPCHK_Version()<300)
  177.     {
  178.         MessageBox(NULL, "Incorrect version of spelledt.dll", "Spell setup", MB_ICONSTOP);
  179.         FreeModule(g.hModFull);
  180.         FreeModule(g.hModQuick);
  181.         return FALSE;
  182.     }
  183.  
  184.     (FARPROC)g.LINK_SPEDT_CheckEdit=GetProcAddress(g.hModQuick, "SPEDT_CheckEdit");
  185.     (FARPROC)g.LINK_SPEDT_CheckEditCustom=GetProcAddress(g.hModQuick, "SPEDT_CheckEditCustom");
  186.     (FARPROC)g.LINK_SPEDT_SetupBox=GetProcAddress(g.hModQuick, "SPEDT_SetupBox");
  187.     (FARPROC)g.LINK_SPEDT_SetupBoxLimited=GetProcAddress(g.hModQuick, "SPEDT_SetupBoxLimited");
  188.     (FARPROC)g.LINK_SPEDT_SetupCustom=GetProcAddress(g.hModQuick, "SPEDT_SetupCustom");
  189.     (FARPROC)g.LINK_SPEDT_CheckGlobal=GetProcAddress(g.hModQuick, "SPEDT_CheckGlobal");
  190.     (FARPROC)g.LINK_SPEDT_CheckGlobalCustom=GetProcAddress(g.hModQuick, "SPEDT_CheckGlobalCustom");
  191.  
  192.     return TRUE;
  193. }
  194.  
  195. /***************************************************************************************************
  196.  
  197.     FreeResources
  198.     -------------
  199.     Free resources
  200.  
  201.     Parameters : none
  202.     Called by  : WinMain
  203.     Calls      : 
  204.     Modifies   :
  205.     Returns    :
  206.  
  207. ***************************************************************************************************/
  208. void FreeResources(void)
  209. {
  210.     FreeModule(g.hModFull);
  211.     FreeModule(g.hModQuick);
  212. }
  213.  
  214. /***************************************************************************************************
  215.  
  216.     WritePrivateProfileInt
  217.     ----------------------
  218.     Suppliment function to GetPrivateProfileInt
  219.  
  220.     Parameters : 
  221.     Called by  : 
  222.     Calls      : 
  223.     Modifies   :
  224.     Returns    :
  225.  
  226. ***************************************************************************************************/
  227. BOOL WritePrivateProfileInt(LPSTR lpSection, LPSTR lpItem, DWORD Int, LPSTR lpFileName)
  228. {
  229.     char            Buffer[20];
  230.  
  231.     itoa((int)Int, Buffer, 10);
  232.     return WritePrivateProfileString(lpSection, lpItem, (LPSTR)Buffer, lpFileName);
  233. }
  234.