home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 June
/
PCWorld_2003-06_cd.bin
/
KOMUNIK
/
MIRRORIT
/
SRC
/
MAINFRM.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1999-01-02
|
6KB
|
203 lines
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "MirrorIt.h"
#include "MainFrm.h"
#include "MirrorItDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_DROPFILES()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
// Global help commands
ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
LoadBarState("Bar");
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
int s, t, b, r, l;
CWinApp* app = AfxGetApp();
// only restore if there is a previously saved position
if ((s = app -> GetProfileInt("Window", "ShowCmd", -1)) != -1 &&
(t = app -> GetProfileInt("Window", "Top", -1)) != -1 &&
(l = app -> GetProfileInt("Window", "Left", -1)) != -1 &&
(b = app -> GetProfileInt("Window", "Bottom", -1)) != -1 &&
(r = app -> GetProfileInt("Window", "Right", -1)) != -1)
{
// restore the window's status
app -> m_nCmdShow = s;
// restore the window's width and height
cs.cx = r - l;
cs.cy = b - t;
// the following correction is needed when the taskbar is
// at the left or top and it is not "auto-hidden"
RECT workArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
l += workArea.left;
t += workArea.top;
// make sure the window is not completely out of sight
int max_x = GetSystemMetrics(SM_CXSCREEN) -
GetSystemMetrics(SM_CXICON);
int max_y = GetSystemMetrics(SM_CYSCREEN) -
GetSystemMetrics(SM_CYICON);
cs.x = min(l, max_x);
cs.y = min(t, max_y);
}
return CFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnDropFiles(HDROP hDropInfo)
{
CMirrorItDoc *pDoc = (CMirrorItDoc *)GetActiveDocument();
if (pDoc)
{
UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0);
CWinApp* pApp = AfxGetApp();
for (UINT iFile = 0; iFile < nFiles; iFile++)
{
TCHAR szFileName[_MAX_PATH];
::DragQueryFile(hDropInfo, iFile, szFileName, _MAX_PATH);
CString filename(szFileName);
CString sessionname(szFileName);
int i = sessionname.ReverseFind('\\');
if (i >= 0)
sessionname = sessionname.Mid(i + 1);
i = sessionname.ReverseFind('.');
if (i >= 0)
{
CString ext = sessionname.Mid(i + 1);
sessionname = sessionname.Left(sessionname.GetLength() - 4);
ext.MakeLower();
if (!ext.Compare("url"))
{
pDoc -> AddSession(sessionname, "");
continue;
}
}
pApp->OpenDocumentFile(szFileName);
}
::DragFinish(hDropInfo);
return;
}
CFrameWnd::OnDropFiles(hDropInfo);
}
void CMainFrame::OnClose()
{
SaveBarState("Bar");
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
AfxGetApp() -> WriteProfileInt("Window", "ShowCmd", wp.showCmd);
AfxGetApp() -> WriteProfileInt("Window", "Top", wp.rcNormalPosition.top);
AfxGetApp() -> WriteProfileInt("Window", "Bottom", wp.rcNormalPosition.bottom);
AfxGetApp() -> WriteProfileInt("Window", "Left", wp.rcNormalPosition.left);
AfxGetApp() -> WriteProfileInt("Window", "Right", wp.rcNormalPosition.right);
CFrameWnd::OnClose();
}