home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Windows 95 Special 1 / WINDOWS95_1.bin / internet / vogon / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-29  |  10.1 KB  |  376 lines

  1. // mainfrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Vogon.h"
  6.  
  7. #include "CntrInfo.h"
  8. #include "CntrItem.h"
  9. #include "VogonDoc.h"
  10. #include "VogonVw.h"
  11.  
  12. #include "MainFrm.h"
  13. #include "UnRegDlg.h"
  14.  
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. /////////////////////////////////////////////////////////////////////////////
  21. // This code is straight from MSDN
  22.  
  23. #ifdef _WIN32
  24. #define LOADLIBRARY_FAILED(x) (x == 0)
  25. #include "winver.h"
  26. #else
  27. #define LOADLIBRARY_FAILED(x) (x <= HINSTANCE_ERROR)
  28. #include "ver.h" 
  29. #endif
  30.  
  31. #include <memory.h>
  32.  
  33. //
  34. //
  35. //
  36. typedef HRESULT (STDAPICALLTYPE *CTLREGPROC)(void) ; //see COMPOBJ.H
  37.  
  38. //
  39. //
  40. //
  41. CRegisterControl::CRegisterControl(CString PathName)
  42. {
  43.    m_strPathName = PathName ;
  44. }
  45.  
  46. //
  47. //
  48. //
  49. CRegisterControl::~CRegisterControl()
  50. {
  51.    m_strPathName.Empty() ; 
  52. }
  53.  
  54. //
  55. //
  56. //
  57. BOOL CRegisterControl::Register()
  58. {
  59.    BOOL bResult = FALSE;
  60.    ASSERT(!m_strPathName.IsEmpty()) ;
  61.  
  62.    if (SupportsSelfRegister()) 
  63.    {  
  64.       char* szPathName = m_strPathName.GetBuffer(m_strPathName.GetLength()) ;
  65.       HINSTANCE hModule = ::LoadLibrary(szPathName) ;
  66.       m_strPathName.ReleaseBuffer(-1) ;
  67.       if (LOADLIBRARY_FAILED(hModule)) return FALSE ;
  68.             
  69.       CTLREGPROC DLLRegisterServer = (CTLREGPROC)::GetProcAddress(hModule,"DllRegisterServer" ) ;
  70.       if (DLLRegisterServer != NULL)
  71.       {
  72.          HRESULT regResult = DLLRegisterServer() ;
  73.          bResult = (regResult == NOERROR) ; 
  74.       }     
  75.       ::FreeLibrary(hModule) ;          
  76.          
  77.    }
  78.    return bResult;   
  79. }
  80.  
  81. //
  82. //
  83. //
  84. BOOL CRegisterControl::Unregister()
  85. {
  86.    BOOL bResult = FALSE ;
  87.    ASSERT(!m_strPathName.IsEmpty()) ;
  88.  
  89.    if (SupportsSelfRegister()) 
  90.    {                                    
  91.       char* szPathName = m_strPathName.GetBuffer(m_strPathName.GetLength()) ;
  92.       HMODULE hModule = ::LoadLibrary(szPathName) ;
  93.       m_strPathName.ReleaseBuffer(-1) ;
  94.       if (LOADLIBRARY_FAILED(hModule)) return FALSE ;
  95.             
  96.       CTLREGPROC DllUnregisterServer = (CTLREGPROC)::GetProcAddress(hModule,"DllUnregisterServer" ) ;
  97.       if (DllUnregisterServer != NULL)
  98.       {
  99.          HRESULT regResult = DllUnregisterServer() ;
  100.          bResult = (regResult == NOERROR) ; 
  101.       }     
  102.       FreeLibrary(hModule) ;
  103.    }                                     
  104.    return bResult;   
  105.  
  106. //
  107. //
  108. //
  109. BOOL CRegisterControl::SupportsSelfRegister()
  110. {
  111.    BOOL bResult = FALSE;
  112.    DWORD  handle;
  113.    DWORD  uiInfoSize;
  114.    UINT  uiVerSize ;
  115.    UINT  uiSize ;
  116.    DWORD* lpBuffer;
  117.    CString strName   ;
  118.    char szName[128] ;
  119.  
  120.    // Get the size of the version information.
  121.    uiInfoSize = ::GetFileVersionInfoSize((LPTSTR)(LPCTSTR)m_strPathName, &handle);
  122.    if (uiInfoSize == 0) 
  123.       return FALSE ;
  124.  
  125.    // Allocate a buffer for the version information.
  126.    char* pbData = new char[uiInfoSize] ;
  127.  
  128.    // Fill the buffer with the version information.
  129.    bResult = ::GetFileVersionInfo((LPTSTR)(LPCTSTR)m_strPathName, handle, uiInfoSize, pbData);  
  130.    if (!bResult) goto NastyGoto ;
  131.  
  132.    // Get the translation information.
  133.    bResult = ::VerQueryValue(pbData, "\\VarFileInfo\\Translation", (void**)&lpBuffer, &uiVerSize);
  134.    if (!bResult) goto NastyGoto ;
  135.  
  136.    bResult = uiVerSize ;
  137.    if (!bResult) goto NastyGoto ;
  138.  
  139.    // Build the path to the key OLESelfRegister using the translation information.
  140.    wsprintf(szName,"\\StringFileInfo\\%04hX%04hX\\OLESelfRegister",LOWORD(*lpBuffer),HIWORD(*lpBuffer)) ;
  141.  
  142.    // Search for the key.
  143.     bResult = ::VerQueryValue(pbData, szName, (void**)&lpBuffer, &uiSize);
  144.  
  145. NastyGoto:
  146.    delete [] pbData ;
  147.    return bResult ;
  148. }
  149.  
  150. // END This code is straight from MSDN
  151. /////////////////////////////////////////////////////////////////////////////
  152.  
  153.  
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CMainFrame
  156.  
  157. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  158.  
  159. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  160.    //{{AFX_MSG_MAP(CMainFrame)
  161.    ON_WM_CREATE()
  162.    ON_COMMAND(ID_VIEW_REGISTERWEBSTER, OnRegisterWebster)
  163.    ON_COMMAND(ID_VIEW_UNREGISTERWEBSTER, OnUnregisterWebster)
  164.    //}}AFX_MSG_MAP
  165.    ON_UPDATE_COMMAND_UI(ID_INDICATOR_STATUS, OnUpdateStatusPane)
  166.    ON_UPDATE_COMMAND_UI(ID_INDICATOR_URL,    OnUpdateUrlPane)
  167. END_MESSAGE_MAP()
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // arrays of IDs used to initialize control bars
  171.  
  172. // toolbar buttons - IDs are command buttons
  173. static UINT BASED_CODE buttons[] =
  174. {
  175.    // same order as in the bitmap 'toolbar.bmp'
  176.    ID_FILE_NEW,
  177.    ID_FILE_OPEN,
  178.    ID_FILE_SAVE,
  179.       ID_SEPARATOR,
  180.    ID_SHOW_PROPERTY_INSPECTOR,
  181.       ID_SEPARATOR,
  182.    ID_VIEW_SLIDESHOW,
  183.    ID_VIEW_SLIDESHOW_SETUP,
  184.       ID_SEPARATOR,
  185.    ID_VIEW_URLFILTER,
  186.    ID_VIEW_REVEALPAGE,
  187.       ID_SEPARATOR,
  188.    ID_VIEW_TEXTRETRIEVAL,
  189.    ID_VIEW_HYPERLINKS,
  190.       ID_SEPARATOR,
  191.    ID_VIEW_ABOUTWEBSTER,
  192.    ID_APP_ABOUT
  193. };
  194.  
  195. static UINT BASED_CODE indicators[] =
  196. {  // status line indicators
  197.    ID_INDICATOR_STATUS,           
  198.    ID_INDICATOR_URL,
  199.    //ID_INDICATOR_CAPS,
  200.    //ID_INDICATOR_NUM,
  201.    //ID_INDICATOR_SCRL,
  202. };
  203.  
  204. /////////////////////////////////////////////////////////////////////////////
  205. // CMainFrame construction/destruction
  206.  
  207. CMainFrame::CMainFrame()
  208. {
  209.    // TODO: add member initialization code here
  210. }
  211.  
  212. CMainFrame::~CMainFrame()
  213. {
  214. }
  215.  
  216. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  217. {
  218.    if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  219.       return -1;
  220.  
  221. #ifdef _WIN32
  222.    if (!m_wndToolBar.Create(this, CBRS_TOOLTIPS | WS_CHILD | WS_VISIBLE | CBRS_TOP) ||
  223. #else   // not _WIN32
  224.    if (!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP) ||
  225. #endif  //     _WIN32
  226.       !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  227.       !m_wndToolBar.SetButtons(buttons,
  228.         sizeof(buttons)/sizeof(UINT)))
  229.    {
  230.       TRACE("Failed to create toolbar\n");
  231.       return -1;      // fail to create
  232.    }
  233.  
  234.    if (!m_wndStatusBar.Create(this) ||
  235.       !m_wndStatusBar.SetIndicators(indicators,
  236.         sizeof(indicators)/sizeof(UINT)))
  237.    {
  238.       TRACE("Failed to create status bar\n");
  239.       return -1;      // fail to create
  240.    }
  241.  
  242. #ifdef NOTNOW
  243.    else
  244.    {  // Default hide the status bar
  245.       m_wndStatusBar.ShowWindow(SW_HIDE);
  246.       RecalcLayout();
  247.    }
  248. #endif // NOTNOW
  249.  
  250.    return 0;
  251. }
  252.  
  253. /////////////////////////////////////////////////////////////////////////////
  254. // CMainFrame diagnostics
  255.  
  256. #ifdef _DEBUG
  257. void CMainFrame::AssertValid() const
  258. {
  259.    CMDIFrameWnd::AssertValid();
  260. }
  261.  
  262. void CMainFrame::Dump(CDumpContext& dc) const
  263. {
  264.    CMDIFrameWnd::Dump(dc);
  265. }
  266.  
  267. #endif //_DEBUG
  268.  
  269. /////////////////////////////////////////////////////////////////////////////
  270. // CMainFrame message handlers
  271.  
  272. /////////////////////////////////////////////////////////////////////////////
  273. //
  274. void CMainFrame::OnUpdateStatusPane(CCmdUI *pCmdUI)
  275. {   // Pane must be enabled, else it is disabled ...
  276.     pCmdUI->Enable(); 
  277.  
  278.     // Default the status to "Idle"
  279.     short status = -1;
  280.  
  281.     // Get the active MDI child window, it contains the view of interest
  282.     CMDIChildWnd* pWnd = MDIGetActive();
  283.     
  284.     // Do we have a child window ?
  285.     if (pWnd)
  286.     {  // Get the active view to get the control to get the status:
  287.        CVogonView* pView = (CVogonView*) pWnd->GetActiveView();
  288.  
  289.        // Do we have a View with a Webster ?
  290.        if (pView && pView->m_pSelection)
  291.        {  // Yes: get the load status of the current visible page
  292.           status = pView->m_pSelection->m_dWebster.GetLoadStatus();
  293.        }
  294.     }
  295.  
  296.     // Convert the status short to a string using carefully-placed string table entries:
  297.     CString stringStatus;
  298.     stringStatus.LoadString(IDS_STATUS_LOADCOMPLETE + status);
  299.  
  300.     // Show the status for the current active page
  301.     pCmdUI->SetText(stringStatus);
  302. }
  303.  
  304. /////////////////////////////////////////////////////////////////////////////
  305. //
  306. void CMainFrame::OnUpdateUrlPane(CCmdUI *pCmdUI)
  307. {   // Pane must be enabled, else it is disabled ...
  308.     pCmdUI->Enable(); 
  309.  
  310.     CString stringUrl(_T("No active URL"));
  311.  
  312.     // Get the active MDI child window, it contains the view of interest
  313.     CMDIChildWnd* pWnd = MDIGetActive();
  314.     
  315.     // Do we have a child window ?
  316.     if (pWnd)
  317.     {  // Get the active view to get the control to get the URL:
  318.        CVogonView* pView = (CVogonView*) pWnd->GetActiveView();
  319.  
  320.        // Do we have a View with a Webster ?
  321.        if (pView && pView->m_pSelection)
  322.        {  // Yes: get the load status of the current visible page
  323.           stringUrl = pView->m_pSelection->m_dWebster.GetPageURL();
  324.        }
  325.     }
  326.  
  327.     // Show the status for the current active page
  328.     pCmdUI->SetText(stringUrl);
  329. }
  330.  
  331. /////////////////////////////////////////////////////////////////////////////
  332. //
  333. void CMainFrame::OnRegisterWebster() 
  334. {
  335.    static char BASED_CODE szFilter[] = "OLE controls (*.ocx) | *.ocx | DLL's (*.dll) | *.dll | OCX and DLL (*.ocx; *.dll) | *.ocx;*.dll | All Files (*.*) | *.* ||" ;
  336.  
  337.    CFileDialog aDlg(TRUE, "OCX", "*.ocx;*.dll", OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST ,szFilter,this ) ;  
  338.  
  339.    if (aDlg.DoModal() == IDOK)
  340.    {
  341.       CString strCtlPathName = aDlg.GetPathName() ;
  342.       CRegisterControl aCtlReg(strCtlPathName) ;
  343.       if (aCtlReg.Register())
  344.       {
  345.             MessageBox("Successful control registration.","Control Registration.",MB_OK | MB_ICONINFORMATION) ;
  346.       }
  347.       else
  348.       {
  349.             MessageBox("Control registration failed.",NULL,MB_OK | MB_ICONEXCLAMATION) ;
  350.       }
  351.    }  
  352. }
  353.  
  354. /////////////////////////////////////////////////////////////////////////////
  355. //
  356. void CMainFrame::OnUnregisterWebster() 
  357. {
  358.    CUnregisterDlg dlgUnReg(this);
  359.  
  360.    if(dlgUnReg.DoModal() == IDOK)
  361.    {
  362.       CRegisterControl aCtlReg(dlgUnReg.m_strThePath); 
  363.       if (aCtlReg.Unregister())
  364.       {
  365.          MessageBox("Control unregistered successfully.","Control Registration.",MB_OK | MB_ICONINFORMATION) ;
  366.       }
  367.       else
  368.       {
  369.          MessageBox("Unable to unregister control.",NULL,MB_OK | MB_ICONEXCLAMATION) ;
  370.       }     
  371.    }
  372. }
  373.  
  374.  
  375.