/***********************************************************************/ /* Copyright (C) 2002 Definitive Solutions, Inc. All Rights Reserved. */ /* THIS COMPUTER PROGRAM IS PROPRIETARY AND CONFIDENTIAL TO DEFINITIVE */ /* SOLUTIONS, INC. AND ITS LICENSORS AND CONTAINS TRADE SECRETS OF */ /* DEFINITIVE SOLUTIONS, INC. THAT ARE PROVIDED PURSUANT TO A WRITTEN */ /* AGREEMENT CONTAINING RESTRICTIONS ON USE AND DISCLOSURE. ANY USE, */ /* REPRODUCTION, OR TRANSFER EXCEPT AS PROVIDED IN SUCH AGREEMENT */ /* IS STRICTLY PROHIBITED. */ /***********************************************************************/ #include "stdafx.h" #include "MyTipDlg.h" #include "MyButtonResource.h" #include "Generic.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // Statics. static const TCHAR szSection[] = _T("MyTipOfTheDay"); static const TCHAR szIntTipID[] = _T("NextTipID"); static const TCHAR szIntStartup[] = _T("DontShowTipUponStartUp"); static const int nFirstTipOfTheDay(17000); ///////////////////////////////////////////////////////////////////////////// // MyTipDlg dialog // Constructor. MyTipDlg::MyTipDlg(const CString& sRegPlacementsKey, CWnd* pParent /* = NULL */ ) : MyDialog(MyTipDlg::IDD, "MyTipDlg", sRegPlacementsKey, pParent) , m_uiTipID(0U) { //{{AFX_DATA_INIT(MyTipDlg) m_bStartup = TRUE; m_sTitle = _T(""); //}}AFX_DATA_INIT // We need to find out what the startup and file position parameters are. // If 'startup' does not exist, we assume that the Tips on startup is // checked TRUE. m_bStartup = ! AfxGetApp()->GetProfileInt(szSection, szIntStartup, 0); m_uiTipID = AfxGetApp()->GetProfileInt(szSection, szIntTipID, 0); GetNextTipString(); } // This destructor is executed whether the user had pressed the escape key // or clicked on the close button. If the user had pressed the escape key, // it is still required to update the filepos in the ini file with the latest // position so that we don't repeat the tips! /* virtual */ MyTipDlg::~MyTipDlg() { AfxGetApp()->WriteProfileInt(szSection, szIntTipID, m_uiTipID); } // void MyTipDlg::DoDataExchange(CDataExchange* pDX) { MyDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(MyTipDlg) DDX_Control(pDX, IDOK, m_buttonOK); DDX_Control(pDX, IDC_MYTIPDLG_PREVTIP, m_buttonPrev); DDX_Control(pDX, IDC_MYTIPDLG_NEXTTIP, m_buttonNext); DDX_Check(pDX, IDC_MYTIPDLG_CHECK_STARTUP, m_bStartup); DDX_Text(pDX, IDC_MYTIPDLG_TIPSTRING, m_sTip); DDX_Text(pDX, IDC_MYTIPDLG_STATIC_TITLE, m_sTitle); DDX_Control(pDX, IDC_MYTIPDLG_STATIC_TITLE, m_staticTitle); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(MyTipDlg, MyDialog) //{{AFX_MSG_MAP(MyTipDlg) ON_BN_CLICKED(IDC_MYTIPDLG_NEXTTIP, OnNextTip) ON_BN_CLICKED(IDC_MYTIPDLG_PREVTIP, OnPrevTip) ON_WM_CTLCOLOR() ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // MyTipDlg message handlers // Handle WM_INITDIALOG. BOOL MyTipDlg::OnInitDialog() { VALIDATE; // You MUST set the controls before you call the base OnInitDialog! SetControlInfo(IDC_MYTIPDLG_TIPSTRING, ANCHOR_LEFT | ANCHOR_TOP | RESIZE_BOTH); SetControlInfo(IDC_MYTIPDLG_STATIC_FRAME, ANCHOR_LEFT | ANCHOR_TOP | RESIZE_BOTH); SetControlInfo(IDC_MYTIPDLG_BULB, ANCHOR_LEFT | ANCHOR_TOP | RESIZE_BOTH); SetControlInfo(IDC_MYTIPDLG_PREVTIP, ANCHOR_RIGHT | ANCHOR_BOTTOM); SetControlInfo(IDC_MYTIPDLG_NEXTTIP, ANCHOR_RIGHT | ANCHOR_BOTTOM); MyDialog::OnInitDialog(); m_staticTitle.SetBkColor(RGB_WHITE); m_buttonPrev.SetIcon(IDI_MYTIPDLG_PREV, 24, 24); m_buttonNext.SetIcon(IDI_MYTIPDLG_NEXT, 24, 24); m_buttonNext.SetImageOffset(80 - 20); m_buttonNext.SetTextOffset(-96 + 20); m_buttonOK.SetIcon(IDI_MYBUTTON_OK, 24, 24); return TRUE; // return TRUE unless you set the focus to a control } // User clicked Next button. void MyTipDlg::OnNextTip() { VALIDATE; UpdateData(true); GetNextTipString(); UpdateData(false); } // User clicked Previous button. void MyTipDlg::OnPrevTip() { VALIDATE; UpdateData(true); GetPrevTipString(); UpdateData(false); } // Get the next tip. void MyTipDlg::GetNextTipString() { VALIDATE; // See which one is next in the string table. if (0 == m_uiTipID) { m_uiTipID = nFirstTipOfTheDay; } else { m_uiTipID++; } // If we can't load it, must be the end - start back at beginning. if (! m_sTip.LoadString(m_uiTipID)) { m_uiTipID = nFirstTipOfTheDay; if (! m_sTip.LoadString(m_uiTipID)) { _ASSERTE(! "Couldn't load the first tip!"); m_sTip = "Oops... couldn't load the first tip!"; } } // Get a count of the number of tips. Do NOT use Generic::LoadString(). CString sTipDummy; for (int nTip = nFirstTipOfTheDay; sTipDummy.LoadString(nTip); ++nTip) { ; } CString sFmt(Generic::LoadString(IDS_MYTIPDLG_TITLE_FORMAT)); m_sTitle.Format(sFmt, m_uiTipID - nFirstTipOfTheDay + 1, nTip - nFirstTipOfTheDay); } // Get the previous tip. void MyTipDlg::GetPrevTipString() { VALIDATE; // See which one is next in the string table. if (0 == m_uiTipID || nFirstTipOfTheDay == m_uiTipID) { m_uiTipID = nFirstTipOfTheDay; } else { --m_uiTipID; } // If we can't load it, must be an error. if (! m_sTip.LoadString(m_uiTipID)) { _ASSERTE(! "Couldn't load the previous tip!"); m_sTip = "Oops... couldn't load the previous tip!"; } // Get a count of the number of tips. Do NOT use Generic::LoadString(). CString sTipDummy; for (int nTip = nFirstTipOfTheDay; sTipDummy.LoadString(nTip); ++nTip) { ; } CString sFmt(Generic::LoadString(IDS_MYTIPDLG_TITLE_FORMAT)); m_sTitle.Format(sFmt, m_uiTipID - nFirstTipOfTheDay + 1, nTip - nFirstTipOfTheDay); } // Force the static control that contains the tip to a white background. HBRUSH MyTipDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { VALIDATE; if (pWnd->GetDlgCtrlID() == IDC_MYTIPDLG_TIPSTRING) { return (HBRUSH) ::GetStockObject(WHITE_BRUSH); } return MyDialog::OnCtlColor(pDC, pWnd, nCtlColor); } // void MyTipDlg::OnOK() { VALIDATE; MyDialog::OnOK(); // Update the startup information stored in the INI file AfxGetApp()->WriteProfileInt(szSection, szIntStartup, ! m_bStartup); } // void MyTipDlg::OnPaint() { VALIDATE; CPaintDC dc(this); // Get paint area for the bitmap of the bulb. CWnd* pStatic = GetDlgItem(IDC_MYTIPDLG_BULB); ASSERT_VALID(pStatic); CRect rcBitmap; pStatic->GetWindowRect(&rcBitmap); ScreenToClient(&rcBitmap); // Paint the background of the bulb bitmap white. CBrush br; br.CreateStockObject(WHITE_BRUSH); dc.FillRect(rcBitmap, &br); // Load bitmap and get dimensions of the bitmap. CBitmap bmp; bmp.LoadBitmap(IDR_MYTIPDLG); BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo); // Draw bitmap in top corner and validate only top portion of window. CDC dcTmp; dcTmp.CreateCompatibleDC(&dc); dcTmp.SelectObject(&bmp); rcBitmap.bottom = bmpInfo.bmHeight + rcBitmap.top; dc.BitBlt(rcBitmap.left, rcBitmap.top, rcBitmap.Width(), rcBitmap.Height(), &dcTmp, 0, 0, SRCCOPY); // Draw out "Did you know..." message next to the bitmap. rcBitmap.left += bmpInfo.bmWidth; dc.SetBkMode(TRANSPARENT); dc.DrawText(Generic::LoadString(IDC_MYTIPDLG_BULB), rcBitmap, DT_VCENTER | DT_SINGLELINE | DT_NOCLIP); // Do not call CDialog::OnPaint() for painting messages. But we call the // MyDialog one so that the gripper gets painted. MyDialog::OnPaint(); }