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