home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / wins / dlgwinmgr.cpp < prev    next >
C/C++ Source or Header  |  1998-04-08  |  21KB  |  783 lines

  1. // DlgWinMgr.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <afxdlgs.h>
  6. #include "resource.h"
  7. #include <ObjModel\addguid.h>
  8. #include <ObjModel\appguid.h>
  9. #include <ObjModel\bldguid.h>
  10. #include <ObjModel\textguid.h>
  11. #include <ObjModel\dbgguid.h>
  12.  
  13. #include "DlgWinMgr.h"
  14. #include "windowslist.h"
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CDlgWinMgr dialog
  24. static _TCHAR BASED_CODE szFilter[] = _T("Named File Lists (*.nfl)|*.nfl|All Files (*.*)|*.*||");
  25.  
  26. CDlgWinMgr::CDlgWinMgr(CWnd* pParent /*=NULL*/)
  27.     : CDialog(CDlgWinMgr::IDD, pParent)
  28. {
  29.     //{{AFX_DATA_INIT(CDlgWinMgr)
  30.     m_fAutoDir = FALSE;
  31.     m_fAutoSize = FALSE;
  32.     m_fAutoVis = FALSE;
  33.     //}}AFX_DATA_INIT
  34.     m_pdirList = NULL;
  35.     m_iSortedCol = 0;
  36. }
  37.  
  38.  
  39. void CDlgWinMgr::DoDataExchange(CDataExchange* pDX)
  40. {
  41.     CDialog::DoDataExchange(pDX);
  42.     //{{AFX_DATA_MAP(CDlgWinMgr)
  43.     DDX_Control(pDX, IDC_BUTTONSELECTALL, m_ctlSelectAll);
  44.     DDX_Control(pDX, IDC_BUTTONREFRESH, m_ctlRefresh);
  45.     DDX_Control(pDX, IDC_BUTTONOPEN, m_ctlOpen);
  46.     DDX_Control(pDX, IDC_BUTTONMAKELIST, m_ctlMakeList);
  47.     DDX_Control(pDX, IDC_BUTTONLOADLIST, m_ctlLoad);
  48.     DDX_Control(pDX, IDC_BUTTONINVERTSEL, m_ctlInvert);
  49.     DDX_Control(pDX, IDC_BUTTONCLOSE, m_ctlClose);
  50.     DDX_Control(pDX, IDC_LIST, m_ctlListWinMgr);
  51.     DDX_Check(pDX, IDC_CHK_AUTODIR, m_fAutoDir);
  52.     DDX_Check(pDX, IDC_CHK_AUTOSIZE, m_fAutoSize);
  53.     DDX_Check(pDX, IDC_CHK_AUTOVIS, m_fAutoVis);
  54.     //}}AFX_DATA_MAP
  55. }
  56.  
  57.  
  58. BEGIN_MESSAGE_MAP(CDlgWinMgr, CDialog)
  59.     //{{AFX_MSG_MAP(CDlgWinMgr)
  60.     ON_BN_CLICKED(IDC_BUTTONCLOSE, OnButtonclose)
  61.     ON_BN_CLICKED(IDC_BUTTONINVERTSEL, OnButtoninvertsel)
  62.     ON_BN_CLICKED(IDC_BUTTONOPEN, OnButtonopen)
  63.     ON_BN_CLICKED(IDC_BUTTONSELECTALL, OnButtonselectall)
  64.     ON_BN_CLICKED(IDC_BUTTONMAKELIST, OnButtonmakelist)
  65.     ON_BN_CLICKED(IDC_BUTTONLOADLIST, OnButtonloadlist)
  66.     ON_BN_CLICKED(IDC_BUTTONREFRESH, OnButtonrefresh)
  67.     ON_BN_CLICKED(IDC_BUTTONMINWINS, OnButtonminwins)
  68.     ON_BN_CLICKED(IDC_BUTTONCLEAR, OnButtonclear)
  69.     ON_MESSAGE(WM_NOTIFY, OnNotify)
  70.     //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. //    ON_NOTIFY( wNotifyCode, id, OnNotify ) can't use because there is no id associated with a tooltip
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CDlgWinMgr message handlers
  76.  
  77. BOOL CDlgWinMgr::OnInitDialog() 
  78. {
  79.     CDialog::OnInitDialog();
  80.     _ASSERTE(sizeof(long) == sizeof(CDlgWinMgr*));
  81.     CString strColTitle;
  82.  
  83.     UpdateData(FALSE);
  84.  
  85.     m_ctlListWinMgr.SetOnClick((LPFNLCOP)OnListClick, (LPARAM)this);
  86.     m_ctlListWinMgr.SetOnDblClick((LPFNLCOP)OnListDblClick, (LPARAM)this);
  87.     m_ctlListWinMgr.SetSort((PFNLVCOMPARE)MySort, (LPARAM)this);
  88.     m_ctlListWinMgr.SetColClick((LPFNLCSOP)OnColClick, (LPARAM)this);
  89.  
  90.     strColTitle.LoadString(IDS_COL_FILENAME);
  91.     m_ctlListWinMgr.InsertColumn(COL_FILENAME, strColTitle);
  92.     strColTitle.LoadString(IDS_COL_TIME);
  93.     m_ctlListWinMgr.InsertColumn(COL_TIME, strColTitle);
  94.     strColTitle.LoadString(IDS_COL_EXT);
  95.     m_ctlListWinMgr.InsertColumn(COL_EXT, strColTitle);
  96.     strColTitle.LoadString(IDS_COL_DIRNAME);
  97.     m_ctlListWinMgr.InsertColumn(COL_DIRNAME, strColTitle);
  98.     strColTitle.LoadString(IDS_COL_DEBUGSIZE);
  99.     m_ctlListWinMgr.InsertColumn(COL_DEBUGSIZE, strColTitle);
  100.     strColTitle.LoadString(IDS_COL_SIZE);
  101.     m_ctlListWinMgr.InsertColumn(COL_SIZE, strColTitle);
  102.  
  103.     FillList();
  104.     m_ctlListWinMgr.DoSort(m_iSortedCol);
  105.     // CG: The following block was added by the ToolTips component.
  106.     {
  107.         // Create the ToolTip control.
  108.         CToolInfo toolinfo;
  109.  
  110.         m_tooltip.Create(this);
  111.         m_tooltip.Activate(TRUE);
  112.  
  113.         m_tooltip.AddTool(GetDlgItem(IDC_CHK_AUTOSIZE), IDS_TIPAUTOSIZE);
  114.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  115.         toolinfo.lpszText = m_szToolTipBuffer;
  116.         m_tooltip.SetToolInfo(&toolinfo);
  117.         m_tooltip.AddTool(GetDlgItem(IDC_CHK_AUTODIR), IDS_TIPAUTODIR);
  118.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  119.         toolinfo.lpszText = m_szToolTipBuffer;
  120.         m_tooltip.SetToolInfo(&toolinfo);
  121.  
  122.         m_tooltip.GetToolInfo(toolinfo, this, IDC_CHK_AUTOSIZE);
  123.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  124.         toolinfo.lpszText = m_szToolTipBuffer;
  125.         m_tooltip.SetToolInfo(&toolinfo);
  126.  
  127.         m_tooltip.AddTool(GetDlgItem(IDC_CHK_AUTOVIS), IDS_TIPAUTOVIS);
  128.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  129.         toolinfo.lpszText = m_szToolTipBuffer;
  130.         m_tooltip.SetToolInfo(&toolinfo);
  131.  
  132.         m_tooltip.AddTool(GetDlgItem(IDC_LIST), IDS_TIPLIST);
  133.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  134.         toolinfo.lpszText = m_szToolTipBuffer;
  135.         m_tooltip.SetToolInfo(&toolinfo);
  136.  
  137.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONREFRESH), IDS_TIPREFRESH);
  138.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  139.         toolinfo.lpszText = m_szToolTipBuffer;
  140.         m_tooltip.SetToolInfo(&toolinfo);
  141.  
  142.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONCLEAR), IDS_TIPCLEAR);
  143.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  144.         toolinfo.lpszText = m_szToolTipBuffer;
  145.         m_tooltip.SetToolInfo(&toolinfo);
  146.  
  147.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONINVERTSEL), IDS_TIPINVERTSEL);
  148.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  149.         toolinfo.lpszText = m_szToolTipBuffer;
  150.         m_tooltip.SetToolInfo(&toolinfo);
  151.  
  152.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONSELECTALL), IDS_TIPSELECTALL);
  153.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  154.         toolinfo.lpszText = m_szToolTipBuffer;
  155.         m_tooltip.SetToolInfo(&toolinfo);
  156.  
  157.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONMAKELIST), IDS_TIPMAKELIST);
  158.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  159.         toolinfo.lpszText = m_szToolTipBuffer;
  160.         m_tooltip.SetToolInfo(&toolinfo);
  161.  
  162.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONLOADLIST), IDS_TIPLOADLIST);
  163.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  164.         toolinfo.lpszText = m_szToolTipBuffer;
  165.         m_tooltip.SetToolInfo(&toolinfo);
  166.  
  167.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONOPEN), IDS_TIPACTIVATE);
  168.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  169.         toolinfo.lpszText = m_szToolTipBuffer;
  170.         m_tooltip.SetToolInfo(&toolinfo);
  171.  
  172.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONMINWINS), IDS_TIPMINWINS);
  173.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  174.         toolinfo.lpszText = m_szToolTipBuffer;
  175.         m_tooltip.SetToolInfo(&toolinfo);
  176.  
  177.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONCLOSE), IDS_TIPCLOSE);
  178.         m_tooltip.GetToolInfo(toolinfo, this, 0);
  179.         toolinfo.lpszText = m_szToolTipBuffer;
  180.         m_tooltip.SetToolInfo(&toolinfo);
  181.  
  182.         
  183.         m_tooltip.SetMaxTipWidth(256);
  184.     }
  185.     return TRUE;  // return TRUE unless you set the focus to a control
  186.                   // EXCEPTION: OCX Property Pages should return FALSE
  187. }
  188.  
  189. BOOL CDlgWinMgr::PreTranslateMessage(MSG* pMsg)
  190. {
  191.     // CG: The following block was added by the ToolTips component.
  192.     {
  193.         // Let the ToolTip process this message.
  194.         m_tooltip.RelayEvent(pMsg);
  195.     }
  196.     // CG: The following block was added by the ToolTips component.
  197.     {
  198.         // Let the ToolTip process this message.
  199.         //m_tooltip.RelayEvent(pMsg);
  200.     }
  201.     return CDialog::PreTranslateMessage(pMsg);    // CG: This was added by the ToolTips component.
  202. }
  203.  
  204. void CDlgWinMgr::SetDirList(CDirList* pList, CWindowsList *pWndList) // pWndList is a misnomer, but...
  205. {
  206.     m_pdirList = pList;
  207.     m_pWndList = pWndList;
  208. }
  209.  
  210. void CDlgWinMgr::OnButtonclose() 
  211. {
  212.     CString strDoc;
  213.     POSITION p;
  214.     int iItem;
  215.  
  216.     p = m_ctlListWinMgr.GetFirstSelectedItemPosition();
  217.     while (p)
  218.     {
  219.         iItem = m_ctlListWinMgr.GetNextSelectedItem(p);
  220.         strDoc = m_ctlListWinMgr.GetItemText(iItem, COL_DIRNAME);
  221.         strDoc += _T('\\');
  222.         strDoc += m_ctlListWinMgr.GetItemText(iItem, COL_FILENAME);
  223.         m_pWndList->CloseDoc(strDoc);
  224.     }
  225.     
  226.     
  227. }
  228.  
  229. void CDlgWinMgr::OnButtoninvertsel() 
  230. {
  231.     int iItem = 0, iItemLast = 0;
  232.     UINT state;
  233.     
  234.     if (m_ctlListWinMgr.GetItemCount() > 0)
  235.     {
  236.         while (iItem != -1)
  237.         {
  238.             state = m_ctlListWinMgr.GetItemState(iItem, LVIS_SELECTED);
  239.             m_ctlListWinMgr.SetItemState(iItem, ~state, LVIS_SELECTED);
  240.             iItem = m_ctlListWinMgr.GetNextItem(iItem, LVNI_BELOW );
  241.             if (iItem == iItemLast)
  242.                 iItem = -1;
  243.             iItemLast = iItem;
  244.         }
  245.     }
  246.     SetButtonStates();
  247. }
  248.  
  249. void CDlgWinMgr::OnButtonopen() 
  250. {
  251.     CString strDoc;
  252.     POSITION p;
  253.     int iItem;
  254.  
  255.     p = m_ctlListWinMgr.GetFirstSelectedItemPosition();
  256.     while (p)
  257.     {
  258.         iItem = m_ctlListWinMgr.GetNextSelectedItem(p);
  259.         strDoc = m_ctlListWinMgr.GetItemText(iItem, COL_DIRNAME);
  260.         strDoc += _T('\\');
  261.         strDoc += m_ctlListWinMgr.GetItemText(iItem, COL_FILENAME);
  262.         m_pWndList->OpenDoc(strDoc);
  263.     }
  264.     
  265. }
  266.  
  267. void CDlgWinMgr::OnButtonselectall() 
  268. {
  269.     int iItem = 0, iItemLast = 0;
  270.     
  271.     if (m_ctlListWinMgr.GetItemCount() > 0)
  272.     {
  273.         while (iItem != -1)
  274.         {
  275.             m_ctlListWinMgr.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  276.             iItem = m_ctlListWinMgr.GetNextItem(iItem, LVNI_BELOW );
  277.             if (iItem == iItemLast)
  278.                 iItem = -1;
  279.             iItemLast = iItem;
  280.         }
  281.     }
  282.     SetButtonStates();
  283. }
  284.  
  285. /*
  286. LIST ideas:
  287.     The list idea is just barely implemented here. It would
  288.     be more useful if you could search for lists, and each
  289.     list could show a description as it was selected.
  290.  
  291.     Each file could also have comments.
  292.     Each file SHOULD have a file position remembered.
  293.  
  294. */
  295. void CDlgWinMgr::OnButtonmakelist() 
  296. {
  297.     CStringList rgStr;
  298.     CString strDoc, strInfo;
  299.     POSITION p;
  300.     CFileItem *pFileItem;
  301.     CRect rectDbg, rect;
  302.     int iItem;
  303.     int iRes;
  304.  
  305.     p = m_ctlListWinMgr.GetFirstSelectedItemPosition();
  306.     while (p)
  307.     {
  308.         iItem = m_ctlListWinMgr.GetNextSelectedItem(p);
  309.         strDoc = m_ctlListWinMgr.GetItemText(iItem, COL_DIRNAME);
  310.         strDoc += _T('\\');
  311.         strDoc += m_ctlListWinMgr.GetItemText(iItem, COL_FILENAME);
  312.         pFileItem = (CFileItem *)m_ctlListWinMgr.GetItemData(iItem);
  313.         rectDbg = pFileItem->GetDbgRect();
  314.         rect = pFileItem->GetRect();
  315.         strInfo.Format(_T("%s*%d,%d,%d,%d | %d,%d,%d,%d"), strDoc, rect.top, rect.left, rect.bottom, rect.right,
  316.                     rectDbg.top, rectDbg.left, rectDbg.bottom, rectDbg.right);
  317.         rgStr.AddTail(strDoc);
  318.     }
  319.  
  320.     if (rgStr.GetCount() > 0)
  321.     {
  322.         CFile fileWndList;
  323.         CFileDialog dlgFile(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
  324.  
  325.         iRes = dlgFile.DoModal();
  326.         if (iRes == IDOK)
  327.         {
  328.             strDoc = dlgFile.GetFileName();
  329.             if (strDoc.ReverseFind(_T('.')) == -1)
  330.             {
  331.                 strDoc += _T(".nfl"); // add the missing extension
  332.             }
  333.             TRY
  334.             {
  335.                 if (fileWndList.Open(strDoc, CFile::modeCreate | CFile::modeWrite))
  336.                 {
  337.                 CArchive ar( &fileWndList, CArchive::store);
  338.  
  339.                 rgStr.Serialize(ar);
  340.                 }
  341.             }
  342.             CATCH(CFileException, e)
  343.             {
  344.                 CString strMsg;
  345.                 CString strErr;
  346.                 e->GetErrorMessage(strErr.GetBuffer(_MAX_PATH), _MAX_PATH);
  347.                 strErr.ReleaseBuffer();
  348.                 strMsg.Format(_T("%s \n    %s"), strErr, strDoc);
  349.                 MessageBox(strMsg, _T("BOOKNOTE"), MB_OK);
  350.             }
  351.             END_CATCH
  352.         }
  353.     }
  354. }
  355.  
  356. void CDlgWinMgr::OnButtonloadlist() 
  357. {
  358.     CFile fileWndList;
  359.     CFileException exptFile;
  360.     CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
  361.     CStringList rgStr;
  362.     CString strDoc, strInfo;
  363.     BOOL fOK = FALSE;
  364.     int iRes, i;
  365.  
  366.     iRes = dlgFile.DoModal();
  367.     if (iRes == IDOK)
  368.     {
  369.         strDoc = dlgFile.GetFileName();
  370.         if (strDoc.ReverseFind(_T('.')) == -1)
  371.         {
  372.             strDoc += _T(".nfl"); // add the missing extension
  373.         }
  374.         TRY
  375.         {
  376.             fileWndList.Open(strDoc, CFile::modeRead, &exptFile);
  377.             CArchive ar( &fileWndList, CArchive::load);
  378.  
  379.             rgStr.Serialize(ar);
  380.             fOK = TRUE;
  381.         }
  382.         CATCH(CFileException, e)
  383.         {
  384.         }
  385.         END_CATCH
  386.     }
  387.     
  388.     if (fOK)
  389.     {
  390.         POSITION p;
  391.  
  392.         p = rgStr.GetHeadPosition();
  393.         while (p)
  394.         {
  395.             strInfo = rgStr.GetNext(p);
  396.             i = strInfo.ReverseFind(_T('*'));
  397.             if (i < 0)
  398.             {
  399.                 strDoc = strInfo; // Assume we didn't store any size info
  400.             }
  401.             else
  402.             {
  403.                 strDoc = strInfo.Left(i);
  404.             }
  405.             if (!strDoc.IsEmpty())
  406.             {
  407.                 CComPtr<IGenericDocument> pDoc;
  408.                 m_pWndList->OpenDoc(strDoc, &pDoc);
  409.                 if (pDoc)
  410.                 {
  411.                     CComPtr<IDispatch> pDispWnd;
  412.                     CComQIPtr<IGenericWindow, &IID_IGenericWindow> pWnd;
  413.  
  414.                     pDoc->get_ActiveWindow(&pDispWnd);
  415.                     if (pDispWnd && i > 0)
  416.                     {
  417.                         pWnd = pDispWnd;
  418.                         pDispWnd = NULL;
  419.  
  420.                         strInfo = strInfo.Mid(i+1);
  421.                         if (!strInfo.IsEmpty())
  422.                         {
  423.                             long t, l, b, r;
  424.                             i = strInfo.Find(_T(','));
  425.                             t = _ttol(strInfo);
  426.                             strInfo = strInfo.Mid(i+1);
  427.                             i = strInfo.Find(_T(','));
  428.                             l = _ttol(strInfo);
  429.                             strInfo = strInfo.Mid(i+1);
  430.                             i = strInfo.Find(_T(','));
  431.                             b = _ttol(strInfo);
  432.                             strInfo = strInfo.Mid(i+1);
  433.                             r = _ttol(strInfo);
  434.                             pWnd->put_Top(t);
  435.                             pWnd->put_Left(l);
  436.                             pWnd->put_Width(r - l);
  437.                             pWnd->put_Height(b - t);
  438.                         }
  439.                     }
  440.                 }
  441.             }
  442.         }
  443.         OnButtonrefresh();
  444.     }
  445. }
  446.  
  447. void CDlgWinMgr::SetVars(BOOL fAutoVis, BOOL fAutoDir, BOOL fAutoSize, int iSortedCol, long lSize)
  448. {
  449.     m_fAutoDir = fAutoDir;
  450.     m_fAutoSize = fAutoSize;
  451.     m_fAutoVis = fAutoVis;
  452.     m_iSortedCol = iSortedCol;
  453.     m_lSize = lSize;
  454. }
  455.  
  456. void CDlgWinMgr::GetVars(BOOL& fAutoVis, BOOL& fAutoDir, BOOL& fAutoSize, int& iSortedCol, long& lSize)
  457. {
  458.     fAutoDir = m_fAutoDir;
  459.     fAutoSize = m_fAutoSize;
  460.     fAutoVis =     m_fAutoVis;
  461.     iSortedCol = m_iSortedCol;
  462.     lSize = m_lSize;
  463. }
  464.  
  465. void CDlgWinMgr::OnButtonrefresh() 
  466. {
  467.     DoClear();
  468.     m_pWndList->WorkspaceOpen();
  469.     FillList();
  470. }
  471.  
  472. int CDlgWinMgr::FillList()
  473. {
  474.     POSITION p;
  475.     CFileItem *pFileItem;
  476.     int i, j, ich;
  477.     CTime timeFile;
  478.     CString strTime, strFile, strRect;
  479.     CRect rect;
  480.     
  481.     i = 0;
  482.     m_ctlListWinMgr.DeleteAllItems();
  483.     if (m_pdirList)
  484.     {
  485.         p = m_pdirList->GetHeadPosition();
  486.         while (p)
  487.         {
  488.             pFileItem = m_pdirList->GetNextPos(p);
  489.             strFile = pFileItem->GetFile();
  490.             j = m_ctlListWinMgr.InsertItem(i, strFile, (LPARAM)pFileItem); // COL_FILENAME
  491.             m_ctlListWinMgr.SetItemText(j, COL_DIRNAME, pFileItem->GetDir());
  492.             timeFile = pFileItem->GetTime();
  493.             strTime = timeFile.Format(_T("%I:%M:%S %p  %d/%m/%Y"));
  494.             m_ctlListWinMgr.SetItemText(j, COL_TIME, strTime);
  495.             ich = strFile.ReverseFind(_T('.'));
  496.             if (ich > 0)
  497.             {
  498.                 if (ich < strFile.GetLength())
  499.                     strFile = strFile.Mid(ich+1);
  500.                 else
  501.                     strFile.Empty();
  502.             }
  503.             m_ctlListWinMgr.SetItemText(j, COL_EXT, strFile);
  504.  
  505.             rect = pFileItem->GetRect();
  506.             strRect.Format(_T("(%d, %d, %d, %d)"), rect.top, rect.left, rect.bottom, rect.right);
  507.             m_ctlListWinMgr.SetItemText(j, COL_SIZE, strRect);
  508.  
  509.             rect = pFileItem->GetDbgRect();
  510.             strRect.Format(_T("(%d, %d, %d, %d)"), rect.top, rect.left, rect.bottom, rect.right);
  511.             m_ctlListWinMgr.SetItemText(j, COL_DEBUGSIZE, strRect);
  512.  
  513.             i++;
  514.         }
  515.     }
  516.     m_ctlListWinMgr.SetWidths();
  517.     SetButtonStates();
  518.     return(i);
  519. }
  520.  
  521. void CDlgWinMgr::SetButtonStates()
  522. {
  523.     int cItems;
  524.     cItems = m_ctlListWinMgr.GetSelectedCount();
  525.     if (cItems)
  526.     {
  527.         m_ctlOpen.EnableWindow(TRUE);
  528.         m_ctlMakeList.EnableWindow(TRUE);
  529.         m_ctlClose.EnableWindow(TRUE);
  530.     }
  531.     else
  532.     {
  533.         m_ctlOpen.EnableWindow(FALSE);
  534.         m_ctlMakeList.EnableWindow(FALSE);
  535.         m_ctlClose.EnableWindow(FALSE);
  536.     }
  537. }
  538.  
  539. void CDlgWinMgr::OnButtonminwins() 
  540. {
  541.     CString strDoc;
  542.     POSITION p;
  543.     int iItem;
  544.  
  545.     p = m_ctlListWinMgr.GetFirstSelectedItemPosition();
  546.     while (p)
  547.     {
  548.         iItem = m_ctlListWinMgr.GetNextSelectedItem(p);
  549.         strDoc = m_ctlListWinMgr.GetItemText(iItem, COL_DIRNAME);
  550.         strDoc += _T('\\');
  551.         strDoc += m_ctlListWinMgr.GetItemText(iItem, COL_FILENAME);
  552.         m_pWndList->DoMinWin(strDoc);
  553.     }
  554.     
  555. }
  556.  
  557.  
  558.  
  559. int CALLBACK CDlgWinMgr::MySort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  560. {
  561.     int iComp = 0;
  562.     CString strOne, strTwo;
  563.     CTime timeOne, timeTwo;
  564.     struct SortInfo *psi;
  565.     psi = (SortInfo *)lParamSort;
  566.     CFileItem *pFIOne, *pFITwo;
  567.     _ASSERTE(psi);
  568.  
  569.     /*
  570.             The comparison function must return a negative value
  571.             if the first item should precede the second, a positive 
  572.             value if the first item should follow the second, or
  573.             zero if the two items are equivalent.
  574.     */
  575.     if (psi)
  576.     {
  577.         CMyListCtrl *pList;
  578.         pList = psi->pList;
  579.         int i;
  580.         _ASSERTE(pList);
  581.  
  582.         iComp = 0;
  583.  
  584.         if (pList)
  585.         {
  586.             pFIOne = (CFileItem *)lParam1;
  587.             pFITwo = (CFileItem *)lParam2;
  588.             _ASSERTE(pFIOne && pFITwo);
  589.             if (pFIOne && pFITwo)
  590.             {
  591.                 switch(abs(psi->iColumn) - 1) // iColumn here is "1 based" so we don't get -0.
  592.                 {
  593.                 case COL_FILENAME:
  594.                     strOne = pFIOne->GetFile();
  595.                     strTwo = pFITwo->GetFile();
  596.                     iComp = strOne.CompareNoCase(strTwo);
  597.                     break;
  598.                 case COL_DIRNAME:
  599.                     strOne = pFIOne->GetDir();
  600.                     strTwo = pFITwo->GetDir();
  601.                     iComp = strOne.CompareNoCase(strTwo);
  602.                     break;
  603.                 case COL_TIME:
  604.                     timeOne = pFIOne->GetTime();
  605.                     timeTwo = pFITwo->GetTime();
  606.                     iComp = timeOne > timeTwo ? 1 : ( timeOne == timeTwo ? 0 : -1);
  607.                     break;
  608.                 case COL_EXT:
  609.                     strOne = pFIOne->GetFile();
  610.                     i = strOne.ReverseFind(_T('.'));
  611.                     if (i > 0)
  612.                     {
  613.                         if (i < strOne.GetLength())
  614.                             strOne = strOne.Mid(i+1);
  615.                         else
  616.                             strOne.Empty();
  617.                     }
  618.                     strTwo = pFITwo->GetFile();
  619.                     i = strTwo.ReverseFind(_T('.'));
  620.                     if (i > 0)
  621.                     {
  622.                         if (i < strTwo.GetLength())
  623.                             strTwo = strTwo.Mid(i+1);
  624.                         else
  625.                             strTwo.Empty();
  626.                     }
  627.                     iComp = strOne.CompareNoCase(strTwo);
  628.                     break;
  629.                 case COL_SIZE:
  630.                     {
  631.                         CRect rectOne, rectTwo;
  632.                         rectOne = pFIOne->GetRect();
  633.                         rectTwo = pFITwo->GetRect();
  634.                         long l1, l2;
  635.                         l1 = rectOne.top * 100000 + rectOne.left;
  636.                         l2 = rectTwo.top * 100000 + rectTwo.top;
  637.                         if (rectOne == rectTwo)
  638.                             iComp = 0;
  639.                         else if (l1 <= l2)
  640.                             iComp = 1;
  641.                         else
  642.                             iComp = -1;
  643.                     }
  644.                     break;
  645.                 case COL_DEBUGSIZE:
  646.                     {
  647.                         CRect rectOne, rectTwo;
  648.                         rectOne = pFIOne->GetDbgRect();
  649.                         rectTwo = pFITwo->GetDbgRect();
  650.                         long l1, l2;
  651.                         l1 = rectOne.top * 100000 + rectOne.left;
  652.                         l2 = rectTwo.top * 100000 + rectTwo.top;
  653.                         if (rectOne == rectTwo)
  654.                             iComp = 0;
  655.                         else if (l1 <= l2)
  656.                             iComp = 1;
  657.                         else
  658.                             iComp = -1;
  659.                     }
  660.                     break;
  661.                 }
  662.                 if (psi->iColumn < 0)
  663.                 {
  664.                     iComp = -iComp; // reverse sorting sense.
  665.                 }
  666.             }
  667.         }
  668.     }
  669.     return(iComp);
  670. }
  671.  
  672.  
  673. void CDlgWinMgr::OnListDblClick(NMHDR *pNMHDR, LRESULT *pResult, LPARAM lParam)
  674. {
  675.     int iItem;
  676.     CWindowsList *pWindowsList;
  677.     CDlgWinMgr *pThis = (CDlgWinMgr *)lParam;
  678.     pNMHDR; // UNREFERENCED
  679.  
  680.     _ASSERTE(pThis);
  681.  
  682.     iItem = pThis->m_ctlListWinMgr.GetCurrentIndex();
  683.     pWindowsList = pThis->m_pWndList;
  684.     if (pWindowsList)
  685.     {
  686.         CString strDoc;
  687.         CFileItem *pItem;
  688.  
  689.         pItem = (CFileItem *)pThis->m_ctlListWinMgr.GetItemData(iItem);
  690.         if (pItem)
  691.         {
  692.             strDoc = pItem->GetDir();
  693.             strDoc += "\\";
  694.             strDoc += pItem->GetFile();
  695.             pWindowsList->OpenDoc(strDoc);
  696.         }
  697.     }
  698.     *pResult = 0;
  699.  
  700. }
  701.  
  702. void CDlgWinMgr::OnListClick(NMHDR *pNMHDR, LRESULT *pResult, LPARAM lParam)
  703. {
  704.     pNMHDR; // UNREFERENCED
  705.     CDlgWinMgr *pThis = (CDlgWinMgr *)lParam;
  706.  
  707.     _ASSERTE(pThis);
  708.     pThis->SetButtonStates();
  709.     *pResult = 0;
  710. }
  711.  
  712.  
  713. void CDlgWinMgr::OnColClick(NMHDR *pNMHDR, LRESULT *pResult, LPARAM lParam, SortInfo *pSortInfo)
  714. {
  715.     NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR;
  716.     CDlgWinMgr *pThis = (CDlgWinMgr *)lParam;
  717.     int iColumn, iColumnLast;
  718.  
  719.     _ASSERTE(pThis);
  720.     
  721.     iColumn = pNMListView->iSubItem + 1;
  722.     iColumnLast = pThis->m_iSortedCol;
  723.     if (iColumn == abs(iColumnLast)) // a repeat so we switch directions?
  724.     {
  725.         iColumn = -iColumnLast;
  726.     }
  727.     pThis->m_iSortedCol = iColumn;
  728.     pSortInfo->iColumn = iColumn;
  729.     *pResult = 0;
  730. }
  731.  
  732. void CDlgWinMgr::OnButtonclear() 
  733. {
  734.     DoClear();
  735.     SetButtonStates();
  736. }
  737.  
  738. void CDlgWinMgr::DoClear()
  739. {
  740.     m_pWndList->Reset();
  741.     m_ctlListWinMgr.DeleteAllItems();
  742. }
  743.  
  744. afx_msg void CDlgWinMgr::OnNotify( NMHDR * pNotifyStruct, LRESULT * result )
  745. {
  746.     result; // UNREFD
  747.     pNotifyStruct; // UNREFD
  748. /*
  749. WM_NOTIFY 
  750.     idCtrl = (int) wParam; 
  751.     pnmh = (LPNMHDR) lParam; 
  752.  
  753. TTN_GETDISPINFO
  754.     lpnmtdi = (LPNMTTDISPINFO)lParam;
  755.  
  756. #define TTN_NEEDTEXT TTN_GETDISPINFO
  757.  
  758. Sent by a tooltip control to retrieve information needed to display a tooltip window. This notification supersedes the TTN_NEEDTEXT notification. This notification is sent in the form of a WM_NOTIFY message. 
  759.  
  760. The return value for this notification is not used. 
  761. lpnmtdi 
  762. Address of an NMTTDISPINFO structure that identifies the tool that needs text and receives the requested information. 
  763. Fill the structure's appropriate fields to return the requested information to the tooltip control. If your message handler sets the uFlags field of the NMTTDISPINFO structure to TTF_DI_SETITEM, the tooltip control stores the information and will not request it again. 
  764.  
  765.           m_tooltip.AddTool(GetDlgItem(IDC_CHK_AUTOSIZE), IDS_TIPAUTOSIZE);
  766.         m_tooltip.AddTool(GetDlgItem(IDC_CHK_AUTODIR), IDS_TIPAUTODIR);
  767.         m_tooltip.AddTool(GetDlgItem(IDC_CHK_AUTOVIS), IDS_TIPAUTOVIS);
  768.         m_tooltip.AddTool(GetDlgItem(IDC_LIST), IDS_TIPLIST);
  769.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONREFRESH), IDS_TIPREFRESH);
  770.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONCLEAR), IDS_TIPCLEAR);
  771.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONINVERTSEL), IDS_TIPINVERTSEL);
  772.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONSELECTALL), IDS_TIPSELECTALL);
  773.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONMAKELIST), IDS_TIPMAKELIST);
  774.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONLOADLIST), IDS_TIPLOADLIST);
  775.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONOPEN), IDS_TIPACTIVATE);
  776.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONMINWINS), IDS_TIPMINWINS);
  777.         m_tooltip.AddTool(GetDlgItem(IDC_BUTTONCLOSE), IDS_TIPCLOSE);
  778.  
  779.  
  780. */
  781.  
  782. }
  783.