📄 saprefsdialog.cpp
字号:
/*********************************************************************
SAPrefsDialog
Copyright (C) 2002 Smaller Animals Software, Inc.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
http://www.smalleranimals.com
smallest@smalleranimals.com
**********************************************************************/
// SAPrefsDialog.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "editcmd.h"
#include "SAPrefsDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSAPrefsDialog dialog
#define BROWSETREE_SIZE 120
#define TOTAL_XGAP 15
#define OPERATOR_PANEL_SIZE 70
#define TOTAL_YGAP 10
#define GRADBAR_SIZE 30
CSAPrefsDialog::CSAPrefsDialog(CWnd* pParent /*=NULL*/)
: CDialog(CSAPrefsDialog::IDD, pParent),m_nMaxSize(0,0)
{
//{{AFX_DATA_INIT(CSAPrefsDialog)
//}}AFX_DATA_INIT
m_iCurPage = -1;
m_pages.RemoveAll();
m_pStartPage = NULL;
m_csTitle = "Untitled";
m_bValidateBeforeChangingPage = false;
}
/////////////////////////////////////////////////////////////////////////////
CSAPrefsDialog::~CSAPrefsDialog()
{
// clean up
for (int i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
if (pPS)
delete pPS;
}
}
/////////////////////////////////////////////////////////////////////////////
void CSAPrefsDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSAPrefsDialog)
DDX_Control(pDX, IDC_PAGE_TREE, m_pageTree);
DDX_Control(pDX, IDC_DLG_FRAME, m_boundingFrame);
DDX_Control(pDX, IDC_CAPTION_BAR, m_captionBar);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSAPrefsDialog, CDialog)
//{{AFX_MSG_MAP(CSAPrefsDialog)
ON_WM_CREATE()
ON_NOTIFY(TVN_SELCHANGED, IDC_PAGE_TREE, OnSelchangedPageTree)
ON_NOTIFY(TVN_GETDISPINFO, IDC_PAGE_TREE, OnGetdispinfoPageTree)
ON_NOTIFY(TVN_SELCHANGING, IDC_PAGE_TREE, OnSelchangingPageTree)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_CHANGE_PAGE, OnChangePage)
ON_MESSAGE(WM_SET_FOCUS_WND, OnSetFocusWnd)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSAPrefsDialog message handlers
/////////////////////////////////////////////////////////////////////////////
BOOL CSAPrefsDialog::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);
ASSERT_VALID(this);
ASSERT(m_hWnd != NULL);
// Don't let CDialog process the Escape key.
if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE))
{
return TRUE;
}
if (CWnd::PreTranslateMessage(pMsg))
return TRUE;
// don't translate dialog messages when
// application is in help mode
CFrameWnd* pFrameWnd = GetTopLevelFrame();
if (pFrameWnd != NULL && pFrameWnd->m_bHelpMode)
return FALSE;
// ensure the dialog messages will not
// eat frame accelerators
pFrameWnd = GetParentFrame();
while (pFrameWnd != NULL)
{
if (pFrameWnd->PreTranslateMessage(pMsg))
return TRUE;
pFrameWnd = pFrameWnd->GetParentFrame();
}
return PreTranslateInput(pMsg);
}
/////////////////////////////////////////////////////////////////////////////
int CSAPrefsDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
/////////////////////////////////////////////////////////////////////////////
BOOL CSAPrefsDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//set size
if(m_nMaxSize.cx >0)
{
#define BUG 25
int nWidth = m_nMaxSize.cx+BROWSETREE_SIZE+TOTAL_XGAP+BUG;
int nHeight = m_nMaxSize.cy+OPERATOR_PANEL_SIZE+TOTAL_YGAP;
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right = rcWindow.left + nWidth;
rcWindow.bottom = rcWindow.top + nHeight;
MoveWindow(rcWindow);
GetClientRect(rcWindow);
//move treectrl
CRect rcTree(rcWindow.left+5,rcWindow.top+5,rcWindow.left+5+BROWSETREE_SIZE+TOTAL_XGAP,rcWindow.bottom-10-OPERATOR_PANEL_SIZE);
m_pageTree.MoveWindow(rcTree);
CRect rcOpStatic(rcTree.left,rcTree.bottom+5,rcTree.right,rcTree.bottom+5+OPERATOR_PANEL_SIZE);
GetDlgItem(IDC_STATIC_ACTIONBAND)->MoveWindow(rcOpStatic);
CRect rcOk(rcOpStatic.left+5,rcOpStatic.top+15,rcOpStatic.right-5,rcOpStatic.top+35);
GetDlgItem(IDOK)->MoveWindow(rcOk);
rcOk.OffsetRect(0,rcOk.Height()+5);
rcOk.DeflateRect(5,0,5,0);
GetDlgItem(IDCANCEL)->MoveWindow(rcOk);
m_frameRect.SetRect(rcTree.right+5,rcTree.top,rcWindow.right-5,rcWindow.bottom-5);
CRect rcGradBar(m_frameRect);
rcGradBar.DeflateRect(0,0,0,m_frameRect.Height()-GRADBAR_SIZE);
m_frameRect.DeflateRect(0,GRADBAR_SIZE,0,0);
m_boundingFrame.MoveWindow(m_frameRect);
GetDlgItem(IDC_CAPTION_BAR)->MoveWindow(rcGradBar);
}
long l = GetWindowLong(m_pageTree.m_hWnd, GWL_STYLE);
#if (_MSC_VER > 1100)
l = l | TVS_TRACKSELECT ;
#else
//#define TVS_TRACKSELECT 0x0200
l = l | 0x0200;
#endif
SetWindowLong(m_pageTree.m_hWnd, GWL_STYLE, l);
// where will the dlgs live?
//m_boundingFrame.GetWindowRect(m_frameRect);
//ScreenToClient(m_frameRect);
//m_frameRect.DeflateRect(2,2);
SetWindowText(m_csTitle);
// set some styles for the pretty page indicator bar
m_captionBar.m_textClr = ::GetSysColor(COLOR_3DFACE);
m_captionBar.m_fontWeight = FW_BOLD;
m_captionBar.m_fontSize = 14;
m_captionBar.m_csFontName = "Verdana";
m_captionBar.SetConstantText(m_csConstantText);
// fill the tree. we'll create the pages as we need them
for (int i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
ASSERT(pPS);
ASSERT(pPS->pDlg);
if (pPS)
{
TV_INSERTSTRUCT tvi;
// find this node's parent...
tvi.hParent = FindHTREEItemForDlg(pPS->pDlgParent);
tvi.hInsertAfter = TVI_LAST;
tvi.item.cchTextMax = 0;
tvi.item.pszText = LPSTR_TEXTCALLBACK;
tvi.item.lParam = (long)pPS;
tvi.item.mask = TVIF_PARAM | TVIF_TEXT;
HTREEITEM hTree = m_pageTree.InsertItem(&tvi);
// keep track of the dlg's we've added (for parent selection)
if (hTree)
{
DWORD dwTree = (DWORD)hTree;
m_dlgMap.SetAt(pPS->pDlg, dwTree);
}
}
}
// start with page 0
if (m_pStartPage==NULL)
{
if (ShowPage(0))
{
m_iCurPage = 0;
}
}
else
{
// find start page
for (int i=0;i<m_pages.GetSize();i++)
{
pageStruct *pPS = (pageStruct *)m_pages.GetAt(i);
ASSERT(pPS);
if (pPS)
{
ASSERT(pPS->pDlg);
if (pPS->pDlg == m_pStartPage)
{
ShowPage(i);
m_iCurPage = i;
break;
}
}
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
HTREEITEM CSAPrefsDialog::FindHTREEItemForDlg(CSAPrefsSubDlg *pParent)
{
// if you didn't specify a parent in AddPage(...) , the
// dialog becomes a root-level entry
if (pParent==NULL)
{
return TVI_ROOT;
}
else
{
DWORD dwHTree;
if (m_dlgMap.Lookup(pParent, dwHTree))
{
return (HTREEITEM)dwHTree;
}
else
{
// you have specified a parent that has not
// been added to the tree - can't do that.
ASSERT(FALSE);
return TVI_ROOT;
}
}
}
/////////////////////////////////////////////////////////////////////////////
bool CSAPrefsDialog::AddPage(CSAPrefsSubDlg &dlg, const char *pCaption, CSAPrefsSubDlg* pDlgParent /*=NULL*/)
{
if(m_hWnd)
{
// can't add once the window has been created
ASSERT(0);
return false;
}
{
CSAPrefsSubDlg dlgSize(dlg.GetID());
//Load DLGTEMPLATE
DLGTEMPLATE* pTemplate;
HINSTANCE hInst= AfxFindResourceHandle(MAKEINTRESOURCE(dlg.GetID()),RT_DIALOG);
if (hInst == NULL)
{
TRACE("Cound not find resource in resource chain");
ASSERT(FALSE);
return false;
}
HRSRC hRsrc = ::FindResource(hInst, MAKEINTRESOURCE(dlg.GetID()),RT_DIALOG);
ASSERT(hRsrc != NULL); HGLOBAL hTemplate = ::LoadResource(hInst, hRsrc);
ASSERT(hTemplate != NULL);
pTemplate = (DLGTEMPLATE*)::LockResource(hTemplate); //Load coresponding DLGINIT resource
void* lpDlgInit;
HGLOBAL hDlgInit = NULL; HRSRC hsDlgInit = ::FindResource(hInst,MAKEINTRESOURCE(dlg.GetID()),RT_DLGINIT);
if(hsDlgInit != NULL)
{
// load it
hDlgInit = ::LoadResource(hInst, hsDlgInit);
ASSERT(hDlgInit != NULL); // lock it
lpDlgInit = ::LockResource(hDlgInit);
ASSERT(lpDlgInit != NULL);
} //ToDo: Modify DLGTEMPLATE in memory if desired CDialog dlg;
ASSERT(dlgSize.Create(dlgSize.GetID()));
CRect rcSize(pTemplate->x,pTemplate->y,pTemplate->cx,pTemplate->cy);
dlgSize.MapDialogRect(&rcSize);
CSize max = rcSize.Size();
if(max.cx>m_nMaxSize.cx)
m_nMaxSize.cx = max.cx;
if(max.cy>m_nMaxSize.cy)
m_nMaxSize.cy = max.cy;
ASSERT(dlgSize.DestroyWindow());
// dlg.InitModalIndirect(pTemplate,NULL,lpDlgInit);
// dlg.DoModal();
::UnlockResource(hTemplate);
::FreeResource(hTemplate);
if(hDlgInit)
{
::UnlockResource(hDlgInit);
::FreeResource(hDlgInit);
}
}
/*
{
CSAPrefsSubDlg dlgSize(dlg.GetID());
ASSERT(dlgSize.Create(dlgSize.GetID()));
CRect rcSize;
dlgSize.GetClientRect(&rcSize);
dlgSize.MapDialogRect(&rcSize);
CSize max = rcSize.Size();
ASSERT(dlgSize.DestroyWindow());
if(max.cx>m_nMaxSize.cx)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -