home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / pserv.cpl / pserv-2.4.exe / source / MainFrm.cpp < prev    next >
C/C++ Source or Header  |  2005-01-05  |  4KB  |  188 lines

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "pserv2.h"
  6.  
  7. #include "MainFrm.h"
  8. #include "CConfiguration.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CMainFrame
  18. CMainFrame* TheMainFrame = NULL;
  19.  
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21.  
  22. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  23.     //{{AFX_MSG_MAP(CMainFrame)
  24.     ON_WM_CREATE()
  25.     ON_COMMAND(ID_ABOUT_PSERV2, OnAboutPserv2)
  26.     ON_WM_CLOSE()
  27.     ON_WM_MOVE()
  28.     ON_WM_SIZE()
  29.     //}}AFX_MSG_MAP
  30.     // Global help commands
  31.     ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
  32.     ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
  33.     ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
  34.     ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
  35.     ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnGetToolbarText )
  36. END_MESSAGE_MAP()
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMainFrame construction/destruction
  40.  
  41. CMainFrame::CMainFrame()
  42.     :   m_bHasBeenShown(FALSE)
  43. {
  44.     TheMainFrame = this;
  45.     
  46. }
  47.  
  48. CMainFrame::~CMainFrame()
  49. {
  50. }
  51.  
  52. void CMainFrame::SwitchMenu(UINT uiMenuID)
  53. {
  54.     CMenu NewMenu;
  55.     NewMenu.LoadMenu(uiMenuID); 
  56.      
  57.     ASSERT(NewMenu);
  58.  
  59.     SetMenu(NULL);
  60.     ::DestroyMenu(m_hMenuDefault); 
  61.     SetMenu(&NewMenu);
  62.     m_hMenuDefault = NewMenu.GetSafeHmenu();
  63. }
  64.  
  65. BOOL CMainFrame::OnGetToolbarText( UINT id, NMHDR * pNMHDR, LRESULT * result )
  66. {
  67.     TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  68.     UINT nID =pNMHDR->idFrom;
  69.     if(nID)
  70.     {
  71.         pTTT->lpszText = MAKEINTRESOURCE(nID);
  72.         pTTT->hinst = AfxGetResourceHandle();
  73.         return(TRUE);
  74.     }
  75.     return(FALSE);
  76. }
  77.  
  78. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  79. {
  80.     if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  81.         return -1;
  82.     
  83.     if (!m_wndToolBar.CreateEx(this) ||
  84.         !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  85.     {
  86.         TRACE0("Failed to create toolbar\n");
  87.         return -1;      // fail to create
  88.     }
  89.     if (!m_wndReBar.Create(this) ||
  90.         !m_wndReBar.AddBar(&m_wndToolBar))
  91.     {
  92.         TRACE0("Failed to create rebar\n");
  93.         return -1;      // fail to create
  94.     }
  95.  
  96.     // TODO: Remove this if you don't want tool tips
  97.     m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  98.         CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_BORDER_3D);
  99.  
  100.     if( !theConfiguration.m_bToolbarVisible )
  101.         m_wndToolBar.ShowWindow(SW_HIDE);
  102.     return 0;
  103. }
  104.  
  105. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  106. {
  107.     if( !CFrameWnd::PreCreateWindow(cs) )
  108.         return FALSE;
  109.     cs.style &= ~FWS_ADDTOTITLE; 
  110.  
  111.     cs.x = theConfiguration.m_dwWindowX;
  112.     cs.y = theConfiguration.m_dwWindowY;
  113.     cs.cx = theConfiguration.m_dwWindowWidth;
  114.     cs.cy = theConfiguration.m_dwWindowHeight;
  115.  
  116.     return TRUE;
  117. }
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CMainFrame diagnostics
  121.  
  122. #ifdef _DEBUG
  123. void CMainFrame::AssertValid() const
  124. {
  125.     CFrameWnd::AssertValid();
  126. }
  127.  
  128. void CMainFrame::Dump(CDumpContext& dc) const
  129. {
  130.     CFrameWnd::Dump(dc);
  131. }
  132.  
  133. #endif //_DEBUG
  134.  
  135.  
  136. void CMainFrame::OnAboutPserv2() 
  137. {
  138.     ShellExecute(m_hWnd, _T("open"), _T("http://p-nand-q.com/e/pserv.html"), _T(""), _T(""), SW_SHOW );    
  139. }
  140.  
  141. void CMainFrame::OnClose() 
  142. {
  143.     theConfiguration.m_bToolbarVisible = m_wndToolBar.IsWindowVisible();
  144.     CFrameWnd::OnClose();
  145. }
  146.  
  147. void CMainFrame::OnMove(int x, int y) 
  148. {
  149.     CFrameWnd::OnMove(x, y);
  150.  
  151.     if(m_bHasBeenShown)
  152.     {
  153.         WINDOWPLACEMENT wp;
  154.         GetWindowPlacement(&wp);
  155.         if( wp.showCmd != SW_SHOWMAXIMIZED )
  156.         {
  157.             RECT rect;
  158.             GetWindowRect(&rect);
  159.             theConfiguration.m_dwWindowX = rect.left;
  160.             theConfiguration.m_dwWindowY = rect.top;
  161.         }
  162.     }
  163. }
  164.  
  165. void CMainFrame::OnSize(UINT nType, int cx, int cy) 
  166. {
  167.     CFrameWnd::OnSize(nType, cx, cy);
  168.     
  169.     if(m_bHasBeenShown)
  170.     {
  171.         RECT rect;
  172.         GetWindowRect(&rect);
  173.         WINDOWPLACEMENT wp;
  174.         GetWindowPlacement(&wp);
  175.         if( wp.showCmd != SW_SHOWMAXIMIZED )
  176.         {
  177.             theConfiguration.m_dwWindowWidth = rect.right - rect.left;
  178.             theConfiguration.m_dwWindowHeight = rect.bottom - rect.top;
  179.             theConfiguration.m_dwShowCmd = SW_SHOW;
  180.         }
  181.         else
  182.         {
  183.             theConfiguration.m_dwShowCmd = SW_SHOWMAXIMIZED;
  184.         }
  185.     }
  186. }
  187.  
  188.