home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dho.zip / DHO / SRC / APPLICAT.CC next >
C/C++ Source or Header  |  1995-09-03  |  5KB  |  191 lines

  1. /****************************************/
  2. /*    Developer Helper Object Set       */
  3. /*  (C) 1994-95 Thomas E. Bednarz, Jr.  */
  4. /*     All rights reserved              */
  5. /***************************************/
  6.  
  7. /* $Id: applicat.cc 1.9 1995/09/03 01:27:59 teb Exp $ */
  8.  
  9.  
  10. #include<applicat.h>
  11. #include<framewin.h>
  12. #include<stdlib.h>
  13.  
  14. TApplication *Application=NULL;
  15. TDesktopWindow *DesktopWin;
  16.  
  17. //-------------------------------------------------------------------
  18. //   getApplication
  19. TApplication *getApplication()
  20. {
  21.    return Application;
  22. }
  23.  
  24. //-------------------------------------------------------------------
  25. //   openINIfile
  26. HINI TApplication::openINIfile(char* fname)
  27. {
  28.    hin = PrfOpenProfile (getAnchorBlock(), (PSZ)fname); 
  29.    return (hin != (HINI)NULL);
  30. }
  31.  
  32.  
  33. //-------------------------------------------------------------------
  34. //   closeINIfile
  35. void TApplication::closeINIfile()
  36. {
  37.    PrfCloseProfile(hin);    
  38. }
  39.  
  40.  
  41.  
  42. //-------------------------------------------------------------------
  43. //   writeINIdata
  44. void TApplication::writeINIdata(char* section, char* index, PVOID val, 
  45.                                 ULONG size)
  46. {
  47.    if (hin != (HINI)NULL)
  48.       PrfWriteProfileData(hin, (PSZ)section, (PSZ)index, val, size);
  49. }
  50.  
  51.  
  52. //-------------------------------------------------------------------
  53. //   inqINIdataSize
  54. PULONG TApplication::inqINIdataSize(char* section, char* index)
  55. {
  56.    PULONG res = 0;
  57.    if (hin != (HINI)NULL)
  58.       
  59.       PrfQueryProfileSize(hin, (PSZ)section, (PSZ)index, res);
  60.    return res;
  61. }
  62.  
  63.  
  64. //-------------------------------------------------------------------
  65. //   getINIdata
  66. BOOL TApplication::getINIdata(char* section, char* index,
  67.                               PVOID buf, ULONG size)
  68. {
  69.    return PrfQueryProfileData(hin, (PSZ)section, 
  70.                               (PSZ)index, buf, &size);
  71. }
  72.  
  73.  
  74. //-------------------------------------------------------------------
  75. //   TApplication
  76. TApplication::TApplication(ULONG resource)
  77. {   
  78.    Application = this;
  79.    DesktopWin = NULL;
  80.    Proc = new TProcess;
  81.    fResource = resource;
  82.    if (Proc==NULL)
  83.    {
  84. #ifdef DEBUG
  85.       WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, 
  86.          (PSZ)"Couldn't create Process Object", 
  87.          (PSZ)"Error!",0, MB_MOVEABLE | MB_CANCEL ); 
  88. #endif
  89.       exit(1);
  90.    }
  91.    MainWin=NULL;
  92. }
  93.  
  94.  
  95.  
  96. //-------------------------------------------------------------------
  97. //   ~TApplication
  98. TApplication::~TApplication()
  99. {   
  100.    if (DesktopWin)
  101.       delete DesktopWin;
  102. }
  103.  
  104.  
  105. //-------------------------------------------------------------------
  106. //   init
  107. void TApplication::init(void)
  108. {
  109.    CreateMainWindow();
  110.    if (MainWin!=NULL)
  111.    {
  112.        if (!MainWin->init())
  113.             handleInitError("Couldn't create Window Frame");
  114.        else
  115.        {
  116.           MainWin->shellSetPosition();
  117.           MainWin->showWindow();
  118.        }
  119.        DesktopWin=new TDesktopWindow;
  120.        if (!DesktopWin->init())
  121.           DesktopWin=NULL;
  122.    }
  123.    else
  124.       handleInitError("Couldn't create Window Object");
  125. }
  126.  
  127.  
  128. //-------------------------------------------------------------------
  129. //   run
  130. void TApplication::run(void)
  131. {
  132.    //  Standard message processing loop. WinGetMsg returns FALSE if the  
  133.    //  returned message is WM_QUIT.  Returns TRUE for all other messages 
  134.  
  135.       while (WinGetMsg(Proc->getAnchorBlock(), &QueMsg, HMODULE(NULL),0,0))
  136.          WinDispatchMsg(Proc->getAnchorBlock(), &QueMsg);
  137.  
  138. }
  139.  
  140.  
  141. //-------------------------------------------------------------------
  142. //   done
  143. void TApplication::done(void)
  144. {
  145.    if (MainWin!=NULL)
  146.       delete(MainWin);
  147.    if (Proc!=NULL)
  148.       delete(Proc);
  149. }
  150.  
  151. //-------------------------------------------------------------------
  152. //   CreateMainWindow
  153. void TApplication::CreateMainWindow(void)
  154. {
  155.    MainWin = new TFrameWindow(fResource, "Standard Window");
  156. }
  157.  
  158. //-------------------------------------------------------------------
  159. //   getClassName
  160. const char *TApplication::getClassName(void)
  161. {
  162.    return "TApplication";
  163. }
  164.  
  165. //-------------------------------------------------------------------
  166. //   getAnchorBlock
  167. HAB TApplication::getAnchorBlock()
  168. {
  169.    return Proc->getAnchorBlock();
  170. }
  171.  
  172. //-------------------------------------------------------------------
  173. //   getMainWindow
  174. TWinBase *TApplication::getMainWindow(void)
  175. {
  176.    return MainWin;  
  177. }
  178.  
  179.  
  180. //-------------------------------------------------------------------
  181. //   handleInitError
  182. void TApplication::handleInitError(char *errMsg)
  183. {
  184. #ifdef DEBUG
  185.       WinMessageBox(HWND_DESKTOP,HWND_DESKTOP, 
  186.          (PSZ)errMsg,
  187.          (PSZ)"Error!",0, MB_MOVEABLE | MB_CANCEL ); 
  188. #endif
  189.       exit(1);
  190. }
  191.