home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / datalist / datalist.exe / %MAINDIR% / SAMPLES / Sample9 / LISTSA~2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-09  |  7.2 KB  |  261 lines

  1. // ListSampleDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ListSample.h"
  6.  
  7. #include "gtlist32.h" //this was created using classwizard (Classes from OLETypeLib)
  8. #include "gtlist.h"
  9.  
  10. #include "ListSampleDlg.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CAboutDlg dialog used for App About
  20.  
  21. class CAboutDlg : public CDialog
  22. {
  23. public:
  24.     CAboutDlg();
  25.  
  26. // Dialog Data
  27.     //{{AFX_DATA(CAboutDlg)
  28.     enum { IDD = IDD_ABOUTBOX };
  29.     //}}AFX_DATA
  30.  
  31.     // ClassWizard generated virtual function overrides
  32.     //{{AFX_VIRTUAL(CAboutDlg)
  33.     protected:
  34.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  35.     //}}AFX_VIRTUAL
  36.  
  37. // Implementation
  38. protected:
  39.     //{{AFX_MSG(CAboutDlg)
  40.     //}}AFX_MSG
  41.     DECLARE_MESSAGE_MAP()
  42. };
  43.  
  44. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  45. {
  46.     //{{AFX_DATA_INIT(CAboutDlg)
  47.     //}}AFX_DATA_INIT
  48. }
  49.  
  50. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  51. {
  52.     CDialog::DoDataExchange(pDX);
  53.     //{{AFX_DATA_MAP(CAboutDlg)
  54.     //}}AFX_DATA_MAP
  55. }
  56.  
  57. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  58.     //{{AFX_MSG_MAP(CAboutDlg)
  59.         // No message handlers
  60.     //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CListSampleDlg dialog
  65.  
  66. CListSampleDlg::CListSampleDlg(CWnd* pParent /*=NULL*/)
  67.     : CDialog(CListSampleDlg::IDD, pParent)
  68. {
  69.     //{{AFX_DATA_INIT(CListSampleDlg)
  70.         // NOTE: the ClassWizard will add member initialization here
  71.     //}}AFX_DATA_INIT
  72.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  73.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  74. }
  75.  
  76. void CListSampleDlg::DoDataExchange(CDataExchange* pDX)
  77. {
  78.     CDialog::DoDataExchange(pDX);
  79.     //{{AFX_DATA_MAP(CListSampleDlg)
  80.         // NOTE: the ClassWizard will add DDX and DDV calls here
  81.     //}}AFX_DATA_MAP
  82. }
  83.  
  84. BEGIN_MESSAGE_MAP(CListSampleDlg, CDialog)
  85.     //{{AFX_MSG_MAP(CListSampleDlg)
  86.     ON_WM_SYSCOMMAND()
  87.     ON_WM_PAINT()
  88.     ON_WM_QUERYDRAGICON()
  89.     //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CListSampleDlg message handlers
  94.  
  95. BOOL CListSampleDlg::OnInitDialog()
  96. {
  97.     CDialog::OnInitDialog();
  98.  
  99.     // Add "About..." menu item to system menu.
  100.  
  101.     // IDM_ABOUTBOX must be in the system command range.
  102.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  103.     ASSERT(IDM_ABOUTBOX < 0xF000);
  104.  
  105.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  106.     CString strAboutMenu;
  107.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  108.     if (!strAboutMenu.IsEmpty())
  109.     {
  110.         pSysMenu->AppendMenu(MF_SEPARATOR);
  111.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  112.     }
  113.  
  114.     // Set the icon for this dialog.  The framework does this automatically
  115.     //  when the application's main window is not a dialog
  116.     SetIcon(m_hIcon, TRUE);            // Set big icon
  117.     SetIcon(m_hIcon, FALSE);        // Set small icon
  118.     
  119.     InitializeList();
  120.  
  121.     return TRUE;  // return TRUE  unless you set the focus to a control
  122. }
  123.  
  124. void CListSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  125. {
  126.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  127.     {
  128.         CAboutDlg dlgAbout;
  129.         dlgAbout.DoModal();
  130.     }
  131.     else
  132.     {
  133.         CDialog::OnSysCommand(nID, lParam);
  134.     }
  135. }
  136.  
  137. // If you add a minimize button to your dialog, you will need the code below
  138. //  to draw the icon.  For MFC applications using the document/view model,
  139. //  this is automatically done for you by the framework.
  140.  
  141. void CListSampleDlg::OnPaint() 
  142. {
  143.     if (IsIconic())
  144.     {
  145.         CPaintDC dc(this); // device context for painting
  146.  
  147.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  148.  
  149.         // Center icon in client rectangle
  150.         int cxIcon = GetSystemMetrics(SM_CXICON);
  151.         int cyIcon = GetSystemMetrics(SM_CYICON);
  152.         CRect rect;
  153.         GetClientRect(&rect);
  154.         int x = (rect.Width() - cxIcon + 1) / 2;
  155.         int y = (rect.Height() - cyIcon + 1) / 2;
  156.  
  157.         // Draw the icon
  158.         dc.DrawIcon(x, y, m_hIcon);
  159.     }
  160.     else
  161.     {
  162.         CDialog::OnPaint();
  163.     }
  164. }
  165.  
  166. // The system calls this to obtain the cursor to display while the user drags
  167. //  the minimized window.
  168. HCURSOR CListSampleDlg::OnQueryDragIcon()
  169. {
  170.     return (HCURSOR) m_hIcon;
  171. }
  172.  
  173. //this function is just a helper
  174. CGTList1* CListSampleDlg::GetList(long ID)
  175. {
  176.     CGTList1* pCtrl = (CGTList1*)(GetDlgItem(ID));
  177.     return pCtrl;
  178. }
  179.  
  180. //this function initializes the list
  181. void CListSampleDlg::InitializeList()
  182. {
  183.     CGTList1* pList = GetList();
  184.  
  185.     //we create these variables to pass to the create function
  186.     VARIANT vError;
  187.     VARIANT vText;
  188.  
  189.     VariantInit(&vError);
  190.     VariantInit(&vText);
  191.  
  192.     vError.vt = VT_ERROR; //this states to use the default
  193.  
  194.     //Add Columns to the list
  195.     vText.vt = VT_BSTR;
  196.     vText.bstrVal = CString("Column0").AllocSysString();
  197.     _DColumnDefs(pList->GetColumnDefs(vError)).Add(vError, vError, vText);
  198.     VariantClear(&vText); //deallocate the string
  199.  
  200.     vText.vt = VT_BSTR;
  201.     vText.bstrVal = CString("Column1").AllocSysString();
  202.     _DColumnDefs(pList->GetColumnDefs(vError)).Add(vError, vError, vText);
  203.     VariantClear(&vText); //deallocate the string
  204.  
  205.     // Add Items to the list
  206.     vText.vt = VT_BSTR;
  207.     vText.bstrVal = CString("Item0Col0").AllocSysString();
  208.     _DListItems(pList->GetListItems(vError)).Add(vError, vError, vText, vError, vError, vError);
  209.     VariantClear(&vText); //deallocate the string
  210.  
  211.     vText.vt = VT_BSTR;
  212.     vText.bstrVal = CString("Item1Col0").AllocSysString();
  213.     _DListItems(pList->GetListItems(vError)).Add(vError, vError, vText, vError, vError, vError);
  214.     VariantClear(&vText); //deallocate the string
  215.  
  216.     vText.vt = VT_BSTR;
  217.     vText.bstrVal = CString("Item2Col0").AllocSysString();
  218.     _DListItems(pList->GetListItems(vError)).Add(vError, vError, vText, vError, vError, vError);
  219.     VariantClear(&vText); //deallocate the string
  220.  
  221.     vText.vt = VT_BSTR;
  222.     vText.bstrVal = CString("Item3Col0").AllocSysString();
  223.     _DListItems(pList->GetListItems(vError)).Add(vError, vError, vText, vError, vError, vError);
  224.     VariantClear(&vText); //deallocate the string
  225.  
  226.     //Set the Text in the second column for eah item
  227.     VARIANT vListItemIndex;
  228.     VariantInit(&vListItemIndex);
  229.     vListItemIndex.vt = VT_I4;
  230.  
  231.     VARIANT vSubItemIndex;
  232.     VariantInit(&vSubItemIndex);
  233.     vSubItemIndex.vt = VT_I4;
  234.     vSubItemIndex.lVal = 1; //we are going to set column #1's text
  235.  
  236.     vListItemIndex.lVal = 0;
  237.     vText.vt = VT_BSTR;
  238.     vText.bstrVal = CString("Item0Col0").AllocSysString();
  239.     _DSubItem(_DListItem(pList->GetListItems(vListItemIndex)).GetSubItems(vSubItemIndex)).SetText("Item0Col1");
  240.     VariantClear(&vText); //deallocate the string
  241.  
  242.     vListItemIndex.lVal = 1;
  243.     vText.vt = VT_BSTR;
  244.     vText.bstrVal = CString("Item0Col0").AllocSysString();
  245.     _DSubItem(_DListItem(pList->GetListItems(vListItemIndex)).GetSubItems(vSubItemIndex)).SetText("Item0Col1");
  246.     VariantClear(&vText); //deallocate the string
  247.  
  248.     vListItemIndex.lVal = 2;
  249.     vText.vt = VT_BSTR;
  250.     vText.bstrVal = CString("Item0Col0").AllocSysString();
  251.     _DSubItem(_DListItem(pList->GetListItems(vListItemIndex)).GetSubItems(vSubItemIndex)).SetText("Item0Col1");
  252.     VariantClear(&vText); //deallocate the string
  253.  
  254.     vListItemIndex.lVal = 3;
  255.     vText.vt = VT_BSTR;
  256.     vText.bstrVal = CString("Item0Col0").AllocSysString();
  257.     _DSubItem(_DListItem(pList->GetListItems(vListItemIndex)).GetSubItems(vSubItemIndex)).SetText("Item0Col1");
  258.     VariantClear(&vText); //deallocate the string
  259.  
  260. }
  261.