Back to index

lightning-sunbird  0.9+nobinonly
cbrowse.cpp
Go to the documentation of this file.
00001 // cbrowse.cpp : Defines the class behaviors for the application.
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "cbrowse.h"
00006 #include "PickerDlg.h"
00007 #include <initguid.h>
00008 #include "Cbrowse_i.c"
00009 #include "TestScriptHelper.h"
00010 #include "ControlEventSink.h"
00011 #include "CBrowserCtlSite.h"
00012 
00013 
00014 #ifdef _DEBUG
00015 #define new DEBUG_NEW
00016 #undef THIS_FILE
00017 static char THIS_FILE[] = __FILE__;
00018 #endif
00019 
00021 // CBrowseApp
00022 
00023 BEGIN_MESSAGE_MAP(CBrowseApp, CWinApp)
00024        //{{AFX_MSG_MAP(CBrowseApp)
00025        //}}AFX_MSG_MAP
00026        ON_COMMAND(ID_HELP, CWinApp::OnHelp)
00027 END_MESSAGE_MAP()
00028 
00030 // CBrowseApp construction
00031 
00032 CBrowseApp::CBrowseApp()
00033 {
00034        // TODO: add construction code here,
00035        // Place all significant initialization in InitInstance
00036 }
00037 
00039 // The one and only CBrowseApp object
00040 
00041 CBrowseApp theApp;
00042 
00044 // CBrowseApp initialization
00045 
00046 BOOL CBrowseApp::InitInstance()
00047 {
00048        // Initialize OLE libraries
00049        if (!AfxOleInit())
00050        {
00051               return FALSE;
00052        }
00053 //     if (!InitATL())
00054 //            return FALSE;
00055 
00056        AfxEnableControlContainer();
00057        _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
00058               REGCLS_MULTIPLEUSE);
00059 
00060 
00061        // Standard initialization
00062        // If you are not using these features and wish to reduce the size
00063        //  of your final executable, you should remove from the following
00064        //  the specific initialization routines you do not need.
00065 
00066 #ifdef _AFXDLL
00067        Enable3dControls();                // Call this when using MFC in a shared DLL
00068 #else
00069        Enable3dControlsStatic();   // Call this when linking to MFC statically
00070 #endif
00071 
00072        int nResponse;
00073 
00074        CPickerDlg pickerDlg;
00075        nResponse = pickerDlg.DoModal();
00076        if (nResponse != IDOK)
00077        {
00078               return FALSE;
00079        }
00080 
00081        m_pDlg = new CBrowseDlg;
00082        m_pDlg->m_clsid = pickerDlg.m_clsid;
00083        m_pDlg->m_bUseCustomDropTarget = pickerDlg.m_bUseCustom;
00084        m_pDlg->m_bUseCustomPopupMenu = pickerDlg.m_bUseCustom;
00085        m_pDlg->Create(IDD_CBROWSE_DIALOG);
00086        m_pMainWnd = m_pDlg;
00087 
00088        // Since the dialog has been closed, return FALSE so that we exit the
00089        //  application, rather than start the application's message pump.
00090        return TRUE;
00091 }
00092 
00093 CBrowseModule _Module;
00094 
00095 BEGIN_OBJECT_MAP(ObjectMap)
00096        OBJECT_ENTRY(CLSID_TestScriptHelper, CTestScriptHelper)
00097 //     OBJECT_ENTRY(CLSID_ControlEventSink, CControlEventSink)
00098 //     OBJECT_ENTRY(CLSID_CBrowserCtlSite, CCBrowserCtlSite)
00099 END_OBJECT_MAP()
00100 
00101 LONG CBrowseModule::Unlock()
00102 {
00103        AfxOleUnlockApp();
00104        return 0;
00105 }
00106 
00107 LONG CBrowseModule::Lock()
00108 {
00109        AfxOleLockApp();
00110        return 1;
00111 }
00112 
00113 LPCTSTR CBrowseModule::FindOneOf(LPCTSTR p1, LPCTSTR p2)
00114 {
00115        while (*p1 != NULL)
00116        {
00117               LPCTSTR p = p2;
00118               while (*p != NULL)
00119               {
00120                      if (*p1 == *p)
00121                             return CharNext(p1);
00122                      p = CharNext(p);
00123               }
00124               p1++;
00125        }
00126        return NULL;
00127 }
00128 
00129 
00130 int CBrowseApp::ExitInstance()
00131 {
00132        if (m_bATLInited)
00133        {
00134               _Module.RevokeClassObjects();
00135               _Module.Term();
00136               CoUninitialize();
00137        }
00138        return CWinApp::ExitInstance();
00139 }
00140 
00141 
00142 BOOL CBrowseApp::InitATL()
00143 {
00144        m_bATLInited = TRUE;
00145 
00146        HRESULT hRes;
00147 
00148 #if _WIN32_WINNT >= 0x0400
00149        // hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
00150 #else
00151        // hRes = CoInitialize(NULL);
00152 #endif
00153        if (!AfxOleInit())
00154        {
00155               return FALSE;
00156        }
00157 
00158 
00159        //if (FAILED(hRes))
00160        //{
00161        //     m_bATLInited = FALSE;
00162        //     return FALSE;
00163        //}
00164 
00165        _Module.Init(ObjectMap, AfxGetInstanceHandle());
00166        _Module.dwThreadID = GetCurrentThreadId();
00167 
00168        LPTSTR lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT
00169        TCHAR szTokens[] = _T("-/");
00170 
00171        BOOL bRun = TRUE;
00172        LPCTSTR lpszToken = _Module.FindOneOf(lpCmdLine, szTokens);
00173        while (lpszToken != NULL)
00174        {
00175               if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
00176               {
00177                      _Module.UpdateRegistryFromResource(IDR_CBROWSE, FALSE);
00178                      _Module.UnregisterServer(TRUE); //TRUE means typelib is unreg'd
00179                      bRun = FALSE;
00180                      break;
00181               }
00182               if (lstrcmpi(lpszToken, _T("RegServer"))==0)
00183               {
00184                      _Module.UpdateRegistryFromResource(IDR_CBROWSE, TRUE);
00185                      _Module.RegisterServer(TRUE);
00186                      bRun = FALSE;
00187                      break;
00188               }
00189               lpszToken = _Module.FindOneOf(lpszToken, szTokens);
00190        }
00191 
00192        if (!bRun)
00193        {
00194               m_bATLInited = FALSE;
00195               _Module.Term();
00196               CoUninitialize();
00197               return FALSE;
00198        }
00199 
00200        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
00201               REGCLS_MULTIPLEUSE);
00202        if (FAILED(hRes))
00203        {
00204               m_bATLInited = FALSE;
00205               CoUninitialize();
00206               return FALSE;
00207        }      
00208 
00209        return TRUE;
00210 }
00211 
00212 int CBrowseApp::Run() 
00213 {
00214     int rv = 1;
00215     try {
00216         rv = CWinApp::Run();
00217     }
00218     catch (CException *e)
00219     {
00220         ASSERT(0);
00221     }
00222     catch (...)
00223     {
00224         ASSERT(0);
00225     }
00226     return rv;
00227 }