home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / WILDASS / SOURCE / APP.CPP < prev    next >
Text File  |  1993-08-14  |  10KB  |  373 lines

  1. // app.cpp
  2. //
  3. // application implementation module
  4. //
  5. // update: 1.00 26-Jul-93 tw
  6. //         1.01 27-Jul-93 tw added intro dialog and ctl3d.dll
  7. //         1.02 27-Jul-93 tw removed EatTime, added buttond to main window
  8. //         1.03 01-Aug-93 tw removed FakeCptn from project; functionality added to CMainWnd for clarity 
  9. //                           added command-handlers for toolbars
  10. //         1.04 06-Aug-93 tw added task handling
  11. //         1.05 08-Aug-93 tw added tiling
  12. //         1.06 08-Aug-93 tw added mouse hook dll
  13.             
  14. #include <afxwin.h>
  15. #include <afxext.h> 
  16. #include <ctl3d.h> 
  17.  
  18. #include "resource.h"                  
  19. #include "app.h"
  20. #include "introdlg.h" 
  21. #include "mainwnd.h"           
  22. #include "tasks.h"
  23. #include "taskdlg.h"
  24. #include "wndlst.h"
  25. #include "optsdlg.h"  
  26. #include "hooksdll.h"
  27. // #include "appdlg.h"
  28. #include "grpdlg.h"
  29. #include "firsttim.h"
  30. #include "aboutdlg.h"  
  31. #include "desktop.h"
  32. #include "progmgr.h"
  33.  
  34. BEGIN_MESSAGE_MAP( CMyApp, CWinApp )
  35.    ON_COMMAND( IDB_TILE1, OnTile1 )
  36.    ON_COMMAND( IDB_TILE2, OnTile2 )
  37.    ON_COMMAND( IDB_TILE3, OnTile3 )
  38.    ON_COMMAND( IDB_TILE4, OnTile4 )
  39.    ON_COMMAND( IDB_WSP1,  OnWsp1 )
  40.    ON_COMMAND( IDB_WSP2,  OnWsp2 )
  41.    ON_COMMAND( IDB_WSP3,  OnWsp3 )
  42.    ON_COMMAND( IDB_WSP4,  OnWsp4 )
  43.    ON_COMMAND( IDB_OPTS1, OnOpts1 )
  44.    ON_COMMAND( IDB_OPTS2, OnOpts2 )
  45.    ON_COMMAND( IDB_OPTS3, OnOpts3 )
  46.    ON_COMMAND( IDB_OPTS4, OnOpts4 )
  47. END_MESSAGE_MAP()   
  48.          
  49. CMyApp theApp("MoreSpace");
  50.  
  51. CMyApp::CMyApp( const char * pszAppName )
  52.  : CWinApp( pszAppName )
  53. {}
  54.  
  55. BOOL
  56. CMyApp::InitInstance()
  57. {                    
  58.    // take care of 3d feature
  59.    Ctl3dRegister( AfxGetInstanceHandle() );
  60.    Ctl3dAutoSubclass( AfxGetInstanceHandle() );
  61.    
  62.    // reset the current application list                      
  63.    m_nCurrentAppList = -1;
  64.    
  65.    // create an intro dialog                         
  66.    CIntroDialog dlgIntro;       
  67.    
  68.    // read the applications for the launch buttons
  69.    // so when we create the main window, the appropriate
  70.    // icons may be displayed
  71.    ReadApplicationInfo();
  72.        
  73.    // create the main window
  74.    m_pMainWnd = new CMainWnd();
  75.       
  76.    // don`t show the window, the mouse hook will do this      
  77.    // m_pMainWnd->ShowWindow( m_nCmdShow );
  78.    
  79.    // read the profile settings
  80.    CString strOptions, strPixelFrame, strComeUp, strStayVisible;
  81.    VERIFY( strOptions.LoadString( IDS_OPTIONS ));
  82.    VERIFY( strPixelFrame.LoadString( IDS_PIXELFRAME ));
  83.    m_cPixelFrame = GetProfileInt( strOptions, strPixelFrame, 0 );
  84.                         
  85.    VERIFY( strComeUp.LoadString( IDS_COMEUP ));                        
  86.    m_fComeUpAllways = GetProfileInt( strOptions, strComeUp, 0 );
  87.    
  88.    VERIFY( strStayVisible.LoadString( IDS_STAYVISIBLE ));                        
  89.    m_fStayVisible = GetProfileInt( strOptions, strStayVisible, 0 );
  90.                      
  91.    // check if this is the first time we are running                     
  92.    // if so, give the user an intro dialog
  93.    if ( GetProfileInt( "FirstTime", "FirstTime", 1 ))
  94.    {
  95.       CFirstTimeDlg dlg;
  96.       dlg.DoModal();
  97.       
  98.       // dump the first time flag, in order to remove the info dialog
  99.       WriteProfileInt( "FirstTime", "FirstTime", 0 );   
  100.    }              
  101.    // if not, restore the last desktop
  102.    else
  103.    {  
  104. // skip this during debug
  105. #ifndef _DEBUG   
  106.       CDesktop desktop("DesktopOnExit");
  107.       desktop.PlayBack();
  108. #endif      
  109.    }
  110.                      
  111.    // tell windows we`re ready to accept files - but
  112.    // only if this makes any sense. translation: only if
  113.    // we are visible when loosing focus
  114.    // dont; buttons get drop info, not us
  115.    // m_pMainWnd->DragAcceptFiles( m_fStayVisible );
  116.    
  117.    // init the mouse hook dll
  118.    // and install the mouse hook filter            
  119.    MsHookDLL_InitDLL( m_pMainWnd->m_hWnd );    
  120.    MsHookDLL_InstallFilter( TRUE );
  121.    
  122.    // set the mouse hook behaviour flag
  123.    MsHookDLL_SetComeUpAllways( m_fComeUpAllways );
  124.  
  125.    return TRUE;    
  126. }                                
  127.  
  128. int      
  129. CMyApp::ExitInstance()      
  130. {  
  131.    TRACE0("+ExitInstance\n");
  132.  
  133.    // tell cl3d we don`t need it anymore
  134.    Ctl3dUnregister( AfxGetInstanceHandle() );
  135.    
  136.    // remove the mouse hook filter
  137.    MsHookDLL_InstallFilter( FALSE );
  138.    
  139.    // dump the Application information to the profile
  140.    WriteApplicationInfo();    
  141.    
  142.    // let CWinApp do the rest
  143.    TRACE0("-ExitInstance\n"); 
  144.    return CWinApp::ExitInstance();
  145. }
  146.  
  147. // interface to options settings
  148. UINT
  149. CMyApp::Settings_PixelFrame() const
  150. {
  151.    return m_cPixelFrame;
  152. }
  153.  
  154. BOOL 
  155. CMyApp::Settings_ComeUpAllways() const
  156. {
  157.    return m_fComeUpAllways;
  158. }
  159.  
  160. BOOL
  161. CMyApp::Settings_StayVisible() const
  162. {
  163.    return m_fStayVisible;
  164. }      
  165.  
  166. const CApplicationList * 
  167. CMyApp::CurrentApplicationList() const
  168. {
  169.    ASSERT( (m_nCurrentAppList >= 0) && (m_nCurrentAppList < nIconButtons) );
  170.    return &m_AppList[m_nCurrentAppList];
  171. }            
  172.  
  173. void
  174. CMyApp::ManageDesktop( const char * pszDesktopName )
  175. {  
  176.    // check if this desktop alread exists
  177.    // if it does, load it,
  178.    // or else save the current desktop to it
  179.    // desktops may be cleared via the 
  180.    // options menu
  181.    CString strTest = AfxGetApp()->GetProfileString( pszDesktopName, "App1" );
  182.  
  183.    // make ourselves invisible
  184.    m_pMainWnd->ShowWindow( SW_HIDE );
  185.    
  186.    // get a desktop
  187.    CDesktop dt( pszDesktopName );
  188.    
  189.    // dump current
  190.    if ( strTest.IsEmpty() )
  191.    {
  192.       dt.Snapshot();
  193.    }
  194.    else
  195.    // load it
  196.    {
  197.       dt.PlayBack();
  198.    }
  199. }
  200.  
  201. void 
  202. CMyApp::OnWsp1()   
  203. {                                       
  204.    ManageDesktop("Desktop1");
  205. }
  206.  
  207. void 
  208. CMyApp::OnWsp2()   
  209. {                
  210.    ManageDesktop("Desktop2");
  211. }
  212.  
  213. void 
  214. CMyApp::OnWsp3()   
  215. {
  216.    ManageDesktop("Desktop3");
  217. }
  218.  
  219. // program manager access
  220. void 
  221. CMyApp::OnWsp4()   
  222. {  
  223.    m_pMainWnd->ShowWindow( SW_HIDE );
  224.    CProgMgrDlg dlg;
  225.    dlg.DoModal();
  226. }
  227.  
  228. void 
  229. CMyApp::OnOpts1()
  230. {                 
  231.    m_pMainWnd->ShowWindow( SW_HIDE );
  232.    CTaskDlg dlg;
  233.    dlg.DoModal();
  234. }
  235.  
  236. void 
  237. CMyApp::OnOpts2()   
  238. {                 
  239.    m_pMainWnd->ShowWindow( SW_HIDE );
  240.    COptsDlg dlg;
  241.    if ( dlg.DoModal() == IDOK )
  242.    {
  243.       // get the new settings and store them, in case OK
  244.       // was clicked
  245.       m_cPixelFrame = dlg.m_cPixelFrame;
  246.  
  247.       // set the behaviour flag
  248.       m_fComeUpAllways = dlg.m_fComeUpAllways;
  249.       MsHookDLL_SetComeUpAllways( m_fComeUpAllways );
  250.       m_fStayVisible = dlg.m_fStayVisible;
  251.      
  252.       // Write the settings to the profile
  253.       CString strOptions, strPixelFrame, strComeUp, strStayVisible;
  254.       VERIFY( strOptions.LoadString( IDS_OPTIONS ));
  255.       VERIFY( strPixelFrame.LoadString( IDS_PIXELFRAME ));
  256.       VERIFY( WriteProfileInt( strOptions, strPixelFrame, m_cPixelFrame ));
  257.       
  258.       VERIFY( strComeUp.LoadString( IDS_COMEUP ) );
  259.       VERIFY( WriteProfileInt( strOptions, strComeUp, m_fComeUpAllways ));
  260.       
  261.       VERIFY( strStayVisible.LoadString( IDS_STAYVISIBLE ));
  262.       VERIFY( WriteProfileInt( strOptions, strStayVisible, m_fStayVisible ));
  263.       
  264.       // tell windows we`re ready to accept files - but
  265.       // only if this makes any sense. translation: only if
  266.       // we are visible when loosing focus
  267.       // m_pMainWnd->DragAcceptFiles( m_fStayVisible );
  268.    }      
  269. }
  270.  
  271. void 
  272. CMyApp::OnOpts3()   
  273. {
  274.    m_pMainWnd->ShowWindow( SW_HIDE );
  275.    WinHelp( 0L, HELP_CONTENTS );
  276. }
  277.  
  278. void 
  279. CMyApp::OnOpts4()   
  280. {  
  281.    m_pMainWnd->ShowWindow( SW_HIDE );
  282.    CAboutDlg dlg( m_pMainWnd );
  283.    dlg.DoModal();
  284. }
  285.  
  286. void
  287. CMyApp::OnLaunchGroup( int nGrp )
  288. {  
  289.    m_pMainWnd->ShowWindow( SW_HIDE );
  290.    // if this group is empty,
  291.    // bring up the edit/launch dialog.
  292.    // if there is only _one_ item in there
  293.    // launch it
  294.    // if ther(-more than one items
  295.    // bring up the edit/launch dialog
  296.    m_nCurrentAppList = nGrp;
  297.    
  298.    if (  m_AppList[nGrp].GetCount() == 1 )
  299.    {
  300.       CApplication * pApp = (CApplication*) m_AppList[nGrp].GetHead(); 
  301.       pApp->Run();
  302.    }
  303.    else
  304.    {   
  305.       OnEditGroup( nGrp );
  306.    }  
  307.    
  308.    m_nCurrentAppList = -1;
  309. }
  310.  
  311. void 
  312. CMyApp::OnEditGroup( int nGrp )
  313. {     
  314.    m_pMainWnd->ShowWindow( SW_HIDE );
  315.    
  316.    // set the current group
  317.    m_nCurrentAppList = nGrp;
  318.    
  319.    CAppGrpDlg dlg;
  320.    
  321.    // if the dialog was succesfully ended,
  322.    // store the CApplications that are in there
  323.    // in the other case, changes are discardedd
  324.    if ( dlg.DoModal() == IDOK )
  325.    {  
  326.       // Remove the items from the current list
  327.       // and refill it with the new items
  328.       m_AppList[nGrp].RemoveAll(); 
  329.       m_AppList[nGrp].Add( &dlg.m_ApplicationList );
  330.  
  331.    }   
  332.  
  333.    m_nCurrentAppList = -1;
  334. }     
  335.  
  336. // add via drag n drop
  337. void 
  338. CMyApp::AddToGroup( int nGrp, const char * pszPath )
  339. {
  340.    // Add this item to the group
  341.    m_AppList[nGrp].Add( pszPath );
  342. }
  343.  
  344. HICON 
  345. CMyApp::Icon( int nApplicationGroup ) const
  346. {
  347.    return m_AppList[nApplicationGroup].Icon();
  348. }
  349.  
  350. void 
  351. CMyApp::ReadApplicationInfo()
  352. {
  353.    for ( int iAppLists=0; iAppLists<nIconButtons; ++iAppLists )
  354.    {
  355.       CApplicationList * pLst = &m_AppList[iAppLists];
  356.       pLst->ReadProfile( iAppLists );
  357.    }
  358. }
  359.  
  360. void 
  361. CMyApp::WriteApplicationInfo()
  362. {
  363.    // iterate the list off AppInfos
  364.    // and within, iterate the apps
  365.    // then, dump the apps
  366.    for ( int iAppLists=0; iAppLists<nIconButtons; ++iAppLists )
  367.    {
  368.       CApplicationList * pLst = &m_AppList[ iAppLists ];
  369.       pLst->DumpProfile( iAppLists );
  370.    }
  371. }
  372.  
  373.