home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Basic / GridOne / setup.EXE / UNBOUNDDIALOGDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-09  |  4.9 KB  |  167 lines

  1. // UnboundDialogDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "UnboundDialog.h"
  6. #include "UnboundDialogDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CUnboundDialogDlg dialog
  16.  
  17. CUnboundDialogDlg::CUnboundDialogDlg(CWnd* pParent /*=NULL*/)
  18.     : CDialog(CUnboundDialogDlg::IDD, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(CUnboundDialogDlg)
  21.         // NOTE: the ClassWizard will add member initialization here
  22.     //}}AFX_DATA_INIT
  23.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  24.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  25. }
  26.  
  27. void CUnboundDialogDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29.     CDialog::DoDataExchange(pDX);
  30.     //{{AFX_DATA_MAP(CUnboundDialogDlg)
  31.         // NOTE: the ClassWizard will add DDX and DDV calls here
  32.     //}}AFX_DATA_MAP
  33.    DDX_BeeGrid(pDX, IDC_GRID1, m_grid);
  34. }
  35.  
  36. BEGIN_MESSAGE_MAP(CUnboundDialogDlg, CDialog)
  37.     //{{AFX_MSG_MAP(CUnboundDialogDlg)
  38.     ON_WM_PAINT()
  39.     ON_WM_QUERYDRAGICON()
  40.     //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CUnboundDialogDlg message handlers
  45.  
  46. BOOL CUnboundDialogDlg::OnInitDialog()
  47. {
  48.     CDialog::OnInitDialog();
  49.  
  50.     // Set the icon for this dialog.  The framework does this automatically
  51.     //  when the application's main window is not a dialog
  52.     SetIcon(m_hIcon, TRUE);            // Set big icon
  53.     SetIcon(m_hIcon, FALSE);        // Set small icon
  54.     
  55.    //
  56.     // Initialize BeeGrid
  57.    //
  58.  
  59.    try
  60.    {
  61.       m_grid.intf->AutoResize = sgNoAutoResize;
  62.  
  63.       // Add few columns
  64.       IsgColumnsPtr spColumns = m_grid.intf->Columns;
  65.       spColumns->RemoveAll(false);
  66.  
  67.       IsgColumnPtr spCol = spColumns->Add(L"Col1");
  68.       spCol->Caption = L"Column 1";
  69.       spCol = spColumns->Add(L"Col2");
  70.       spCol->Caption = L"Column 2";
  71.       spCol = spColumns->Add(L"Col3");
  72.       spCol->Caption = L"Column 3";
  73.  
  74.       spCol = spColumns->Add(L"Col4");
  75.       spCol->Caption = L"Column 4";
  76.  
  77.       // Col4 is a droplist
  78.       spCol->Caption = L"DropList";
  79.       IsgControlPtr spCtl = spCol->Control;
  80.       
  81.       spCtl->Type      = sgCellDropList;
  82.       spCtl->SortOrder = sgNoSorting;
  83.       spCtl->PopupRows = 4;
  84.  
  85.       // Load image list
  86.       CImageList images;
  87.       images.Create(IDB_IMAGES, 16, 0, CLR_DEFAULT);
  88.       m_grid.intf->PutImages(long(images.GetSafeHandle()));
  89.  
  90.       // Initialize value items collection
  91.       IsgValueItemsPtr spValueItems = spCol->ValueItems;
  92.       spValueItems->Add(1L, L"One",   _variant_t(0L));
  93.       spValueItems->Add(2L, L"Two",   _variant_t(1L));
  94.       spValueItems->Add(3L, L"Three", _variant_t(2L));
  95.       spValueItems->Add(4L, L"Four",  _variant_t(3L));
  96.       spValueItems->Add(5L, L"Five",  _variant_t(4L));
  97.       spValueItems->Add(6L, L"Six",   _variant_t(5L));
  98.       spValueItems->Add(7L, L"Seven", _variant_t(6L));
  99.       spValueItems->Add(8L, L"Yes",   _variant_t(sgbipFirst + 17L));  // Use built-in image list
  100.       spValueItems->Add(9L, L"No",    _variant_t(sgbipFirst + 16L));  // Use built-in image list
  101.       spValueItems->CycleOnClick = VARIANT_TRUE;
  102.  
  103.       // Set row count
  104.       const int rowCount = 100;
  105.       m_grid.intf->DataRowCount = rowCount;
  106.  
  107.       // Fill data
  108.       IsgArrayPtr spArray = m_grid.intf->Array;
  109.       for (long row = 0; row < rowCount; ++row)
  110.       {
  111.          spArray->Value[row][0] = long(row % 8);
  112.          spArray->Value[row][1] = row;
  113.       }
  114.  
  115.       // Change border color
  116.       m_grid.intf->Styles->Item[L"GridBackground"]->BorderColor = RGB(130, 132, 130);
  117.  
  118.       // Add groupings
  119.       IsgGroupsPtr spGroups = m_grid.intf->Groups;
  120.       spGroups->Add(L"Col1", sgSortAscending, sgSortTypeDefault, true, false);
  121.       m_grid.intf->RefreshGroups(sgExpandGroups);
  122.  
  123.    }
  124.    catch (_com_error& e)
  125.    {
  126.       AfxMessageBox(e.Description());
  127.    }
  128.    
  129.     return TRUE;  // return TRUE  unless you set the focus to a control
  130. }
  131.  
  132. // If you add a minimize button to your dialog, you will need the code below
  133. //  to draw the icon.  For MFC applications using the document/view model,
  134. //  this is automatically done for you by the framework.
  135.  
  136. void CUnboundDialogDlg::OnPaint() 
  137. {
  138.     if (IsIconic())
  139.     {
  140.         CPaintDC dc(this); // device context for painting
  141.  
  142.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  143.  
  144.         // Center icon in client rectangle
  145.         int cxIcon = GetSystemMetrics(SM_CXICON);
  146.         int cyIcon = GetSystemMetrics(SM_CYICON);
  147.         CRect rect;
  148.         GetClientRect(&rect);
  149.         int x = (rect.Width() - cxIcon + 1) / 2;
  150.         int y = (rect.Height() - cyIcon + 1) / 2;
  151.  
  152.         // Draw the icon
  153.         dc.DrawIcon(x, y, m_hIcon);
  154.     }
  155.     else
  156.     {
  157.         CDialog::OnPaint();
  158.     }
  159. }
  160.  
  161. // The system calls this to obtain the cursor to display while the user drags
  162. //  the minimized window.
  163. HCURSOR CUnboundDialogDlg::OnQueryDragIcon()
  164. {
  165.     return (HCURSOR) m_hIcon;
  166. }
  167.